use of org.hisp.dhis.user.UserAuthorityGroup in project dhis2-core by dhis2.
the class ObjectBundleServiceUserTest method testCreateUserRoleWithDataSetProgramAssignment.
@Test
public void testCreateUserRoleWithDataSetProgramAssignment() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/userrole_program_dataset_assignment.json").getInputStream(), RenderFormat.JSON);
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.CREATE_AND_UPDATE);
params.setAtomicMode(AtomicMode.ALL);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
assertTrue(objectBundleValidationService.validate(bundle).getErrorReports().isEmpty());
objectBundleService.commit(bundle);
List<UserAuthorityGroup> userRoles = manager.getAll(UserAuthorityGroup.class);
assertEquals(1, userRoles.size());
UserAuthorityGroup userRole = userRoles.get(0);
assertNotNull(userRole);
assertEquals(1, userRole.getDataSets().size());
assertEquals(1, userRole.getPrograms().size());
}
use of org.hisp.dhis.user.UserAuthorityGroup in project dhis2-core by dhis2.
the class DefaultAdminUserPopulator method executeInTransaction.
@Override
public void executeInTransaction() {
// user.
if (userService.getUserCount() > 0) {
return;
}
// ---------------------------------------------------------------------
// Assumes no UserAuthorityGroup called "Superuser" in database
// ---------------------------------------------------------------------
String username = "admin";
String password = "district";
User user = new User();
user.setUid("M5zQapPyTZI");
user.setCode("admin");
user.setFirstName(username);
user.setSurname(username);
userService.addUser(user);
UserAuthorityGroup userAuthorityGroup = new UserAuthorityGroup();
userAuthorityGroup.setUid("yrB6vc5Ip3r");
userAuthorityGroup.setCode("Superuser");
userAuthorityGroup.setName("Superuser");
userAuthorityGroup.setDescription("Superuser");
userAuthorityGroup.setAuthorities(ALL_AUTHORITIES);
userService.addUserAuthorityGroup(userAuthorityGroup);
user.setUuid(UUID.fromString("6507f586-f154-4ec1-a25e-d7aa51de5216"));
user.setCode(username);
user.setUsername(username);
user.getUserAuthorityGroups().add(userAuthorityGroup);
userService.encodeAndSetPassword(user, password);
userService.addUser(user);
}
use of org.hisp.dhis.user.UserAuthorityGroup in project dhis2-core by dhis2.
the class DataApprovalServiceCategoryOptionGroupTest method mockUser.
// -------------------------------------------------------------------------
// Set up/tear down helper methods
// -------------------------------------------------------------------------
private MockCurrentUserService mockUser(String userName, OrganisationUnit orgUnit, String... auths) {
MockCurrentUserService mockCurrentUserService = new MockCurrentUserService(false, Sets.newHashSet(orgUnit), Sets.newHashSet(orgUnit), auths);
User user = mockCurrentUserService.getCurrentUser();
user.setFirstName("Test");
user.setSurname(userName);
user.setUsername(userName);
for (UserAuthorityGroup role : user.getUserAuthorityGroups()) {
// Arbitrary name
role.setName(CodeGenerator.generateUid());
userService.addUserAuthorityGroup(role);
}
userService.addUser(user);
return mockCurrentUserService;
}
use of org.hisp.dhis.user.UserAuthorityGroup in project dhis2-core by dhis2.
the class AclServiceTest method testUserBCanUpdateEventVisualizationWithAuthority.
@Test
void testUserBCanUpdateEventVisualizationWithAuthority() {
// Given
User userA = createUser('A');
manager.save(userA);
EventVisualization eventVisualization = new EventVisualization();
eventVisualization.setAutoFields();
eventVisualization.setName("FavA");
eventVisualization.setCreatedBy(userA);
eventVisualization.getSharing().setOwner(userA);
eventVisualization.setPublicAccess(AccessStringHelper.DEFAULT);
eventVisualization.setType(EventVisualizationType.COLUMN);
assertTrue(aclService.canUpdate(userA, eventVisualization));
manager.save(eventVisualization);
// Then
UserAuthorityGroup userAuthorityGroup = new UserAuthorityGroup();
userAuthorityGroup.setAutoFields();
userAuthorityGroup.setName("UR");
userAuthorityGroup.getAuthorities().add("F_EVENT_VISUALIZATION_PUBLIC_ADD");
manager.save(userAuthorityGroup);
User userB = createUser('B');
userB.getUserAuthorityGroups().add(userAuthorityGroup);
manager.save(userB);
eventVisualization.getSharing().addUserAccess(new UserAccess(userB, AccessStringHelper.FULL));
manager.update(eventVisualization);
assertTrue(aclService.canUpdate(userB, eventVisualization));
}
use of org.hisp.dhis.user.UserAuthorityGroup in project dhis2-core by dhis2.
the class AclServiceTest method testUserBCanUpdateVisualizationWithAuthority.
@Test
void testUserBCanUpdateVisualizationWithAuthority() {
User userA = createUser('A');
manager.save(userA);
Visualization visualization = new Visualization();
visualization.setAutoFields();
visualization.setName("FavA");
visualization.setCreatedBy(userA);
visualization.getSharing().setOwner(userA);
visualization.setPublicAccess(AccessStringHelper.DEFAULT);
visualization.setType(VisualizationType.COLUMN);
assertTrue(aclService.canUpdate(userA, visualization));
manager.save(visualization);
UserAuthorityGroup userAuthorityGroup = new UserAuthorityGroup();
userAuthorityGroup.setAutoFields();
userAuthorityGroup.setName("UR");
userAuthorityGroup.getAuthorities().add("F_VISUALIZATION_PUBLIC_ADD");
manager.save(userAuthorityGroup);
User userB = createUser('B');
userB.getUserAuthorityGroups().add(userAuthorityGroup);
manager.save(userB);
visualization.getSharing().addUserAccess(new UserAccess(userB, AccessStringHelper.FULL));
manager.update(visualization);
assertTrue(aclService.canUpdate(userB, visualization));
}
Aggregations