Skip to content

Commit

Permalink
Add application/topic admins to payload for detail pages
Browse files Browse the repository at this point in the history
Signed-off-by: montesm <montesm@objectcomputing.com>
  • Loading branch information
montesmoci committed Dec 4, 2023
1 parent e1500cc commit 0de4ce0
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,15 @@ public HttpResponse deleteById(Long actionIntervalId) {
}

public ActionIntervalDTO createDTO(ActionInterval actionInterval) {
List<String> admins = groupUserService.getAllTopicAdminsOfGroup(actionInterval.getPermissionsGroup().getId());
return new ActionIntervalDTO(
actionInterval.getId(),
actionInterval.getName(),
actionInterval.getPermissionsGroup().getId(),
actionInterval.getPermissionsGroup().getName(),
actionInterval.getStartDate(),
actionInterval.getEndDate());
actionInterval.getEndDate(),
admins);
}

private void checkExistenceAndAdminAuthorization(Optional<ActionInterval> actionIntervalOptional) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.time.Instant;
import java.util.List;

@Introspected
public class ActionIntervalDTO implements EntityDTO {
Expand All @@ -34,6 +35,7 @@ public class ActionIntervalDTO implements EntityDTO {
private String name;
private Long groupId;
private String groupName;
private List<String> admins;

@NotNull
@JsonFormat(shape = JsonFormat.Shape.STRING)
Expand All @@ -46,22 +48,14 @@ public class ActionIntervalDTO implements EntityDTO {
public ActionIntervalDTO() {
}

public ActionIntervalDTO(Long id, String name, Long groupId, String groupName, Instant startDate, Instant endDate) {
public ActionIntervalDTO(Long id, String name, Long groupId, String groupName, Instant startDate, Instant endDate, List<String> admins) {
this.id = id;
this.name = name;
this.groupId = groupId;
this.groupName = groupName;
this.startDate = startDate;
this.endDate = endDate;
}

public ActionIntervalDTO(ActionInterval actionInterval) {
this.id = actionInterval.getId();
this.name = actionInterval.getName();
this.groupId = actionInterval.getPermissionsGroup().getId();
this.groupName = actionInterval.getPermissionsGroup().getName();
this.startDate = actionInterval.getStartDate();
this.endDate = actionInterval.getEndDate();
this.admins = admins;
}

public Long getId() {
Expand Down Expand Up @@ -92,6 +86,14 @@ public String getGroupName() {
return groupName;
}

public List<String> getAdmins() {
return admins;
}

public void setAdmins(List<String> admins) {
this.admins = admins;
}

public void setGroupName(String groupName) {
this.groupName = groupName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.time.Instant;
import java.util.List;

@Introspected
public class ApplicationDTO implements EntityDTO {
Expand All @@ -42,6 +43,8 @@ public class ApplicationDTO implements EntityDTO {
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Instant dateUpdated;

private List<String> admins;

public ApplicationDTO() {
}

Expand Down Expand Up @@ -119,4 +122,12 @@ public Instant getDateUpdated() {
public void setDateUpdated(Instant dateUpdated) {
this.dateUpdated = dateUpdated;
}

public List<String> getAdmins() {
return admins;
}

public void setAdmins(List<String> admins) {
this.admins = admins;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ public HttpResponse show(Long id) {
throw new DPMException(ResponseStatusCodes.UNAUTHORIZED, HttpStatus.UNAUTHORIZED);
}
ApplicationDTO applicationDTO = new ApplicationDTO(application);
List<String> applicationAdmins = groupUserService.getAllApplicationAdminsOfGroup(application.getPermissionsGroup().getId());
applicationDTO.setAdmins(applicationAdmins);

return HttpResponse.ok(applicationDTO);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ public GrantDTO findById(Long grantId) {
}
}

return createDTO(grantOptional.get());
GrantDTO grantDTO = createDTO(grantOptional.get());
List<String> admins = groupUserService.getAllTopicAdminsOfGroup(grantOptional.get().getId());
grantDTO.setAdmins(admins);

return grantDTO;
}

public Publisher<HttpResponse<GrantDTO>> create(String grantToken, CreateGrantDTO createGrantDTO) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import io.micronaut.core.annotation.Introspected;
import io.unityfoundation.dds.permissions.manager.model.EntityDTO;

import java.util.List;

@Introspected
public class GrantDTO implements EntityDTO {
private final Long id;
Expand All @@ -27,6 +29,7 @@ public class GrantDTO implements EntityDTO {
private final String groupName;
private final Long durationInMilliseconds;
private final String durationMetadata;
private List<String> admins;

public GrantDTO(Long id, String name, Long applicationId, String applicationName, String applicationGroupName, Long groupId, String groupName, Long durationInMilliseconds, String durationMetadata) {
this.id = id;
Expand Down Expand Up @@ -77,4 +80,12 @@ public Long getDurationInMilliseconds() {
public String getDurationMetadata() {
return durationMetadata;
}

public List<String> getAdmins() {
return admins;
}

public void setAdmins(List<String> admins) {
this.admins = admins;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,14 @@ public HttpResponse deleteById(Long grantDurationId) {
}

public GrantDurationDTO createDTO(GrantDuration grantDuration) {
return new GrantDurationDTO(
grantDuration.getId(),
List<String> admins = groupUserService.getAllTopicAdminsOfGroup(grantDuration.getPermissionsGroup().getId());
return new GrantDurationDTO(grantDuration.getId(),
grantDuration.getName(),
grantDuration.getPermissionsGroup().getId(),
grantDuration.getPermissionsGroup().getName(),
grantDuration.getDurationInMilliseconds(),
grantDuration.getDurationMetadata()
);
grantDuration.getDurationMetadata(),
admins);
}

private void checkExistenceAndAdminAuthorization(Optional<GrantDuration> grantDurationOptional) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.List;

@Introspected
public class GrantDurationDTO implements EntityDTO {
Expand All @@ -37,16 +38,19 @@ public class GrantDurationDTO implements EntityDTO {

private String durationMetadata;

private List<String> admins;

public GrantDurationDTO() {
}

public GrantDurationDTO(Long id, String name, Long groupId, String groupName, Long durationInMilliseconds, String durationMetadata) {
public GrantDurationDTO(Long id, String name, Long groupId, String groupName, Long durationInMilliseconds, String durationMetadata, List<String> admins) {
this.id = id;
this.name = name;
this.groupId = groupId;
this.groupName = groupName;
this.durationInMilliseconds = durationInMilliseconds;
this.durationMetadata = durationMetadata;
this.admins = admins;
}

public Long getId() {
Expand Down Expand Up @@ -96,4 +100,12 @@ public String getDurationMetadata() {
public void setDurationMetadata(String durationMetadata) {
this.durationMetadata = durationMetadata;
}

public List<String> getAdmins() {
return admins;
}

public void setAdmins(List<String> admins) {
this.admins = admins;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,7 @@ public interface GroupUserRepository extends PageableRepository<GroupUser, Long>
Page<Group> findPermissionsGroupByPermissionsUserEqualsAndPermissionsGroupNameContainsIgnoreCaseAndGroupAdminTrue(User permissionsUser, String group, Pageable pageable);
Page<Group> findPermissionsGroupByPermissionsUserEqualsAndPermissionsGroupNameContainsIgnoreCaseAndTopicAdminTrue(User permissionsUser, String group, Pageable pageable);
Page<Group> findPermissionsGroupByPermissionsUserEqualsAndPermissionsGroupNameContainsIgnoreCaseAndApplicationAdminTrue(User permissionsUser, String group, Pageable pageable);

List<User> findPermissionsUserByPermissionsGroupIdAndTopicAdminTrue(Long groupId);
List<User> findPermissionsUserByPermissionsGroupIdAndApplicationAdminTrue(Long groupId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -334,4 +334,14 @@ public HttpResponse checkUserExists(Long id) {
}
throw new DPMException(ResponseStatusCodes.USER_NOT_FOUND, HttpStatus.NOT_FOUND);
}

public List<String> getAllTopicAdminsOfGroup(Long groupId) {
return groupUserRepository.findPermissionsUserByPermissionsGroupIdAndTopicAdminTrue(groupId).stream()
.map(User::getEmail).collect(Collectors.toList());
}

public List<String> getAllApplicationAdminsOfGroup(Long groupId) {
return groupUserRepository.findPermissionsUserByPermissionsGroupIdAndApplicationAdminTrue(groupId).stream()
.map(User::getEmail).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.time.Instant;
import java.util.List;

@Introspected
public class TopicDTO implements EntityDTO {
Expand All @@ -38,6 +39,7 @@ public class TopicDTO implements EntityDTO {
private Long group;
private String groupName;
private String canonicalName;
private List<String> admins;

@JsonFormat(shape = JsonFormat.Shape.STRING)
private Instant dateCreated;
Expand Down Expand Up @@ -141,4 +143,12 @@ public Instant getDateUpdated() {
public void setDateUpdated(Instant dateUpdated) {
this.dateUpdated = dateUpdated;
}

public List<String> getAdmins() {
return admins;
}

public void setAdmins(List<String> admins) {
this.admins = admins;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ public HttpResponse show(Long id) {
throw new DPMException(ResponseStatusCodes.UNAUTHORIZED, HttpStatus.UNAUTHORIZED);
}
TopicDTO topicResponseDTO = new TopicDTO(topic);
List<String> adminEmails = groupUserService.getAllTopicAdminsOfGroup(topic.getPermissionsGroup().getId());
topicResponseDTO.setAdmins(adminEmails);

return HttpResponse.ok(topicResponseDTO);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ public TopicSetDTO findById(Long topicSetId) {

checkExistenceAndAuthorization(topicSetOptional);

return createDTO(topicSetOptional.get());
TopicSetDTO topicSetDTO = createDTO(topicSetOptional.get());
List<String> admins = groupUserService.getAllTopicAdminsOfGroup(topicSetOptional.get().getId());
topicSetDTO.setAdmins(admins);

return topicSetDTO;
}

// POST /topic-set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.unityfoundation.dds.permissions.manager.model.EntityDTO;

import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.Set;

Expand All @@ -29,6 +30,7 @@ public class TopicSetDTO implements EntityDTO {
private Long groupId;
private String groupName;
private Set<Map<Long, String>> topics;
private List<String> admins;

@JsonFormat(shape = JsonFormat.Shape.STRING)
private Instant dateCreated;
Expand Down Expand Up @@ -86,6 +88,14 @@ public void setTopics(Set<Map<Long, String>> topics) {
this.topics = topics;
}

public List<String> getAdmins() {
return admins;
}

public void setAdmins(List<String> admins) {
this.admins = admins;
}

public Instant getDateCreated() {
return dateCreated;
}
Expand Down

0 comments on commit 0de4ce0

Please sign in to comment.