https://github.com/dasch-swiss/dsp-permissions-scripts
Science Score: 26.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (13.1%) to scientific vocabulary
Repository
Basic Info
- Host: GitHub
- Owner: dasch-swiss
- License: apache-2.0
- Language: Python
- Default Branch: main
- Size: 505 KB
Statistics
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 1
- Releases: 0
Metadata Files
README.md
DSP Permissions Scripts
A collection of scripts to handle permissions in DSP.
💡 Note
The code and logs of accomplished projects can be found on Google Drive
Local setup to run the scripts in this repository
Set up the virtual environment with uv:
curl -LsSf https://astral.sh/uv/install.sh | shuv sync --all-extras --devsource .venv/bin/activate- Set the virtual environment's Python interpreter as default interpreter in your IDE, so that your IDE uses the correct Python version and the correct dependencies.
How to use this repo
- Make a copy of
dsp_permissions_scripts/template.pyand adapt it to your needs. - The template is the only file you should modify. All other code can be considered as consume-only library.
- If you interact with a server that needs credentials, set them in a
.envfile:
```bash # DO NOT COMMIT THIS FILE TO GIT!
PRODEMAIL="your.name@dasch.swiss" PRODPASSWORD="pw-on-app.dasch.swiss"
TESTEMAIL="your-name@dasch.swiss" TESTPASSWORD="pw-on-app.test.dasch.swiss"
DEVEMAIL="your-name@dasch.swiss" DEVPASSWORD="pw-on-app.dev.dasch.swiss" ```
- For a first, exploratory run, comment out the parts of the template that make the modifications.
- You will get JSON files in
project_data/<shortcode>/with the permissions retrieved from the server. - Based on these, write your code to modify the permissions.
- Run the entire script.
The DSP permissions system
There are 3 permissions systems:
- AP: Administrative Permissions
- define what users of a certain group can do on project level (e.g. create resources, modify groups, etc.)
- OAP: Object Access Permissions
- define permissions of objects (resources and values)
- OAPs grant rights to certain user groups.
- The
<permissions>tags in the XML of DSP-TOOLS define OAPs.
- DOAP: Default Object Access Permissions
- configured on a per-project basis
- defines what should happen if a resource/property/value is created without OAP.
- If a new project without DOAPs is created, there is a default DOAP configuration. (Until now it isn't possible to specify DOAPs when creating a project.)
The permissions system of DSP is documented here.
The /admin/permissions endpoint of DSP-API is documented
here.
AP: Administrative Permissions
A user group can have one or more of the following permissions:
ProjectResourceCreateAllPermission: is allowed to create resources inside the projectProjectResourceCreateRestrictedPermission: is allowed to create resources of certain classes inside the projectProjectAdminAllPermission: is allowed to do anything on project levelProjectAdminGroupAllPermission: is allowed to modify group info and group membership on all groups of the projectProjectAdminGroupRestrictedPermission: is allowed to modify group info and group membership on certain groups of the projectProjectAdminRightsAllPermission: is allowed to change the permissions on all objects belonging to the project
💡 Note
This example file contains 2 APs that:
- grant to
knora-admin:ProjectAdminthe rights to do anything on project level, and to create resources of any class.- grant to
knora-admin:ProjectMemberthe rights to create resources of any class.
OAP: Object Access Permissions
OAPs grant rights to certain user groups. These are mapped to each other using permission strings (represented as scopes in this repo).
OAPs are attached to either a resource or a value (value of a property), but not to a property.
1. Rights
A group can have exactly one of these rights:
- (no right): If no permission is defined for a certain group of users, these users cannot view any resources/values.
RVrestricted view permission: Same asV, but if it is applied to an image, the image is shown with a reduced resolution or with a watermark overlay.Vview permission: The user can view a resource or a value, but cannot modify it.Mmodify permission: The user can modify the element, but cannot mark it as deleted. The original resource or value will be preserved.Ddelete permission: The user is allowed to mark an element as deleted. The original resource or value will be preserved.CRchange right permission: The user can change the permission of a resource or value. The user is also allowed to permanently delete (erase) a resource.
Every right of this row includes all previous rights.
2. User Groups
The user doesn't hold the permissions directly, but belongs to an arbitrary number of groups which hold the permissions. There are built-in groups and project specific groups:
- Built-in groups: Every user is automatically in at least one of the following built-in groups:
UnknownUser: The user is not known to DSP (not logged in).KnownUser: The user is logged in, but not a member of the project the data element belongs to.ProjectMember: The user belongs to the same project as the data element.ProjectAdmin: The user is project administrator in the project the data element belongs to.Creator: The user is the owner of the element (created the element).SystemAdmin: The user is a system administrator.
- Project specific groups:
- projects can define their own groups
3. Permission strings / scopes
Permission strings (represented as scopes in this repo) are used to grant rights to certain user groups.
💡 Note
This example file contains an OAP that grants the following rights to the resource
http://rdfh.ch/0102/XwwqVvWgSmuHRobQubg9uQ:
- Project admins have change rights.
- The creator has deletion rights.
- Project members have view rights.
- All others (logged-in or logged-out users) have restricted view rights.
The string representation of this scope would be:
CR knora-admin:ProjectAdmin|D knora-admin:Creator|M knora-admin:ProjectMember|RV knora-admin:UnknownUser,knora-admin:KnownUser.
DOAP: Default Object Access Permissions
DOAPs are always project-related, but more specifically, they are:
- Either group-related: I belong to a group and create a resource, which OAPs does the resource get?
- Or ontology-related:
- class-related: resources of some classes are public, while resources of other classes are restricted
- property-related: some properties are public, while other properties are restricted
- or a combination of class/property-related
💡 Note
This example file contains 2 DOAPs that encode the following information:
- If a
ProjectAdmincreates a resource, the resource's OAP would grant
- change rights to
ProjectAdmin- deletion rights to
CreatorandProjectMember- view rights to
KnownUserandUnknownUser- If a
ProjectMembercreates a resource, the resources OAP would grant the same permissions to the same user groups.
Precedence rule
Group-related and class-related DOAPs cannot be combined, but there is a precedence rule.
If a user creates a resource, DSP checks the following places for DOAPs:
- First: User belongs to group
ProjectAdmin: take DOAPs ofProjectAdmin - Then: The class of the resource-to-be-created has DOAPs: take DOAPs of the class
- ...
- Last: User belongs to group
ProjectMember: take DOAPs ofProjectMember
See the docs for more details.
Typical use cases
If permissions need to be changed, it is usually because of one of the following reasons:
- Use case 1: The project is unhappy with their default DOAPs. They want other permissions when creating a resource via the APP.
- Use case 2: It's already too late, the project has created resources,
and now they want to change the permissions of these resources.
- The wrong OAPs of existing resources must be adapted.
- The DOAPs must be adapted, so that new resources get the correct OAPs.
If we modify DOAPs, we usually have to modify them for the groups ProjectMember and ProjectAdmin,
because these are the two groups that always exist.
Owner
- Name: DaSCH - Swiss National Data and Service Center for the Humanities
- Login: dasch-swiss
- Kind: organization
- Email: info@dasch.swiss
- Location: Switzerland
- Website: https://dasch.swiss
- Twitter: DaSCHSwiss
- Repositories: 35
- Profile: https://github.com/dasch-swiss
Development repositories of the DaSCH.
GitHub Events
Total
- Delete event: 12
- Issue comment event: 5
- Push event: 68
- Pull request review comment event: 10
- Pull request review event: 11
- Pull request event: 32
- Create event: 14
Last Year
- Delete event: 12
- Issue comment event: 5
- Push event: 68
- Pull request review comment event: 10
- Pull request review event: 11
- Pull request event: 32
- Create event: 14
Issues and Pull Requests
Last synced: 10 months ago
All Time
- Total issues: 0
- Total pull requests: 6
- Average time to close issues: N/A
- Average time to close pull requests: 20 days
- Total issue authors: 0
- Total pull request authors: 2
- Average comments per issue: 0
- Average comments per pull request: 0.17
- Merged pull requests: 1
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 6
- Average time to close issues: N/A
- Average time to close pull requests: 20 days
- Issue authors: 0
- Pull request authors: 2
- Average comments per issue: 0
- Average comments per pull request: 0.17
- Merged pull requests: 1
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- jnussbaum (3)
Pull Request Authors
- jnussbaum (50)
- dependabot[bot] (3)
- Nora-Olivia-Ammann (2)
Top Labels
Issue Labels
Pull Request Labels
Dependencies
- actions/checkout v4 composite
- actions/setup-python v5 composite
- annotated-types 0.6.0
- certifi 2024.2.2
- cfgv 3.4.0
- charset-normalizer 3.3.2
- colorama 0.4.6
- distlib 0.3.8
- filelock 3.13.4
- identify 2.5.35
- idna 3.7
- iniconfig 2.0.0
- mypy 1.9.0
- mypy-extensions 1.0.0
- nodeenv 1.8.0
- packaging 24.0
- platformdirs 4.2.0
- pluggy 1.4.0
- pre-commit 3.7.0
- pydantic 2.6.4
- pydantic-core 2.16.3
- pytest 8.1.1
- pytest-unordered 0.6.0
- python-dotenv 1.0.1
- pyyaml 6.0.1
- requests 2.31.0
- ruff 0.3.7
- setuptools 69.5.1
- types-requests 2.31.0.20240406
- typing-extensions 4.11.0
- urllib3 2.2.1
- virtualenv 20.25.1
- mypy ^1.9.0 develop
- pre-commit ^3.7.0 develop
- pytest ^8.1.1 develop
- pytest-unordered ^0.6.0 develop
- python-dotenv ^1.0.1 develop
- ruff ^0.3.7 develop
- types-requests ^2.31.0.20240406 develop
- pydantic ^2.6.4
- python ^3.12.0
- requests ^2.31.0