OwnCloud: Fix issues with non-event attachments

This commit is contained in:
Adrian Moennich 2022-06-19 16:25:11 +02:00
parent 170c1fac76
commit 679c037c54
3 changed files with 30 additions and 16 deletions

View File

@ -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/<int:category_id>/manage/attachments/add/owncloud', 'owncloud_category',
RHAddCategoryAttachmentOwncloud, methods=('GET', 'POST'), defaults={'object_type': 'category'})
blueprint.add_url_rule('/event/<int:event_id>/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/<int:category_id>' + prefix
else:
prefix = '/event/<int:event_id>' + prefix
blueprint.add_url_rule(prefix + '/attachments/add/owncloud', 'upload_owncloud',
_dispatch(RHAddEventAttachmentOwncloud, RHAddCategoryAttachmentOwncloud),
methods=('GET', 'POST'), defaults={'object_type': object_type})

View File

@ -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'))

View File

@ -1,10 +1,10 @@
{% set service_name = service_name or _('the cloud') %}
<a href="#" class="i-button js-dialog-action"
data-href="{{ url_for_plugin('owncloud.owncloud_event', event_id=id) }}"
data-href="{{ url_for_plugin('owncloud.upload_owncloud', linked_object) }}"
data-title="{%- trans -%}Add files from {{ service_name }}{%- endtrans -%}">
<span class="{{ 'icon-cloud2' if not button_icon_url }}"></span>
{%- if button_icon_url -%}
<img height="24" src="{{ button_icon_url }}">
<img height="24" src="{{ button_icon_url }}" alt="">
{%- endif -%}
<span class="button-label">{%- trans -%}From {{ service_name }}{%- endtrans -%}</span>
</a>