diff --git a/config/alfresco/messages/webclient.properties b/config/alfresco/messages/webclient.properties index 4ebe7922dd..75bdfb5f0d 100644 --- a/config/alfresco/messages/webclient.properties +++ b/config/alfresco/messages/webclient.properties @@ -1720,6 +1720,7 @@ by=by assignee=Assignee comment=Comment invalid_task=The task being viewed is no longer valid, it has probably been completed by another user. +error_webprj_does_not_exist=Web project {0} does not exist (it may have been deleted) # Workflow Definitions wf_review_options=Review Options diff --git a/source/java/org/alfresco/web/bean/wcm/AVMBrowseBean.java b/source/java/org/alfresco/web/bean/wcm/AVMBrowseBean.java index fefb6f06a4..470329ebf8 100644 --- a/source/java/org/alfresco/web/bean/wcm/AVMBrowseBean.java +++ b/source/java/org/alfresco/web/bean/wcm/AVMBrowseBean.java @@ -25,7 +25,6 @@ package org.alfresco.web.bean.wcm; import java.io.FileNotFoundException; -import java.io.Serializable; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collections; @@ -52,9 +51,7 @@ import org.alfresco.model.ContentModel; import org.alfresco.model.WCMAppModel; import org.alfresco.repo.avm.AVMNodeConverter; import org.alfresco.repo.avm.AVMNodeType; -import org.alfresco.repo.avm.actions.AVMUndoSandboxListAction; import org.alfresco.repo.web.scripts.FileTypeImageUtils; -import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.ActionService; import org.alfresco.service.cmr.avm.AVMNodeDescriptor; import org.alfresco.service.cmr.avm.AVMService; @@ -75,11 +72,11 @@ import org.alfresco.service.cmr.security.AccessStatus; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.workflow.WorkflowService; import org.alfresco.service.cmr.workflow.WorkflowTask; -import org.alfresco.util.NameMatcher; -import org.alfresco.util.Pair; -import org.alfresco.util.VirtServerUtils; +import org.alfresco.wcm.asset.AssetInfo; +import org.alfresco.wcm.asset.AssetInfoImpl; import org.alfresco.wcm.sandbox.SandboxInfo; import org.alfresco.wcm.sandbox.SandboxService; +import org.alfresco.wcm.util.WCMUtil; import org.alfresco.wcm.webproject.WebProjectInfo; import org.alfresco.wcm.webproject.WebProjectService; import org.alfresco.web.app.Application; @@ -91,6 +88,7 @@ import org.alfresco.web.bean.BrowseBean; import org.alfresco.web.bean.NavigationBean; import org.alfresco.web.bean.repository.Node; import org.alfresco.web.bean.repository.Repository; +import org.alfresco.web.bean.repository.User; import org.alfresco.web.bean.search.SearchContext; import org.alfresco.web.forms.FormInstanceData; import org.alfresco.web.forms.FormNotFoundException; @@ -1070,6 +1068,18 @@ public class AVMBrowseBean implements IContextListener return false; } + public boolean getIsManagerOrPublisherRole() + { + Node wpNode = getWebsite(); + if (wpNode != null) + { + User user = Application.getCurrentUser(FacesContext.getCurrentInstance()); + String userRole = getWebProjectService().getWebUserRole(wpNode.getNodeRef(), user.getUserName()); + return (WCMUtil.ROLE_CONTENT_MANAGER.equals(userRole) || WCMUtil.ROLE_CONTENT_PUBLISHER.equals(userRole)); + } + return false; + } + /** * @return true to show all sandboxes visible to this user, false to only show the current user sandbox */ @@ -1086,6 +1096,7 @@ public class AVMBrowseBean implements IContextListener this.showAllSandboxes = value; } + /** * @return true if the website has had a deployment attempt */ @@ -1645,8 +1656,9 @@ public class AVMBrowseBean implements IContextListener */ public void revertNode(ActionEvent event) { - final String path = getPathFromEventArgs(event); - final List namesForDisplayMsg = new LinkedList(); + String avmPath = getPathFromEventArgs(event); + String sbStoreId = WCMUtil.getSandboxStoreId(avmPath); + List namesForDisplayMsg = new LinkedList(); UserTransaction tx = null; final FacesContext context = FacesContext.getCurrentInstance(); try @@ -1654,49 +1666,40 @@ public class AVMBrowseBean implements IContextListener tx = Repository.getUserTransaction(context, false); tx.begin(); - AVMNodeDescriptor node = getAvmService().lookup(-1, path, true); + AVMNodeDescriptor node = getAvmService().lookup(-1, avmPath, true); if (node != null) { FormInstanceData fid = null; - if (getAvmService().hasAspect(-1, path, WCMAppModel.ASPECT_RENDITION)) + if (getAvmService().hasAspect(-1, avmPath, WCMAppModel.ASPECT_RENDITION)) { - fid = this.getFormsService().getRendition(-1, path).getPrimaryFormInstanceData(); + fid = this.getFormsService().getRendition(-1, avmPath).getPrimaryFormInstanceData(); } - else if (getAvmService().hasAspect(-1, path, WCMAppModel.ASPECT_FORM_INSTANCE_DATA)) + else if (getAvmService().hasAspect(-1, avmPath, WCMAppModel.ASPECT_FORM_INSTANCE_DATA)) { - fid = this.getFormsService().getFormInstanceData(-1, path); + fid = this.getFormsService().getFormInstanceData(-1, avmPath); } - List> versionPaths = new ArrayList>(); + List paths = new ArrayList(); if (fid != null) { - versionPaths.add(new Pair(-1, fid.getPath())); + paths.add(WCMUtil.getStoreRelativePath(fid.getPath())); namesForDisplayMsg.add(fid.getName()); for (Rendition r : fid.getRenditions()) { - versionPaths.add(new Pair(-1, r.getPath())); + paths.add(WCMUtil.getStoreRelativePath(r.getPath())); namesForDisplayMsg.add(r.getName()); } } else { - versionPaths.add(new Pair(-1, path)); + paths.add(WCMUtil.getStoreRelativePath(avmPath)); namesForDisplayMsg.add(node.getName()); } - final Map args = new HashMap(1, 1.0f); - args.put(AVMUndoSandboxListAction.PARAM_NODE_LIST, (Serializable)versionPaths); - Action action = this.getActionService().createAction(AVMUndoSandboxListAction.NAME, args); - this.getActionService().executeAction(action, null); // dummy action ref + + getSandboxService().revertList(sbStoreId, paths); } // commit the transaction tx.commit(); - - // possibly update webapp after commit - - if (VirtServerUtils.requiresUpdateNotification(path)) - { - AVMUtil.updateVServerWebapp(path, true); - } // if we get here, all was well - output friendly status message to the user this.displayStatusMessage(context, @@ -2162,46 +2165,47 @@ public class AVMBrowseBean implements IContextListener final HtmlCommandButton button = (HtmlCommandButton) event.getComponent(); List params = button.getChildren(); - String userStore = null; - String stagingStore = null; + String userStorePath = null; + //String stagingStorePath = null; for (Object obj : params) { UIParameter uip = (UIParameter) obj; if (uip.getName().equals("userStorePath")) { - userStore = (String) uip.getValue(); + userStorePath = (String) uip.getValue(); } + /* if (uip.getName().equals("stagingStorePath")) { stagingStore = (String) uip.getValue(); } + */ } - NameMatcher matcher = (NameMatcher) FacesContextUtils.getRequiredWebApplicationContext(FacesContext.getCurrentInstance()).getBean("globalPathExcluder"); - - // calcluate the list of differences between the user store and the staging area - List diffs = this.getAvmSyncService().compare(-1, userStore, -1, stagingStore, matcher); - List> versionPaths = new ArrayList>(); + String[] storePath = WCMUtil.splitPath(userStorePath); + + List assets = sbService.listChanged(storePath[0], storePath[1], true); + + String sbStoreId = storePath[0]; + + List paths = new ArrayList(); List tasks = null; - for (AVMDifference diff : diffs) + for (AssetInfo asset : assets) { - if (diff.getDifferenceCode() == AVMDifference.CONFLICT) + if (asset.getDiffCode() == AVMDifference.CONFLICT) { - AVMNodeDescriptor node = getAvmService().lookup(-1, diff.getSourcePath(), true); + // TODO refactor getAssociatedTasksForNode to use AssetInfo instead of AVMNodeDescriptor + AVMNodeDescriptor node = ((AssetInfoImpl)asset).getAVMNodeDescriptor(); if (tasks == null) { - tasks = AVMWorkflowUtil.getAssociatedTasksForSandbox(AVMUtil.getStoreName(diff.getSourcePath())); + tasks = AVMWorkflowUtil.getAssociatedTasksForSandbox(sbStoreId); } if (AVMWorkflowUtil.getAssociatedTasksForNode(node, tasks).size() == 0) { - String revertPath = diff.getSourcePath(); - versionPaths.add(new Pair(-1, revertPath)); + paths.add(asset.getPath()); } } } - - Map args = new HashMap(1, 1.0f); - args.put(AVMUndoSandboxListAction.PARAM_NODE_LIST, (Serializable) versionPaths); - Action action = this.getActionService().createAction(AVMUndoSandboxListAction.NAME, args); - this.getActionService().executeAction(action, null); + + sbService.revertList(sbStoreId, paths); } } diff --git a/source/java/org/alfresco/web/bean/wcm/ManageReviewTaskDialog.java b/source/java/org/alfresco/web/bean/wcm/ManageReviewTaskDialog.java index fb4eb30f31..64da3f4497 100644 --- a/source/java/org/alfresco/web/bean/wcm/ManageReviewTaskDialog.java +++ b/source/java/org/alfresco/web/bean/wcm/ManageReviewTaskDialog.java @@ -24,6 +24,7 @@ */ package org.alfresco.web.bean.wcm; +import java.text.MessageFormat; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -31,10 +32,14 @@ import java.util.Map; import javax.faces.context.FacesContext; import javax.transaction.UserTransaction; +import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.linkvalidation.LinkValidationReport; import org.alfresco.repo.domain.PropertyValue; -import org.alfresco.wcm.sandbox.SandboxConstants; +import org.alfresco.service.cmr.avm.AVMNotFoundException; import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.security.AccessStatus; +import org.alfresco.service.cmr.security.PermissionService; +import org.alfresco.wcm.sandbox.SandboxConstants; import org.alfresco.wcm.util.WCMUtil; import org.alfresco.web.app.Application; import org.alfresco.web.bean.repository.Repository; @@ -53,10 +58,13 @@ public class ManageReviewTaskDialog extends ManageTaskDialog { private static final long serialVersionUID = 59524560340308134L; + private static final String MSG_WEB_PRJ_DOES_NOT_EXIST = "error_webprj_does_not_exist"; + protected String store; protected String webapp; protected NodeRef webProjectRef; protected AVMBrowseBean avmBrowseBean; + protected PermissionService permissionService; private static final Log logger = LogFactory.getLog(ManageReviewTaskDialog.class); @@ -85,8 +93,15 @@ public class ManageReviewTaskDialog extends ManageTaskDialog this.store = this.workflowPackage.getStoreRef().getIdentifier(); // get the web project noderef for the workflow store + String wpStoreId = WCMUtil.getWebProjectStoreId(this.store); this.webProjectRef = getWebProjectService().getWebProjectNodeFromStore(WCMUtil.getWebProjectStoreId(this.store)); + if (this.webProjectRef == null) + { + String mesg = MessageFormat.format(Application.getMessage(context, MSG_WEB_PRJ_DOES_NOT_EXIST), wpStoreId); + throw new AlfrescoRuntimeException(mesg); + } + PropertyValue val = this.getAvmService().getStoreProperty(this.store, SandboxConstants.PROP_LINK_VALIDATION_REPORT); if (val != null) @@ -184,6 +199,14 @@ public class ManageReviewTaskDialog extends ManageTaskDialog this.avmBrowseBean = avmBrowseBean; } + /** + * @param permissionService PermissionService instance + */ + public void setPermissionService(PermissionService permissionService) + { + this.permissionService = permissionService; + } + /** * @return Determines if there are any test servers configured for the * web project this task belongs to @@ -203,7 +226,7 @@ public class ManageReviewTaskDialog extends ManageTaskDialog { result = Boolean.FALSE; - if (this.webProjectRef != null) + if (this.webProjectRef != null && permissionService.hasPermission(webProjectRef, PermissionService.READ_PROPERTIES).equals(AccessStatus.ALLOWED)) { List testServers = DeploymentUtil.findTestServers(this.webProjectRef, false); if (testServers != null) @@ -227,8 +250,16 @@ public class ManageReviewTaskDialog extends ManageTaskDialog */ public boolean getDeployAttempted() { - PropertyValue propVal = getAvmService().getStoreProperty(this.store, + PropertyValue propVal = null; + try + { + propVal = getAvmService().getStoreProperty(this.store, SandboxConstants.PROP_LAST_DEPLOYMENT_ID); + } + catch (AVMNotFoundException nfe) + { + // ignore - eg. web project deleted + } return (propVal != null); } diff --git a/source/java/org/alfresco/web/ui/wcm/component/UISandboxSnapshots.java b/source/java/org/alfresco/web/ui/wcm/component/UISandboxSnapshots.java index 5ace485e6e..f3918d917f 100644 --- a/source/java/org/alfresco/web/ui/wcm/component/UISandboxSnapshots.java +++ b/source/java/org/alfresco/web/ui/wcm/component/UISandboxSnapshots.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2008 Alfresco Software Limited. + * Copyright (C) 2005-2009 Alfresco Software Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -247,10 +247,8 @@ public class UISandboxSnapshots extends SelfRenderingComponent determineDeploymentStatus(context, webProjectRef, sandbox, nodeService, avmService); Map requestMap = context.getExternalContext().getRequestMap(); - for (int i = versions.size() - 1; i >= 0; i--) // reverse order + for (SandboxVersion item : versions) { - SandboxVersion item = versions.get(i); - // only display snapshots with a valid label/tag - others are system generated snapshots if (! item.isSystemGenerated()) { diff --git a/source/java/org/alfresco/web/ui/wcm/component/UIUserSandboxes.java b/source/java/org/alfresco/web/ui/wcm/component/UIUserSandboxes.java index 8d09148b41..5d7c6d46ed 100644 --- a/source/java/org/alfresco/web/ui/wcm/component/UIUserSandboxes.java +++ b/source/java/org/alfresco/web/ui/wcm/component/UIUserSandboxes.java @@ -336,7 +336,7 @@ public class UIUserSandboxes extends SelfRenderingComponent implements Serializa if (showAllSandboxes) { Map userRoles = null; - if (currentUserRole.equals(WCMUtil.ROLE_CONTENT_MANAGER)) + if (currentUserRole.equals(WCMUtil.ROLE_CONTENT_MANAGER) || currentUserRole.equals(WCMUtil.ROLE_CONTENT_PUBLISHER)) { Map allUserRoles = wpService.listWebUsers(websiteRef); @@ -408,8 +408,8 @@ public class UIUserSandboxes extends SelfRenderingComponent implements Serializa if ((showAllSandboxes && (currentUserName.equals(username) || - AVMUtil.ROLE_CONTENT_MANAGER.equals(currentUserRole) || - AVMUtil.ROLE_CONTENT_PUBLISHER.equals(currentUserRole))) || + WCMUtil.ROLE_CONTENT_MANAGER.equals(currentUserRole) || + WCMUtil.ROLE_CONTENT_PUBLISHER.equals(currentUserRole))) || showAllSandboxes == false) { if (logger.isDebugEnabled()) @@ -558,7 +558,7 @@ public class UIUserSandboxes extends SelfRenderingComponent implements Serializa menu.getChildren().add(refresh); // Delete Sandbox action - if (AVMUtil.ROLE_CONTENT_MANAGER.equals(currentUserRole)) + if (WCMUtil.ROLE_CONTENT_MANAGER.equals(currentUserRole)) { UIActionLink delete = createAction(context, mainStore, username, ACT_REMOVE_SANDBOX, "/images/icons/delete_sandbox.gif", diff --git a/source/web/WEB-INF/faces-config-beans.xml b/source/web/WEB-INF/faces-config-beans.xml index 9de71580bc..8c7dfda923 100644 --- a/source/web/WEB-INF/faces-config-beans.xml +++ b/source/web/WEB-INF/faces-config-beans.xml @@ -2604,6 +2604,10 @@ avmBrowseBean #{AVMBrowseBean} + + permissionService + #{PermissionService} + diff --git a/source/web/jsp/wcm/browse-website.jsp b/source/web/jsp/wcm/browse-website.jsp index 6e4e4045d3..bbb7d18c90 100644 --- a/source/web/jsp/wcm/browse-website.jsp +++ b/source/web/jsp/wcm/browse-website.jsp @@ -1,5 +1,5 @@ <%-- - * Copyright (C) 2005-2007 Alfresco Software Limited. + * Copyright (C) 2005-2009 Alfresco Software Limited. * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -233,7 +233,7 @@ <%-- used by the panel to add additional component facets --%> - +