diff --git a/examples/set_permissions.py b/examples/set_permissions.py index 8b2b59f10ac033110af846eef0ed90356a09553d..3637f89e3b2911e470b71c3239fda35723f7be55 100755 --- a/examples/set_permissions.py +++ b/examples/set_permissions.py @@ -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.")