use of io.lumeer.api.model.User in project engine by Lumeer.
the class ProjectFacade method getProjects.
public List<Project> getProjects() {
User user = authenticatedUser.getCurrentUser();
Set<String> groups = authenticatedUser.getCurrentUserGroups();
DatabaseQuery query = DatabaseQuery.createBuilder(user.getEmail()).groups(groups).build();
return projectDao.getProjects(query).stream().map(this::keepOnlyActualUserRoles).collect(Collectors.toList());
}
use of io.lumeer.api.model.User in project engine by Lumeer.
the class UserFacade method updateUser.
public User updateUser(String organizationId, String userId, User user) {
checkOrganizationInUser(organizationId, user);
checkPermissions(organizationId);
User storedUser = userDao.getUserById(userId);
return updateStoredUserGroups(organizationId, storedUser, user);
}
use of io.lumeer.api.model.User in project engine by Lumeer.
the class UserFacade method createUser.
public User createUser(String organizationId, User user) {
checkOrganizationInUser(organizationId, user);
checkPermissions(organizationId);
User storedUser = userDao.getUserByEmail(user.getEmail());
if (storedUser == null) {
return userDao.createUser(user);
}
return updateStoredUserGroups(organizationId, storedUser, user);
}
use of io.lumeer.api.model.User in project engine by Lumeer.
the class PermissionsCheckerTest method preparePermissionsChecker.
@Before
public void preparePermissionsChecker() {
User user = Mockito.mock(User.class);
Mockito.when(user.getGroups()).thenReturn(Collections.singletonMap("LMR", Collections.singleton(GROUP)));
UserCache userCache = Mockito.mock(UserCache.class);
Mockito.when(userCache.getUser(USER)).thenReturn(user);
AuthenticatedUser authenticatedUser = Mockito.mock(AuthenticatedUser.class);
Mockito.when(authenticatedUser.getCurrentUsername()).thenReturn(USER);
Mockito.when(authenticatedUser.getUserEmail()).thenReturn(USER);
Mockito.when(authenticatedUser.getCurrentUserGroups()).thenReturn(Collections.singleton(GROUP));
permissionsChecker = new PermissionsChecker(userCache, authenticatedUser);
}
use of io.lumeer.api.model.User in project engine by Lumeer.
the class MongoUserDaoTest method testCreateUserAnotherOrganization.
@Test
public void testCreateUserAnotherOrganization() {
User user = prepareUser();
User stored = mongoUserDao.createUser(user);
Map<String, Set<String>> groups = new HashMap<>(stored.getGroups());
groups.put(organization2.getId(), GROUPS);
user.setGroups(groups);
mongoUserDao.updateUser(stored.getId(), user);
User storedUser = mongoUserDao.databaseCollection().find(MongoFilters.idFilter(stored.getId())).first();
assertThat(storedUser).isNotNull();
assertThat(storedUser.getEmail()).isEqualTo(user.getEmail());
assertThat(storedUser.getName()).isEqualTo(user.getName());
assertThat(storedUser.getGroups()).containsKeys(organization.getId(), organization2.getId());
assertThat(storedUser.getGroups().get(organization.getId())).containsOnlyElementsOf(GROUPS);
assertThat(storedUser.getGroups().get(organization2.getId())).containsOnlyElementsOf(GROUPS);
}
Aggregations