/** * Make sure that this resource is locked.<p> * * @throws CmsException if something goes wrong */ protected void ensureLock() throws CmsException { CmsLock lock = m_cms.getLock(m_resource); if (lock.isUnlocked() || !lock.isLockableBy(m_cms.getRequestContext().getCurrentUser())) { m_cms.lockResourceTemporary(m_cms.getSitePath(m_resource)); } }
match = lock.isLockableBy(m_lockableByUser); match = !lock.isLockableBy(m_notLockableByUser);
match = lock.isLockableBy(m_lockableByUser); match = !lock.isLockableBy(m_notLockableByUser);
/** * Deletes the given resource which is part of a form session project.<p> * * @param cms the CMS context to use * @param res the resource to delete * * @throws CmsException if something goes wrong */ private void deleteResourceFromProject(CmsObject cms, CmsResource res) throws CmsException { CmsLock lock = cms.getLock(res); if (lock.isUnlocked() || lock.isLockableBy(cms.getRequestContext().getCurrentUser())) { cms.lockResourceTemporary(res); } else { cms.changeLock(res); } cms.deleteResource(cms.getSitePath(res), CmsResource.DELETE_PRESERVE_SIBLINGS); }
/** * @see org.opencms.gwt.shared.rpc.I_CmsVfsService#getFileReplaceInfo(org.opencms.util.CmsUUID) */ public CmsReplaceInfo getFileReplaceInfo(CmsUUID structureId) throws CmsRpcException { CmsReplaceInfo result = null; try { CmsObject cms = getCmsObject(); CmsResource res = cms.readResource(structureId, CmsResourceFilter.IGNORE_EXPIRATION); CmsListInfoBean fileInfo = getPageInfo(res); boolean isLockable = cms.getLock(res).isLockableBy(cms.getRequestContext().getCurrentUser()); long maxFileSize = OpenCms.getWorkplaceManager().getFileBytesMaxUploadSize(cms); result = new CmsReplaceInfo(fileInfo, cms.getSitePath(res), isLockable, maxFileSize); } catch (Throwable e) { error(e); } return result; }
/** * Deletes the category identified by the given path.<p> * * Only the most global category matching the given category path for the * given resource will be affected.<p> * * This method will try to lock the involved resource.<p> * * @param cms the current cms context * @param categoryPath the path of the category to delete * @param referencePath the reference path to find the category repositories * * @throws CmsException if something goes wrong */ public void deleteCategory(CmsObject cms, String categoryPath, String referencePath) throws CmsException { CmsCategory category = readCategory(cms, categoryPath, referencePath); String folderPath = cms.getRequestContext().removeSiteRoot(category.getRootPath()); CmsLock lock = cms.getLock(folderPath); if (lock.isNullLock()) { cms.lockResource(folderPath); } else if (lock.isLockableBy(cms.getRequestContext().currentUser())) { cms.changeLock(folderPath); } cms.deleteResource(folderPath, CmsResource.DELETE_PRESERVE_SIBLINGS); }
/** * Collects the allowable actions for a relation.<p> * * @param cms the current CMS context * @param file the source of the relation * @param relation the relation object * * @return the allowable actions for the given resource */ protected AllowableActions collectAllowableActions(CmsObject cms, CmsResource file, CmsRelation relation) { try { Set<Action> aas = new LinkedHashSet<Action>(); AllowableActionsImpl result = new AllowableActionsImpl(); CmsLock lock = cms.getLock(file); CmsUser user = cms.getRequestContext().getCurrentUser(); boolean canWrite = !cms.getRequestContext().getCurrentProject().isOnlineProject() && (lock.isOwnedBy(user) || lock.isLockableBy(user)) && cms.hasPermissions(file, CmsPermissionSet.ACCESS_WRITE, false, CmsResourceFilter.DEFAULT); addAction(aas, Action.CAN_GET_PROPERTIES, true); addAction(aas, Action.CAN_DELETE_OBJECT, canWrite && !relation.getType().isDefinedInContent()); result.setAllowableActions(aas); return result; } catch (CmsException e) { handleCmsException(e); return null; } }
/** * Deletes the category identified by the given path.<p> * * Only the most global category matching the given category path for the * given resource will be affected.<p> * * This method will try to lock the involved resource.<p> * * @param cms the current cms context * @param categoryPath the path of the category to delete * @param referencePath the reference path to find the category repositories * * @throws CmsException if something goes wrong */ public void deleteCategory(CmsObject cms, String categoryPath, String referencePath) throws CmsException { CmsCategory category = readCategory(cms, categoryPath, referencePath); String folderPath = cms.getRequestContext().removeSiteRoot(category.getRootPath()); CmsLock lock = cms.getLock(folderPath); if (lock.isNullLock()) { cms.lockResource(folderPath); } else if (lock.isLockableBy(cms.getRequestContext().getCurrentUser())) { cms.changeLock(folderPath); } cms.deleteResource(folderPath, CmsResource.DELETE_PRESERVE_SIBLINGS); }
CmsUser user = cms.getRequestContext().getCurrentUser(); boolean canWrite = !cms.getRequestContext().getCurrentProject().isOnlineProject() && (lock.isOwnedBy(user) || lock.isLockableBy(user)) && cms.hasPermissions(file, CmsPermissionSet.ACCESS_WRITE, false, CmsResourceFilter.DEFAULT); boolean isReadOnly = !canWrite;
/** * Renames/Moves a category from the old path to the new one.<p> * * This method will keep all categories in their original repository.<p> * * @param cms the current cms context * @param oldCatPath the path of the category to move * @param newCatPath the new category path * @param referencePath the reference path to find the category * * @throws CmsException if something goes wrong */ public void moveCategory(CmsObject cms, String oldCatPath, String newCatPath, String referencePath) throws CmsException { CmsCategory category = readCategory(cms, oldCatPath, referencePath); String catPath = cms.getRequestContext().removeSiteRoot(category.getRootPath()); CmsLock lock = cms.getLock(catPath); if (lock.isNullLock()) { cms.lockResource(catPath); } else if (lock.isLockableBy(cms.getRequestContext().getCurrentUser())) { cms.changeLock(catPath); } cms.moveResource( catPath, cms.getRequestContext().removeSiteRoot(internalCategoryRootPath(category.getBasePath(), newCatPath))); }
/** * Renames/Moves a category from the old path to the new one.<p> * * This method will keep all categories in their original repository.<p> * * @param cms the current cms context * @param oldCatPath the path of the category to move * @param newCatPath the new category path * @param referencePath the reference path to find the category * * @throws CmsException if something goes wrong */ public void moveCategory(CmsObject cms, String oldCatPath, String newCatPath, String referencePath) throws CmsException { CmsCategory category = readCategory(cms, oldCatPath, referencePath); String catPath = cms.getRequestContext().removeSiteRoot(category.getRootPath()); CmsLock lock = cms.getLock(catPath); if (lock.isNullLock()) { cms.lockResource(catPath); } else if (lock.isLockableBy(cms.getRequestContext().currentUser())) { cms.changeLock(catPath); } cms.moveResource(catPath, cms.getRequestContext().removeSiteRoot( internalCategoryRootPath(category.getBasePath(), newCatPath))); }
/** * Recursively steps up to the resource that is the originator of the given * resource which has an inherited lock.<p> * * @param absoluteResourcename the absolute resource with the inherited lock * * @throws CmsException if something goes wrong */ private void unlockInherited(final String absoluteResourcename) throws CmsException { CmsObject cms = getCms(); CmsLock parentLock = getParentLock(absoluteResourcename); if (!parentLock.isNullLock()) { if (parentLock.isInherited()) { unlockInherited(parentLock.getResourceName()); } else { if (!parentLock.isLockableBy(cms.getRequestContext().getCurrentUser())) { cms.changeLock(cms.getRequestContext().removeSiteRoot(parentLock.getResourceName())); } cms.unlockResource(cms.getRequestContext().removeSiteRoot(parentLock.getResourceName())); } } } }
CmsUser user = cms.getRequestContext().getCurrentUser(); CmsLock lock = cms.getLock(ancestorFolder); if (!lock.isLockableBy(user)) { errorMessage = "Can not lock parent folder '" + parentFolder + "'.";
/** * Finishes the session and publishes the changed resources if necessary.<p> * * @throws CmsException if something goes wrong */ public void finish() throws CmsException { m_finished = true; m_requiresCleanup = false; CmsProject project = getProject(); CmsObject projectCms = OpenCms.initCmsObject(m_adminCms); projectCms.getRequestContext().setCurrentProject(project); if (m_configuration.isAutoPublish()) { // we don't necessarily publish with the user who has the locks on the resources, so we need to steal the locks List<CmsResource> projectResources = projectCms.readProjectView(project.getUuid(), CmsResource.STATE_KEEP); for (CmsResource projectResource : projectResources) { CmsLock lock = projectCms.getLock(projectResource); if (!lock.isUnlocked() && !lock.isLockableBy(projectCms.getRequestContext().getCurrentUser())) { projectCms.changeLock(projectResource); } } OpenCms.getPublishManager().publishProject( projectCms, new CmsLogReport(Locale.ENGLISH, CmsUgcSession.class)); } else { // try to unlock everything - we don't need this in case of auto-publish, since publishing already unlocks the resources projectCms.unlockProject(project.getUuid()); } }
/** * Returns the lock information to the given resource.<p> * * @param resource the resource * * @return lock information, if the page is locked by another user * * @throws CmsException if something goes wrong reading the lock owner user */ private String getLockInfo(CmsResource resource) throws CmsException { CmsObject cms = getCmsObject(); CmsResourceUtil resourceUtil = new CmsResourceUtil(cms, resource); CmsLock lock = resourceUtil.getLock(); String lockInfo = null; if (!lock.isLockableBy(cms.getRequestContext().getCurrentUser())) { if (lock.getType() == CmsLockType.PUBLISH) { lockInfo = Messages.get().getBundle(OpenCms.getWorkplaceManager().getWorkplaceLocale(cms)).key( Messages.GUI_LOCKED_FOR_PUBLISH_0); } else { CmsUser lockOwner = cms.readUser(lock.getUserId()); lockInfo = Messages.get().getBundle(OpenCms.getWorkplaceManager().getWorkplaceLocale(cms)).key( Messages.GUI_LOCKED_BY_1, lockOwner.getFullName()); } } return lockInfo; }
/** * Checks the lock state of the resource and locks it if the autolock feature is enabled.<p> * * @param resource the resource name which is checked * @param type indicates the mode {@link CmsLockType#EXCLUSIVE} or {@link CmsLockType#TEMPORARY} * * @throws CmsException if reading or locking the resource fails */ public void checkLock(String resource, CmsLockType type) throws CmsException { CmsResource res = getCms().readResource(resource, CmsResourceFilter.ALL); CmsLock lock = getCms().getLock(res); boolean lockable = lock.isLockableBy(getCms().getRequestContext().currentUser()); if (OpenCms.getWorkplaceManager().autoLockResources()) { // autolock is enabled, check the lock state of the resource if (lockable) { // resource is lockable, so lock it automatically if (type == CmsLockType.TEMPORARY) { getCms().lockResourceTemporary(resource); } else { getCms().lockResource(resource); } } else { throw new CmsException(Messages.get().container(Messages.ERR_WORKPLACE_LOCK_RESOURCE_1, resource)); } } else { if (!lockable) { throw new CmsException(Messages.get().container(Messages.ERR_WORKPLACE_LOCK_RESOURCE_1, resource)); } } }
/** * Checks the lock state of the resource and locks it if the autolock feature is enabled.<p> * * @param resource the resource name which is checked * @param type indicates the mode {@link CmsLockType#EXCLUSIVE} or {@link CmsLockType#TEMPORARY} * * @throws CmsException if reading or locking the resource fails */ public void checkLock(String resource, CmsLockType type) throws CmsException { CmsResource res = getCms().readResource(resource, CmsResourceFilter.ALL); CmsLock lock = getCms().getLock(res); boolean lockable = lock.isLockableBy(getCms().getRequestContext().getCurrentUser()); if (OpenCms.getWorkplaceManager().autoLockResources()) { // autolock is enabled, check the lock state of the resource if (lockable) { // resource is lockable, so lock it automatically if (type == CmsLockType.TEMPORARY) { getCms().lockResourceTemporary(resource); } else { getCms().lockResource(resource); } } else { throw new CmsException(Messages.get().container(Messages.ERR_WORKPLACE_LOCK_RESOURCE_1, resource)); } } else { if (!lockable) { throw new CmsException(Messages.get().container(Messages.ERR_WORKPLACE_LOCK_RESOURCE_1, resource)); } } }
/** * Checks is the current resource can be edited by the current user.<p> * * @param locale the locale to use for the messages * @param ignoreExpiration <code>true</code> to ignore resource release and expiration date * * @return an empty string if editable, or a localized string with the reason * * @throws CmsException if something goes wrong */ public String getNoEditReason(Locale locale, boolean ignoreExpiration) throws CmsException { String reason = ""; if (m_resource instanceof I_CmsHistoryResource) { reason = Messages.get().getBundle(locale).key(Messages.GUI_NO_EDIT_REASON_HISTORY_0); } else if (!m_cms.hasPermissions( m_resource, CmsPermissionSet.ACCESS_WRITE, false, ignoreExpiration ? CmsResourceFilter.IGNORE_EXPIRATION : CmsResourceFilter.DEFAULT) || !isEditable()) { reason = Messages.get().getBundle(locale).key(Messages.GUI_NO_EDIT_REASON_PERMISSION_0); } else if (!getLock().isLockableBy(m_cms.getRequestContext().getCurrentUser())) { if (getLock().getSystemLock().isPublish()) { reason = Messages.get().getBundle(locale).key(Messages.GUI_PUBLISH_TOOLTIP_0); } else { reason = Messages.get().getBundle(locale).key(Messages.GUI_NO_EDIT_REASON_LOCK_1, getLockedByName()); } } return reason; }
CmsLock currentLock) throws CmsLockException { if (!currentLock.isLockableBy(user)) {
CmsLock currentLock) throws CmsLockException { if (!currentLock.isLockableBy(user)) {