use of org.uberfire.security.Contributor in project kie-wb-common by kiegroup.
the class BranchManagementPresenterTest method mockLibraryPlaces.
private void mockLibraryPlaces() {
final Branch branch = mock(Branch.class);
doReturn("myBranch").when(branch).getName();
final Repository repository = mock(Repository.class);
doReturn(Arrays.asList(branch)).when(repository).getBranches();
doReturn("myProject").when(repository).getIdentifier();
final OrganizationalUnit organizationalUnit = mock(OrganizationalUnit.class);
final List<Contributor> organizationalUnitContributors = new ArrayList<>();
doReturn(organizationalUnitContributors).when(organizationalUnit).getContributors();
doReturn("mySpace").when(organizationalUnit).getName();
final Space space = mock(Space.class);
final WorkspaceProject project = mock(WorkspaceProject.class);
doReturn(repository).when(project).getRepository();
doReturn(organizationalUnit).when(project).getOrganizationalUnit();
doReturn(space).when(project).getSpace();
doReturn(branch).when(project).getBranch();
doReturn(mock(Module.class)).when(project).getMainModule();
doReturn(project).when(libraryPlaces).getActiveWorkspace();
doReturn(organizationalUnit).when(libraryPlaces).getActiveSpace();
}
use of org.uberfire.security.Contributor in project kie-wb-common by kiegroup.
the class LibraryServiceImpl method createDefaultOrganizationalUnit.
private OrganizationalUnit createDefaultOrganizationalUnit() {
if (!authorizationManager.authorize(OrganizationalUnit.RESOURCE_TYPE, OrganizationalUnitAction.CREATE, sessionInfo.getIdentity())) {
throw new UnauthorizedException("User :user has no permissions to :type -> :action".replace(":user", sessionInfo.getIdentity().getIdentifier()).replace(":type", OrganizationalUnit.RESOURCE_TYPE.getName()).replace(":action", OrganizationalUnitAction.CREATE.getName()));
}
final LibraryPreferences preferences = getPreferences();
final List<Contributor> contributors = new ArrayList<>();
contributors.add(new Contributor(preferences.getOrganizationalUnitPreferences().getOwner(), ContributorType.OWNER));
return ouService.createOrganizationalUnit(preferences.getOrganizationalUnitPreferences().getName(), preferences.getOrganizationalUnitPreferences().getGroupId(), Collections.emptyList(), contributors);
}
use of org.uberfire.security.Contributor in project kie-wb-common by kiegroup.
the class LibraryServiceImpl method getRepositoryContributors.
private List<Contributor> getRepositoryContributors(final OrganizationalUnit organizationalUnit) {
final OrganizationalUnit ou = ouService.getOrganizationalUnit(organizationalUnit.getName());
final Collection<Contributor> spaceContributors = ou.getContributors();
final List<Contributor> contributors = spaceContributors.stream().filter(c -> !sessionInfo.getIdentity().getIdentifier().equals(c.getUsername())).collect(Collectors.toList());
if (spaceContributors.size() == contributors.size()) {
spaceContributors.add(new Contributor(sessionInfo.getIdentity().getIdentifier(), ContributorType.CONTRIBUTOR));
ouService.updateOrganizationalUnit(ou.getName(), ou.getDefaultGroupId(), spaceContributors);
}
contributors.add(new Contributor(sessionInfo.getIdentity().getIdentifier(), ContributorType.OWNER));
return contributors;
}
use of org.uberfire.security.Contributor in project kie-wb-common by kiegroup.
the class LibraryServiceImplTest method createProjectFromInvalidTemplateTest.
@Test(expected = IllegalStateException.class)
public void createProjectFromInvalidTemplateTest() {
final List<Contributor> spaceContributors = new ArrayList<>();
spaceContributors.add(new Contributor("user1", ContributorType.OWNER));
spaceContributors.add(new Contributor("user2", ContributorType.ADMIN));
spaceContributors.add(new Contributor("admin", ContributorType.CONTRIBUTOR));
final OrganizationalUnit organizationalUnit = mock(OrganizationalUnit.class);
doReturn("ou").when(organizationalUnit).getName();
doReturn("org.ou").when(organizationalUnit).getDefaultGroupId();
doReturn(spaceContributors).when(organizationalUnit).getContributors();
doReturn(organizationalUnit).when(ouService).getOrganizationalUnit("ou");
final String templateId = "invalid-template";
doThrow(IllegalStateException.class).when(archetypeService).getTemplateRepository(templateId);
final POM pom = mock(POM.class);
libraryService.createProject(organizationalUnit, pom, DeploymentMode.VALIDATED, templateId);
}
use of org.uberfire.security.Contributor in project kie-wb-common by kiegroup.
the class ContributorsListItemPresenter method save.
public void save() {
final Contributor contributor = new Contributor(view.getName(), view.getRole());
contributorsListService.getContributors(currentContributors -> {
isValid(contributor, currentContributors).then(isValid -> {
if (isValid) {
final List<Contributor> updatedContributors = new ArrayList<>();
if (persistedContributor == null) {
updatedContributors.addAll(currentContributors);
} else {
updatedContributors.addAll(currentContributors.stream().filter(c -> !c.equals(persistedContributor)).collect(Collectors.toList()));
}
updatedContributors.add(contributor);
view.showBusyIndicator(view.getSavingMessage());
contributorsListService.saveContributors(updatedContributors, () -> {
persistedContributor = contributor;
view.setupViewMode(contributor);
parentPresenter.itemIsNotBeingEdited();
view.hideBusyIndicator();
notificationEvent.fire(new NotificationEvent(view.getSaveSuccessMessage(), NotificationEvent.NotificationType.SUCCESS));
parentPresenter.refresh();
}, new HasBusyIndicatorDefaultErrorCallback(view));
}
return promises.resolve();
});
});
}
Aggregations