Search in sources :

Example 16 with GroupingsServiceResult

use of edu.hawaii.its.api.type.GroupingsServiceResult in project uhgroupings by uhawaii-system-its-ti-iam.

the class MembershipServiceImpl method deleteGroupingMemberByUuid.

// todo
// finds a user by a uuid and remove them from a grouping
@Override
public List<GroupingsServiceResult> deleteGroupingMemberByUuid(String ownerUsername, String groupingPath, String userToDeleteUuid) {
    logger.info("deleteGroupingMemberByUuid; ownerUsername: " + ownerUsername + "; groupingPath: " + groupingPath + "; userToDelete: " + userToDeleteUuid + ";");
    List<GroupingsServiceResult> gsrList = new ArrayList<>();
    String action = ownerUsername + " deletes " + userToDeleteUuid + " from " + groupingPath;
    String basis = groupingPath + BASIS;
    String exclude = groupingPath + EXCLUDE;
    String include = groupingPath + INCLUDE;
    Person personToDelete = new Person(null, userToDeleteUuid, null);
    boolean inBasis = mas.isMember(basis, personToDelete);
    boolean inComposite = mas.isMember(groupingPath, personToDelete);
    boolean inExclude = mas.isMember(exclude, personToDelete);
    // if they are in the include group, get them out
    gsrList.add(deleteGroupMemberByUuid(ownerUsername, include, userToDeleteUuid));
    // make sure userToDelete is actually in the Grouping
    if (inComposite) {
        // if they are not in the include group, then they are in the basis, so add them to the exclude group
        if (inBasis) {
            gsrList.addAll(addGroupMemberByUuid(ownerUsername, exclude, userToDeleteUuid));
        }
    } else // since they are not in the Grouping, do nothing, but return SUCCESS
    {
        gsrList.add(hs.makeGroupingsServiceResult(SUCCESS + userToDeleteUuid + " was not in " + groupingPath, action));
    }
    // should not be in exclude if not in basis
    if (!inBasis && inExclude) {
        gsrList.add(deleteGroupMemberByUuid(ownerUsername, exclude, userToDeleteUuid));
    }
    return gsrList;
}
Also used : GroupingsServiceResult(edu.hawaii.its.api.type.GroupingsServiceResult) ArrayList(java.util.ArrayList) Person(edu.hawaii.its.api.type.Person)

Example 17 with GroupingsServiceResult

use of edu.hawaii.its.api.type.GroupingsServiceResult in project uhgroupings by uhawaii-system-its-ti-iam.

the class GroupAttributeServiceImpl method changeGroupAttributeStatus.

// turns the attribute on or off in a group
public GroupingsServiceResult changeGroupAttributeStatus(String groupPath, String ownerUsername, String attributeName, boolean attributeOn) {
    GroupingsServiceResult gsr;
    String verb = "removed from ";
    if (attributeOn) {
        verb = "added to ";
    }
    String action = attributeName + " has been " + verb + groupPath + " by " + ownerUsername;
    if (mas.isOwner(groupPath, ownerUsername) || mas.isAdmin(ownerUsername)) {
        boolean hasAttribute = groupHasAttribute(groupPath, attributeName);
        if (attributeOn) {
            if (!hasAttribute) {
                assignGroupAttributes(attributeName, OPERATION_ASSIGN_ATTRIBUTE, groupPath);
                gsr = hs.makeGroupingsServiceResult(SUCCESS, action);
            } else {
                gsr = hs.makeGroupingsServiceResult(SUCCESS + ", " + attributeName + " already existed", action);
            }
        } else {
            if (hasAttribute) {
                assignGroupAttributes(attributeName, OPERATION_REMOVE_ATTRIBUTE, groupPath);
                gsr = hs.makeGroupingsServiceResult(SUCCESS, action);
            } else {
                gsr = hs.makeGroupingsServiceResult(SUCCESS + ", " + attributeName + " did not exist", action);
            }
        }
    } else {
        gsr = hs.makeGroupingsServiceResult(FAILURE + ", " + ownerUsername + "does not have permission to set " + attributeName + " because " + ownerUsername + " does not own " + groupPath, action);
    }
    return gsr;
}
Also used : GroupingsServiceResult(edu.hawaii.its.api.type.GroupingsServiceResult)

Example 18 with GroupingsServiceResult

use of edu.hawaii.its.api.type.GroupingsServiceResult in project uhgroupings by uhawaii-system-its-ti-iam.

the class GroupAttributeServiceImpl method changeOptOutStatus.

// turn the ability for users to opt-out of a grouping on or off
@Override
public List<GroupingsServiceResult> changeOptOutStatus(String groupingPath, String ownerUsername, boolean optOutOn) {
    List<GroupingsServiceResult> results = new ArrayList<>();
    if (mas.isOwner(groupingPath, ownerUsername) || mas.isAdmin(ownerUsername)) {
        results.add(assignGrouperPrivilege(EVERY_ENTITY, PRIVILEGE_OPT_IN, groupingPath + EXCLUDE, optOutOn));
        results.add(assignGrouperPrivilege(EVERY_ENTITY, PRIVILEGE_OPT_OUT, groupingPath + INCLUDE, optOutOn));
        results.add(changeGroupAttributeStatus(groupingPath, ownerUsername, OPT_OUT, optOutOn));
    } else {
        GroupingsServiceResult failure = hs.makeGroupingsServiceResult(FAILURE + ", " + ownerUsername + " does not own " + groupingPath, "change opt out status for " + groupingPath + " to " + optOutOn);
        results.add(failure);
    }
    return results;
}
Also used : GroupingsServiceResult(edu.hawaii.its.api.type.GroupingsServiceResult) ArrayList(java.util.ArrayList)

Example 19 with GroupingsServiceResult

use of edu.hawaii.its.api.type.GroupingsServiceResult in project uhgroupings by uhawaii-system-its-ti-iam.

the class GroupAttributeServiceImpl method changeOptInStatus.

// turn the ability for users to opt-in to a grouping on or off
@Override
public List<GroupingsServiceResult> changeOptInStatus(String groupingPath, String ownerUsername, boolean optInOn) {
    List<GroupingsServiceResult> results = new ArrayList<>();
    if (mas.isOwner(groupingPath, ownerUsername) || mas.isAdmin(ownerUsername)) {
        results.add(assignGrouperPrivilege(EVERY_ENTITY, PRIVILEGE_OPT_IN, groupingPath + INCLUDE, optInOn));
        results.add(assignGrouperPrivilege(EVERY_ENTITY, PRIVILEGE_OPT_OUT, groupingPath + EXCLUDE, optInOn));
        results.add(changeGroupAttributeStatus(groupingPath, ownerUsername, OPT_IN, optInOn));
    } else {
        GroupingsServiceResult failure = hs.makeGroupingsServiceResult(FAILURE + ", " + ownerUsername + " does not own " + groupingPath, "change opt in status for " + groupingPath + " to " + optInOn);
        results.add(failure);
    }
    return results;
}
Also used : GroupingsServiceResult(edu.hawaii.its.api.type.GroupingsServiceResult) ArrayList(java.util.ArrayList)

Example 20 with GroupingsServiceResult

use of edu.hawaii.its.api.type.GroupingsServiceResult in project uhgroupings by uhawaii-system-its-ti-iam.

the class GroupingsRestControllerTest method deleteAdminTest.

@Test
@WithMockUhUser(username = "admin")
public void deleteAdminTest() throws Exception {
    given(membershipService.deleteAdmin("admin", "newAdmin")).willReturn(new GroupingsServiceResult("SUCCESS", "delete admin"));
    mockMvc.perform(post("/api/groupings/newAdmin/deleteAdmin").with(csrf())).andExpect(status().isOk()).andExpect(jsonPath("resultCode").value("SUCCESS")).andExpect(jsonPath("action").value("delete admin"));
}
Also used : GroupingsServiceResult(edu.hawaii.its.api.type.GroupingsServiceResult) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) WithMockUhUser(edu.hawaii.its.groupings.controller.WithMockUhUser)

Aggregations

GroupingsServiceResult (edu.hawaii.its.api.type.GroupingsServiceResult)43 Test (org.junit.Test)32 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)32 GroupingsServiceResultException (edu.hawaii.its.api.type.GroupingsServiceResultException)15 WithMockUhUser (edu.hawaii.its.groupings.controller.WithMockUhUser)15 ArrayList (java.util.ArrayList)15 Grouping (edu.hawaii.its.api.type.Grouping)6 WsSubjectLookup (edu.internet2.middleware.grouperClient.ws.beans.WsSubjectLookup)4 Person (edu.hawaii.its.api.type.Person)3 WsAddMemberResults (edu.internet2.middleware.grouperClient.ws.beans.WsAddMemberResults)3 WsDeleteMemberResults (edu.internet2.middleware.grouperClient.ws.beans.WsDeleteMemberResults)2 WsGetAttributeAssignmentsResults (edu.internet2.middleware.grouperClient.ws.beans.WsGetAttributeAssignmentsResults)2 Group (edu.hawaii.its.api.type.Group)1 GroupingsHTTPException (edu.hawaii.its.api.type.GroupingsHTTPException)1 Membership (edu.hawaii.its.api.type.Membership)1 WsResultMeta (edu.internet2.middleware.grouperClient.ws.beans.WsResultMeta)1 WsStemLookup (edu.internet2.middleware.grouperClient.ws.beans.WsStemLookup)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1