Search in sources :

Example 1 with CheckIn

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);
}
Also used : PermissionException(com.objectcomputing.checkins.exceptions.PermissionException) MemberProfile(com.objectcomputing.checkins.services.memberprofile.MemberProfile) CheckIn(com.objectcomputing.checkins.services.checkins.CheckIn) UUID(java.util.UUID)

Example 2 with CheckIn

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"));
}
Also used : Role(com.objectcomputing.checkins.services.role.Role) MemberProfile(com.objectcomputing.checkins.services.memberprofile.MemberProfile) CheckIn(com.objectcomputing.checkins.services.checkins.CheckIn) Test(org.junit.jupiter.api.Test)

Example 3 with CheckIn

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());
}
Also used : Role(com.objectcomputing.checkins.services.role.Role) MemberProfile(com.objectcomputing.checkins.services.memberprofile.MemberProfile) CheckIn(com.objectcomputing.checkins.services.checkins.CheckIn) Test(org.junit.jupiter.api.Test)

Example 4 with CheckIn

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"));
}
Also used : Role(com.objectcomputing.checkins.services.role.Role) MemberProfile(com.objectcomputing.checkins.services.memberprofile.MemberProfile) CheckIn(com.objectcomputing.checkins.services.checkins.CheckIn) Test(org.junit.jupiter.api.Test)

Example 5 with CheckIn

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());
}
Also used : Role(com.objectcomputing.checkins.services.role.Role) MemberProfile(com.objectcomputing.checkins.services.memberprofile.MemberProfile) CheckIn(com.objectcomputing.checkins.services.checkins.CheckIn) Test(org.junit.jupiter.api.Test)

Aggregations

CheckIn (com.objectcomputing.checkins.services.checkins.CheckIn)144 MemberProfile (com.objectcomputing.checkins.services.memberprofile.MemberProfile)141 Test (org.junit.jupiter.api.Test)127 HttpClientResponseException (io.micronaut.http.client.exceptions.HttpClientResponseException)59 JsonNode (com.fasterxml.jackson.databind.JsonNode)55 Role (com.objectcomputing.checkins.services.role.Role)45 UUID (java.util.UUID)15 Map (java.util.Map)9 PermissionException (com.objectcomputing.checkins.exceptions.PermissionException)6 Drive (com.google.api.services.drive.Drive)3 NotFoundException (com.objectcomputing.checkins.exceptions.NotFoundException)3 CheckinDocument (com.objectcomputing.checkins.services.checkindocument.CheckinDocument)3 MicronautTest (io.micronaut.test.annotation.MicronautTest)3 File (com.google.api.services.drive.model.File)2 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)1 InputStreamContent (com.google.api.client.http.InputStreamContent)1 FileList (com.google.api.services.drive.model.FileList)1 BadArgException (com.objectcomputing.checkins.exceptions.BadArgException)1 java.io (java.io)1