Search in sources :

Example 1 with PersonId

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

the class GetPersonIdItemsActionHandler_TestCase method shouldOnlyMatchExact.

@Test
public void shouldOnlyMatchExact() {
    when(action.getItemNames()).thenReturn(Arrays.asList("John Smith"));
    GetPersonIdItemsResult result = actionHandler.execute(action, mock(ExecutionContext.class));
    assertThat(result.getItems(), hasItems(new PersonId(johnSmith_UpperCase.getUserName())));
}
Also used : ExecutionContext(edu.stanford.bmir.protege.web.server.dispatch.ExecutionContext) PersonId(edu.stanford.bmir.protege.web.shared.sharing.PersonId) GetPersonIdItemsResult(edu.stanford.bmir.protege.web.shared.itemlist.GetPersonIdItemsResult) Test(org.junit.Test)

Example 2 with PersonId

use of edu.stanford.bmir.protege.web.shared.sharing.PersonId 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

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