Skip to content

Commit

Permalink
add visibility setting to custom metadata (to exclude some fields fro…
Browse files Browse the repository at this point in the history
…m public api)
  • Loading branch information
brookgagnon committed Sep 13, 2024
1 parent 1b37441 commit 121af8a
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 2 deletions.
3 changes: 2 additions & 1 deletion controllers/metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ public function metadata_save()
$data['select_options'] = trim($this->data('select_options'));
$data['mode'] = trim($this->data('mode'));
$data['id3_key'] = trim($this->data('id3_key'));

$data['visibility'] = $this->data('visibility');
$data['default'] = $this->data('default');

if (is_array($data['default'])) {
$data['default'] = array_map('trim', $data['default']);
} else {
Expand Down
7 changes: 7 additions & 0 deletions html/media/metadata_addedit.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
</ob-field-select>
</div>

<div class="fieldrow">
<label class="required" data-t>Visibility</label>
<ob-field-select data-edit id="metadata_visibility">
<ob-option selected value="public">Allow Public</ob-option>
<ob-option value="visible">Internal Only</ob-option>
</div>

<div class="fieldrow">
<label class="required" data-t>Options (one per line)</label>
<ob-field-textarea data-edit wrap="off" id="metadata_select_options"></ob-field-textarea>
Expand Down
1 change: 1 addition & 0 deletions js/media/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ OB.Media.metadataSave = function () {
field.default = $("#metadata_default").val();
field.mode = document.querySelector("#metadata_mode").value;
field.id3_key = document.querySelector("#metadata_id3_key").value;
field.visibility = document.querySelector("#metadata_visibility").value;

OB.API.post("metadata", "metadata_save", field, function (response) {
if (response.status == false) {
Expand Down
1 change: 1 addition & 0 deletions models/media_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ public function get_init_what($args = [])
$this->db->what('users.display_name', 'owner_name');

foreach ($args['metadata_fields'] as $metadata_field) {
// add the field to the select portion of the query
$query_select = $metadata_field->querySelect();
if (!is_array($query_select)) {
$query_select = [$query_select];
Expand Down
13 changes: 12 additions & 1 deletion models/mediametadata_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public function get_all_objects()
$class = 'OB\Classes\Base\Metadata';
}

// exclude this field if not public and not authenticated
if ($column['visibility'] != 'public' && !$this->user->check_authenticated()) {
continue;
}

$objects[] = new $class($column['name'], $column['description'], $column['type'], $column['settings']);
}

Expand Down Expand Up @@ -194,6 +199,11 @@ public function validate($data, $id)
return [false,'The field type is not valid.'];
}

//T The visibility setting is not valid.
if (array_search($data['visibility'], ['visible','public']) === false) {
return [false,'The visibility setting is not valid.'];
}

return [true,'Valid.'];
}

Expand All @@ -210,6 +220,7 @@ public function save($data, $id)
$save = [];
$save['settings'] = [];
$save['description'] = $data['description'];
$save['visibility'] = $data['visibility'];

// if editing, use name/type from existing field.
if ($id) {
Expand All @@ -231,7 +242,7 @@ public function save($data, $id)
$save['settings']['options'] = $save_options;
}

// mode, default, and id3 key
// visibility, mode, default, and id3 key
$save['settings']['mode'] = $data['mode'];
$save['settings']['default'] = $data['default'];
$save['settings']['id3_key'] = $data['id3_key'];
Expand Down
20 changes: 20 additions & 0 deletions updates/20240913.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

class OBUpdate20240913 extends OBUpdate
{
public function items()
{
$updates = [];
$updates[] = 'Add visibility option to metadata fields.';
return $updates;
}

public function run()
{
$this->db->query('
ALTER TABLE `media_metadata` ADD COLUMN `visibility` ENUM("visible", "public") NOT NULL DEFAULT "public";
');

return true;
}
}

0 comments on commit 121af8a

Please sign in to comment.