Skip to content

Commit 11b25e2

Browse files
authored
Merge pull request #2002 from zlamalp/membergroup
CORE,RPC: Added removeAttributes for member,group and user
2 parents 6b3695c + 5d676a6 commit 11b25e2

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

perun-core/src/main/java/cz/metacentrum/perun/core/api/AttributesManager.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3259,6 +3259,20 @@ public interface AttributesManager {
32593259
*/
32603260
void removeAttributes(PerunSession sess, Member member, Group group, List<? extends AttributeDefinition> attributes) throws InternalErrorException, PrivilegeException, AttributeNotExistsException, MemberNotExistsException, GroupNotExistsException, WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException;
32613261

3262+
3263+
/**
3264+
* PRIVILEGE: Remove attributes only when principal has access to write on them.
3265+
* <p>
3266+
* Batch version of removeAttribute. This method automatically skip all core attributes which can't be removed this way.
3267+
* If workWithUserAttributes is true, unset also user attributes.
3268+
*
3269+
* @param workWithUserAttributes if true, remove also user attributes, if false, remove only member-group attributes
3270+
*
3271+
* @throws AttributeNotExistsException if the any of attributes doesn't exists in underlying data source
3272+
* @see cz.metacentrum.perun.core.api.AttributesManager#removeAttribute(PerunSession, Member, Group, AttributeDefinition)
3273+
*/
3274+
void removeAttributes(PerunSession sess, Member member, Group group, List<? extends AttributeDefinition> attributes, boolean workWithUserAttributes) throws InternalErrorException, PrivilegeException, AttributeNotExistsException, MemberNotExistsException, GroupNotExistsException, WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException;
3275+
32623276
/**
32633277
* Unset all attributes for the member in the group.
32643278
* <p>

perun-core/src/main/java/cz/metacentrum/perun/core/entry/AttributesManagerEntry.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3561,6 +3561,11 @@ public void removeAttribute(PerunSession sess, Member member, Group group, Attri
35613561

35623562
@Override
35633563
public void removeAttributes(PerunSession sess, Member member, Group group, List<? extends AttributeDefinition> attributes) throws InternalErrorException, PrivilegeException, AttributeNotExistsException, MemberNotExistsException, GroupNotExistsException, WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException {
3564+
removeAttributes(sess, member, group, attributes, false);
3565+
}
3566+
3567+
@Override
3568+
public void removeAttributes(PerunSession sess, Member member, Group group, List<? extends AttributeDefinition> attributes, boolean workWithUserAttributes) throws InternalErrorException, PrivilegeException, AttributeNotExistsException, MemberNotExistsException, GroupNotExistsException, WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException {
35643569
Utils.checkPerunSession(sess);
35653570
getPerunBl().getMembersManagerBl().checkMemberExists(sess, member);
35663571
getPerunBl().getGroupsManagerBl().checkGroupExists(sess, group);
@@ -3569,7 +3574,7 @@ public void removeAttributes(PerunSession sess, Member member, Group group, List
35693574
for(AttributeDefinition attrDef: attributes) {
35703575
if(!AuthzResolver.isAuthorizedForAttribute(sess, ActionType.WRITE, attrDef, member, group)) throw new PrivilegeException("Principal has no access to remove attribute = " + attrDef);
35713576
}
3572-
getAttributesManagerBl().removeAttributes(sess, member, group, attributes);
3577+
getAttributesManagerBl().removeAttributes(sess, member, group, attributes, workWithUserAttributes);
35733578
}
35743579

35753580
@Override

perun-rpc/src/main/java/cz/metacentrum/perun/rpc/methods/AttributesManagerMethod.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2847,7 +2847,13 @@ public Void call(ApiCaller ac, Deserializer parms) throws PerunException {
28472847
attributes);
28482848
}
28492849
} else if (parms.contains("member")) {
2850-
if (parms.contains("workWithUserAttributes")) {
2850+
if (parms.contains("workWithUserAttributes") && parms.contains("group")) {
2851+
ac.getAttributesManager().removeAttributes(ac.getSession(),
2852+
ac.getMemberById(parms.readInt("member")),
2853+
ac.getGroupById(parms.readInt("group")),
2854+
attributes,
2855+
parms.readBoolean("workWithUserAttributes"));
2856+
} else if (parms.contains("workWithUserAttributes")) {
28512857
ac.getAttributesManager().removeAttributes(ac.getSession(),
28522858
ac.getMemberById(parms.readInt("member")),
28532859
parms.readBoolean("workWithUserAttributes"), attributes);

0 commit comments

Comments
 (0)