Search in sources :

Example 11 with Contributor

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();
}
Also used : Space(org.uberfire.spaces.Space) Repository(org.guvnor.structure.repositories.Repository) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) Branch(org.guvnor.structure.repositories.Branch) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) ArrayList(java.util.ArrayList) Contributor(org.uberfire.security.Contributor) Module(org.guvnor.common.services.project.model.Module)

Example 12 with Contributor

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);
}
Also used : UnauthorizedException(org.jboss.errai.security.shared.exception.UnauthorizedException) LibraryPreferences(org.kie.workbench.common.screens.library.api.preferences.LibraryPreferences) ArrayList(java.util.ArrayList) Contributor(org.uberfire.security.Contributor)

Example 13 with Contributor

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;
}
Also used : FileTime(org.uberfire.java.nio.file.attribute.FileTime) Date(java.util.Date) ProjectAssetsQuery(org.kie.workbench.common.screens.library.api.ProjectAssetsQuery) GAV(org.guvnor.common.services.project.model.GAV) LoggerFactory(org.slf4j.LoggerFactory) AuthorizationManager(org.uberfire.security.authz.AuthorizationManager) OrganizationalUnitService(org.guvnor.structure.organizationalunit.OrganizationalUnitService) ExampleRepository(org.kie.workbench.common.screens.examples.model.ExampleRepository) FolderItem(org.kie.workbench.common.screens.explorer.model.FolderItem) Paths(org.uberfire.backend.server.util.Paths) POM(org.guvnor.common.services.project.model.POM) BranchPermissions(org.guvnor.structure.organizationalunit.config.BranchPermissions) RefactoringQueryService(org.kie.workbench.common.services.refactoring.service.RefactoringQueryService) LibraryValueFileNameIndexTerm(org.kie.workbench.common.services.refactoring.backend.server.query.standard.LibraryValueFileNameIndexTerm) KieModuleService(org.kie.workbench.common.services.shared.project.KieModuleService) Map(java.util.Map) ContributorType(org.uberfire.security.ContributorType) Service(org.jboss.errai.bus.server.annotations.Service) SessionInfo(org.uberfire.rpc.SessionInfo) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) RepositoryAction(org.guvnor.structure.security.RepositoryAction) LibraryValueRepositoryRootIndexTerm(org.kie.workbench.common.services.refactoring.backend.server.query.standard.LibraryValueRepositoryRootIndexTerm) UserManagerService(org.uberfire.ext.security.management.api.service.UserManagerService) Repository(org.guvnor.structure.repositories.Repository) SpaceConfigStorageRegistry(org.guvnor.structure.organizationalunit.config.SpaceConfigStorageRegistry) LibraryInfo(org.kie.workbench.common.screens.library.api.LibraryInfo) Collection(java.util.Collection) Set(java.util.Set) LibraryService(org.kie.workbench.common.screens.library.api.LibraryService) LibraryValueFileExtensionIndexTerm(org.kie.workbench.common.services.refactoring.backend.server.query.standard.LibraryValueFileExtensionIndexTerm) Collectors(java.util.stream.Collectors) NoSuchFileException(org.uberfire.java.nio.file.NoSuchFileException) List(java.util.List) DeploymentMode(org.guvnor.common.services.project.service.DeploymentMode) OrganizationalUnitRepositoryInfo(org.kie.workbench.common.screens.library.api.OrganizationalUnitRepositoryInfo) LibraryPreferences(org.kie.workbench.common.screens.library.api.preferences.LibraryPreferences) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) ClusterService(org.uberfire.commons.cluster.ClusterService) PageResponse(org.uberfire.paging.PageResponse) AssetQueryResult(org.kie.workbench.common.screens.library.api.AssetQueryResult) AssetInfo(org.kie.workbench.common.screens.library.api.AssetInfo) PortablePreconditions.checkNotNull(org.kie.soup.commons.validation.PortablePreconditions.checkNotNull) RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow) ArchetypeService(org.kie.workbench.common.screens.archetype.mgmt.shared.services.ArchetypeService) SearchRequestImpl(org.uberfire.ext.security.management.impl.SearchRequestImpl) ArrayList(java.util.ArrayList) Package(org.guvnor.common.services.project.model.Package) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Archetype(org.kie.workbench.common.screens.archetype.mgmt.shared.model.Archetype) Named(javax.inject.Named) Path(org.uberfire.backend.vfs.Path) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) FolderItemType(org.kie.workbench.common.screens.explorer.model.FolderItemType) Logger(org.slf4j.Logger) FindAllLibraryAssetsQuery(org.kie.workbench.common.services.refactoring.backend.server.query.standard.FindAllLibraryAssetsQuery) ExplorerServiceHelper(org.kie.workbench.common.screens.explorer.backend.server.ExplorerServiceHelper) WorkspaceProjectService(org.guvnor.common.services.project.service.WorkspaceProjectService) ExamplesService(org.kie.workbench.common.screens.examples.service.ExamplesService) Contributor(org.uberfire.security.Contributor) NewWorkspaceProjectUtils(org.guvnor.common.services.project.utils.NewWorkspaceProjectUtils) User(org.jboss.errai.security.shared.api.identity.User) RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) OrganizationalUnitAction(org.guvnor.structure.security.OrganizationalUnitAction) UnauthorizedException(org.jboss.errai.security.shared.exception.UnauthorizedException) ImportProject(org.kie.workbench.common.screens.examples.model.ImportProject) IOService(org.uberfire.io.IOService) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm) Collections(java.util.Collections) Branch(org.guvnor.structure.repositories.Branch) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) Contributor(org.uberfire.security.Contributor)

Example 14 with Contributor

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);
}
Also used : OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) ArrayList(java.util.ArrayList) Contributor(org.uberfire.security.Contributor) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) POM(org.guvnor.common.services.project.model.POM) Test(org.junit.Test)

Example 15 with Contributor

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();
        });
    });
}
Also used : ArrayList(java.util.ArrayList) HasBusyIndicatorDefaultErrorCallback(org.uberfire.ext.widgets.common.client.callbacks.HasBusyIndicatorDefaultErrorCallback) Contributor(org.uberfire.security.Contributor) NotificationEvent(org.uberfire.workbench.events.NotificationEvent)

Aggregations

Contributor (org.uberfire.security.Contributor)31 ArrayList (java.util.ArrayList)25 Test (org.junit.Test)22 OrganizationalUnit (org.guvnor.structure.organizationalunit.OrganizationalUnit)11 Repository (org.guvnor.structure.repositories.Repository)8 POM (org.guvnor.common.services.project.model.POM)6 Consumer (java.util.function.Consumer)4 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)4 List (java.util.List)3 Branch (org.guvnor.structure.repositories.Branch)3 Before (org.junit.Before)3 Collections (java.util.Collections)2 Map (java.util.Map)2 Module (org.guvnor.common.services.project.model.Module)2 BranchPermissions (org.guvnor.structure.organizationalunit.config.BranchPermissions)2 UnauthorizedException (org.jboss.errai.security.shared.exception.UnauthorizedException)2 Archetype (org.kie.workbench.common.screens.archetype.mgmt.shared.model.Archetype)2 ExampleRepository (org.kie.workbench.common.screens.examples.model.ExampleRepository)2 LibraryPreferences (org.kie.workbench.common.screens.library.api.preferences.LibraryPreferences)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2