/
permission.py
58 lines (46 loc) · 1.93 KB
/
permission.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#############################################################################
#
# Copyright (c) 2006-2007 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Grokkers for security-related components."""
import sys
import martian
import grokcore.component
import grokcore.security
from zope.security.interfaces import IPermission
from martian.error import GrokError
PY2 = sys.version_info[0] == 2
if not PY2:
unicode = lambda s: s
def default_fallback_to_name(factory, module, name, **data):
return name
class PermissionGrokker(martian.ClassGrokker):
martian.component(grokcore.security.Permission)
martian.priority(1500)
martian.directive(grokcore.component.name)
martian.directive(grokcore.component.title,
get_default=default_fallback_to_name)
martian.directive(grokcore.component.description)
def execute(self, factory, config, name, title, description, **kw):
if not name:
raise GrokError(
"A permission needs to have a dotted name for its id. Use "
"grok.name to specify one.", factory)
permission = factory(
unicode(name), unicode(title), unicode(description))
config.action(
discriminator=('utility', IPermission, name),
callable=grokcore.component.provideUtility,
args=(permission, IPermission, name),
order=-1 # need to do this early in the process
)
return True