Summary
This cube allows definition of local permissions using a generic CWPermission entity type which you should use in your schema definition.
A CWPermission entity type:
has a name and a label
means groups linked to it through the ‘require_group’ relation have the <name> permission on entities linked through the ‘require_permission’ object relation.
To speed-up things, a ‘has_group_permission’ relation is automatically maintained, so ‘P require_group G, U in_group G’ is equivalent to ‘U has_group_permission P’.
Client cubes should explicitly add ‘X granted_permission CWPermission’ and ‘X require_permission CWPermission’ for each type that should have local permission, the first one being explicitly granted and the other automatically propagated. Hence possible subjects of granted_permission should be a subset of require_permission possible subjects.
You should then use require_permission in your schema security definition, since this is the one which is automatically propagated.
Example of configuration
class granted_permission(RelationDefinition):
subject = 'Project'
object = 'CWPermission'
class require_permission(RelationDefinition):
subject = ('Project', 'Version')
object = 'CWPermission'
class Project(EntityType):
"""a project, only visible to managers and users having the 'view' local permission
"""
__permissions__ = {
'read': ('managers', ERQLExpression('X require_permission P, P name "view", '
'U has_group_permission P'),),
'update': ('managers', 'owners',),
'delete': ('managers', ),
'add': ('managers', 'users',),)
}
class Version(EntityType):
"""a version defines the content of a particular project's release"""
__permissions__ = {
'read': ('managers', ERQLExpression('X require_permission P, P name "view", '
'U has_group_permission P'),),
'update': ('managers', 'owners',),
'delete': ('managers', ),
'add': ('managers', 'users',),)
}
class version_of(RelationDefinition):
"""link a version to its project. A version is necessarily linked to one and
only one project.
"""
__permissions__ = {
'read': ('managers', 'users',),
'delete': ('managers', ),
'add': ('managers', RRQLExpression('O require_permission P, P name "manage",'
'U has_group_permission P'),)
}
subject = 'Version'
object = 'Project'
cardinality = '1*'
This configuration indicates that we’ve two distinct permissions (forthcoming CWPermission entities):
one named ‘view’, which allows some users to view a particular project and its versions
another named “manage” which provides rights to create new versions on a project
Now the idea is that managers will grant permission on projects, and those will then be propagated as configured. You will want to use sets in cubicweb_localperms.hooks to configure how permissions should be propagated when desired. In our example, put in your cube’s hooks.py something like:
from cubicweb_localperms import hooks
# relations where the "main" entity is the object. We could also
# have modified hooks.S_RELS for relations where the "main" entity
# is the subject
hooks.O_RELS.add('version_of')
The permission given to a project will be automatically added/removed as version are created / deleted.
Last but not least, when defining the entity class for Project, defines __permissions__ as below:
class Project(AnyEntity):
__permissions__ = ('view', 'manage',)
So that when going on the ‘security’ view for a project (in ‘more actions’ sub-menu by default), you should be proposed an interface to configurate local permissions with a combo-box prefilled with proper permission names instead of a free text input, which greatly reduces the risk of error.
Also, you’ll find in cubicweb_localperms some functions to ease building of rql expression in your schema definition. Those written in above example could be written as below using those functions:
from cubicweb_localperms import xexpr, oexpr
class Project(EntityType):
__permissions__ = {'read': ('managers', xexpr('view'),),
'update': ('managers', 'owners',),
'delete': ('managers', ),
'add': ('managers', 'users',),)
}
class Version(EntityType):
__permissions__ = {'read': ('managers', xexpr('view'),),
'update': ('managers', 'owners',),
'delete': ('managers', ),
'add': ('managers', 'users',),)
}
class version_of(RelationDefinition):
__permissions__ = {'read': ('managers', 'users',),
'update': ('managers', 'owners',),
'delete': ('managers', ),
'add': ('managers', oexpr('manage'),)
}
Metadata
Release files for cubicweb-localperms 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cubicweb_localperms-1.1.0.tar.gz | 15.9 kB | Without provenance | Details for cubicweb_localperms-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cubicweb_localperms-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for cubicweb_localperms-1.1.0-py3-none-any.whl |
Total release size: 34.9 kB
Release files / cubicweb_localperms-1.1.0.tar.gz
| Download URL | cubicweb_localperms-1.1.0.tar.gz |
|---|---|
| Size | 15.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e86bba6d0b3216a86a6fa67f88a972a918201f953db04fcd6badf7a8744b51be
|
|
BLAKE2b-256 checksum How to use checksums |
17cfc3bd36fb2e6a76af83f01935a5b2137761f62a853ba50abd6a2354a8d55e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.9
|
Release files / cubicweb_localperms-1.1.0-py3-none-any.whl
| Download URL | cubicweb_localperms-1.1.0-py3-none-any.whl |
|---|---|
| Size | 19.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fca6b804504625b8cfaa56abe882af697e8588235f6f81a5bdb3161b65509b09
|
|
BLAKE2b-256 checksum How to use checksums |
e8b23174156b7c723feead96e770978b5b6d6794e3e4cfddffa3525e87642a6e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.9
|
Security for cubicweb-localperms 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.