From 679c037c54d09146b367adba4081ad7cbabf5f92 Mon Sep 17 00:00:00 2001 From: Adrian Moennich Date: Sun, 19 Jun 2022 16:25:11 +0200 Subject: [PATCH] OwnCloud: Fix issues with non-event attachments --- owncloud/indico_owncloud/blueprint.py | 20 +++++++++++++---- owncloud/indico_owncloud/plugin.py | 22 ++++++++++--------- .../templates/owncloud_button.html | 4 ++-- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/owncloud/indico_owncloud/blueprint.py b/owncloud/indico_owncloud/blueprint.py index 1d0c517..77df04f 100644 --- a/owncloud/indico_owncloud/blueprint.py +++ b/owncloud/indico_owncloud/blueprint.py @@ -5,13 +5,25 @@ # them and/or modify them under the terms of the MIT License; # see the LICENSE file for more details. +import itertools + from indico.core.plugins import IndicoPluginBlueprint +from indico.modules.attachments.blueprint import _dispatch +from indico.modules.events import event_management_object_url_prefixes from indico_owncloud.controllers import RHAddCategoryAttachmentOwncloud, RHAddEventAttachmentOwncloud blueprint = IndicoPluginBlueprint('owncloud', 'indico_owncloud') -blueprint.add_url_rule('/category//manage/attachments/add/owncloud', 'owncloud_category', - RHAddCategoryAttachmentOwncloud, methods=('GET', 'POST'), defaults={'object_type': 'category'}) -blueprint.add_url_rule('/event//manage/attachments/add/owncloud', 'owncloud_event', - RHAddEventAttachmentOwncloud, methods=('GET', 'POST'), defaults={'object_type': 'event'}) + + +items = itertools.chain(event_management_object_url_prefixes.items(), [('category', ['/manage'])]) +for object_type, prefixes in items: + for prefix in prefixes: + if object_type == 'category': + prefix = '/category/' + prefix + else: + prefix = '/event/' + prefix + blueprint.add_url_rule(prefix + '/attachments/add/owncloud', 'upload_owncloud', + _dispatch(RHAddEventAttachmentOwncloud, RHAddCategoryAttachmentOwncloud), + methods=('GET', 'POST'), defaults={'object_type': object_type}) diff --git a/owncloud/indico_owncloud/plugin.py b/owncloud/indico_owncloud/plugin.py index 55f004c..b81078d 100644 --- a/owncloud/indico_owncloud/plugin.py +++ b/owncloud/indico_owncloud/plugin.py @@ -11,7 +11,10 @@ from wtforms.validators import DataRequired from indico.core.plugins import IndicoPlugin from indico.modules.attachments.views import WPEventAttachments -from indico.modules.categories.views import WPCategoryManagement +from indico.modules.categories.views import WPCategory, WPCategoryManagement +from indico.modules.events.contributions.views import WPContributions, WPManageContributions +from indico.modules.events.sessions.views import WPDisplaySession, WPManageSessions +from indico.modules.events.timetable.views import WPManageTimetable from indico.modules.events.views import WPConferenceDisplay, WPSimpleEventDisplay from indico.web.forms.base import IndicoForm @@ -47,20 +50,19 @@ class OwncloudPlugin(IndicoPlugin): def init(self): super().init() self.template_hook('attachment-sources', self._inject_owncloud_button) - self.inject_bundle('owncloud.js', WPEventAttachments) - self.inject_bundle('owncloud.js', WPSimpleEventDisplay) - self.inject_bundle('owncloud.js', WPConferenceDisplay) - self.inject_bundle('owncloud.js', WPCategoryManagement) - self.inject_bundle('main.css', WPEventAttachments) - self.inject_bundle('main.css', WPSimpleEventDisplay) - self.inject_bundle('main.css', WPConferenceDisplay) - self.inject_bundle('main.css', WPCategoryManagement) + wps = ( + WPCategory, WPSimpleEventDisplay, WPConferenceDisplay, WPDisplaySession, WPContributions, + WPCategoryManagement, WPEventAttachments, WPManageContributions, WPManageSessions, WPManageTimetable + ) + for wp in wps: + self.inject_bundle('owncloud.js', wp) + self.inject_bundle('main.css', wp) def get_blueprints(self): return blueprint def _inject_owncloud_button(self, linked_object=None, **kwargs): if is_configured(): - return render_plugin_template('owncloud_button.html', id=linked_object.id, linked_object=linked_object, + return render_plugin_template('owncloud_button.html', linked_object=linked_object, service_name=self.settings.get('service_name'), button_icon_url=self.settings.get('button_icon_url')) diff --git a/owncloud/indico_owncloud/templates/owncloud_button.html b/owncloud/indico_owncloud/templates/owncloud_button.html index b9bec45..d1ffff2 100644 --- a/owncloud/indico_owncloud/templates/owncloud_button.html +++ b/owncloud/indico_owncloud/templates/owncloud_button.html @@ -1,10 +1,10 @@ {% set service_name = service_name or _('the cloud') %} {%- if button_icon_url -%} - + {%- endif -%} {%- trans -%}From {{ service_name }}{%- endtrans -%}