X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FNBI.git;a=blobdiff_plain;f=osm_nbi%2Fadmin_topics.py;h=7d1e85dd03079c06ba65eeac464ae0c00f19de66;hp=efcb0f17d03ee5da52db53542d4974dfe6af230d;hb=1546f2a46d99a4741b23857e6ceb4b813223e297;hpb=08ddb14b077121ffced28e41c441fef31b6bb6a1;ds=sidebyside diff --git a/osm_nbi/admin_topics.py b/osm_nbi/admin_topics.py index efcb0f1..7d1e85d 100644 --- a/osm_nbi/admin_topics.py +++ b/osm_nbi/admin_topics.py @@ -547,7 +547,7 @@ class UserTopicAuth(UserTopic): users = self.auth.get_user_list(filter_q) if len(users) == 1: - return self.format_on_show(users[0]) + return users[0] elif len(users) > 1: raise EngineException("Too many users found", HTTPStatus.CONFLICT) else: @@ -596,6 +596,16 @@ class UserTopicAuth(UserTopic): rid = role[0]["_id"] if "add_project_role_mappings" not in indata: indata["add_project_role_mappings"] = [] + if "remove_project_role_mappings" not in indata: + indata["remove_project_role_mappings"] = [] + if isinstance(indata.get("projects"), dict): + # backward compatible + for k, v in indata["projects"].items(): + if k.startswith("$") and v is None: + indata["remove_project_role_mappings"].append({"project": k[1:]}) + elif k.startswith("$+"): + indata["add_project_role_mappings"].append({"project": v, "role": rid}) + del indata["projects"] for proj in indata.get("projects", []) + indata.get("add_projects", []): indata["add_project_role_mappings"].append({"project": proj, "role": rid}) @@ -665,7 +675,7 @@ class UserTopicAuth(UserTopic): :param filter_q: filter of data to be applied :return: The list, it can be empty if no one match the filter. """ - users = [self.format_on_show(user) for user in self.auth.get_user_list(filter_q)] + users = self.auth.get_user_list(filter_q) return users @@ -766,9 +776,10 @@ class ProjectTopicAuth(ProjectTopic): # If any user is using this project, raise CONFLICT exception if not session["force"]: for user in self.auth.get_user_list(): - if _id in [proj["_id"] for proj in user.get("projects", [])]: - raise EngineException("Project '{}' ({}) is being used by user '{}'" - .format(db_content["name"], _id, user["username"]), HTTPStatus.CONFLICT) + for prm in user.get("project_role_mappings"): + if prm["project"] == _id: + raise EngineException("Project '{}' ({}) is being used by user '{}'" + .format(db_content["name"], _id, user["username"]), HTTPStatus.CONFLICT) # If any VNFD, NSD, NST, PDU, etc. is using this project, raise CONFLICT exception if not session["force"]: @@ -1000,9 +1011,10 @@ class RoleTopicAuth(BaseTopic): # If any user is using this role, raise CONFLICT exception for user in self.auth.get_user_list(): - if _id in [prl["_id"] for proj in user.get("projects", []) for prl in proj.get("roles", [])]: - raise EngineException("Role '{}' ({}) is being used by user '{}'" - .format(role["name"], _id, user["username"]), HTTPStatus.CONFLICT) + for prm in user.get("project_role_mappings"): + if prm["role"] == _id: + raise EngineException("Role '{}' ({}) is being used by user '{}'" + .format(role["name"], _id, user["username"]), HTTPStatus.CONFLICT) @staticmethod def format_on_new(content, project_id=None, make_public=False): # TO BE REMOVED ?