Skip to content

Commit

Permalink
Fixes #239
Browse files Browse the repository at this point in the history
  • Loading branch information
oharsta committed Oct 18, 2024
1 parent 0ea0505 commit f08020a
Show file tree
Hide file tree
Showing 7 changed files with 293 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ NOTES.txt
private_key_pkcs8.pem
JSON.md
spieldata
teams-api-calls.md
19 changes: 1 addition & 18 deletions server/src/main/java/access/api/InvitationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,24 +124,7 @@ public ResponseEntity<Void> deleteInvitation(@PathVariable("id") Long id,
@PutMapping("/{id}")
public ResponseEntity<Map<String, Integer>> resendInvitation(@PathVariable("id") Long id,
@Parameter(hidden = true) User user) {
LOG.debug(String.format("/resendInvitation/%s by user %s", id, user.getEduPersonPrincipalName()));
//We need to assert validations on the roles soo we need to load them
Invitation invitation = invitationRepository.findById(id).orElseThrow(() -> new NotFoundException("Invitation not found"));
List<Role> requestedRoles = invitation.getRoles().stream()
.map(InvitationRole::getRole).toList();
Authority intendedAuthority = invitation.getIntendedAuthority();
UserPermissions.assertValidInvitation(user, intendedAuthority, requestedRoles);
List<GroupedProviders> groupedProviders = manage.getGroupedProviders(requestedRoles);

mailBox.sendInviteMail(user, invitation, groupedProviders, invitation.getLanguage());
if (invitation.getExpiryDate().isBefore(Instant.now())) {
invitation.setExpiryDate(Instant.now().plus(Period.ofDays(14)));
invitationRepository.save(invitation);
}

AccessLogger.invitation(LOG, Event.Resend, invitation);

return Results.createResult();
return this.invitationOperations.resendInvitation(id, user, null);
}

@GetMapping("public")
Expand Down
37 changes: 37 additions & 0 deletions server/src/main/java/access/api/InvitationOperations.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import access.logging.Event;
import access.mail.MailBox;
import access.model.*;
import access.repository.InvitationRepository;
import access.security.RemoteUser;
import access.security.RemoteUserPermissions;
import access.security.UserPermissions;
Expand All @@ -18,9 +19,11 @@
import org.springframework.util.CollectionUtils;

import java.time.Instant;
import java.time.Period;
import java.time.temporal.ChronoUnit;
import java.util.Comparator;
import java.util.List;
import java.util.Map;

import static java.util.stream.Collectors.toSet;

Expand Down Expand Up @@ -106,4 +109,38 @@ public ResponseEntity<InvitationResponse> sendInvitation(InvitationRequest invit
return ResponseEntity.status(HttpStatus.CREATED).body(new InvitationResponse(HttpStatus.CREATED.value(), recipientInvitationURLs));
}

public ResponseEntity<Map<String, Integer>> resendInvitation(Long id,
User user,
RemoteUser remoteUser) {
String name = user != null ? user.getEduPersonPrincipalName() : remoteUser.getDisplayName();

LOG.debug(String.format("/resendInvitation/%s by user %s", id, name));

//We need to assert validations on the roles soo we need to load them
InvitationRepository invitationRepository = this.invitationResource.getInvitationRepository();

Invitation invitation = invitationRepository.findById(id).orElseThrow(() -> new NotFoundException("Invitation not found"));
List<Role> requestedRoles = invitation.getRoles().stream()
.map(InvitationRole::getRole).toList();
Authority intendedAuthority = invitation.getIntendedAuthority();
if (user != null) {
UserPermissions.assertValidInvitation(user, intendedAuthority, requestedRoles);
} else {
RemoteUserPermissions.assertApplicationAccess(remoteUser, requestedRoles);
}

List<GroupedProviders> groupedProviders = this.invitationResource.getManage().getGroupedProviders(requestedRoles);
Provisionable provisionable = user != null ? user : remoteUser;

this.invitationResource.getMailBox().sendInviteMail(provisionable, invitation, groupedProviders, invitation.getLanguage());
if (invitation.getExpiryDate().isBefore(Instant.now())) {
invitation.setExpiryDate(Instant.now().plus(Period.ofDays(14)));
invitationRepository.save(invitation);
}

AccessLogger.invitation(LOG, Event.Resend, invitation);

return Results.createResult();
}

}
2 changes: 1 addition & 1 deletion server/src/main/java/access/api/RoleController.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public RoleController(Config config,
public ResponseEntity<List<Role>> rolesByApplication(@Parameter(hidden = true) User user) {
LOG.debug(String.format("/roles for user %s", user.getEduPersonPrincipalName()));

if (user.isSuperUser() && !config.isRoleSearchRequired()) {
if (user.isSuperUser()) {
return ResponseEntity.ok(manage.addManageMetaData(roleRepository.findAll()));
}
UserPermissions.assertAuthority(user, Authority.INSTITUTION_ADMIN);
Expand Down
Loading

0 comments on commit f08020a

Please sign in to comment.