Search in sources :

Example 6 with RBACRole

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

the class GitProjectHandler method getReadableSubmodules.

private Set<String> getReadableSubmodules(ILocalGitRepositoryManager localRepoManager) throws IOException {
    Set<String> readableSubmodules = new HashSet<>();
    List<String> relativeSubmodulePaths = localRepoManager.getSubmodulePaths();
    for (String relativeSubmodulePath : relativeSubmodulePaths) {
        if (relativeSubmodulePath != null) {
            if (relativeSubmodulePath.startsWith(SOURCE_DOCUMENT_SUBMODULES_DIRECTORY_NAME)) {
                String documentId = Paths.get(localRepoManager.getRepositoryWorkTree().toURI()).resolve(relativeSubmodulePath).getFileName().toString();
                RBACRole resourceRole = rolesPerResource.get(documentId);
                if ((resourceRole != null) && hasPermission(resourceRole, RBACPermission.DOCUMENT_READ)) {
                    readableSubmodules.add(relativeSubmodulePath);
                }
            } else if (relativeSubmodulePath.startsWith(ANNOTATION_COLLECTION_SUBMODULES_DIRECTORY_NAME)) {
                String collectionId = Paths.get(localRepoManager.getRepositoryWorkTree().toURI()).resolve(relativeSubmodulePath).getFileName().toString();
                RBACRole resourceRole = rolesPerResource.get(collectionId);
                if ((resourceRole != null) && hasPermission(resourceRole, RBACPermission.COLLECTION_READ)) {
                    readableSubmodules.add(relativeSubmodulePath);
                }
            } else if (relativeSubmodulePath.startsWith(TAGSET_SUBMODULES_DIRECTORY_NAME)) {
                String tagsetId = Paths.get(localRepoManager.getRepositoryWorkTree().toURI()).resolve(relativeSubmodulePath).getFileName().toString();
                RBACRole resourceRole = rolesPerResource.get(tagsetId);
                if ((resourceRole != null) && hasPermission(resourceRole, RBACPermission.TAGSET_READ)) {
                    readableSubmodules.add(relativeSubmodulePath);
                }
            }
        }
    }
    return readableSubmodules;
}
Also used : RBACRole(de.catma.rbac.RBACRole)

Example 7 with RBACRole

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

the class GitProjectHandler method verifyCollections.

public void verifyCollections() throws Exception {
    List<AnnotationCollectionReference> collectionRefs = getCollectionReferences();
    Set<String> documentIds = getDocuments().stream().map(SourceDocument::getUuid).collect(Collectors.toSet());
    Set<AnnotationCollectionReference> staleCollectionCandidates = new HashSet<>();
    for (AnnotationCollectionReference collectionRef : collectionRefs) {
        String documentId = collectionRef.getSourceDocumentId();
        if (!documentIds.contains(documentId)) {
            staleCollectionCandidates.add(collectionRef);
        }
    }
    if (!staleCollectionCandidates.isEmpty()) {
        try (ILocalGitRepositoryManager localGitRepoManager = this.localGitRepositoryManager) {
            localGitRepoManager.open(projectId, GitProjectManager.getProjectRootRepositoryName(projectId));
            Set<String> verifiedDeleted = localGitRepoManager.verifyDeletedResources(staleCollectionCandidates.stream().map(AnnotationCollectionReference::getSourceDocumentId).collect(Collectors.toSet()));
            localGitRepoManager.detach();
            // TODO: unnecessary to loop over all collections when only the stale candidates can end up in verifiedDeleted
            for (AnnotationCollectionReference collectionRef : collectionRefs) {
                String collectionId = collectionRef.getId();
                RBACRole collectionRole = rolesPerResource.get(collectionId);
                if (collectionRole != null && hasPermission(collectionRole, RBACPermission.COLLECTION_DELETE_OR_EDIT)) {
                    if (verifiedDeleted.contains(collectionRef.getSourceDocumentId())) {
                        logger.info(String.format("Removing stale Collection %1$s with ID %2$s due to removal of corresp. Document with ID %3$s", collectionRef.getName(), collectionRef.getId(), collectionRef.getSourceDocumentId()));
                        removeCollection(collectionRef);
                    }
                }
            }
        }
    }
}
Also used : ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) RBACRole(de.catma.rbac.RBACRole) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference)

Example 8 with RBACRole

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

the class GitProjectHandler method getTagsets.

public List<TagsetDefinition> getTagsets() {
    ArrayList<TagsetDefinition> result = new ArrayList<>();
    try (ILocalGitRepositoryManager localRepoManager = this.localGitRepositoryManager) {
        localRepoManager.open(projectId, GitProjectManager.getProjectRootRepositoryName(projectId));
        List<Path> paths = localRepoManager.getSubmodulePaths().stream().filter(path -> path != null && path.startsWith(TAGSET_SUBMODULES_DIRECTORY_NAME)).map(path -> Paths.get(localRepoManager.getRepositoryWorkTree().toURI()).resolve(path)).collect(Collectors.toList());
        localRepoManager.detach();
        GitTagsetHandler gitTagsetHandler = new GitTagsetHandler(localRepoManager, this.remoteGitServerManager, this.credentialsProvider);
        for (Path tagsetPath : paths) {
            try {
                String tagsetId = tagsetPath.getFileName().toString();
                RBACRole resourceRole = rolesPerResource.get(tagsetId);
                if ((resourceRole != null) && hasPermission(resourceRole, RBACPermission.TAGSET_READ)) {
                    TagsetDefinition tagset = gitTagsetHandler.getTagset(projectId, tagsetPath.getFileName().toString());
                    result.add(tagset);
                }
            } catch (Exception e) {
                logger.log(Level.SEVERE, String.format("error loading Tagset %1$s for project %2$s", tagsetPath, projectId), e);
            }
        }
    } catch (Exception e) {
        logger.log(Level.SEVERE, String.format("error loading Tagsets for project %1$s", projectId), e);
    }
    return result;
}
Also used : Path(java.nio.file.Path) ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) Reply(de.catma.document.comment.Reply) java.util(java.util) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) Status(org.eclipse.jgit.api.Status) RBACRole(de.catma.rbac.RBACRole) User(de.catma.user.User) Level(java.util.logging.Level) IRemoteGitManagerRestricted(de.catma.repository.git.interfaces.IRemoteGitManagerRestricted) Comment(de.catma.document.comment.Comment) Member(de.catma.user.Member) Pair(de.catma.util.Pair) IDGenerator(de.catma.util.IDGenerator) RBACSubject(de.catma.rbac.RBACSubject) CommitInfo(de.catma.project.CommitInfo) Nonnull(javax.annotation.Nonnull) Path(java.nio.file.Path) CATMAPropertyKey(de.catma.properties.CATMAPropertyKey) ProgressListener(de.catma.backgroundservice.ProgressListener) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) Files(java.nio.file.Files) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) TermInfo(de.catma.indexer.TermInfo) CredentialsProvider(org.eclipse.jgit.transport.CredentialsProvider) FileUtils(org.apache.commons.io.FileUtils) Constants(org.eclipse.jgit.lib.Constants) IOException(java.io.IOException) SourceDocument(de.catma.document.source.SourceDocument) AnnotationCollection(de.catma.document.annotation.AnnotationCollection) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) SourceDocumentInfo(de.catma.document.source.SourceDocumentInfo) File(java.io.File) TagReference(de.catma.document.annotation.TagReference) de.catma.project.conflict(de.catma.project.conflict) de.catma.tag(de.catma.tag) JsonLdWebAnnotation(de.catma.repository.git.serialization.models.json_ld.JsonLdWebAnnotation) JGitInternalException(org.eclipse.jgit.api.errors.JGitInternalException) Paths(java.nio.file.Paths) MergeResult(org.eclipse.jgit.api.MergeResult) JGitRepoManager(de.catma.repository.git.managers.JGitRepoManager) ContentInfoSet(de.catma.document.source.ContentInfoSet) RBACPermission(de.catma.rbac.RBACPermission) FilenameUtils(org.apache.commons.io.FilenameUtils) StatusPrinter(de.catma.repository.git.managers.StatusPrinter) InputStream(java.io.InputStream) ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) RBACRole(de.catma.rbac.RBACRole) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException) JGitInternalException(org.eclipse.jgit.api.errors.JGitInternalException)

Example 9 with RBACRole

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

the class ResourcePermissionView method createRoleEditor.

private Binding<Resource, RBACRole> createRoleEditor(Member member) {
    final ComboBox<RBACRole> roleBox = new ComboBox<>();
    roleBox.setEmptySelectionAllowed(false);
    Binder<Resource> binder = permissionGrid.getEditor().getBinder();
    binder.addStatusChangeListener(new StatusChangeListener() {

        @Override
        public void statusChange(StatusChangeEvent event) {
            Resource resource = (Resource) event.getBinder().getBean();
            Collection<RBACRole> availableRoles = new HashSet<RBACRole>();
            if (resource != null) {
                RBACRole role = permissionMatrix.get(resource, member);
                availableRoles.add(role);
                RBACRole projectRole = member.getRole();
                availableRoles.add(projectRole);
                if (projectRole.getAccessLevel() == RBACRole.REPORTER.getAccessLevel()) {
                    if (resource.isCollection()) {
                        availableRoles.add(RBACRole.ASSISTANT);
                    }
                } else if (projectRole.getAccessLevel() == RBACRole.GUEST.getAccessLevel()) {
                    availableRoles.add(RBACRole.REPORTER);
                    if (resource.isCollection()) {
                        availableRoles.add(RBACRole.ASSISTANT);
                    }
                }
            }
            roleBox.setItems(availableRoles);
            roleBox.setEnabled(availableRoles.size() > 1);
        }
    });
    return binder.bind(roleBox, resource -> permissionMatrix.get(resource, member), (resource, role) -> handleRoleChange(resource, member, role));
}
Also used : StatusChangeListener(com.vaadin.data.StatusChangeListener) StatusChangeEvent(com.vaadin.data.StatusChangeEvent) RBACRole(de.catma.rbac.RBACRole) ComboBox(com.vaadin.ui.ComboBox) Collection(java.util.Collection)

Example 10 with RBACRole

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

the class GitProjectHandler method getCollectionReferences.

public List<AnnotationCollectionReference> getCollectionReferences() {
    ArrayList<AnnotationCollectionReference> collectionReferences = new ArrayList<>();
    try (ILocalGitRepositoryManager localRepoManager = this.localGitRepositoryManager) {
        try {
            localRepoManager.open(projectId, GitProjectManager.getProjectRootRepositoryName(projectId));
            List<Path> paths = localRepoManager.getSubmodulePaths().stream().filter(path -> path != null && path.startsWith(ANNOTATION_COLLECTION_SUBMODULES_DIRECTORY_NAME)).map(path -> Paths.get(localRepoManager.getRepositoryWorkTree().toURI()).resolve(path)).collect(Collectors.toList());
            localRepoManager.detach();
            GitMarkupCollectionHandler gitMarkupCollectionHandler = new GitMarkupCollectionHandler(localRepoManager, this.remoteGitServerManager, this.credentialsProvider);
            for (Path collectionPath : paths) {
                String collectionId = collectionPath.getFileName().toString();
                RBACRole resourceRole = rolesPerResource.get(collectionId);
                if ((resourceRole != null) && hasPermission(resourceRole, RBACPermission.COLLECTION_READ)) {
                    try {
                        collectionReferences.add(gitMarkupCollectionHandler.getCollectionReference(projectId, collectionId));
                    } catch (Exception e) {
                        logger.log(Level.SEVERE, String.format("error loading Collection reference %1$s for project %2$s", collectionPath, projectId), e);
                    }
                }
            }
        } catch (Exception e) {
            logger.log(Level.SEVERE, String.format("error loading Collection references for project %1$s", projectId), e);
        }
    }
    return collectionReferences;
}
Also used : Path(java.nio.file.Path) ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) Reply(de.catma.document.comment.Reply) java.util(java.util) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) Status(org.eclipse.jgit.api.Status) RBACRole(de.catma.rbac.RBACRole) User(de.catma.user.User) Level(java.util.logging.Level) IRemoteGitManagerRestricted(de.catma.repository.git.interfaces.IRemoteGitManagerRestricted) Comment(de.catma.document.comment.Comment) Member(de.catma.user.Member) Pair(de.catma.util.Pair) IDGenerator(de.catma.util.IDGenerator) RBACSubject(de.catma.rbac.RBACSubject) CommitInfo(de.catma.project.CommitInfo) Nonnull(javax.annotation.Nonnull) Path(java.nio.file.Path) CATMAPropertyKey(de.catma.properties.CATMAPropertyKey) ProgressListener(de.catma.backgroundservice.ProgressListener) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) Files(java.nio.file.Files) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) TermInfo(de.catma.indexer.TermInfo) CredentialsProvider(org.eclipse.jgit.transport.CredentialsProvider) FileUtils(org.apache.commons.io.FileUtils) Constants(org.eclipse.jgit.lib.Constants) IOException(java.io.IOException) SourceDocument(de.catma.document.source.SourceDocument) AnnotationCollection(de.catma.document.annotation.AnnotationCollection) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) SourceDocumentInfo(de.catma.document.source.SourceDocumentInfo) File(java.io.File) TagReference(de.catma.document.annotation.TagReference) de.catma.project.conflict(de.catma.project.conflict) de.catma.tag(de.catma.tag) JsonLdWebAnnotation(de.catma.repository.git.serialization.models.json_ld.JsonLdWebAnnotation) JGitInternalException(org.eclipse.jgit.api.errors.JGitInternalException) Paths(java.nio.file.Paths) MergeResult(org.eclipse.jgit.api.MergeResult) JGitRepoManager(de.catma.repository.git.managers.JGitRepoManager) ContentInfoSet(de.catma.document.source.ContentInfoSet) RBACPermission(de.catma.rbac.RBACPermission) FilenameUtils(org.apache.commons.io.FilenameUtils) StatusPrinter(de.catma.repository.git.managers.StatusPrinter) InputStream(java.io.InputStream) ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) RBACRole(de.catma.rbac.RBACRole) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException) JGitInternalException(org.eclipse.jgit.api.errors.JGitInternalException)

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