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
2b65b94c
Commit
2b65b94c
authored
3 years ago
by
Alexander Kreft
Browse files
Options
Downloads
Patches
Plain Diff
Removed activate user function and some error fixes.
parent
b78fc431
No related branches found
Branches containing commit
Tags
v0.9.0
Tags containing commit
2 merge requests
!8
F set permissions
,
!6
F set permissions
Pipeline
#41308
passed with warnings
1 year ago
Stage: code_style
Stage: linting
Stage: test
Stage: deploy
Changes
1
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/set_permissions.py
+17
-17
17 additions, 17 deletions
examples/set_permissions.py
with
17 additions
and
17 deletions
examples/set_permissions.py
+
17
−
17
View file @
2b65b94c
...
...
@@ -32,7 +32,6 @@ pycaosdb.ini configuration can create new entities.
import
caosdb
as
db
from
caosdb
import
administration
as
admin
from
caosdb.utils.caosdb_admin
import
do_activate_user
,
do_retrieve_user
,
do_retrieve_role
,
do_create_role
,
do_add_user_roles
,
do_retrieve_user_roles
def
assert_user_and_role
():
...
...
@@ -48,35 +47,35 @@ out : tuple
"""
try
:
human_user
=
do
_retrieve_user
(
user_name
=
"
jane
"
)
do_activ
ate_user
(
user_
name
=
"
jane
"
)
human_user
=
admin
.
_retrieve_user
(
"
jane
"
)
admin
.
_upd
ate_user
(
name
=
"
jane
"
,
status
=
"
ACTIVE
"
)
except
db
.
HTTPResourceNotFoundError
:
human_user
=
admin
.
_insert_user
(
"
jane
"
,
password
=
"
Human_Rememberable_Password_1234
"
,
status
=
"
ACTIVE
"
)
try
:
alien_user
=
do
_retrieve_user
(
user_name
=
"
xaxys
"
)
do_activ
ate_user
(
user_
name
=
"
jane
"
)
alien_user
=
admin
.
_retrieve_user
(
"
xaxys
"
)
admin
.
_upd
ate_user
(
name
=
"
xaxys
"
,
status
=
"
ACTIVE
"
)
except
db
.
HTTPResourceNotFoundError
:
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
=
do
_retrieve_role
(
role_name
=
"
human
"
)
human_role
=
admin
.
_retrieve_role
(
"
human
"
)
except
db
.
HTTPResourceNotFoundError
:
human_role
=
do_create_role
(
role_name
=
"
human
"
,
role_description
=
"
An Earthling.
"
)
human_role
=
admin
.
_insert_role
(
"
human
"
,
"
An Earthling.
"
)
try
:
alien_role
=
do
_retrieve_role
(
role_name
=
"
alien
"
)
alien_role
=
admin
.
_retrieve_role
(
"
alien
"
)
except
db
.
HTTPResourceNotFoundError
:
alien_role
=
do_create_role
(
role_name
=
"
alien
"
,
role_description
=
"
An Extra-terrestrial.
"
)
alien_role
=
admin
.
_insert_role
(
"
alien
"
,
"
An Extra-terrestrial.
"
)
do_add_u
se
r
_roles
(
user_name
=
"
jane
"
,
user_roles
=
[
"
human
"
])
do_add_u
se
r
_roles
(
user_name
=
"
xaxys
"
,
user_roles
=
[
"
alien
"
])
admin
.
_
se
t
_roles
(
"
jane
"
,
[
"
human
"
])
admin
.
_
se
t
_roles
(
"
xaxys
"
,
[
"
alien
"
])
return
((
"
jane
"
,
list
(
do_retrieve_user_roles
(
user_name
=
"
jane
"
))),
(
"
xaxys
"
,
list
(
do_retrieve_user_roles
(
user_name
=
"
xaxys
"
))))
return
((
"
jane
"
,
list
(
admin
.
_get_roles
(
"
jane
"
))),
(
"
xaxys
"
,
list
(
admin
.
_get_roles
(
"
xaxys
"
))))
def
get_entities
(
count
=
1
):
...
...
@@ -202,10 +201,10 @@ None
print
(
"
Retrieval of all entities was successfully denied.
"
)
def
create_entities
():
def
create_
test_
entities
():
"""
Create some test entities.
After calling this function, there will be a
n
RecordType
"
Human Food
"
with the corresponding Records
"
Bread
"
,
"
Tomatoes
"
, and
"
Twinkies
"
.
After calling this function, there will be a RecordType
"
Human Food
"
with the corresponding Records
"
Bread
"
,
"
Tomatoes
"
, and
"
Twinkies
"
inserted in the database
.
"""
rt
=
db
.
RecordType
(
name
=
"
Human Food
"
,
description
=
"
Food that can be eaten only by humans
"
).
insert
()
food
=
(
"
Bread
"
,
"
Tomatoes
"
,
"
Twinkies
"
)
...
...
@@ -222,6 +221,8 @@ def create_entities():
def
main
():
"""
The main function of this script.
"""
"""
Create some test entities
"""
create_test_entities
()
"""
Create new users
"""
human
,
alien
=
assert_user_and_role
()
"""
Load the newly created entities.
"""
...
...
@@ -235,4 +236,3 @@ def main():
if
__name__
==
"
__main__
"
:
main
()
# create_entities()
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