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());
}
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());
}
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);
}
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());
}
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());
}
Aggregations