Changeset 2045

Show
Ignore:
Timestamp:
06/18/09 09:40:36 (9 months ago)
Author:
JensDiemer
Message:
  • limit update section to superusers only
  • move page_admin.check_permissions into a generic decorator
Location:
branches/0.9/pylucid_project
Files:
1 added
4 modified

Legend:

Unmodified
Added
Removed
  • branches/0.9/pylucid_project/apps/pylucid/templates/admin/base_site.html

    r2032 r2045  
    8383        <a href="#TODO">{% trans 'admin menu' %}</a> 
    8484    </li> 
     85    {% if user.is_superuser %} 
    8586    <li> 
    8687        <a href="{% url PyLucidUpdate-menu %}">{% trans 'update section' %}</a> 
    8788    </li> 
     89    {% endif %} 
    8890</ul> 
    8991{% endif %} 
  • branches/0.9/pylucid_project/apps/pylucid_update/urls.py

    r1931 r2045  
    88 
    99from pylucid_project.apps.pylucid_update import views 
     10from pylucid.decorators import superuser_only 
    1011 
    1112urlpatterns = patterns('', 
    12     url(r'^$',                      views.menu,                 name='PyLucidUpdate-menu'), 
    13     url(r'^update08/$',             views.update08,             name='PyLucidUpdate-update08'), 
    14     url(r'^update08templates/$',    views.update08templates,    name='PyLucidUpdate-update08templates'), 
    15     url(r'^update08styles/$',       views.update08styles,       name='PyLucidUpdate-update08styles'), 
     13    url(r'^$', 
     14        superuser_only(views.menu), 
     15        name='PyLucidUpdate-menu' 
     16    ), 
     17    url(r'^update08/$', 
     18        superuser_only(views.update08), 
     19        name='PyLucidUpdate-update08' 
     20    ), 
     21    url(r'^update08templates/$', 
     22        superuser_only(views.update08templates), 
     23        name='PyLucidUpdate-update08templates' 
     24    ), 
     25    url(r'^update08styles/$', 
     26        superuser_only(views.update08styles), 
     27        name='PyLucidUpdate-update08styles' 
     28    ), 
    1629) 
  • branches/0.9/pylucid_project/apps/pylucid_update/views.py

    r2040 r2045  
    11# coding: utf-8 
     2 
     3""" 
     4    PyLucid update views 
     5    ~~~~~~~~~~~~~~~~~~~~ 
     6 
     7    Last commit info: 
     8    ~~~~~~~~~~~~~~~~~ 
     9    $LastChangedDate:$ 
     10    $Rev:$ 
     11    $Author: JensDiemer $ 
     12 
     13    :copyleft: 2009 by the PyLucid team, see AUTHORS for more details. 
     14    :license: GNU GPL v3 or above, see LICENSE for more details. 
     15""" 
    216 
    317import posixpath 
     
    822from django.shortcuts import render_to_response 
    923from django.template.loader import find_template_source 
    10 from django.contrib.auth.decorators import login_required 
    1124 
    1225from dbtemplates.models import Template 
     
    2033 
    2134 
    22 @login_required 
    2335def menu(request): 
    2436    """ Display a menu with all update view links """ 
     
    2739    } 
    2840    return render_to_response('pylucid_update/menu.html', context, context_instance=RequestContext(request)) 
    29  
    30  
    31  
    3241 
    3342 
     
    225234 
    226235 
    227 @login_required 
    228236def update08(request): 
    229237    """ Update PyLucid v0.8 model data to v0.9 models """ 
     
    247255 
    248256 
    249 @login_required 
    250257def update08templates(request): 
    251258    title = "Update PyLucid v0.8 templates" 
     
    346353     
    347354 
    348 @login_required 
     355 
    349356def update08styles(request): 
    350357    title = "Update PyLucid v0.8 styles" 
  • branches/0.9/pylucid_project/pylucid_plugins/page_admin/views.py

    r2043 r2045  
    1 # coding:utf-8 
     1# coding: utf-8 
    22 
    3 import warnings 
     3""" 
     4    PyLucid page admin 
     5    ~~~~~~~~~~~~~~~~~~ 
     6 
     7    Last commit info: 
     8    ~~~~~~~~~~~~~~~~~ 
     9    $LastChangedDate:$ 
     10    $Rev:$ 
     11    $Author: JensDiemer $ 
     12 
     13    :copyleft: 2009 by the PyLucid team, see AUTHORS for more details. 
     14    :license: GNU GPL v3 or above, see LICENSE for more details. 
     15""" 
    416 
    517from django.conf import settings 
    618from django.template import RequestContext 
    719from django.utils.translation import ugettext as _ 
    8 from django.core.exceptions import PermissionDenied 
    920from django.http import HttpResponse, HttpResponseRedirect 
    1021 
    1122from pylucid.markup.converter import apply_markup 
    1223from pylucid.shortcuts import render_pylucid_response 
     24from pylucid.decorators import check_permissions 
    1325 
    1426from page_admin.forms import EditPageForm 
    1527 
    1628 
    17 EDIT_PERMISSIONS = ( 
     29PAGE_EDIT_PERMISSIONS = ( 
    1830    u'pylucid.change_pagecontent', 
    1931    u'pylucid.change_pagemeta' 
    20 ) 
     32)  
    2133 
    2234 
    23 def check_permissions(request, permissions): 
    24     """ 
    25     TODO: Add a log entry, if user has not all permissions. 
    26     """ 
    27     assert isinstance(permissions, (list, tuple)) 
    28     user = request.user 
    29      
    30     if not user.is_authenticated(): 
    31         if settings.DEBUG: # Usefull?? 
    32             warnings.warn("Anonymous can't edit page.") 
    33         raise PermissionDenied 
    34          
    35     if not user.has_perms(permissions): 
    36         if settings.DEBUG: # Usefull?? 
    37             msg = "User %r has not all permissions: %r (existing permissions: %r)" % ( 
    38                 user, permissions, user.get_all_permissions() 
    39             ) 
    40             warnings.warn(msg) 
    41         raise PermissionDenied() 
    42      
    43  
    44  
    45 def _edit_page(request, form_url): 
    46     check_permissions(request, EDIT_PERMISSIONS) 
    47      
     35def _edit_page(request, form_url):    
    4836    pagemeta_instance = request.PYLUCID.pagemeta 
    4937    pagecontent_instance = request.PYLUCID.pagecontent 
     
    9381 
    9482 
     83@check_permissions(permissions=PAGE_EDIT_PERMISSIONS) 
    9584def http_get_view(request):   
    9685    action = request.GET["page_admin"]