Skip to content

Commit

Permalink
SHIBUI-2393/2493
Browse files Browse the repository at this point in the history
fixed issue when changing dynamic registration group
  • Loading branch information
chasegawa committed Dec 6, 2022
1 parent cd4594b commit d7cd6fb
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import edu.internet2.tier.shibboleth.admin.ui.security.exception.InvalidGroupRegexException;
import edu.internet2.tier.shibboleth.admin.ui.security.model.Group;
import edu.internet2.tier.shibboleth.admin.ui.security.service.IGroupService;
import edu.internet2.tier.shibboleth.admin.ui.service.DynamicRegistrationService;
import edu.internet2.tier.shibboleth.admin.ui.service.EntityDescriptorService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.tags.Tags;
Expand Down Expand Up @@ -33,6 +34,9 @@ public class GroupController {
@Autowired
private EntityDescriptorService entityDescriptorService;

@Autowired
private DynamicRegistrationService dynamicRegistrationService;

@Secured("ROLE_ADMIN")
@PostMapping
@Transactional
Expand Down Expand Up @@ -71,6 +75,7 @@ public ResponseEntity<?> getOne(@PathVariable String resourceId) throws Persiste
public ResponseEntity<?> update(@RequestBody Group group) throws PersistentEntityNotFound, InvalidGroupRegexException {
Group result = groupService.updateGroup(group);
entityDescriptorService.checkApprovalStatusOfEntitiesForGroup(result);
dynamicRegistrationService.checkApprovalStatusOfEntitiesForGroup(result);
return ResponseEntity.ok(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
public interface DynamicRegistrationInfoRepository extends JpaRepository<DynamicRegistrationInfo, String> {
List<DynamicRegistrationInfo> findAllByIdOfOwner(String idOfOwner);

@Query(value="SELECT dri.resourceId FROM DynamicRegistrationInfo dri WHERE dri.idOfOwner = :groupId AND dri.enabled = false")
List<String> findAllResourceIdsByIdOfOwnerAndNotEnabled(@Param("groupId") String groupId);

DynamicRegistrationInfo findByResourceId(String id);

@Query(value = "SELECT dri FROM DynamicRegistrationInfo dri " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import edu.internet2.tier.shibboleth.admin.ui.exception.ObjectIdExistsException;
import edu.internet2.tier.shibboleth.admin.ui.exception.PersistentEntityNotFound;
import edu.internet2.tier.shibboleth.admin.ui.exception.UnsupportedShibUiOperationException;
import edu.internet2.tier.shibboleth.admin.ui.security.model.Group;
import org.springframework.http.HttpStatus;

import java.util.List;
Expand All @@ -14,6 +15,8 @@ public interface DynamicRegistrationService {
DynamicRegistrationRepresentation approveDynamicRegistration(String resourceId, boolean status)
throws PersistentEntityNotFound, ForbiddenException;

void checkApprovalStatusOfEntitiesForGroup(Group result);

DynamicRegistrationRepresentation createNew(DynamicRegistrationRepresentation dynRegRepresentation) throws ObjectIdExistsException,
MissingRequiredFieldsException;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.internet2.tier.shibboleth.admin.ui.service;

import edu.internet2.tier.shibboleth.admin.ui.domain.EntityDescriptor;
import edu.internet2.tier.shibboleth.admin.ui.domain.frontend.DynamicRegistrationRepresentation;
import edu.internet2.tier.shibboleth.admin.ui.domain.oidc.DynamicRegistrationInfo;
import edu.internet2.tier.shibboleth.admin.ui.exception.ForbiddenException;
Expand Down Expand Up @@ -237,4 +238,18 @@ public DynamicRegistrationRepresentation updateGroupForDynamicRegistration(Strin
DynamicRegistrationInfo savedEntity = repository.save(existingDri);
return new DynamicRegistrationRepresentation(savedEntity);
}

/**
* Update the approval status of entities that were in some approval state but the group approvers were added/removed.
*/
@Override
public void checkApprovalStatusOfEntitiesForGroup(Group group) {
repository.findAllResourceIdsByIdOfOwnerAndNotEnabled(group.getResourceId()).forEach(id -> {
DynamicRegistrationInfo dri = repository.findByResourceId(id);
int approvedCount = dri.approvedCount(); // total number of approvals so far
List<Approvers> theApprovers = groupService.find(dri.getIdOfOwner()).getApproversList();
dri.setApproved(approvedCount >= theApprovers.size());
dri = repository.save(dri);
});
}
}

0 comments on commit d7cd6fb

Please sign in to comment.