Search in sources :

Example 1 with RBACRole

use of de.catma.rbac.RBACRole in project catma by forTEXT.

the class ResourcePermissionView method initData.

private void initData(TreeData<Resource> resourceData, Collection<TagsetDefinition> tagsets) {
    try {
        permissionGrid.removeAllColumns();
        permissionGrid.addColumn(resource -> resource.getIcon(), new HtmlRenderer()).setWidth(70);
        permissionGrid.addColumn(resource -> resource.getName()).setWidth(250).setCaption("Resource");
        TreeData<Resource> items = new TreeData<Resource>();
        for (Resource documentResource : resourceData.getRootItems()) {
            Set<Member> documentMembers = project.getResourceMembers(documentResource.getResourceId());
            documentMembers.forEach(member -> permissionMatrix.put(documentResource, member, member.getRole()));
            items.addItem(null, documentResource);
            Collection<Resource> collectionResources = resourceData.getChildren(documentResource);
            for (Resource collectionResource : collectionResources) {
                Set<Member> collectionMembers = project.getResourceMembers(collectionResource.getResourceId());
                collectionMembers.forEach(member -> permissionMatrix.put(collectionResource, member, member.getRole()));
                items.addItem(documentResource, collectionResource);
            }
        }
        for (TagsetDefinition tagset : tagsets) {
            Set<Member> tagsetMembers = project.getResourceMembers(tagset.getUuid());
            TagsetResource tagsetResource = new TagsetResource(tagset, project.getProjectId());
            tagsetMembers.forEach(member -> permissionMatrix.put(tagsetResource, member, member.getRole()));
            items.addItem(null, tagsetResource);
        }
        for (Member member : permissionMatrix.columnKeySet()) {
            Column<Resource, String> memberColumn = permissionGrid.addColumn(resource -> {
                RBACRole role = permissionMatrix.get(resource, member);
                return role == null ? "" : role.getRoleName();
            }).setWidth(120).setCaption(member.getName()).setDescriptionGenerator(resource -> member.preciseName());
            // only reporter and lower can be upgraded for specific resources
            if (member.getRole().getAccessLevel() <= RBACRole.REPORTER.getAccessLevel()) {
                memberColumn.setEditorBinding(createRoleEditor(member));
            } else {
                memberColumn.setHidable(true);
                memberColumn.setHidden(true);
            }
        }
        permissionDataProvider = new TreeDataProvider<>(items);
        permissionGrid.setDataProvider(permissionDataProvider);
        permissionGrid.expand(resourceData.getRootItems());
    } catch (IOException e) {
        errorHandler.showAndLogError("Failed to fetch permissions", e);
    }
}
Also used : Column(com.vaadin.ui.Grid.Column) Alignment(com.vaadin.ui.Alignment) ComboBox(com.vaadin.ui.ComboBox) UI(com.vaadin.ui.UI) HashBasedTable(com.google.common.collect.HashBasedTable) Window(com.vaadin.ui.Window) RBACRole(de.catma.rbac.RBACRole) ActionGridComponent(de.catma.ui.component.actiongrid.ActionGridComponent) SearchFilterProvider(de.catma.ui.component.actiongrid.SearchFilterProvider) Binding(com.vaadin.data.Binder.Binding) HashSet(java.util.HashSet) Member(de.catma.user.Member) ErrorHandler(de.catma.ui.module.main.ErrorHandler) Label(com.vaadin.ui.Label) TagsetDefinition(de.catma.tag.TagsetDefinition) TreeDataProvider(com.vaadin.data.provider.TreeDataProvider) TreeGridFactory(de.catma.ui.component.TreeGridFactory) TreeData(com.vaadin.data.TreeData) Project(de.catma.project.Project) Collection(java.util.Collection) Set(java.util.Set) IOException(java.io.IOException) StatusChangeListener(com.vaadin.data.StatusChangeListener) TreeGrid(com.vaadin.ui.TreeGrid) Binder(com.vaadin.data.Binder) MarginInfo(com.vaadin.shared.ui.MarginInfo) StatusChangeEvent(com.vaadin.data.StatusChangeEvent) List(java.util.List) Button(com.vaadin.ui.Button) HorizontalLayout(com.vaadin.ui.HorizontalLayout) SerializablePredicate(com.vaadin.server.SerializablePredicate) HelpWindow(de.catma.ui.dialog.HelpWindow) HtmlRenderer(com.vaadin.ui.renderers.HtmlRenderer) SelectionMode(com.vaadin.ui.Grid.SelectionMode) Table(com.google.common.collect.Table) IOException(java.io.IOException) TagsetDefinition(de.catma.tag.TagsetDefinition) RBACRole(de.catma.rbac.RBACRole) HtmlRenderer(com.vaadin.ui.renderers.HtmlRenderer) TreeData(com.vaadin.data.TreeData) Member(de.catma.user.Member)

Example 2 with RBACRole

use of de.catma.rbac.RBACRole in project catma by forTEXT.

the class ProjectInvitationDialog method initComponents.

private void initComponents() {
    setModal(true);
    setWidth("60%");
    setHeight("90%");
    VerticalLayout content = new VerticalLayout();
    content.setSizeFull();
    lInvitationCode = new Label("", ContentMode.HTML);
    lInvitationCode.setVisible(false);
    content.addComponent(lInvitationCode);
    cbOwnCollection = new CheckBox("Create one collection per Document and joined User", false);
    cbOwnCollection.setValue(false);
    content.addComponent(cbOwnCollection);
    cbOwnCollection.setEnabled(!documentsForCollectionCreation.isEmpty());
    documentGrid = new Grid<>();
    documentGrid.setSizeFull();
    documentGrid.setRowHeight(45);
    documentGrid.setCaption("Documents");
    documentGrid.setDataProvider(new ListDataProvider<>(documentsForCollectionCreation));
    documentGrid.setSelectionMode(SelectionMode.MULTI);
    documentGrid.addColumn(resource -> resource.getIcon(), new HtmlRenderer()).setWidth(100);
    Function<Resource, String> buildNameFunction = (resource) -> {
        StringBuilder sb = new StringBuilder().append("<div class='documentsgrid__doc'> ").append("<div class='documentsgrid__doc__title'> ").append(resource.getName()).append("</div>");
        if (resource.hasDetail()) {
            sb.append("<span class='documentsgrid__doc__author'> ").append(resource.getDetail()).append("</span>");
        }
        sb.append("</div>");
        return sb.toString();
    };
    documentGrid.addColumn(resource -> buildNameFunction.apply(resource), new HtmlRenderer()).setCaption("Name");
    // .setExpandRatio(1);
    documentGrid.setEnabled(false);
    content.addComponent(documentGrid);
    content.setExpandRatio(documentGrid, 1f);
    roleBox = new ComboBox<RBACRole>("Role", Lists.newArrayList(RBACRole.GUEST, RBACRole.REPORTER, RBACRole.ASSISTANT, RBACRole.MAINTAINER));
    roleBox.setWidth("100%");
    roleBox.setItemCaptionGenerator(RBACRole::getRoleName);
    roleBox.setEmptySelectionAllowed(false);
    content.addComponent(roleBox);
    joinedUsersConsole = new ListSelect<>("Joined Users", joinedUsers);
    joinedUsersConsole.setWidth("100%");
    joinedUsersConsole.setCaption("Users");
    joinedUsersConsole.setReadOnly(true);
    joinedUsersConsole.setVisible(false);
    content.addComponent(joinedUsersConsole);
    HorizontalLayout buttonPanel = new HorizontalLayout();
    buttonPanel.setWidth("100%");
    buttonPanel.setMargin(new MarginInfo(true, false));
    btnInvite = new Button("Invite");
    btnStopInvite = new Button("Stop invitation");
    progressIndicator = new ProgressBar();
    progressIndicator.setIndeterminate(false);
    progressIndicator.setVisible(false);
    buttonPanel.addComponent(progressIndicator);
    buttonPanel.setExpandRatio(progressIndicator, 0.5f);
    buttonPanel.addComponent(btnInvite);
    buttonPanel.addComponent(btnStopInvite);
    buttonPanel.setComponentAlignment(btnInvite, Alignment.BOTTOM_RIGHT);
    buttonPanel.setComponentAlignment(btnStopInvite, Alignment.BOTTOM_RIGHT);
    buttonPanel.setExpandRatio(btnInvite, 0.5f);
    content.addComponent(buttonPanel);
    content.setComponentAlignment(buttonPanel, Alignment.BOTTOM_RIGHT);
    setContent(content);
}
Also used : VerticalLayout(com.vaadin.ui.VerticalLayout) Alignment(com.vaadin.ui.Alignment) ComboBox(com.vaadin.ui.ComboBox) UI(com.vaadin.ui.UI) Window(com.vaadin.ui.Window) RBACRole(de.catma.rbac.RBACRole) Function(java.util.function.Function) MembersChangedEvent(de.catma.ui.events.MembersChangedEvent) ArrayList(java.util.ArrayList) EventBus(com.google.common.eventbus.EventBus) JoinedProjectMessage(de.catma.ui.events.JoinedProjectMessage) Lists(com.google.common.collect.Lists) CheckBox(com.vaadin.ui.CheckBox) Notification(com.vaadin.ui.Notification) Gson(com.google.gson.Gson) Label(com.vaadin.ui.Label) HazelcastConfiguration(de.catma.hazelcast.HazelcastConfiguration) Cache(javax.cache.Cache) ListSelect(com.vaadin.ui.ListSelect) ProgressBar(com.vaadin.ui.ProgressBar) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ListDataProvider(com.vaadin.data.provider.ListDataProvider) ContentMode(com.vaadin.shared.ui.ContentMode) InvitationRequestMessage(de.catma.ui.events.InvitationRequestMessage) ClickEvent(com.vaadin.ui.Button.ClickEvent) Project(de.catma.project.Project) Caching(javax.cache.Caching) Collectors(java.util.stream.Collectors) MarginInfo(com.vaadin.shared.ui.MarginInfo) List(java.util.List) Button(com.vaadin.ui.Button) Type(com.vaadin.ui.Notification.Type) HorizontalLayout(com.vaadin.ui.HorizontalLayout) ITopic(com.hazelcast.core.ITopic) HtmlRenderer(com.vaadin.ui.renderers.HtmlRenderer) HazelCastService(de.catma.hazelcast.HazelCastService) SelectionMode(com.vaadin.ui.Grid.SelectionMode) Grid(com.vaadin.ui.Grid) Label(com.vaadin.ui.Label) HorizontalLayout(com.vaadin.ui.HorizontalLayout) RBACRole(de.catma.rbac.RBACRole) Button(com.vaadin.ui.Button) CheckBox(com.vaadin.ui.CheckBox) MarginInfo(com.vaadin.shared.ui.MarginInfo) VerticalLayout(com.vaadin.ui.VerticalLayout) HtmlRenderer(com.vaadin.ui.renderers.HtmlRenderer) ProgressBar(com.vaadin.ui.ProgressBar)

Example 3 with RBACRole

use of de.catma.rbac.RBACRole in project catma by forTEXT.

the class GitlabManagerRestricted method getRolesPerResource.

public Map<String, RBACRole> getRolesPerResource(String projectId) throws IOException {
    try {
        Group group = restrictedGitLabApi.getGroupApi().getGroup(projectId);
        Map<String, AccessLevel> permMap = getResourcePermissions(group.getId());
        return permMap.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> RBACRole.forValue(e.getValue().value)));
    } catch (GitLabApiException e) {
        throw new IOException("Permission retrieval failed!", e);
    }
}
Also used : NotesApi(org.gitlab4j.api.NotesApi) JsonObject(com.google.gson.JsonObject) Reply(de.catma.document.comment.Reply) AccessLevel(org.gitlab4j.api.models.AccessLevel) ProjectFilter(org.gitlab4j.api.models.ProjectFilter) StringUtils(org.apache.commons.lang3.StringUtils) Author(org.gitlab4j.api.models.Author) IssuesApi(org.gitlab4j.api.IssuesApi) ChangeUserAttributeEvent(de.catma.ui.events.ChangeUserAttributeEvent) Map(java.util.Map) Group(org.gitlab4j.api.models.Group) IssueState(org.gitlab4j.api.Constants.IssueState) GroupApi(org.gitlab4j.api.GroupApi) Visibility(org.gitlab4j.api.models.Visibility) CATMAPropertyKey(de.catma.properties.CATMAPropertyKey) IGitUserInformation(de.catma.repository.git.interfaces.IGitUserInformation) GitMember(de.catma.repository.git.GitMember) Pager(org.gitlab4j.api.Pager) GitlabUtils(de.catma.repository.git.GitlabUtils) Set(java.util.Set) Logger(java.util.logging.Logger) SerializationHelper(de.catma.repository.git.serialization.SerializationHelper) Collectors(java.util.stream.Collectors) ProjectReference(de.catma.project.ProjectReference) Objects(java.util.Objects) List(java.util.List) ProjectApi(org.gitlab4j.api.ProjectApi) Optional(java.util.Optional) GitLabApiException(org.gitlab4j.api.GitLabApiException) Status(org.gitlab4j.api.models.ImportStatus.Status) CacheBuilder(com.google.common.cache.CacheBuilder) GitLabApi(org.gitlab4j.api.GitLabApi) RBACPermission(de.catma.rbac.RBACPermission) Permissions(org.gitlab4j.api.models.Permissions) GroupFilter(org.gitlab4j.api.models.GroupFilter) Namespace(org.gitlab4j.api.models.Namespace) HashMap(java.util.HashMap) RBACRole(de.catma.rbac.RBACRole) JsonParser(com.google.gson.JsonParser) User(de.catma.user.User) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) EventBus(com.google.common.eventbus.EventBus) IRemoteGitManagerRestricted(de.catma.repository.git.interfaces.IRemoteGitManagerRestricted) Comment(de.catma.document.comment.Comment) ForkStatus(de.catma.project.ForkStatus) GitProjectManager(de.catma.repository.git.GitProjectManager) Note(org.gitlab4j.api.models.Note) IDGenerator(de.catma.util.IDGenerator) Subscribe(com.google.common.eventbus.Subscribe) CreateRepositoryResponse(de.catma.repository.git.CreateRepositoryResponse) Issue(org.gitlab4j.api.models.Issue) IOException(java.io.IOException) Project(org.gitlab4j.api.models.Project) Maps(com.google.common.collect.Maps) IssueFilter(org.gitlab4j.api.models.IssueFilter) TimeUnit(java.util.concurrent.TimeUnit) Member(org.gitlab4j.api.models.Member) Cache(com.google.common.cache.Cache) Collections(java.util.Collections) BackgroundService(de.catma.backgroundservice.BackgroundService) GitUser(de.catma.repository.git.GitUser) Group(org.gitlab4j.api.models.Group) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException) Map(java.util.Map) HashMap(java.util.HashMap) AccessLevel(org.gitlab4j.api.models.AccessLevel)

Example 4 with RBACRole

use of de.catma.rbac.RBACRole in project catma by forTEXT.

the class AbstractMemberDialog method initComponents.

private void initComponents(String description) {
    this.descriptionLabel = new Label(description);
    descriptionLabel.setHeight("50px");
    cbUsers = new ComboBox<>("Member");
    cbUsers.setWidth("100%");
    cbUsers.setPageLength(20);
    cbUsers.setItemCaptionGenerator(User::preciseName);
    cbRole = new ComboBox<RBACRole>("Role", Lists.newArrayList(RBACRole.GUEST, RBACRole.REPORTER, RBACRole.ASSISTANT, RBACRole.MAINTAINER));
    cbRole.setWidth("100%");
    cbRole.setItemCaptionGenerator(RBACRole::getRoleName);
    cbRole.setEmptySelectionAllowed(false);
}
Also used : User(de.catma.user.User) RBACRole(de.catma.rbac.RBACRole) Label(com.vaadin.ui.Label)

Example 5 with RBACRole

use of de.catma.rbac.RBACRole in project catma by forTEXT.

the class ProjectCard method initData.

private void initData() {
    try {
        RBACRole projectRole = rbacManager.getRoleOnProject(projectManager.getUser(), projectReference.getProjectId());
        // normally done in reload();
        rbacEnforcer.enforceConstraints(projectRole);
    } catch (IOException e) {
        errorLogger.showAndLogError("can't fetch permissions" + projectReference.getName(), e);
    }
}
Also used : RBACRole(de.catma.rbac.RBACRole) IOException(java.io.IOException)

Aggregations

RBACRole (de.catma.rbac.RBACRole)12 IOException (java.io.IOException)6 User (de.catma.user.User)5 Collectors (java.util.stream.Collectors)5 AnnotationCollectionReference (de.catma.document.annotation.AnnotationCollectionReference)4 Comment (de.catma.document.comment.Comment)4 Reply (de.catma.document.comment.Reply)4 CATMAPropertyKey (de.catma.properties.CATMAPropertyKey)4 RBACPermission (de.catma.rbac.RBACPermission)4 ILocalGitRepositoryManager (de.catma.repository.git.interfaces.ILocalGitRepositoryManager)4 IRemoteGitManagerRestricted (de.catma.repository.git.interfaces.IRemoteGitManagerRestricted)4 Member (de.catma.user.Member)4 IDGenerator (de.catma.util.IDGenerator)4 Level (java.util.logging.Level)4 Logger (java.util.logging.Logger)4 Label (com.vaadin.ui.Label)3 List (java.util.List)3 EventBus (com.google.common.eventbus.EventBus)2 MarginInfo (com.vaadin.shared.ui.MarginInfo)2 Alignment (com.vaadin.ui.Alignment)2