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