Search in sources :

Example 6 with Feature

use of se.inera.intyg.infra.security.common.model.Feature in project webcert by sklintyg.

the class UserApiController method updateFeatures.

private void updateFeatures(boolean active, String name, Map<String, Feature> features) {
    if (active) {
        Feature feature = new Feature();
        feature.setName(name);
        feature.setGlobal(true);
        features.put(name, feature);
    } else {
        features.remove(name);
    }
}
Also used : Feature(se.inera.intyg.infra.security.common.model.Feature)

Example 7 with Feature

use of se.inera.intyg.infra.security.common.model.Feature in project webcert by sklintyg.

the class SignaturServiceImplTest method serverSignatureSuccessUniqueIntyg.

@Test
public void serverSignatureSuccessUniqueIntyg() {
    Feature f = new Feature();
    f.setIntygstyper(ImmutableList.of(INTYG_TYPE));
    f.setGlobal(true);
    user.getFeatures().put(AuthoritiesConstants.FEATURE_UNIKT_INTYG, f);
    when(mockUtkastRepository.findOne(INTYG_ID)).thenReturn(completedUtkast);
    when(mockUtkastRepository.save(any(Utkast.class))).thenReturn(completedUtkast);
    when(mockUtkastRepository.findAllByPatientPersonnummerAndIntygsTypIn(any(String.class), anySet())).thenReturn(Collections.emptyList());
    SignaturTicket signatureTicket = intygSignatureService.serverSignature(INTYG_ID, completedUtkast.getVersion());
    verify(intygService).storeIntyg(completedUtkast);
    verify(notificationService).sendNotificationForDraftSigned(any(Utkast.class));
    verify(logService).logSignIntyg(any(LogRequest.class));
    assertNotNull(signatureTicket);
    assertNotNull(completedUtkast.getSignatur());
    assertEquals(UtkastStatus.SIGNED, completedUtkast.getStatus());
}
Also used : LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Feature(se.inera.intyg.infra.security.common.model.Feature) SignaturTicket(se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket) Test(org.junit.Test)

Example 8 with Feature

use of se.inera.intyg.infra.security.common.model.Feature in project webcert by sklintyg.

the class SignaturServiceImplTest method serverSignatureFailureUniqueIntyg.

@Test
public void serverSignatureFailureUniqueIntyg() {
    Feature f = new Feature();
    f.setIntygstyper(ImmutableList.of(INTYG_TYPE));
    f.setGlobal(true);
    user.getFeatures().put(AuthoritiesConstants.FEATURE_UNIKT_INTYG, f);
    when(mockUtkastRepository.findOne(INTYG_ID)).thenReturn(completedUtkast);
    Utkast otherUtkast = createUtkast("otherId", 1L, INTYG_TYPE, UtkastStatus.SIGNED, "", null, "otherEnhet", PERSON_ID);
    otherUtkast.setSignatur(new Signatur());
    when(mockUtkastRepository.findAllByPatientPersonnummerAndIntygsTypIn(any(String.class), anySet())).thenReturn(ImmutableList.of(otherUtkast));
    try {
        intygSignatureService.serverSignature(INTYG_ID, completedUtkast.getVersion());
    } catch (WebCertServiceException e) {
        assertEquals(WebCertServiceErrorCodeEnum.INVALID_STATE_INTYG_EXISTS, e.getErrorCode());
    }
}
Also used : Signatur(se.inera.intyg.webcert.persistence.utkast.model.Signatur) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Feature(se.inera.intyg.infra.security.common.model.Feature) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Test(org.junit.Test)

Example 9 with Feature

use of se.inera.intyg.infra.security.common.model.Feature in project webcert by sklintyg.

the class PageControllerTest method createMockUser.

private WebCertUser createMockUser(boolean doctor, String... features) {
    Role role = AUTHORITIES_RESOLVER.getRole(AuthoritiesConstants.ROLE_LAKARE);
    if (!doctor) {
        role = AUTHORITIES_RESOLVER.getRole(AuthoritiesConstants.ROLE_ADMIN);
    }
    WebCertUser user = new WebCertUser();
    user.setRoles(AuthoritiesResolverUtil.toMap(role));
    user.setAuthorities(AuthoritiesResolverUtil.toMap(role.getPrivileges(), Privilege::getName));
    user.setVardgivare(Collections.singletonList(createMockVardgivare()));
    user.setFeatures(Stream.of(features).collect(Collectors.toMap(Function.identity(), s -> {
        Feature feature = new Feature();
        feature.setName(s);
        feature.setGlobal(true);
        feature.setIntygstyper(Collections.singletonList(INTYG_TYP_FK7263));
        return feature;
    })));
    return user;
}
Also used : Role(se.inera.intyg.infra.security.common.model.Role) Feature(se.inera.intyg.infra.security.common.model.Feature) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 10 with Feature

use of se.inera.intyg.infra.security.common.model.Feature in project webcert by sklintyg.

the class UserApiControllerTest method testUserFeaturesDisableDisabled.

@Test
public void testUserFeaturesDisableDisabled() {
    // Given
    final WebUserFeaturesRequest webUserFeaturesRequest = new WebUserFeaturesRequest();
    webUserFeaturesRequest.setJsLoggning(false);
    final HashMap<String, Feature> features = new HashMap<>();
    when(webCertUser.getFeatures()).thenReturn(features);
    // When
    userApiController.userFeatures(webUserFeaturesRequest);
    // Then
    Mockito.verify(webCertUser, times(1)).setFeatures(captor.capture());
    assertFalse(captor.getValue().containsKey(AuthoritiesConstants.FEATURE_JS_LOGGNING));
}
Also used : WebUserFeaturesRequest(se.inera.intyg.webcert.web.web.controller.api.dto.WebUserFeaturesRequest) HashMap(java.util.HashMap) Feature(se.inera.intyg.infra.security.common.model.Feature) Test(org.junit.Test)

Aggregations

Feature (se.inera.intyg.infra.security.common.model.Feature)25 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)13 Test (org.junit.Test)10 HashMap (java.util.HashMap)6 WebUserFeaturesRequest (se.inera.intyg.webcert.web.web.controller.api.dto.WebUserFeaturesRequest)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Privilege (se.inera.intyg.infra.security.common.model.Privilege)2 RequestOrigin (se.inera.intyg.infra.security.common.model.RequestOrigin)2 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)2 Consumes (javax.ws.rs.Consumes)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Vardenhet (se.inera.intyg.infra.integration.hsa.model.Vardenhet)1 Vardgivare (se.inera.intyg.infra.integration.hsa.model.Vardgivare)1 Role (se.inera.intyg.infra.security.common.model.Role)1 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)1 Signatur (se.inera.intyg.webcert.persistence.utkast.model.Signatur)1 LogRequest (se.inera.intyg.webcert.web.service.log.dto.LogRequest)1 SignaturTicket (se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket)1