use of edu.stanford.bmir.protege.web.shared.access.RoleId 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);
}
use of edu.stanford.bmir.protege.web.shared.access.RoleId in project webprotege by protegeproject.
the class RoleOracleImpl method get.
public static RoleOracleImpl get() {
RoleOracleImpl impl = new RoleOracleImpl();
for (BuiltInRole builtInRole : BuiltInRole.values()) {
List<RoleId> parentRoles = builtInRole.getParents().stream().map(BuiltInRole::getRoleId).collect(toList());
List<ActionId> actions = builtInRole.getActions().stream().map(BuiltInAction::getActionId).collect(toList());
impl.addRole(new Role(builtInRole.getRoleId(), parentRoles, actions));
}
return impl;
}
use of edu.stanford.bmir.protege.web.shared.access.RoleId 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
}
}
}
Aggregations