/** * Locks the given project. The lock will be set if this project is not * locked. * * @param name a project name to lock */ @POST @Path("lockProject/{name}") public Response lockProject(@PathParam("name") String name) throws WorkspaceException, ProjectException { // When locking the project only EDIT_PROJECTS privilege is needed because we modify the project's state. if (!isGranted(Privileges.EDIT_PROJECTS)) { return Response.status(Status.FORBIDDEN).entity("Doesn't have EDIT PROJECTS privilege").build(); } RulesProject project = workspaceManager.getUserWorkspace(getUser()).getProject(name); if (project.isLocked()) { String lockedBy = project.getLockInfo().getLockedBy().getUserName(); return Response.status(Status.FORBIDDEN).entity("Already locked by '" + lockedBy + "'").build(); } project.lock(); return Response.ok().build(); }
/** * Locks the given project. The lock will be set if this project is not * locked. * * @param name a project name to lock */ @POST @Path("lockProject/{name}") public Response lockProject(@PathParam("name") String name) throws WorkspaceException, ProjectException { // When locking the project only EDIT_PROJECTS privilege is needed because we modify the project's state. if (!isGranted(Privileges.EDIT_PROJECTS)) { return Response.status(Status.FORBIDDEN).entity("Doesn't have EDIT PROJECTS privilege").build(); } RulesProject project = workspaceManager.getUserWorkspace(getUser()).getProject(name); if (project.isLocked()) { String lockedBy = project.getLockInfo().getLockedBy().getUserName(); return Response.status(Status.FORBIDDEN).entity("Already locked by '" + lockedBy + "'").build(); } project.lock(); return Response.ok().build(); }
/** * Unlocks the given project. The unlock will be set if this project is * locked by current user. * * @param name a project name to unlock. */ @POST @Path("unlockProject/{name}") public Response unlockProject(@PathParam("name") String name) throws WorkspaceException, ProjectException { // When unlocking the project locked by current user, only EDIT_PROJECTS privilege is needed because we modify the project's state. // UNLOCK_PROJECTS privilege is needed only to unlock the project locked by other user (it's not our case). if (!isGranted(Privileges.EDIT_PROJECTS)) { return Response.status(Status.FORBIDDEN).entity("Doesn't have EDIT PROJECTS privilege").build(); } RulesProject project = workspaceManager.getUserWorkspace(getUser()).getProject(name); if (!project.isLocked()) { return Response.status(Status.FORBIDDEN).entity("The project is not locked.").build(); } else if (!project.isLockedByMe()) { String lockedBy = project.getLockInfo().getLockedBy().getUserName(); return Response.status(Status.FORBIDDEN).entity("Locked by '" + lockedBy + "'").build(); } project.unlock(); return Response.ok().build(); }
protected boolean isLockedByUser(LockInfo lockInfo, CommonUser user) { if (lockInfo.isLocked()) { CommonUser lockedBy = lockInfo.getLockedBy(); return lockedBy.getUserName().equals(user.getUserName()) || isLockedByDefaultUser(lockedBy, user); } return false; }
/** * Unlocks the given project. The unlock will be set if this project is * locked by current user. * * @param name a project name to unlock. */ @POST @Path("unlockProject/{name}") public Response unlockProject(@PathParam("name") String name) throws WorkspaceException, ProjectException { // When unlocking the project locked by current user, only EDIT_PROJECTS privilege is needed because we modify the project's state. // UNLOCK_PROJECTS privilege is needed only to unlock the project locked by other user (it's not our case). if (!isGranted(Privileges.EDIT_PROJECTS)) { return Response.status(Status.FORBIDDEN).entity("Doesn't have EDIT PROJECTS privilege").build(); } RulesProject project = workspaceManager.getUserWorkspace(getUser()).getProject(name); if (!project.isLocked()) { return Response.status(Status.FORBIDDEN).entity("The project is not locked.").build(); } else if (!project.isLockedByMe()) { String lockedBy = project.getLockInfo().getLockedBy().getUserName(); return Response.status(Status.FORBIDDEN).entity("Locked by '" + lockedBy + "'").build(); } project.unlock(); return Response.ok().build(); }
public String getLockedUserName() { LockInfo lockInfo = getLockInfo(); return lockInfo.isLocked() ? lockInfo.getLockedBy().getUserName() : ""; }
String lockedBy = project.getLockInfo().getLockedBy().getUserName(); return Response.status(Status.FORBIDDEN).entity("Already locked by '" + lockedBy + "'").build();
String lockedBy = project.getLockInfo().getLockedBy().getUserName(); return Response.status(Status.FORBIDDEN).entity("Already locked by '" + lockedBy + "'").build();
protected static String generateComments(UserWorkspaceProject userProject) { if (userProject.isLocalOnly()) { return "Local"; } if (userProject.isDeleted()) { return "Deleted"; } if (userProject.isOpenedForEditing()) { return null; } if (userProject.isOpened()) { String activeVersion = userProject.getFileData().getVersion(); if (activeVersion != null && userProject.isOpenedOtherVersion()) { return "Revision " + activeVersion; } } LockInfo lock = userProject.getLockInfo(); if (lock.isLocked()) { if (userProject.isLockedByMe(lock)) { return "Locked by you. Please close this project."; } else { return "Locked by " + lock.getLockedBy().getUserName(); } } return null; }
protected static String generateComments(UserWorkspaceProject userProject) { if (userProject.isLocalOnly()) { return "Local"; } if (userProject.isDeleted()) { return "Deleted"; } if (userProject.isOpenedForEditing()) { return null; } if (userProject.isOpened()) { String activeVersion = userProject.getFileData().getVersion(); if (activeVersion != null && userProject.isOpenedOtherVersion()) { return "Revision " + activeVersion; } } LockInfo lock = userProject.getLockInfo(); if (lock.isLocked()) { if (userProject.isLockedByMe(lock)) { return "Locked by you. Please close this project."; } else { return "Locked by " + lock.getLockedBy().getUserName(); } } return null; }
return "Locked by you. Please close this project."; } else { return "Locked by " + lock.getLockedBy().getUserName();
private ProjectDescription getProjectDescription(AProject project) { ProjectDescription description = new ProjectDescription(); description.setName(project.getName()); ProjectVersion version = project.getVersion(); description.setVersion(version.getRevision()); VersionInfo versionInfo = version.getVersionInfo(); description.setModifiedBy(versionInfo.getCreatedBy()); description.setModifiedAt(versionInfo.getCreatedAt()); boolean locked = project.isLocked(); description.setLocked(locked); if (locked) { LockInfo lockInfo = project.getLockInfo(); description.setLockedBy(lockInfo.getLockedBy().getUserName()); description.setLockedAt(lockInfo.getLockedAt()); } return description; }
private ProjectDescription getProjectDescription(AProject project) { ProjectDescription description = new ProjectDescription(); description.setName(project.getName()); ProjectVersion version = project.getVersion(); description.setVersion(version.getRevision()); VersionInfo versionInfo = version.getVersionInfo(); description.setModifiedBy(versionInfo.getCreatedBy()); description.setModifiedAt(versionInfo.getCreatedAt()); boolean locked = project.isLocked(); description.setLocked(locked); if (locked) { LockInfo lockInfo = project.getLockInfo(); description.setLockedBy(lockInfo.getLockedBy().getUserName()); description.setLockedAt(lockInfo.getLockedAt()); } return description; }