Attachment 'security_rules3.patch'
Download 1 * looking for arch@arch.thinkmo.de--2003-archives/moin--main--1.5--patch-376 to compare with
2 * comparing to arch@arch.thinkmo.de--2003-archives/moin--main--1.5--patch-376
3 M MoinMoin/multiconfig.py
4 M MoinMoin/security.py
5 A MoinMoin/securityrule.py
6
7 * modified files
8
9 --- orig/MoinMoin/multiconfig.py
10 +++ mod/MoinMoin/multiconfig.py
11 @@ -10,6 +10,8 @@
12 from MoinMoin import error
13 import MoinMoin.auth as authmodule
14
15 +import MoinMoin.securityrule as SecurityRule
16 +
17 _url_re_cache = None
18 _farmconfig_mtime = None
19 _config_cache = {}
20 @@ -168,6 +170,7 @@
21 acl_rights_before = u""
22 acl_rights_after = u""
23 acl_rights_valid = ['read', 'write', 'delete', 'revert', 'admin']
24 + security_rules = [] #Test: security_rules = [{'rule' :SecurityRule.vaild_user, "is_non": 1, "write": 0}]
25
26 actions_excluded = [] # ['DeletePage', 'AttachFile', 'RenamePage']
27 allow_xslt = 0
28
29
30 --- orig/MoinMoin/security.py
31 +++ mod/MoinMoin/security.py
32 @@ -43,11 +43,26 @@
33 return self.write(editor.page_name)
34
35 def __getattr__(self, attr):
36 - """ if attr is one of the rights in acl_rights_valid, then return a
37 - checking function for it. Else raise an error.
38 - """
39 request = self.request
40 Page = self.Page
41 +
42 + # check right in security_rules
43 + for s in request.cfg.security_rules:
44 + # Make Sure the SecurityRules have 'rule' and 'is_non'
45 + # and the SecurityRules is a Dict.
46 + try:
47 + if s.has_key('rule') and s.has_key('is_non'):
48 + valid_security_rule = 1
49 + except AttributeError:
50 + valid_security_rule = 0
51 + if valid_security_rule:
52 + sr = s['rule']
53 + security_rule = sr(request.user, s)
54 + attr_security_rule = getattr(security_rule, attr, 0)
55 + if attr_security_rule:
56 + return lambda pagename, **kw: attr_security_rule(pagename, **kw)
57 +
58 + # If cann't check in security_rules, try it in moin_acl
59 if attr in request.cfg.acl_rights_valid:
60 return lambda pagename, Page=Page, request=request, attr=attr: Page(request, pagename).getACL(request).may(request, self.name, attr)
61 else:
62
63
64 --- orig/MoinMoin/securityrule.py
65 +++ mod/MoinMoin/securityrule.py
66 @@ -0,0 +1,49 @@
67 +# -*- coding: iso-8859-1 -*-
68 +"""
69 +@copyright: (c) Bastian Blank, Florian Festi, Thomas Waldmann
70 +@copyright: MoinMoin:FrankieChow
71 +@license: GNU GPL, see COPYING for details.
72 +"""
73 +
74 +class security_rules_obj:
75 + """ Template of SecurityRules Object
76 + """
77 +
78 + def __init__(self, user, dict):
79 + """ Calculate the permissons `user` has.
80 + """
81 + self.user = user
82 + self.name = user.name
83 + self.request = user._request
84 + self.dict = dict
85 + is_non = self.dict['is_non']
86 + # FixMe: What about this logic relationship
87 + if is_non and self.check_rule():
88 + self.rule_result = 1
89 + elif is_non and not self.check_rule():
90 + self.rule_result = 0
91 + elif not is_non and self.check_rule():
92 + self.rule_result = 0
93 + elif not is_non and not self.check_rule():
94 + self.rule_result = 1
95 +
96 + def true(self, pagename, **kw):
97 + return 1
98 + def false(self, pagename, **kw):
99 + return 0
100 +
101 + def __getattr__(self, attr):
102 + if not self.rule_result: raise AttributeError, attr
103 + if self.dict.has_key(attr):
104 + if self.dict[attr]:
105 + return lambda pagename, **kw: self.true(pagename, **kw)
106 + else:
107 + return lambda pagename, **kw: self.false(pagename, **kw)
108 + else: raise AttributeError, attr
109 +
110 +class vaild_user(security_rules_obj):
111 + def check_rule(self):
112 + if self.user.valid:
113 + return 1
114 + else:
115 + return 0
116
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.