Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split the grokkker from meta.py into meta/role.py and meta/permission.py
- Loading branch information
1 parent
a4d5c76
commit 87f2f63
Showing
7 changed files
with
75 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<configure | ||
xmlns="http://namespaces.zope.org/zope" | ||
xmlns:grok="http://namespaces.zope.org/grok"> | ||
<include package="grokcore.component" file="meta.zcml" /> | ||
<grok:grok package=".meta.permission" /> | ||
</configure> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
<configure | ||
xmlns="http://namespaces.zope.org/zope" | ||
xmlns:grok="http://namespaces.zope.org/grok"> | ||
|
||
<!-- Load the grokkers --> | ||
<include package="grokcore.component" file="meta.zcml" /> | ||
<grok:grok package=".meta" /> | ||
|
||
<grok:grok package=".meta.permission" /> | ||
<grok:grok package=".meta.role" /> | ||
</configure> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
############################################################################# | ||
# | ||
# 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 martian | ||
import grokcore.component | ||
import grokcore.component.util | ||
import grokcore.security | ||
|
||
from zope.security.interfaces import IPermission | ||
from martian.error import GrokError | ||
|
||
|
||
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) | ||
# We can safely convert to unicode, since the directives make sure | ||
# it is either unicode already or ASCII. | ||
permission = factory(unicode(name), unicode(title), | ||
unicode(description)) | ||
|
||
config.action( | ||
discriminator=('utility', IPermission, name), | ||
callable=grokcore.component.util.provideUtility, | ||
args=(permission, IPermission, name), | ||
order=-1 # need to do this early in the process | ||
) | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters