Search in sources :

Example 16 with Group

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();
}
Also used : Response(javax.ws.rs.core.Response) Group(io.lumeer.api.model.Group) Entity(javax.ws.rs.client.Entity) Test(org.junit.Test)

Example 17 with Group

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();
}
Also used : Group(io.lumeer.api.model.Group) User(io.lumeer.api.model.User) Organization(io.lumeer.api.model.Organization) WorkspaceKeeper(io.lumeer.core.WorkspaceKeeper) ViewDao(io.lumeer.storage.api.dao.ViewDao) DocumentDao(io.lumeer.storage.api.dao.DocumentDao) Role(io.lumeer.api.model.Role) Project(io.lumeer.api.model.Project) UserDao(io.lumeer.storage.api.dao.UserDao) LinkTypeDao(io.lumeer.storage.api.dao.LinkTypeDao) GroupDao(io.lumeer.storage.api.dao.GroupDao) FavoriteItemDao(io.lumeer.storage.api.dao.FavoriteItemDao) CollectionDao(io.lumeer.storage.api.dao.CollectionDao) Before(org.junit.Before)

Example 18 with Group

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));
}
Also used : Group(io.lumeer.api.model.Group)

Example 19 with 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;
}
Also used : Permission(io.lumeer.api.model.Permission) RoleUtils(io.lumeer.api.util.RoleUtils) RoleType(io.lumeer.api.model.RoleType) ResourceNotFoundException(io.lumeer.storage.api.exception.ResourceNotFoundException) ProjectDao(io.lumeer.storage.api.dao.ProjectDao) Set(java.util.Set) InvitationType(io.lumeer.api.model.InvitationType) Collectors(java.util.stream.Collectors) GroupDao(io.lumeer.storage.api.dao.GroupDao) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Group(io.lumeer.api.model.Group) Project(io.lumeer.api.model.Project) List(java.util.List) Role(io.lumeer.api.model.Role) ResourceType(io.lumeer.api.model.ResourceType) Resource(io.lumeer.api.model.common.Resource) RequestScoped(javax.enterprise.context.RequestScoped) Organization(io.lumeer.api.model.Organization) Project(io.lumeer.api.model.Project) Group(io.lumeer.api.model.Group) Organization(io.lumeer.api.model.Organization)

Example 20 with Group

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();
}
Also used : Group(io.lumeer.api.model.Group) Project(io.lumeer.api.model.Project) User(io.lumeer.api.model.User) AuthenticatedUser(io.lumeer.core.auth.AuthenticatedUser) Organization(io.lumeer.api.model.Organization) AppId(io.lumeer.api.model.AppId) Permissions(io.lumeer.api.model.Permissions) Permission(io.lumeer.api.model.Permission) Before(org.junit.Before)

Aggregations

Group (io.lumeer.api.model.Group)44 Test (org.junit.Test)22 Organization (io.lumeer.api.model.Organization)19 Permissions (io.lumeer.api.model.Permissions)16 Project (io.lumeer.api.model.Project)16 Role (io.lumeer.api.model.Role)16 User (io.lumeer.api.model.User)16 Before (org.junit.Before)15 AuthenticatedUser (io.lumeer.core.auth.AuthenticatedUser)14 Permission (io.lumeer.api.model.Permission)10 Response (javax.ws.rs.core.Response)9 Collection (io.lumeer.api.model.Collection)7 LumeerAssertions.assertPermissions (io.lumeer.test.util.LumeerAssertions.assertPermissions)6 List (java.util.List)4 LinkType (io.lumeer.api.model.LinkType)2 Query (io.lumeer.api.model.Query)2 QueryStem (io.lumeer.api.model.QueryStem)2 ResourceType (io.lumeer.api.model.ResourceType)2 RoleType (io.lumeer.api.model.RoleType)2 Resource (io.lumeer.api.model.common.Resource)2