changeset 147:c7e83ed2ee4b

edit_bar, actions_excluded - use endpoint names as entries edit_bar now has tuples like (endpointname, label) so we can easier build the edit_bar html in the template. order is now important, the edit_bar entries will be rendered in the order given. actions_excluded now uses the same endpointnames as edit_bar editbar.html - much less duplication now Note: if there is no real endpoint in the python code (because functionality is implemented in JS or there is no functionality), use 'special.*' endpoint. dropped some nb* css class names from editbar.html (unused). do not check cfg.mail_enabled any more if a user wants to subscribe something: * there may be other notification means than email * a user can subscribe/unsubscribe now, even if email is not (yet) enabled * simplifies the code Do not specialcase modify_item (remove write acl check) - there are also other views which may require writability and we do not check it for them either.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 20 Mar 2011 19:28:06 +0100
parents 751ebb4ff42b
children 972943980b7b
files MoinMoin/apps/frontend/views.py MoinMoin/config/default.py MoinMoin/templates/editbar.html MoinMoin/templates/layout.html MoinMoin/templates/show.html
diffstat 5 files changed, 100 insertions(+), 149 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/views.py	Sun Mar 20 17:00:45 2011 +0100
+++ b/MoinMoin/apps/frontend/views.py	Sun Mar 20 19:28:06 2011 +0100
@@ -674,10 +674,6 @@
         msg = _("You must login to use this action: %(action)s.", action="subscribe/unsubscribe"), "error"
     elif not u.may.read(item_name):
         msg = _("You are not allowed to subscribe to an item you may not read."), "error"
-    elif not cfg.mail_enabled:
-        msg = _("This wiki is not enabled for mail processing."), "error"
-    elif not u.email:
-        msg = _("Add your email address in your user settings to use subscriptions."), "error"
     elif u.isSubscribedTo([item_name]):
         # Try to unsubscribe
         if not u.unsubscribe(item_name):
--- a/MoinMoin/config/default.py	Sun Mar 20 17:00:45 2011 +0100
+++ b/MoinMoin/config/default.py	Sun Mar 20 19:28:06 2011 +0100
@@ -308,9 +308,8 @@
      None,
      "Class object hook for implementing security restrictions or relaxations"),
     ('actions_excluded',
-     ['copy',  # has questionable behaviour regarding subpages a user can't read, but can copy
-     ],
-     "Exclude unwanted actions (list of strings)"),
+     [],
+     "Exclude unwanted endpoints (list of strings)"),
 
     ('password_checker', DefaultExpression('_default_password_checker'),
      'checks whether a password is acceptable (default check is length >= 6, at least 4 different chars, no keyboard sequence, not username used somehow (you can switch this off by using `None`)'),
@@ -355,8 +354,35 @@
     ('trail_size', 5,
      "Number of items in the trail of recently visited items"),
 
-    ('edit_bar', ['Show', 'Highlight', 'Meta', 'Modify', 'Comments', 'Download', 'History', 'Subscribe', 'Quicklink', 'Index', 'Supplementation', 'GlobalHistory', 'GlobalIndex', 'GlobalTags', 'WhatRefersHere', 'SiteMap', 'SimilarItems', 'Copy', 'Rename', 'Delete', 'Destroy', 'Administration', ],
-     'list of edit bar entries'),
+    ('edit_bar', [
+        # (endpointname, label, check_item_exists
+        ('frontend.show_item', L_('Show'), False, ),
+        ('frontend.highlight_item', L_('Highlight'), True, ),
+        ('frontend.show_item_meta', L_('Meta'), True, ),
+        ('frontend.get_item', L_('Download'), True, ),
+        ('frontend.history', L_('History'), True, ),
+        ('frontend.quicklink_item', None, True, ),
+        ('frontend.subscribe_item', None, True, ),
+        ('special.comments', None, True, ),
+        ('frontend.index', L_('Index'), False, ),
+        ('special.supplementation', None, False, ),
+        ('frontend.backrefs', L_('What refers here?'), False, ),
+        ('frontend.sitemap', L_('Local Site Map'), True, ),
+        ('frontend.similar_names', L_('Items with similar names'), False, ),
+        ('special.delimiter', None, None, ),
+        ('frontend.modify_item', L_('Modify'), False, ),
+        ('frontend.copy_item', L_('Copy'), True, ),
+        ('frontend.rename_item', L_('Rename'), True, ),
+        ('frontend.delete_item', L_('Delete'), True, ),
+        ('frontend.destroy_item', L_('Destroy'), True, ),
+        ('special.delimiter', None, None, ),
+        ('frontend.global_history', L_('Global History'), False, ),
+        ('frontend.global_index', L_('Global Items Index'), False, ),
+        ('frontend.global_tags', L_('Global Tags Index'), False, ),
+        ('special.delimiter', None, None, ),
+        ('admin.index', L_('Administration & Docs'), False, ),
+     ],
+     'list of edit bar entries (list of tuples (endpoint, label))'),
     ('history_count', (100, 200), "number of revisions shown for info/history action (default_count_shown, max_count_shown)"),
 
     ('show_hosts', True,
--- a/MoinMoin/templates/editbar.html	Sun Mar 20 17:00:45 2011 +0100
+++ b/MoinMoin/templates/editbar.html	Sun Mar 20 19:28:06 2011 +0100
@@ -1,142 +1,71 @@
 {% set exists = storage.has_item(item_name) %}
 <ul class="moin-editbar">
-    {% if 'Show' in cfg.edit_bar and 'show' not in cfg.actions_excluded -%}
-        <li>
-        <a href="{{ url_for('frontend.show_item', item_name=item_name) }}" rel="nofollow"> {{ _('Show') }}</a>
-        </li>
-    {%- endif %}
-    {% if exists and 'Highlight' in cfg.edit_bar and 'highlight' not in cfg.actions_excluded -%}
-        <li>
-        <a href="{{ url_for('frontend.highlight_item', item_name=item_name) }}" rel="nofollow"> {{ _('Highlight') }}</a>
-        </li>
-    {%- endif %}
-    {% if exists and 'Meta' in cfg.edit_bar and 'meta' not in cfg.actions_excluded -%}
-        <li>
-        <a href="{{ url_for('frontend.show_item_meta', item_name=item_name) }}" rel="nofollow"> {{ _('Meta') }}</a>
-        </li>
-    {%- endif %}
-    {% if exists and 'Download' in cfg.edit_bar and 'get' not in cfg.actions_excluded -%}
-        <li>
-            <a href="{{ url_for('frontend.get_item', item_name=item_name) }}" rel="nofollow">{{ _('Download') }}</a>
-        </li>
-    {%- endif %}
-    {% if exists and 'History' in cfg.edit_bar and 'history' not in cfg.actions_excluded -%}
-        <li>
-            <a href="{{ url_for('frontend.history', item_name=item_name) }}" rel="nofollow">{{ _('History') }}</a>
-        </li>
-    {%- endif %}
-    {% if 'Quicklink' in cfg.edit_bar and 'quicklink' not in cfg.actions_excluded
-       and user.valid -%}
-        <li>
-            <a class="nbquicklink" href="{{ url_for('frontend.quicklink_item', item_name=item_name) }}" rel="nofollow">
-            {% if user.isQuickLinkedTo([item_name]) -%}
-                {{ _('Remove Link') }}
-            {% else -%}
-                {{ _('Add Link') }}
-            {%- endif %}
-            </a>
-        </li>
-    {%- endif %}
-    {% if 'Subscribe' in cfg.edit_bar and 'subscribe' not in cfg.actions_excluded
-       and user.valid and cfg.mail_enabled -%}
-        <li>
-            <a class="nbsubscribe" href="{{ url_for('frontend.subscribe_item', item_name=item_name) }}" rel="nofollow">
-            {% if user.isSubscribedTo([item_name]) %}
-                    {{ _('Unsubscribe') }}
-            {% else %}
-                    {{ _('Subscribe') }}
-            {% endif %}
-            </a>
-        </li>
-    {%- endif %}
-    {% if 'Comments' in cfg.edit_bar and 'comments' not in cfg.actions_excluded -%}
-        <li class="toggleCommentsButton" style="display:none;">
-            <a href="#" class="nbcomment" onClick="toggleComments();return false;">{{ _('Comments') }}</a>
-        </li>
-    {%- endif %}
-    {% if 'Index' in cfg.edit_bar and 'index' not in cfg.actions_excluded -%}
-        <li>
-            <a class="nbindex" href="{{ url_for('frontend.index', item_name=item_name) }}" rel="nofollow">{{ _('Index') }}</a>
-        </li>
-    {%- endif %}
-    {% if 'Supplementation' in cfg.edit_bar and 'supplementation' not in cfg.actions_excluded -%}
-        {%- for sub_item_name in cfg.supplementation_item_names -%}
-            {% set current_sub = item_name.rsplit('/', 1)[-1] %}
-            {%- if not current_sub in cfg.supplementation_item_names -%}
-                {% set supp_name = '%s/%s' % (item_name, sub_item_name) -%}
-                {% if storage.has_item(supp_name) or user.may.write(supp_name) %}
-                    <li>
-                        <a class="nbsupplementation" href="{{ url_for('frontend.show_item', item_name=supp_name) }}" rel="nofollow">{{ _(sub_item_name) }}</a>
-                    </li>
+    {% for endpoint, label, check_exists in cfg.edit_bar if not endpoint in cfg.actions_excluded %}
+        {% if (not check_exists or check_exists and exists) and endpoint in [
+               'frontend.show_item', 'frontend.index',
+               'frontend.highlight_item', 'frontend.show_item_meta', 'frontend.get_item',
+               'frontend.get_item', 'frontend.history', 'frontend.backrefs', 'frontend.sitemap',
+               'frontend.similar_names',
+               'frontend.modify_item',
+               'frontend.copy_item', 'frontend.rename_item', 'frontend.delete_item', 'frontend.destroy_item',
+           ] -%}
+            <li>
+            <a href="{{ url_for(endpoint, item_name=item_name) }}" rel="nofollow"> {{ label }}</a>
+            </li>
+        {%- endif %}
+
+        {% if endpoint in [
+            'frontend.global_history', 'frontend.global_index', 'frontend.global_tags',
+            'admin.index',
+           ] -%}
+            <li>
+            <a href="{{ url_for(endpoint) }}" rel="nofollow"> {{ label }}</a>
+            </li>
+        {%- endif %}
+
+        {% if endpoint == 'frontend.quicklink_item' and user.valid -%}
+            <li>
+                <a href="{{ url_for(endpoint, item_name=item_name) }}" rel="nofollow">
+                {% if user.isQuickLinkedTo([item_name]) -%}
+                    {{ _('Remove Link') }}
+                {% else -%}
+                    {{ _('Add Link') }}
                 {%- endif %}
-            {%- endif %}
-        {%- endfor -%}
-    {%- endif %}
-    {% if exists and 'WhatRefersHere' in cfg.edit_bar and 'backrefs' not in cfg.actions_excluded -%}
-        <li>
-        <a href="{{ url_for('frontend.backrefs', item_name=item_name) }}" rel="nofollow"> {{ _('What refers here?') }}</a>
-        </li>
-    {%- endif %}
-    {% if exists and 'SiteMap' in cfg.edit_bar and 'sitemap' not in cfg.actions_excluded -%}
-        <li>
-        <a href="{{ url_for('frontend.sitemap', item_name=item_name) }}" rel="nofollow"> {{ _('Local Site Map') }}</a>
-        </li>
-    {%- endif %}
-    {% if exists and 'SimilarItems' in cfg.edit_bar and 'similar_names' not in cfg.actions_excluded -%}
-        <li>
-        <a href="{{ url_for('frontend.similar_names', item_name=item_name) }}" rel="nofollow"> {{ _('Items with similar names') }}</a>
-        </li>
-    {%- endif %}
-    <li>*</li>
-    {% if 'Modify' in cfg.edit_bar and 'modify' not in cfg.actions_excluded -%}
-        <li>
-        {% if user.may.write(item_name) %}
-            <a href="{{ url_for('frontend.modify_item', item_name=item_name) }}" rel="nofollow"> {{ _('Modify') }}</a>
-        {% else %}
-            {{ _('Immutable Item')}}
-        {% endif %}
-        </li>
-    {%- endif %}
-    {% if exists and 'Copy' in cfg.edit_bar and 'copy' not in cfg.actions_excluded -%}
-        <li>
-        <a href="{{ url_for('frontend.copy_item', item_name=item_name) }}" rel="nofollow"> {{ _('Copy') }}</a>
-        </li>
-    {%- endif %}
-    {% if exists and 'Rename' in cfg.edit_bar and 'rename' not in cfg.actions_excluded -%}
-        <li>
-        <a href="{{ url_for('frontend.rename_item', item_name=item_name) }}" rel="nofollow"> {{ _('Rename') }}</a>
-        </li>
-    {%- endif %}
-    {% if exists and 'Delete' in cfg.edit_bar and 'delete' not in cfg.actions_excluded -%}
-        <li>
-        <a href="{{ url_for('frontend.delete_item', item_name=item_name) }}" rel="nofollow"> {{ _('Delete') }}</a>
-        </li>
-    {%- endif %}
-    {% if exists and 'Destroy' in cfg.edit_bar and 'destroy' not in cfg.actions_excluded -%}
-        <li>
-        <a href="{{ url_for('frontend.destroy_item', item_name=item_name) }}" rel="nofollow"> {{ _('Destroy') }}</a>
-        </li>
-    {%- endif %}
-    <li>*</li>
-    {% if 'GlobalHistory' in cfg.edit_bar and 'global_history' not in cfg.actions_excluded -%}
-        <li>
-        <a href="{{ url_for('frontend.global_history') }}" rel="nofollow"> {{ _('Global History') }}</a>
-        </li>
-    {%- endif %}
-    {% if 'GlobalIndex' in cfg.edit_bar and 'global_index' not in cfg.actions_excluded -%}
-        <li>
-        <a href="{{ url_for('frontend.global_index') }}" rel="nofollow"> {{ _('Global Items Index') }}</a>
-        </li>
-    {%- endif %}
-    {% if 'GlobalTags' in cfg.edit_bar and 'global_tags' not in cfg.actions_excluded -%}
-        <li>
-        <a href="{{ url_for('frontend.global_tags') }}" rel="nofollow"> {{ _('Global Tags Index') }}</a>
-        </li>
-    {%- endif %}
-    <li>*</li>
-    {% if 'Administration' in cfg.edit_bar and 'admin' not in cfg.actions_excluded -%}
-        <li>
-        <a href="{{ url_for('admin.index') }}" rel="nofollow"> {{ _('Administration & Docs') }}</a>
-        </li>
-    {%- endif %}
+                </a>
+            </li>
+        {%- endif %}
+        {% if endpoint == 'frontend.subscribe_item' and user.valid -%}
+            <li>
+                <a href="{{ url_for(endpoint, item_name=item_name) }}" rel="nofollow">
+                {% if user.isSubscribedTo([item_name]) %}
+                        {{ _('Unsubscribe') }}
+                {% else %}
+                        {{ _('Subscribe') }}
+                {% endif %}
+                </a>
+            </li>
+        {%- endif %}
+
+        {% if endpoint == 'special.delimiter' -%}
+            <li>*</li>
+        {%- endif %}
+        {% if endpoint == 'special.comments' -%}
+            <li class="toggleCommentsButton" style="display:none;">
+                <a href="#" onClick="toggleComments();return false;">{{ _('Comments') }}</a>
+            </li>
+        {%- endif %}
+        {% if endpoint == 'special.supplementation' -%}
+            {%- for sub_item_name in cfg.supplementation_item_names -%}
+                {% set current_sub = item_name.rsplit('/', 1)[-1] %}
+                {%- if not current_sub in cfg.supplementation_item_names -%}
+                    {% set supp_name = '%s/%s' % (item_name, sub_item_name) -%}
+                    {% if storage.has_item(supp_name) or user.may.write(supp_name) %}
+                        <li>
+                            <a href="{{ url_for('frontend.show_item', item_name=supp_name) }}" rel="nofollow">{{ _(sub_item_name) }}</a>
+                        </li>
+                    {%- endif %}
+                {%- endif %}
+            {%- endfor -%}
+        {%- endif %}
+    {% endfor %}
 </ul>
--- a/MoinMoin/templates/layout.html	Sun Mar 20 17:00:45 2011 +0100
+++ b/MoinMoin/templates/layout.html	Sun Mar 20 19:28:06 2011 +0100
@@ -41,7 +41,7 @@
                 <a href="{{ wiki_href }}" {% if not exists %}class="moin-nonexistent"{% endif %} rel="nofollow" title="{{ title }}">
                     {{ aliasname }}
                 </a>
-                {% if 'usersettings' not in cfg.actions_excluded -%}
+                {% if 'frontend.usersettings' not in cfg.actions_excluded -%}
                     <span class="sep"> | </span>
                     <a href="{{ url_for('frontend.usersettings') }}" class="moin-usersettings" rel="nofollow">{{ _('Settings') }}</a>
                 {%- endif %}
--- a/MoinMoin/templates/show.html	Sun Mar 20 17:00:45 2011 +0100
+++ b/MoinMoin/templates/show.html	Sun Mar 20 19:28:06 2011 +0100
@@ -5,7 +5,7 @@
     {{ super() }}
     <link rel="alternate" title="{{ item_name }} changes" href="{{ url_for('feed.atom', item_name=item_name) }}" type="application/atom+xml" />
     {# universal edit button support #}
-    {%- if user.may.write(item_name) and 'modify' not in cfg.actions_excluded -%}
+    {%- if user.may.write(item_name) and 'frontend.modify_item' not in cfg.actions_excluded -%}
     <link rel="alternate" type="application/wiki" title="{{ _('Modify') }}" href="{{ url_for('frontend.modify_item', item_name=item_name) }}" />
     {%- endif %}
 {% endblock %}