use of com.objectcomputing.checkins.services.checkins.CheckIn in project check-ins by objectcomputing.
the class PrivateNoteServicesImpl method save.
@Override
public PrivateNote save(@NotNull PrivateNote privateNote) {
MemberProfile currentUser = currentUserServices.getCurrentUser();
Boolean isAdmin = currentUserServices.isAdmin();
Boolean isPdl = currentUserServices.hasRole(RoleType.PDL);
final UUID checkinId = privateNote.getCheckinid();
final UUID createdById = privateNote.getCreatedbyid();
CheckIn checkinRecord = checkinServices.read(checkinId);
Boolean isCompleted = checkinRecord != null ? checkinRecord.isCompleted() : false;
validate(privateNote.getId() != null, "Found unexpected id %s for private note", privateNote.getId());
validate(checkinId == null || createdById == null, "Invalid private note %s", privateNote);
validate(checkinRecord == null, "Checkin doesn't exits for given checkin Id");
validate(memberProfileServices.getById(createdById) == null, "Member %s doesn't exist", createdById);
if (!isAdmin) {
if (!checkinServices.accessGranted(checkinRecord.getId(), currentUser.getId()) || isCompleted) {
throw new PermissionException("User is unauthorized to do this operation");
}
if (currentUser.getId().equals(checkinRecord.getTeamMemberId())) {
throw new PermissionException("User is unauthorized to do this operation");
}
}
return privateNoteRepository.save(privateNote);
}
use of com.objectcomputing.checkins.services.checkins.CheckIn in project check-ins by objectcomputing.
the class CheckinNoteControllerTest method testCreateCheckinNoteByMember.
@Test
void testCreateCheckinNoteByMember() {
MemberProfile memberProfile = createADefaultMemberProfile();
MemberProfile memberProfileForPDL = createADefaultMemberProfileForPdl(memberProfile);
Role role = createAndAssignRole(RoleType.MEMBER, memberProfile);
CheckIn checkIn = createADefaultCheckIn(memberProfile, memberProfileForPDL);
CheckinNoteCreateDTO checkinNoteCreateDTO = new CheckinNoteCreateDTO();
checkinNoteCreateDTO.setCheckinid(checkIn.getId());
checkinNoteCreateDTO.setCreatedbyid(memberProfileForPDL.getId());
checkinNoteCreateDTO.setDescription("test");
final HttpRequest<CheckinNoteCreateDTO> request = HttpRequest.POST("", checkinNoteCreateDTO).basicAuth(memberProfile.getWorkEmail(), role.getRole());
final HttpResponse<CheckinNote> response = client.toBlocking().exchange(request, CheckinNote.class);
CheckinNote checkinNote = response.body();
assertNotNull(checkinNote);
assertEquals(HttpStatus.CREATED, response.getStatus());
assertEquals(checkinNoteCreateDTO.getCheckinid(), checkinNote.getCheckinid());
assertEquals(checkinNoteCreateDTO.getCreatedbyid(), checkinNote.getCreatedbyid());
assertEquals(String.format("%s/%s", request.getPath(), checkinNote.getId()), response.getHeaders().get("location"));
}
use of com.objectcomputing.checkins.services.checkins.CheckIn in project check-ins by objectcomputing.
the class CheckinNoteControllerTest method testFindCheckinNoteByCheckinIdForAdmin.
@Test
void testFindCheckinNoteByCheckinIdForAdmin() {
MemberProfile memberProfile = createADefaultMemberProfile();
MemberProfile memberProfileForPDL = createADefaultMemberProfileForPdl(memberProfile);
MemberProfile memberProfileForUnrelatedUser = createAnUnrelatedUser();
Role role = createAndAssignRole(RoleType.ADMIN, memberProfileForUnrelatedUser);
CheckIn checkIn = createADefaultCheckIn(memberProfile, memberProfileForPDL);
CheckinNote checkinNote = createADefaultCheckInNote(checkIn, memberProfile);
final HttpRequest<?> request = HttpRequest.GET(String.format("/?checkinid=%s", checkinNote.getCheckinid())).basicAuth(memberProfileForUnrelatedUser.getWorkEmail(), role.getRole());
final HttpResponse<Set<CheckinNote>> response = client.toBlocking().exchange(request, Argument.setOf(CheckinNote.class));
assertEquals(Set.of(checkinNote), response.body());
assertEquals(HttpStatus.OK, response.getStatus());
}
use of com.objectcomputing.checkins.services.checkins.CheckIn in project check-ins by objectcomputing.
the class CheckinNoteControllerTest method testCreateCheckinNoteByPdl.
@Test
void testCreateCheckinNoteByPdl() {
MemberProfile memberProfileOfPDL = createADefaultMemberProfile();
MemberProfile memberProfileOfUser = createADefaultMemberProfileForPdl(memberProfileOfPDL);
Role role = createAndAssignRole(RoleType.PDL, memberProfileOfUser);
CheckIn checkIn = createADefaultCheckIn(memberProfileOfPDL, memberProfileOfUser);
CheckinNoteCreateDTO checkinNoteCreateDTO = new CheckinNoteCreateDTO();
checkinNoteCreateDTO.setCheckinid(checkIn.getId());
checkinNoteCreateDTO.setCreatedbyid(memberProfileOfPDL.getId());
checkinNoteCreateDTO.setDescription("test");
final HttpRequest<CheckinNoteCreateDTO> request = HttpRequest.POST("", checkinNoteCreateDTO).basicAuth(memberProfileOfPDL.getWorkEmail(), role.getRole());
final HttpResponse<CheckinNote> response = client.toBlocking().exchange(request, CheckinNote.class);
CheckinNote checkinNote = response.body();
assertNotNull(checkinNote);
assertEquals(HttpStatus.CREATED, response.getStatus());
assertEquals(checkinNoteCreateDTO.getCheckinid(), checkinNote.getCheckinid());
assertEquals(checkinNoteCreateDTO.getCreatedbyid(), checkinNote.getCreatedbyid());
assertEquals(String.format("%s/%s", request.getPath(), checkinNote.getId()), response.getHeaders().get("location"));
}
use of com.objectcomputing.checkins.services.checkins.CheckIn in project check-ins by objectcomputing.
the class CheckinNoteControllerTest method testFindCheckinNoteByCreatedByIdByMember.
@Test
void testFindCheckinNoteByCreatedByIdByMember() {
MemberProfile memberProfile = createADefaultMemberProfile();
MemberProfile memberProfileForPDL = createADefaultMemberProfileForPdl(memberProfile);
Role role = createAndAssignRole(RoleType.PDL, memberProfileForPDL);
CheckIn checkIn = createADefaultCheckIn(memberProfile, memberProfileForPDL);
CheckinNote checkinNote = createADefaultCheckInNote(checkIn, memberProfileForPDL);
final HttpRequest<?> request = HttpRequest.GET(String.format("/?createdbyid=%s", checkinNote.getCreatedbyid())).basicAuth(memberProfileForPDL.getWorkEmail(), role.getRole());
final HttpResponse<Set<CheckinNote>> response = client.toBlocking().exchange(request, Argument.setOf(CheckinNote.class));
assertEquals(Set.of(checkinNote), response.body());
assertEquals(HttpStatus.OK, response.getStatus());
}
Aggregations