~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/security.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mfrom: (0.9.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080622211713-fpo2zrq3s5dfecxg
Tags: 1.7.0-3
Simplify /etc/moin/wikilist format: "USER URL" (drop unneeded middle
CONFIG_DIR that was wrongly advertised as DATA_DIR).  Make
moin-mass-migrate handle both formats and warn about deprecation of
the old one.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: iso-8859-1 -*-
2
 
"""
3
 
    MoinMoin - Wiki Security Interface
4
 
 
5
 
    This implements the basic interface for user permissions and
6
 
    system policy. If you want to define your own policy, inherit
7
 
    from the base class 'Permissions', so that when new permissions
8
 
    are defined, you get the defaults.
9
 
 
10
 
    Then assign your new class to "SecurityPolicy" in wikiconfig;
11
 
    and I mean the class, not an instance of it!
12
 
 
13
 
    @copyright: 2000-2004 by J�rgen Hermann <jh@web.de>
14
 
    @license: GNU GPL, see COPYING for details.
15
 
"""
16
 
 
17
 
#############################################################################
18
 
### Basic Permissions Interface -- most features enabled by default
19
 
#############################################################################
20
 
 
21
 
 
22
 
class Permissions:
23
 
    """ Basic interface for user permissions and system policy.
24
 
 
25
 
        Note that you still need to allow some of the related actions, this
26
 
        just controls their behaviour, not their activation.
27
 
    """
28
 
 
29
 
    def __init__(self, user):
30
 
        """ Calculate the permissons `user` has.
31
 
        """
32
 
        from MoinMoin.Page import Page
33
 
        self.Page = Page
34
 
        self.name = user.name
35
 
        self.request = user._request
36
 
 
37
 
    def save(self, editor, newtext, rev, **kw):
38
 
        """ Check whether user may save a page.
39
 
 
40
 
            `editor` is the PageEditor instance, the other arguments are
41
 
            those of the `PageEditor.saveText` method.
42
 
        """
43
 
        return self.write(editor.page_name)
44
 
 
45
 
    def __getattr__(self, attr):
46
 
        """ if attr is one of the rights in acl_rights_valid, then return a
47
 
            checking function for it. Else raise an error.
48
 
        """
49
 
        request = self.request
50
 
        Page = self.Page
51
 
        if attr in request.cfg.acl_rights_valid:
52
 
            return lambda pagename, Page=Page, request=request, attr=attr: Page(request, pagename).getACL(request).may(request, self.name, attr)
53
 
        else:
54
 
            raise AttributeError, attr
55
 
        
56
 
 
57
 
# make an alias for the default policy
58
 
Default = Permissions
59