Search in sources :

Example 1 with UserBuilder

use of org.eclipse.vorto.repository.services.UserBuilder in project vorto by eclipse.

the class WorkflowTest method testStartReleaseModelWithReleasedDependencies.

@Test
public void testStartReleaseModelWithReleasedDependencies() throws Exception {
    ModelInfo typeModel = importModel("Color.type");
    workflow.start(typeModel.getId(), createUserContext("alex", PLAYGROUND));
    ModelInfo fbModel = importModel("Colorlight.fbmodel");
    workflow.start(fbModel.getId(), createUserContext("alex", PLAYGROUND));
    setReleaseState(typeModel);
    when(userRepository.findByUsername(createUserContext(getCallerId(), PLAYGROUND).getUsername())).thenReturn(new UserBuilder().withName(getCallerId()).withAuthenticationProviderID(GITHUB).build());
    fbModel = workflow.doAction(fbModel.getId(), createUserContext(getCallerId(), PLAYGROUND), SimpleWorkflowModel.ACTION_RELEASE.getName());
    assertEquals(SimpleWorkflowModel.STATE_IN_REVIEW.getName(), fbModel.getState());
}
Also used : ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) UserBuilder(org.eclipse.vorto.repository.services.UserBuilder) Test(org.junit.Test)

Example 2 with UserBuilder

use of org.eclipse.vorto.repository.services.UserBuilder in project vorto by eclipse.

the class WorkflowTest method testStartReleaseModelWithNonReleasedDependencies.

@Test
public void testStartReleaseModelWithNonReleasedDependencies() throws Exception {
    ModelInfo typeModel = importModel("Color.type");
    workflow.start(typeModel.getId(), createUserContext("alex", PLAYGROUND));
    ModelInfo fbModel = importModel("Colorlight.fbmodel");
    workflow.start(fbModel.getId(), createUserContext("alex", PLAYGROUND));
    when(userRepository.findByUsername(createUserContext(getCallerId(), PLAYGROUND).getUsername())).thenReturn(new UserBuilder().withName(getCallerId()).withAuthenticationProviderID(GITHUB).build());
    workflow.doAction(fbModel.getId(), createUserContext(getCallerId(), PLAYGROUND), SimpleWorkflowModel.ACTION_RELEASE.getName());
    assertEquals("InReview", this.repositoryFactory.getRepositoryByModel(typeModel.getId()).getById(typeModel.getId()).getState());
    assertEquals("InReview", this.repositoryFactory.getRepositoryByModel(fbModel.getId()).getById(fbModel.getId()).getState());
}
Also used : ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) UserBuilder(org.eclipse.vorto.repository.services.UserBuilder) Test(org.junit.Test)

Example 3 with UserBuilder

use of org.eclipse.vorto.repository.services.UserBuilder in project vorto by eclipse.

the class DefaultUserAccountService method createNonTechnicalUser.

/**
 * Creates and persists a new, non-technical user contextually to a new user signing up.<br/>
 * The entity will be saved twice, so the generated ID can be used to populate the
 * {@code created_by} value.<br/>
 * Will fail is the user already exists or cannot be persisted for extraneous reasons.
 *
 * @param username
 * @param provider
 * @param subject
 * @return
 * @throws
 */
@Transactional(rollbackOn = { IllegalArgumentException.class, IllegalStateException.class, InvalidUserException.class })
public User createNonTechnicalUser(String username, String provider, String subject) throws InvalidUserException {
    if (cache.withUser(username).getUser() != null) {
        throw new IllegalArgumentException("User with given username already exists");
    }
    User saved = userRepository.save(new UserBuilder().withName(username).withAuthenticationProviderID(provider).withAuthenticationSubject(subject).build());
    if (null == saved) {
        throw new IllegalStateException("Could not persist new user");
    }
    // sets "created by" field once ID is generated and saves again
    saved.setCreatedBy(saved.getId());
    return userRepository.save(saved);
}
Also used : User(org.eclipse.vorto.repository.domain.User) UserBuilder(org.eclipse.vorto.repository.services.UserBuilder) Transactional(javax.transaction.Transactional)

Example 4 with UserBuilder

use of org.eclipse.vorto.repository.services.UserBuilder in project vorto by eclipse.

the class NamespaceControllerIntegrationTest method updateCollaboratorNoSubject.

@Test
public void updateCollaboratorNoSubject() throws Exception {
    // creates the collaborator payload and the existing user
    String otherUser = "userstandard2";
    Collaborator collaborator = new Collaborator(otherUser, GITHUB, null, Lists.newArrayList("model_viewer", "model_creator"));
    userRepository.save(new UserBuilder().withName(otherUser).withAuthenticationProviderID(GITHUB).build());
    repositoryServer.perform(put("/rest/namespaces/com.mycompany/users").content(objectMapper.writeValueAsString(collaborator)).contentType(MediaType.APPLICATION_JSON).with(userSysadmin)).andExpect(status().isOk());
}
Also used : Collaborator(org.eclipse.vorto.repository.web.api.v1.dto.Collaborator) UserBuilder(org.eclipse.vorto.repository.services.UserBuilder) Test(org.junit.Test)

Example 5 with UserBuilder

use of org.eclipse.vorto.repository.services.UserBuilder in project vorto by eclipse.

the class NamespaceControllerIntegrationTest method updateCollaboratorWithoutPermissions.

@Test
public void updateCollaboratorWithoutPermissions() throws Exception {
    // creates user and collaborator to add
    String otherUser = "userstandard2";
    Collaborator collaborator = new Collaborator(otherUser, GITHUB, null, Lists.newArrayList("model_viewer", "model_creator"));
    userRepository.save(new UserBuilder().withName(otherUser).withAuthenticationProviderID(GITHUB).build());
    // tries to add other user as yet another user, who has no rights to that namespace
    repositoryServer.perform(put(String.format("/rest/namespaces/%s/users", "com.mycompany")).content(objectMapper.writeValueAsString(collaborator)).contentType(MediaType.APPLICATION_JSON).with(userModelViewer)).andExpect(status().isForbidden());
}
Also used : Collaborator(org.eclipse.vorto.repository.web.api.v1.dto.Collaborator) UserBuilder(org.eclipse.vorto.repository.services.UserBuilder) Test(org.junit.Test)

Aggregations

UserBuilder (org.eclipse.vorto.repository.services.UserBuilder)14 Test (org.junit.Test)11 ModelInfo (org.eclipse.vorto.repository.core.ModelInfo)5 Collaborator (org.eclipse.vorto.repository.web.api.v1.dto.Collaborator)5 User (org.eclipse.vorto.repository.domain.User)4 HashSet (java.util.HashSet)2 SecurityMockMvcRequestPostProcessors (org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors)2 Transactional (javax.transaction.Transactional)1 DefaultUserAccountService (org.eclipse.vorto.repository.account.impl.DefaultUserAccountService)1 IUserContext (org.eclipse.vorto.repository.core.IUserContext)1 UserRepositoryRoles (org.eclipse.vorto.repository.domain.UserRepositoryRoles)1 UserNamespaceRoleService (org.eclipse.vorto.repository.services.UserNamespaceRoleService)1 InvalidUserException (org.eclipse.vorto.repository.services.exceptions.InvalidUserException)1 UserDto (org.eclipse.vorto.repository.web.account.dto.UserDto)1