Search in sources :

Example 1 with SharingSetting

use of edu.stanford.bmir.protege.web.shared.sharing.SharingSetting in project webprotege by protegeproject.

the class ProjectSharingSettingsManagerImpl method getProjectSharingSettings.

@Override
public ProjectSharingSettings getProjectSharingSettings(ProjectId projectId) {
    List<SharingSetting> sharingSettings = new ArrayList<>();
    ProjectResource projectResource = new ProjectResource(projectId);
    Collection<Subject> subjects = accessManager.getSubjectsWithAccessToResource(projectResource);
    subjects.stream().filter(s -> !s.isGuest()).filter(s -> s.getUserName().isPresent()).map(s -> UserId.getUserId(s.getUserName().get())).forEach(u -> {
        Collection<RoleId> roles = accessManager.getAssignedRoles(Subject.forUser(u), projectResource);
        Roles.toSharingPermission(roles).ifPresent(p -> sharingSettings.add(new SharingSetting(PersonId.of(u), p)));
    });
    Collection<RoleId> signedInUserRoles = accessManager.getAssignedRoles(forAnySignedInUser(), projectResource);
    Optional<SharingPermission> linkSharing = Roles.toSharingPermission(signedInUserRoles);
    return new ProjectSharingSettings(projectId, linkSharing, sharingSettings);
}
Also used : Subject(edu.stanford.bmir.protege.web.server.access.Subject) java.util(java.util) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) RoleId(edu.stanford.bmir.protege.web.shared.access.RoleId) Collections.emptySet(java.util.Collections.emptySet) Subject.forUser(edu.stanford.bmir.protege.web.server.access.Subject.forUser) LoggerFactory(org.slf4j.LoggerFactory) PersonId(edu.stanford.bmir.protege.web.shared.sharing.PersonId) SharingSetting(edu.stanford.bmir.protege.web.shared.sharing.SharingSetting) Inject(javax.inject.Inject) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) Collectors.toMap(java.util.stream.Collectors.toMap) AccessManager(edu.stanford.bmir.protege.web.server.access.AccessManager) Subject.forAnySignedInUser(edu.stanford.bmir.protege.web.server.access.Subject.forAnySignedInUser) SharingPermission(edu.stanford.bmir.protege.web.shared.sharing.SharingPermission) HasGetUserIdByUserIdOrEmail(edu.stanford.bmir.protege.web.server.user.HasGetUserIdByUserIdOrEmail) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) ProjectResource(edu.stanford.bmir.protege.web.server.access.ProjectResource) ProjectSharingSettings(edu.stanford.bmir.protege.web.shared.sharing.ProjectSharingSettings) SharingPermission(edu.stanford.bmir.protege.web.shared.sharing.SharingPermission) ProjectSharingSettings(edu.stanford.bmir.protege.web.shared.sharing.ProjectSharingSettings) SharingSetting(edu.stanford.bmir.protege.web.shared.sharing.SharingSetting) ProjectResource(edu.stanford.bmir.protege.web.server.access.ProjectResource) RoleId(edu.stanford.bmir.protege.web.shared.access.RoleId) Subject(edu.stanford.bmir.protege.web.server.access.Subject)

Example 2 with SharingSetting

use of edu.stanford.bmir.protege.web.shared.sharing.SharingSetting in project webprotege by protegeproject.

the class ProjectSharingSettingsManagerImpl method setProjectSharingSettings.

@Override
public void setProjectSharingSettings(ProjectSharingSettings settings) {
    ProjectId projectId = settings.getProjectId();
    ProjectResource projectResource = new ProjectResource(projectId);
    // Remove existing assignments
    accessManager.getSubjectsWithAccessToResource(projectResource).forEach(subject -> accessManager.setAssignedRoles(subject, projectResource, Collections.emptySet()));
    Map<PersonId, SharingSetting> map = settings.getSharingSettings().stream().collect(toMap(SharingSetting::getPersonId, s -> s, (s1, s2) -> s1));
    Optional<SharingPermission> linkSharingPermission = settings.getLinkSharingPermission();
    linkSharingPermission.ifPresent(permission -> {
        Collection<RoleId> roleId = Roles.fromSharingPermission(permission);
        accessManager.setAssignedRoles(forAnySignedInUser(), projectResource, roleId);
    });
    if (!linkSharingPermission.isPresent()) {
        accessManager.setAssignedRoles(forAnySignedInUser(), projectResource, emptySet());
    }
    for (SharingSetting setting : map.values()) {
        PersonId personId = setting.getPersonId();
        Optional<UserId> userId = userLookup.getUserByUserIdOrEmail(personId.getId());
        if (userId.isPresent()) {
            ImmutableSet<RoleId> roles = Roles.fromSharingPermission(setting.getSharingPermission());
            accessManager.setAssignedRoles(forUser(userId.get()), projectResource, roles);
        } else {
            logger.info("User in sharing setting not found.  An email invitation needs to be sent");
        // TODO
        // We need to send the user an email invitation
        }
    }
}
Also used : Subject(edu.stanford.bmir.protege.web.server.access.Subject) java.util(java.util) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) RoleId(edu.stanford.bmir.protege.web.shared.access.RoleId) Collections.emptySet(java.util.Collections.emptySet) Subject.forUser(edu.stanford.bmir.protege.web.server.access.Subject.forUser) LoggerFactory(org.slf4j.LoggerFactory) PersonId(edu.stanford.bmir.protege.web.shared.sharing.PersonId) SharingSetting(edu.stanford.bmir.protege.web.shared.sharing.SharingSetting) Inject(javax.inject.Inject) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) Collectors.toMap(java.util.stream.Collectors.toMap) AccessManager(edu.stanford.bmir.protege.web.server.access.AccessManager) Subject.forAnySignedInUser(edu.stanford.bmir.protege.web.server.access.Subject.forAnySignedInUser) SharingPermission(edu.stanford.bmir.protege.web.shared.sharing.SharingPermission) HasGetUserIdByUserIdOrEmail(edu.stanford.bmir.protege.web.server.user.HasGetUserIdByUserIdOrEmail) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) ProjectResource(edu.stanford.bmir.protege.web.server.access.ProjectResource) ProjectSharingSettings(edu.stanford.bmir.protege.web.shared.sharing.ProjectSharingSettings) SharingPermission(edu.stanford.bmir.protege.web.shared.sharing.SharingPermission) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) RoleId(edu.stanford.bmir.protege.web.shared.access.RoleId) PersonId(edu.stanford.bmir.protege.web.shared.sharing.PersonId) SharingSetting(edu.stanford.bmir.protege.web.shared.sharing.SharingSetting) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) ProjectResource(edu.stanford.bmir.protege.web.server.access.ProjectResource)

Aggregations

ImmutableSet (com.google.common.collect.ImmutableSet)2 AccessManager (edu.stanford.bmir.protege.web.server.access.AccessManager)2 ProjectResource (edu.stanford.bmir.protege.web.server.access.ProjectResource)2 Subject (edu.stanford.bmir.protege.web.server.access.Subject)2 Subject.forAnySignedInUser (edu.stanford.bmir.protege.web.server.access.Subject.forAnySignedInUser)2 Subject.forUser (edu.stanford.bmir.protege.web.server.access.Subject.forUser)2 HasGetUserIdByUserIdOrEmail (edu.stanford.bmir.protege.web.server.user.HasGetUserIdByUserIdOrEmail)2 RoleId (edu.stanford.bmir.protege.web.shared.access.RoleId)2 ProjectId (edu.stanford.bmir.protege.web.shared.project.ProjectId)2 PersonId (edu.stanford.bmir.protege.web.shared.sharing.PersonId)2 ProjectSharingSettings (edu.stanford.bmir.protege.web.shared.sharing.ProjectSharingSettings)2 SharingPermission (edu.stanford.bmir.protege.web.shared.sharing.SharingPermission)2 SharingSetting (edu.stanford.bmir.protege.web.shared.sharing.SharingSetting)2 UserId (edu.stanford.bmir.protege.web.shared.user.UserId)2 java.util (java.util)2 Collections.emptySet (java.util.Collections.emptySet)2 Collectors.toMap (java.util.stream.Collectors.toMap)2 Inject (javax.inject.Inject)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2