use of io.lumeer.api.model.Group in project engine by Lumeer.
the class GroupServiceIT method testUpdateUser.
@Test
public void testUpdateUser() {
groupDao.createGroup(new Group(GROUP1));
Group storedGroup = getGroup(GROUP1);
assertThat(storedGroup).isNotNull();
Group updateGroup = new Group(GROUP2);
Entity entity = Entity.json(updateGroup);
Response response = client.target(getPath(organization.getCode())).path(storedGroup.getId()).request(MediaType.APPLICATION_JSON).buildPut(entity).invoke();
assertThat(response).isNotNull();
assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
storedGroup = getGroup(GROUP1);
assertThat(storedGroup).isNull();
storedGroup = getGroup(GROUP2);
assertThat(storedGroup).isNotNull();
}
use of io.lumeer.api.model.Group in project engine by Lumeer.
the class PermissionsCheckerTest method preparePermissionsChecker.
@Before
public void preparePermissionsChecker() {
User user = Mockito.mock(User.class);
Mockito.when(user.getId()).thenReturn(USER);
Mockito.when(user.getOrganizations()).thenReturn(Collections.singleton("LMR"));
AuthenticatedUser authenticatedUser = Mockito.mock(AuthenticatedUser.class);
Mockito.when(authenticatedUser.getCurrentUserId()).thenReturn(USER);
Mockito.when(authenticatedUser.getUserEmail()).thenReturn(USER);
Organization organization = Mockito.mock(Organization.class);
preparePermissions(organization, Collections.singleton(new Role(RoleType.Read)), Collections.emptySet());
Mockito.when(organization.getId()).thenReturn("LMR");
Project project = Mockito.mock(Project.class);
preparePermissions(project, Collections.singleton(new Role(RoleType.Read)), Collections.emptySet());
Mockito.when(project.getId()).thenReturn("LMR");
WorkspaceKeeper workspaceKeeper = Mockito.mock(WorkspaceKeeper.class);
Mockito.when(workspaceKeeper.getOrganization()).thenReturn(Optional.of(organization));
Mockito.when(workspaceKeeper.getProject()).thenReturn(Optional.of(project));
CollectionDao collectionDao = Mockito.mock(CollectionDao.class);
LinkTypeDao linkTypeDao = Mockito.mock(LinkTypeDao.class);
ViewDao viewDao = Mockito.mock(ViewDao.class);
UserDao userDao = Mockito.mock(UserDao.class);
Mockito.when(userDao.getUserById(USER)).thenReturn(user);
GroupDao groupDao = Mockito.mock(GroupDao.class);
Group group = Mockito.mock(Group.class);
Mockito.when(group.getId()).thenReturn(GROUP);
Mockito.when(group.getUsers()).thenReturn(Collections.singletonList(USER));
Mockito.when(groupDao.getAllGroups("LMR")).thenReturn(Collections.singletonList(group));
FavoriteItemDao favoriteItemDao = Mockito.mock(FavoriteItemDao.class);
DocumentDao documentDao = Mockito.mock(DocumentDao.class);
permissionsChecker = new PermissionsChecker(authenticatedUser, workspaceKeeper, userDao, groupDao, collectionDao, viewDao, linkTypeDao, favoriteItemDao, documentDao);
permissionsChecker.init();
}
use of io.lumeer.api.model.Group in project engine by Lumeer.
the class GroupFacade method updateGroup.
public Group updateGroup(String groupId, Group group) {
permissionsChecker.checkGroupsHandle();
checkPermissions(RoleType.UserConfig);
Group storedGroup = groupDao.getGroup(groupId);
if (!storedGroup.getName().equals(group.getName())) {
checkGroupName(group.getName());
}
group.setId(groupId);
if (group.getUsers() == null) {
group.setUsers(new ArrayList<>());
}
group.setUsers(group.getUsers().stream().distinct().collect(Collectors.toList()));
permissionsChecker.getPermissionAdapter().invalidateUserCache();
return mapGroupData(groupDao.updateGroup(groupId, group));
}
use of io.lumeer.api.model.Group in project engine by Lumeer.
the class GroupFacade method addGroupsToWorkspace.
public List<Group> addGroupsToWorkspace(final String organizationId, final String projectId, final List<Group> groups, final InvitationType invitationType) {
permissionsChecker.checkGroupsHandle();
// we need at least project management rights
Project project = checkProjectPermissions(organizationId, projectId);
Organization organization = organizationFacade.getOrganizationById(organizationId);
Set<String> organizationGroupsIds = groupDao.getAllGroups(organizationId).stream().map(Group::getId).collect(Collectors.toSet());
List<Group> validGroups = groups.stream().filter(group -> organizationGroupsIds.contains(group.getId())).collect(Collectors.toList());
// we need to filter only group who can't read organization, otherwise organization permissions will be unnecessarily checked
List<Group> organizationGroups = validGroups.stream().filter(group -> !permissionsChecker.hasRole(organization, RoleType.Read, group)).collect(Collectors.toList());
addGroupsToOrganization(organization, organizationGroups);
addGroupsToProject(organization, project, validGroups, invitationType);
return validGroups;
}
use of io.lumeer.api.model.Group in project engine by Lumeer.
the class PusherAdapterIT method configureProject.
@Before
public void configureProject() {
user = userDao.createUser(new User(USER));
otherUser = userDao.createUser(new User("otherUser"));
Organization organization = new Organization();
organization.setCode(ORGANIZATION_CODE);
Permissions organizationPermissions = new Permissions();
final Permission userPermission = Permission.buildWithRoles(this.user.getId(), READ_ROLES);
organizationPermissions.updateUserPermissions(userPermission);
organization.setPermissions(organizationPermissions);
this.organization = organizationDao.createOrganization(organization);
projectDao.setOrganization(this.organization);
groupDao.setOrganization(this.organization);
group = groupDao.createGroup(new Group(GROUP, List.of(user.getId(), otherUser.getId())));
user.setOrganizations(Collections.singleton(this.organization.getId()));
user = userDao.updateUser(user.getId(), user);
otherUser.setOrganizations(Collections.singleton(this.organization.getId()));
otherUser = userDao.updateUser(otherUser.getId(), otherUser);
Project project = new Project();
project.setCode(PROJECT_CODE);
Permissions projectPermissions = new Permissions();
projectPermissions.updateUserPermissions(Permission.buildWithRoles(this.user.getId(), READ_ROLES));
project.setPermissions(projectPermissions);
this.project = projectDao.createProject(project);
collectionDao.setProject(project);
viewDao.setProject(project);
linkTypeDao.setProject(project);
FacadeAdapter facadeAdapter = new FacadeAdapter(permissionsChecker.getPermissionAdapter());
ResourceAdapter resourceAdapter = new ResourceAdapter(permissionsChecker.getPermissionAdapter(), collectionDao, linkTypeDao, viewDao, userDao);
pusherAdapter = new PusherAdapter(new AppId(""), facadeAdapter, resourceAdapter, permissionsChecker.getPermissionAdapter(), viewDao, linkTypeDao, collectionDao);
permissionsChecker.getPermissionAdapter().invalidateUserCache();
}
Aggregations