Skip to content

Commit

Permalink
I18nDemo: Disable cloning when not logged in (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasr8 authored Jun 12, 2024
1 parent 18b369b commit abf00f8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions i18n_demo/indico_i18n_demo/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
from indico.modules.categories.models.categories import Category
from indico.modules.categories.operations import create_category as _create_category
from indico.modules.events.cloning import get_event_cloners
from indico.modules.events.controllers.base import RHEventBase
from indico.modules.events.controllers.base import RHProtectedEventBase
from indico.modules.events.operations import clone_event
from indico.web.flask.util import url_for


class RHCloneEvent(RHEventBase):
class RHCloneEvent(RHProtectedEventBase):
"""Clone an event to a user's personal category.
If the category does not exist, it will be created.
Expand Down
2 changes: 1 addition & 1 deletion i18n_demo/indico_i18n_demo/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def _inject_clone_button(self, event, **kwargs):
return

if event.category != test_category and not event.category.is_descendant_of(test_category):
return render_plugin_template('clone_button.html', event=event)
return render_plugin_template('clone_button.html', event=event, disabled=not session.user)

def _intercept_make_email(self, sender, func, args, **kwargs):
ret = func(**args.arguments)
Expand Down
20 changes: 11 additions & 9 deletions i18n_demo/indico_i18n_demo/templates/clone_button.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<button type="button"
class="ui tiny compact button ui-qtip"
style="margin-left: 2em;"
title="Clone event into your personal category with full management rights"
data-href="{{ url_for('plugin_i18n_demo.clone_event', event) }}"
data-method="POST">
<i aria-hidden="true" class="icon clone alternate"></i>
Clone
</button>
{% set enabled_message = 'Clone event into your personal category with full management rights' %}
{% set disabled_message = 'You must be logged in to clone events' %}
<span class="ui-qtip" style="margin-left: 2em;" title="{{ disabled_message if disabled else enabled_message }}">
<button type="button"
class="ui tiny compact button {{ 'disabled' if disabled }}"
data-href="{{ url_for('plugin_i18n_demo.clone_event', event) }}"
data-method="POST">
<i aria-hidden="true" class="icon clone alternate"></i>
Clone
</button>
</span>

0 comments on commit abf00f8

Please sign in to comment.