Search in sources :

Example 1 with WorkspaceKeeper

use of io.lumeer.core.WorkspaceKeeper 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 2 with WorkspaceKeeper

use of io.lumeer.core.WorkspaceKeeper in project engine by Lumeer.

the class AuthenticatedUser method createDemoWorkspaceIfNeeded.

private void createDemoWorkspaceIfNeeded(User user) {
    if (user.getOrganizations() != null && !user.getOrganizations().isEmpty()) {
        return;
    }
    Organization organization = createDemoOrganization(user);
    user.setOrganizations(Collections.singleton(organization.getId()));
    ((WorkspaceKeeper) selectedWorkspace).setOrganizationId(organization.getId());
    eventLogFacade.logEvent(user, "A new user " + user.getEmail() + " logged for the first time in the system. " + "Organization " + organization.getCode() + " was created for them.");
}
Also used : Organization(io.lumeer.api.model.Organization) WorkspaceKeeper(io.lumeer.core.WorkspaceKeeper)

Aggregations

Organization (io.lumeer.api.model.Organization)2 WorkspaceKeeper (io.lumeer.core.WorkspaceKeeper)2 Group (io.lumeer.api.model.Group)1 Project (io.lumeer.api.model.Project)1 Role (io.lumeer.api.model.Role)1 User (io.lumeer.api.model.User)1 CollectionDao (io.lumeer.storage.api.dao.CollectionDao)1 DocumentDao (io.lumeer.storage.api.dao.DocumentDao)1 FavoriteItemDao (io.lumeer.storage.api.dao.FavoriteItemDao)1 GroupDao (io.lumeer.storage.api.dao.GroupDao)1 LinkTypeDao (io.lumeer.storage.api.dao.LinkTypeDao)1 UserDao (io.lumeer.storage.api.dao.UserDao)1 ViewDao (io.lumeer.storage.api.dao.ViewDao)1 Before (org.junit.Before)1