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);
}
}
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());
}
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());
}
}
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;
}
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));
}
Aggregations