diff --git a/perun-base/src/main/resources/perun-roles.yml b/perun-base/src/main/resources/perun-roles.yml index 80089e4376..9b36311f4b 100644 --- a/perun-base/src/main/resources/perun-roles.yml +++ b/perun-base/src/main/resources/perun-roles.yml @@ -6209,6 +6209,15 @@ perun_policies: include_policies: - default_policy + getAssociatedResources_Facility_User_policy: + policy_roles: + - FACILITYADMIN: Facility + - FACILITYOBSERVER: Facility + - SELF: User + - PERUNOBSERVER: + include_policies: + - default_policy + findUsers_String_policy: policy_roles: - PERUNOBSERVER: diff --git a/perun-core/src/main/java/cz/metacentrum/perun/core/api/UsersManager.java b/perun-core/src/main/java/cz/metacentrum/perun/core/api/UsersManager.java index 84550aae73..f0d0cc81ef 100644 --- a/perun-core/src/main/java/cz/metacentrum/perun/core/api/UsersManager.java +++ b/perun-core/src/main/java/cz/metacentrum/perun/core/api/UsersManager.java @@ -716,6 +716,21 @@ UserExtSource getUserExtSourceByExtLogin(PerunSession perunSession, ExtSource so */ List getAssignedRichResources(PerunSession sess, User user) throws UserNotExistsException, PrivilegeException; + /** + * Return all resources of specified facility with which user is associated through all his members. + * Does not require ACTIVE group-resource assignment. + * + * @param sess + * @param facility + * @param user + * @return All resources with which user is associated + * + * @throws UserNotExistsException + * @throws FacilityNotExistsException + * @throws PrivilegeException + */ + List getAssociatedResources(PerunSession sess, Facility facility, User user) throws UserNotExistsException, FacilityNotExistsException, PrivilegeException; + /** * Returns list of users who matches the searchString, searching name, id, uuid, email, logins. * diff --git a/perun-core/src/main/java/cz/metacentrum/perun/core/entry/UsersManagerEntry.java b/perun-core/src/main/java/cz/metacentrum/perun/core/entry/UsersManagerEntry.java index 25a8c74b97..15e9293b1a 100644 --- a/perun-core/src/main/java/cz/metacentrum/perun/core/entry/UsersManagerEntry.java +++ b/perun-core/src/main/java/cz/metacentrum/perun/core/entry/UsersManagerEntry.java @@ -839,6 +839,20 @@ public List getAssignedRichResources(PerunSession sess, User user) return getUsersManagerBl().getAssignedRichResources(sess, user); } + @Override + public List getAssociatedResources(PerunSession sess, Facility facility, User user) throws UserNotExistsException, FacilityNotExistsException, PrivilegeException { + Utils.checkPerunSession(sess); + + if(!AuthzResolver.authorizedInternal(sess, "getAssociatedResources_Facility_User_policy", facility, user)) { + throw new PrivilegeException(sess, "getAssociatedResources"); + } + + getUsersManagerBl().checkUserExists(sess, user); + perunBl.getFacilitiesManagerBl().checkFacilityExists(sess, facility); + + return getUsersManagerBl().getAssociatedResources(sess, facility, user); + } + @Override public List findUsers(PerunSession sess, String searchString) throws PrivilegeException { Utils.checkPerunSession(sess); diff --git a/perun-openapi/openapi.yml b/perun-openapi/openapi.yml index d7e66ebd30..9201e09a20 100644 --- a/perun-openapi/openapi.yml +++ b/perun-openapi/openapi.yml @@ -9554,6 +9554,21 @@ paths: default: $ref: '#/components/responses/ExceptionResponse' + /json/usersManager/getAssociatedResources: + get: + tags: + - UsersManager + operationId: getAssociatedResourcesForUser + summary: Get all resources associated with the user on the facility + parameters: + - $ref: '#/components/parameters/facilityId' + - $ref: '#/components/parameters/userId' + responses: + '200': + $ref: '#/components/responses/ListOfResourcesResponse' + default: + $ref: '#/components/responses/ExceptionResponse' + /json/usersManager/getUsersByIds: get: tags: diff --git a/perun-rpc/src/main/java/cz/metacentrum/perun/rpc/methods/UsersManagerMethod.java b/perun-rpc/src/main/java/cz/metacentrum/perun/rpc/methods/UsersManagerMethod.java index 13cf1c2edb..783af8f9e2 100644 --- a/perun-rpc/src/main/java/cz/metacentrum/perun/rpc/methods/UsersManagerMethod.java +++ b/perun-rpc/src/main/java/cz/metacentrum/perun/rpc/methods/UsersManagerMethod.java @@ -1119,6 +1119,26 @@ public List call(ApiCaller ac, Deserializer parms) throws PerunExc } }, + /*# + * Return all resources of specified facility with which user is associated through all his members. + * Does not require ACTIVE group-resource assignment. + * + * @param facility int Facility id + * @param user int User id + * @return List All resources with which user is associated + */ + + getAssociatedResources { + + @Override + public List call(ApiCaller ac, Deserializer parms) throws PerunException { + Facility facility = ac.getFacilityById(parms.readInt("facility")); + User user = ac.getUserById(parms.readInt("user")); + return ac.getUsersManager().getAssociatedResources(ac.getSession(), facility, user); + } + }, + + /*# * Checks if the login is available in the namespace. Return 1 if yes, 0 if no. *