From: Christian Heller Date: Wed, 11 Dec 2024 02:17:44 +0000 (+0100) Subject: Add config option to (dis-)allow file data editing. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/static/%7B%7B%20web_path%20%7D%7D/ledger?a=commitdiff_plain;h=1b7bc0ebee28b97a72114edacb3b860ce0c4bba1;p=ytplom Add config option to (dis-)allow file data editing. --- diff --git a/src/templates/file_data.tmpl b/src/templates/file_data.tmpl index 7e54370..82dc50d 100644 --- a/src/templates/file_data.tmpl +++ b/src/templates/file_data.tmpl @@ -9,31 +9,38 @@ td.tag_checkboxes { width: 1em; } {% block body %} +{% if allow_edit %}
+{% endif %} + + + + + + +
path: {{file.rel_path}}
present: {% if file.present %}yes{% else %}no{% endif %}
YouTube ID: {{file.yt_id}}
tags {% for tag in file.tags %} - + {% endfor %} +{% if allow_edit %} +{% endif %} +
{{tag}}
add: @@ -45,15 +52,23 @@ td.tag_checkboxes { width: 1em; }
+
flags: {% for flag_name in flag_names %} -{{ flag_name }}:
+{{ flag_name }}:
{% endfor %}
+{% if allow_edit %}
+{% endif %} {% endblock %} diff --git a/src/ytplom/http.py b/src/ytplom/http.py index b845c76..97f4ada 100644 --- a/src/ytplom/http.py +++ b/src/ytplom/http.py @@ -174,6 +174,9 @@ class _TaskHandler(BaseHTTPRequestHandler): self._redirect(Path(postvars.first_for('redir_target'))) def _receive_file_data(self, digest: Hash, postvars: _ReqMap) -> None: + if not self.server.config.allow_file_edit: + self._send_http('no way', code=403) + return with DbConn() as conn: file = VideoFile.get_one(conn, digest) file.set_flags({FILE_FLAGS[FlagName(name)] @@ -314,6 +317,7 @@ class _TaskHandler(BaseHTTPRequestHandler): self._send_rendered_template( _NAME_TEMPLATE_FILE_DATA, {'file': file, + 'allow_edit': self.server.config.allow_file_edit, 'flag_names': list(FILE_FLAGS), 'unused_tags': unused_tags}) diff --git a/src/ytplom/misc.py b/src/ytplom/misc.py index e052e49..f07986a 100644 --- a/src/ytplom/misc.py +++ b/src/ytplom/misc.py @@ -29,7 +29,8 @@ DEFAULTS = { 'port_remote': 8090, 'background_color': '#ffffff', 'queries_cutoff': '', - 'tags_prefilter_str': '' + 'tags_prefilter_str': '', + 'allow_file_edit': True } # type definitions for mypy @@ -92,6 +93,7 @@ class Config: background_color: str queries_cutoff: str tags_prefilter_str: str + allow_file_edit: bool def __init__(self): def set_attrs_from_dict(d):