Skip to content
Snippets Groups Projects
Commit 2b65b94c authored by Alexander Kreft's avatar Alexander Kreft
Browse files

Removed activate user function and some error fixes.

parent b78fc431
Branches
Tags
2 merge requests!8F set permissions,!6F set permissions
Pipeline #41308 passed with warnings
...@@ -32,7 +32,6 @@ pycaosdb.ini configuration can create new entities. ...@@ -32,7 +32,6 @@ pycaosdb.ini configuration can create new entities.
import caosdb as db import caosdb as db
from caosdb import administration as admin 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(): def assert_user_and_role():
...@@ -48,35 +47,35 @@ out : tuple ...@@ -48,35 +47,35 @@ out : tuple
""" """
try: try:
human_user = do_retrieve_user(user_name="jane") human_user = admin._retrieve_user("jane")
do_activate_user(user_name="jane") admin._update_user(name="jane", status="ACTIVE")
except db.HTTPResourceNotFoundError: except db.HTTPResourceNotFoundError:
human_user = admin._insert_user( human_user = admin._insert_user(
"jane", password="Human_Rememberable_Password_1234", status="ACTIVE") "jane", password="Human_Rememberable_Password_1234", status="ACTIVE")
try: try:
alien_user = do_retrieve_user(user_name="xaxys") alien_user = admin._retrieve_user("xaxys")
do_activate_user(user_name="jane") admin._update_user(name="xaxys", status="ACTIVE")
except db.HTTPResourceNotFoundError: except db.HTTPResourceNotFoundError:
alien_user = admin._insert_user("xaxys", password="4321_Syxax", alien_user = admin._insert_user("xaxys", password="4321_Syxax",
status="ACTIVE") status="ACTIVE")
# At the moment, the return value is only "ok" for successful insertions. # At the moment, the return value is only "ok" for successful insertions.
try: try:
human_role = do_retrieve_role(role_name="human") human_role = admin._retrieve_role("human")
except db.HTTPResourceNotFoundError: except db.HTTPResourceNotFoundError:
human_role = do_create_role(role_name="human", role_description="An Earthling.") human_role = admin._insert_role("human", "An Earthling.")
try: try:
alien_role = do_retrieve_role(role_name="alien") alien_role = admin._retrieve_role("alien")
except db.HTTPResourceNotFoundError: 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_user_roles(user_name="jane", user_roles=["human"]) admin._set_roles("jane", ["human"])
do_add_user_roles(user_name="xaxys", user_roles=["alien"]) admin._set_roles("xaxys", ["alien"])
return (("jane", list(do_retrieve_user_roles(user_name="jane"))), return (("jane", list(admin._get_roles("jane"))),
("xaxys", list(do_retrieve_user_roles(user_name="xaxys")))) ("xaxys", list(admin._get_roles("xaxys"))))
def get_entities(count=1): def get_entities(count=1):
...@@ -202,10 +201,10 @@ None ...@@ -202,10 +201,10 @@ None
print("Retrieval of all entities was successfully denied.") print("Retrieval of all entities was successfully denied.")
def create_entities(): def create_test_entities():
"""Create some test entities. """Create some test entities.
After calling this function, there will be an RecordType "Human Food" with the corresponding Records After calling this function, there will be a RecordType "Human Food" with the corresponding Records
"Bread", "Tomatoes", and "Twinkies". "Bread", "Tomatoes", and "Twinkies" inserted in the database.
""" """
rt = db.RecordType(name="Human Food", description="Food that can be eaten only by humans").insert() rt = db.RecordType(name="Human Food", description="Food that can be eaten only by humans").insert()
food = ("Bread", "Tomatoes", "Twinkies") food = ("Bread", "Tomatoes", "Twinkies")
...@@ -222,6 +221,8 @@ def create_entities(): ...@@ -222,6 +221,8 @@ def create_entities():
def main(): def main():
"""The main function of this script.""" """The main function of this script."""
"""Create some test entities"""
create_test_entities()
"""Create new users""" """Create new users"""
human, alien = assert_user_and_role() human, alien = assert_user_and_role()
"""Load the newly created entities.""" """Load the newly created entities."""
...@@ -235,4 +236,3 @@ def main(): ...@@ -235,4 +236,3 @@ def main():
if __name__ == "__main__": if __name__ == "__main__":
main() main()
# create_entities()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment