Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move the Role component from grok to grokcore.security too
- Loading branch information
1 parent
d6e176d
commit 968196a
Showing
12 changed files
with
226 additions
and
21 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
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
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
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,15 @@ | ||
""" | ||
A role has to have a name to be defined. | ||
>>> grokcore.security.testing.grok(__name__) | ||
Traceback (most recent call last): | ||
GrokError: A role needs to have a dotted name for its id. | ||
Use grok.name to specify one. | ||
""" | ||
|
||
import zope.interface | ||
import grokcore.security | ||
import grokcore.security.testing | ||
|
||
class MissingName(grokcore.security.Role): | ||
pass |
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,35 @@ | ||
""" | ||
A Role component optionally defines what permission it comprises. | ||
The grok.permissions() directive is used to specify the set of permissions | ||
that are aggregated in the particular Role. The permissions can be referenced | ||
by "name" or by class. | ||
>>> grokcore.security.testing.grok(__name__) | ||
""" | ||
|
||
import grokcore.component as grok | ||
import grokcore.security.testing | ||
from grokcore.security import Role | ||
from grokcore.security import Permission, permissions | ||
import zope.interface | ||
|
||
class FirstPermission(Permission): | ||
grok.name('first permission') | ||
|
||
class SecondPermission(Permission): | ||
grok.name('second permission') | ||
|
||
class RoleComprisingTwoPermissionsByName(Role): | ||
grok.name('ByName') | ||
permissions( | ||
'first permission', | ||
'second permission' | ||
) | ||
|
||
class RoleComprisingTwoPermissionsByClass(Role): | ||
grok.name('ByClass') | ||
permissions( | ||
FirstPermission, | ||
SecondPermission | ||
) |
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,78 @@ | ||
""" | ||
A Role component have a title and description, that can be internationalized. | ||
Let's grok this package and check we still have a Message object for the | ||
internationalized title and description of the defined roles. | ||
>>> grokcore.security.testing.grok(__name__) | ||
>>> from zope.securitypolicy.interfaces import IRole | ||
>>> from zope.component import getUtility | ||
>>> from zope.i18nmessageid import Message | ||
A grok.Role without any internationalization. | ||
The id, title and description should be unicode:: | ||
>>> role = getUtility(IRole, name="RoleWithoutI18n") | ||
>>> role.id | ||
u'RoleWithoutI18n' | ||
>>> role.title | ||
u'RoleWithoutI18n' | ||
>>> role.description | ||
u'My role without i18n' | ||
>>> | ||
>>> isinstance(role.id, Message) | ||
False | ||
>>> isinstance(role.title, Message) | ||
False | ||
>>> isinstance(role.description, Message) | ||
False | ||
A grok.Role registered with the name and description directives only, both | ||
internationalized. | ||
The id is taken from the name directive and should not be a Message object. | ||
The title is taken from the name directive because the title directive | ||
is not used. | ||
:: | ||
>>> role = getUtility(IRole, name="RoleWithI18n") | ||
>>> isinstance(role.id, Message) | ||
False | ||
>>> isinstance(role.title, Message) | ||
True | ||
>>> isinstance(role.description, Message) | ||
True | ||
A grok.Role registered with name, title and description directives:: | ||
>>> role = getUtility(IRole, name="RoleWithI18nTitle") | ||
>>> isinstance(role.id, Message) | ||
False | ||
>>> isinstance(role.title, Message) | ||
True | ||
>>> isinstance(role.description, Message) | ||
True | ||
""" | ||
|
||
import grokcore.component as grok | ||
import grokcore.security | ||
|
||
from grokcore.security import Role | ||
from zope.i18nmessageid import MessageFactory | ||
|
||
_ = MessageFactory("testi18n") | ||
|
||
|
||
class RoleWithoutI18n(Role): | ||
grok.name('RoleWithoutI18n') | ||
grok.description('My role without i18n') | ||
|
||
|
||
class RoleWithI18n(Role): | ||
grok.name(_('RoleWithI18n')) | ||
grok.description(_(u'My role with i18n')) | ||
|
||
|
||
class RoleWithI18nTitle(Role): | ||
grok.name('RoleWithI18nTitle') | ||
grok.title(_('RoleWithI18n')) | ||
grok.description(_(u'My role with i18n')) |
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