Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-pylib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-pylib
Commits
8630518e
Commit
8630518e
authored
4 years ago
by
florian
Browse files
Options
Downloads
Patches
Plain Diff
WIP: New errors in set_permissions example
parent
d7681304
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/set_permissions.py
+21
-12
21 additions, 12 deletions
examples/set_permissions.py
with
21 additions
and
12 deletions
examples/set_permissions.py
+
21
−
12
View file @
8630518e
...
...
@@ -51,26 +51,26 @@ out : tuple
try
:
human_user
=
admin
.
_retrieve_user
(
"
jane
"
)
_activate_user
(
"
jane
"
)
except
db
.
EntityDoesNotExistError
:
except
db
.
ResourceNotFoundException
:
human_user
=
admin
.
_insert_user
(
"
jane
"
,
password
=
"
Human_Rememberable_Password_1234
"
,
status
=
"
ACTIVE
"
)
try
:
alien_user
=
admin
.
_retrieve_user
(
"
xaxys
"
)
_activate_user
(
"
xaxys
"
)
except
db
.
EntityDoesNotExistError
:
except
db
.
ResourceNotFoundException
:
alien_user
=
admin
.
_insert_user
(
"
xaxys
"
,
password
=
"
4321_Syxax
"
,
status
=
"
ACTIVE
"
)
# At the moment, the return value is only "ok" for successful insertions.
try
:
human_role
=
admin
.
_retrieve_role
(
"
human
"
)
except
db
.
EntityDoesNotExistError
:
except
db
.
ResourceNotFoundException
:
human_role
=
admin
.
_insert_role
(
"
human
"
,
"
An Earthling.
"
)
try
:
alien_role
=
admin
.
_retrieve_role
(
"
alien
"
)
except
db
.
EntityDoesNotExistError
:
except
db
.
ResourceNotFoundException
:
alien_role
=
admin
.
_insert_role
(
"
alien
"
,
"
An Extra-terrestrial.
"
)
admin
.
_set_roles
(
"
jane
"
,
[
"
human
"
])
...
...
@@ -111,9 +111,11 @@ Returns
out : Container
A container of retrieved entities, the length is given by the parameter count.
"""
cont
=
db
.
execute_query
(
"
FIND RECORD Guitar
"
,
flags
=
{
"
P
"
:
"
0L{n}
"
.
format
(
n
=
count
)})
cont
=
db
.
execute_query
(
"
FIND RECORD Guitar
"
,
flags
=
{
"
P
"
:
"
0L{n}
"
.
format
(
n
=
count
)})
if
len
(
cont
)
!=
count
:
raise
db
.
CaosDBException
(
msg
=
"
Incorrect number of entitities returned.
"
)
raise
db
.
CaosDBException
(
msg
=
"
Incorrect number of entitities returned.
"
)
return
cont
...
...
@@ -138,7 +140,8 @@ general : bool, optional
# Set general permissions
if
general
:
grant
=
admin
.
PermissionRule
(
action
=
"
grant
"
,
permission
=
"
RETRIEVE:OWNER
"
)
grant
=
admin
.
PermissionRule
(
action
=
"
grant
"
,
permission
=
"
RETRIEVE:OWNER
"
)
deny
=
admin
.
PermissionRule
(
action
=
"
deny
"
,
permission
=
"
RETRIEVE:FILE
"
)
admin
.
_set_permissions
(
role
=
role_grant
,
permission_rules
=
[
grant
])
...
...
@@ -189,9 +192,12 @@ None
for
ent
in
cont
:
ent
.
retrieve
()
print
(
"
Successfully retrieved all entities.
"
)
except
db
.
AuthorizationException
:
print
(
ent
)
print
(
"
Could not retrieve this entity although it should have been possible!
"
)
except
db
.
TransactionError
as
te
:
if
te
.
has_error
(
db
.
AuthorizationException
):
print
(
ent
)
print
(
"
Could not retrieve this entity although it should have been possible!
"
)
else
:
raise
te
# Switch to user without permissions
db
.
configure_connection
(
username
=
denied_user
[
0
],
password
=
denied_user
[
1
],
...
...
@@ -206,8 +212,11 @@ None
denied_all
=
False
print
(
ent
)
print
(
"
Could retrieve this entity although it should not have been possible!
"
)
except
db
.
AuthorizationException
:
pass
except
db
.
TransactionError
as
te
:
# Only do something if an error wasn't caused by an
# AuthorizationException
if
not
te
.
has_error
(
db
.
AuthorizationException
):
raise
te
if
denied_all
:
print
(
"
Retrieval of all entities was successfully denied.
"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment