/** * Detemines if the signed in user is the owner of the specified project * * @param projectId The project id * @return <code>true</code> if the project exists AND there is a user signed in AND the signed in * user is the owner of the project, otherwise <code>false</code>. */ protected boolean isSignedInUserProjectOwner(ProjectId projectId) { UserId userId = getUserInSession(); if (userId.isGuest()) { return false; } MetaProjectManager mpm = getMetaProjectManager(); MetaProject metaProject = mpm.getMetaProject(); ProjectInstance project = metaProject.getProject(projectId.getId()); if (project == null) { return false; } User owner = project.getOwner(); return owner != null && userId.getUserName().equals(owner.getName()); }
/** * Determines if the signed in user is an admin. * * @return <code>true</code> if there is a user signed in AND the signed in user corresponds to a * user which exists where that user is an admin, otherwise <code>false</code> */ protected boolean isSignedInUserAdmin() { UserId userId = getUserInSession(); if (userId.isGuest()) { return false; } MetaProjectManager mpm = getMetaProjectManager(); MetaProject metaProject = mpm.getMetaProject(); User user = metaProject.getUser(userId.getUserName()); if (user == null) { return false; } for (Group group : user.getGroups()) { if (OntologyShareAccessConstants.ADMIN_GROUP.equals(group.getName())) { return true; } } return false; }
public List<ProjectDetails> getListableReadableProjects(UserId userId) { Policy policy = metaproject.getPolicy(); User user = policy.getUserByName(userId.getUserName()); List<ProjectDetails> result = new ArrayList<ProjectDetails>(); for (ProjectInstance projectInstance : metaproject.getProjects()) { final String name = projectInstance.getName(); if (name != null && ProjectId.isWelFormedProjectId(name)) { final ProjectId projectId = ProjectId.get(name); if (isAuthorisedToReadAndList(policy, user, projectInstance)) { OWLAPIProjectDocumentStore ds = OWLAPIProjectDocumentStore.getProjectDocumentStore(projectId); if (ds.exists()) { final ProjectDetails projectDetails = createProjectDetailsFromProjectInstance(projectInstance); result.add(projectDetails); } } } } return result; }