diff --git a/config/alfresco/messages/webclient.properties b/config/alfresco/messages/webclient.properties index 78868eda95..188b7bcd26 100644 --- a/config/alfresco/messages/webclient.properties +++ b/config/alfresco/messages/webclient.properties @@ -334,7 +334,6 @@ sizeQuota=Quota # Note - these come from the server, the english translation is generally the same Administrator=Administrator Consumer=Consumer -Read=Consumer Coordinator=Coordinator Collaborator=Collaborator Contributor=Contributor @@ -570,6 +569,31 @@ select_users=Select Users to add to this Group selected_users=Selected Users groups_err_group_name=Group ID cannot contain the characters: {0} groups_err_exists=A group ID with the same name already exists, group identifiers must be unique. +Read=Read +Write=Write +Delete=Delete +permission=Permission +permissions=Permissions +manage_permissions_title=Manage permissions for ''{0}'' +manage_permissions_subtitle=Manage the permissions you have granted to users who access your folder or file. +manage_permissions=Manage permissions +view_permissions=View permissions +set_permissions=Set permissions +change_permissions=Change Permissions +set_permissions_title=Setting Permissions for ''{0}'' +set_permissions_subtitle=This dialog allows you to give other users access to your folder or file +select_usersgroups_perms=Select user/group and their permission(s) +selected_usersgroups_perms=Selected users/groups and their permission(s) +remove_permissions_title=Remove User ''{0}'' +remove_permissions_subtitle=To remove all permissions for user, click Yes. +remove_permissions=Are you sure you want to remove all permissions for this user? +edit_permissions_title=Modify permissions for ''{0}'' +view_permissions_title=View permissions for ''{0}'' +edit_permissions_subtitle=Modify the permissions granted to a user for accessing your folder or file. +view_permissions_subtitle=The permissions granted to a user for accessing your folder or file. +select_perm=Select permission +selected_perm=Selected permission +change_user_perms=Change User Permissions # Invite Users Wizard messages invite_title=Invite Users Wizard diff --git a/config/alfresco/web-client-config-dialogs.xml b/config/alfresco/web-client-config-dialogs.xml index cfa8a27033..f497e45216 100644 --- a/config/alfresco/web-client-config-dialogs.xml +++ b/config/alfresco/web-client-config-dialogs.xml @@ -340,11 +340,16 @@ title-id="edit_permissions_title" description-id="edit_permissions_subtitle" /> + + diff --git a/config/alfresco/web-client-config-wcm-actions.xml b/config/alfresco/web-client-config-wcm-actions.xml index 6b5b9bc489..dc7f182d77 100644 --- a/config/alfresco/web-client-config-wcm-actions.xml +++ b/config/alfresco/web-client-config-wcm-actions.xml @@ -237,6 +237,44 @@ + + + + ChangePermissions + + org.alfresco.web.action.evaluator.ManagePermissionIsMainStoreEvaluator + manage_permissions + /images/icons/edit_group.gif + dialog:managePermissions + #{AVMBrowseBean.setupContentAction} + + #{actionContext.id} + + + + + + set_permissions + org.alfresco.web.action.evaluator.ManagePermissionIsMainStoreEvaluator + /images/icons/manage_permissions.gif + dialog:setPermissions + + + + + + Read + + org.alfresco.web.action.evaluator.ViewPermissionEvaluator + view_permissions + /images/icons/person.gif + dialog:viewPermissions + #{AVMBrowseBean.setupContentAction} + + #{actionContext.id} + + + @@ -346,6 +384,8 @@ + + @@ -357,6 +397,8 @@ + + @@ -414,6 +456,8 @@ + + @@ -423,6 +467,8 @@ + + @@ -461,6 +507,11 @@ + + + + + diff --git a/source/java/org/alfresco/web/action/evaluator/ManagePermissionIsMainStoreEvaluator.java b/source/java/org/alfresco/web/action/evaluator/ManagePermissionIsMainStoreEvaluator.java new file mode 100644 index 0000000000..84b37a0aac --- /dev/null +++ b/source/java/org/alfresco/web/action/evaluator/ManagePermissionIsMainStoreEvaluator.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2005-2008 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 as + * published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. As a special exception to the terms and conditions of version 2.0 of the GPL, you may redistribute this Program in connection with Free/Libre and + * Open Source Software ("FLOSS") applications as described in Alfresco's FLOSS exception. You should have recieved a copy of the text describing the FLOSS exception, and it is + * also available here: http://www.alfresco.com/legal/licensing" + */ + +package org.alfresco.web.action.evaluator; + +import org.alfresco.repo.avm.AVMNodeConverter; +import org.alfresco.web.bean.repository.Node; +import org.alfresco.web.bean.wcm.AVMUtil; +import org.alfresco.web.bean.wcm.ManagePermissionsDialog; + +/** + * UI Action Evaluator - Evaluates whether the change and remove permissions action should be visible. + * + * @author Sergey Gavrusev + */ +public class ManagePermissionIsMainStoreEvaluator extends BaseActionEvaluator +{ + + private static final long serialVersionUID = 4221869509273412546L; + + /* + * (non-Javadoc) + * + * @see org.alfresco.web.action.evaluator.BaseActionEvaluator#evaluate(org.alfresco.web.bean.repository.Node) + */ + public boolean evaluate(final Node node) + { + boolean result = false; + final String path = AVMNodeConverter.ToAVMVersionPath(node.getNodeRef()).getSecond(); + if (!AVMUtil.isMainStore(AVMUtil.getStoreName(path))) + { + result = true; + } + return result; + } + + /* + * (non-Javadoc) + * + * @see org.alfresco.web.action.evaluator.BaseActionEvaluator#evaluate(java.lang.Object) + */ + @Override + public boolean evaluate(final Object obj) + { + if (obj instanceof ManagePermissionsDialog) + { + return ((ManagePermissionsDialog) obj).isRendered(); + } + return false; + } + +} diff --git a/source/java/org/alfresco/web/action/evaluator/ViewPermissionEvaluator.java b/source/java/org/alfresco/web/action/evaluator/ViewPermissionEvaluator.java new file mode 100644 index 0000000000..6c28b23c3a --- /dev/null +++ b/source/java/org/alfresco/web/action/evaluator/ViewPermissionEvaluator.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2005-2008 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 as + * published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. As a special exception to the terms and conditions of version 2.0 of the GPL, you may redistribute this Program in connection with Free/Libre and + * Open Source Software ("FLOSS") applications as described in Alfresco's FLOSS exception. You should have recieved a copy of the text describing the FLOSS exception, and it is + * also available here: http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.web.action.evaluator; + +import org.alfresco.repo.avm.AVMNodeConverter; +import org.alfresco.web.bean.repository.Node; +import org.alfresco.web.bean.wcm.AVMUtil; +import org.alfresco.web.bean.wcm.ManagePermissionsDialog; + +/** + * UI Action Evaluator - Evaluates whether the view permissions action should be visible. + * + * @author Sergey Gavrusev + */ +public class ViewPermissionEvaluator extends BaseActionEvaluator +{ + + private static final long serialVersionUID = 1340473144312214960L; + + /* + * (non-Javadoc) + * + * @see org.alfresco.web.action.evaluator.BaseActionEvaluator#evaluate(org.alfresco.web.bean.repository.Node) + */ + @Override + public boolean evaluate(final Node node) + { + boolean result = true; + final String path = AVMNodeConverter.ToAVMVersionPath(node.getNodeRef()).getSecond(); + if (!AVMUtil.isMainStore(AVMUtil.getStoreName(path))) + { + result = false; + } + return result; + + } + + /* + * (non-Javadoc) + * + * @see org.alfresco.web.action.evaluator.BaseActionEvaluator#evaluate(java.lang.Object) + */ + @Override + public boolean evaluate(Object obj) + { + if (obj instanceof ManagePermissionsDialog) + { + return !((ManagePermissionsDialog) obj).isRendered(); + } + return false; + } + +} diff --git a/source/java/org/alfresco/web/bean/wcm/BasePermissionsDialog.java b/source/java/org/alfresco/web/bean/wcm/BasePermissionsDialog.java new file mode 100644 index 0000000000..f359138a1c --- /dev/null +++ b/source/java/org/alfresco/web/bean/wcm/BasePermissionsDialog.java @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2005-2008 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 as + * published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. As a special exception to the terms and conditions of version 2.0 of the GPL, you may redistribute this Program in connection with Free/Libre and + * Open Source Software ("FLOSS") applications as described in Alfresco's FLOSS exception. You should have recieved a copy of the text describing the FLOSS exception, and it is + * also available here: http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.web.bean.wcm; + +import java.util.Map; + +import javax.faces.context.FacesContext; + +import org.alfresco.service.cmr.security.PermissionService; +import org.alfresco.web.bean.dialog.BaseDialogBean; +import org.alfresco.web.bean.repository.Repository; + +/** + * Base class for Permissions dialogs + * + * @author Sergei Gavrusev + */ +public class BasePermissionsDialog extends BaseDialogBean +{ + + private static final long serialVersionUID = -1027989430514037278L; + + /** PermissionService bean reference */ + transient protected PermissionService permissionService; + private AVMBrowseBean avmBrowseBean; + + /* + * (non-Javadoc) + * + * @see org.alfresco.web.bean.dialog.BaseDialogBean#init(java.util.Map) + */ + @Override + public void init(Map parameters) + { + + super.init(parameters); + + } + + /** + * Getter for permissionService + * + * @return permissionService + */ + protected PermissionService getPermissionService() + { + if (permissionService == null) + { + permissionService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getPermissionService(); + } + return permissionService; + } + + /** + * @param permissionService permission service + */ + protected void setPermissionService(final PermissionService permissionService) + { + this.permissionService = permissionService; + } + + /* + * (non-Javadoc) + * + * @see org.alfresco.web.bean.dialog.BaseDialogBean#finishImpl(javax.faces.context.FacesContext, java.lang.String) + */ + @Override + protected String finishImpl(FacesContext context, String outcome) throws Exception + { + return outcome; + } + + /** + * Getter for avmBrowseBean + * + * @return avmBrowseBean + */ + public AVMBrowseBean getAvmBrowseBean() + { + return avmBrowseBean; + } + + /** + * @param avmBrowseBean The avmBrowseBean to set. + */ + public void setAvmBrowseBean(final AVMBrowseBean avmBrowseBean) + { + this.avmBrowseBean = avmBrowseBean; + } + +} diff --git a/source/java/org/alfresco/web/bean/wcm/EditPermissionsDialog.java b/source/java/org/alfresco/web/bean/wcm/EditPermissionsDialog.java new file mode 100644 index 0000000000..9967ef5552 --- /dev/null +++ b/source/java/org/alfresco/web/bean/wcm/EditPermissionsDialog.java @@ -0,0 +1,250 @@ +/* + * Copyright (C) 2005-2008 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 as + * published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. As a special exception to the terms and conditions of version 2.0 of the GPL, you may redistribute this Program in connection with Free/Libre and + * Open Source Software ("FLOSS") applications as described in Alfresco's FLOSS exception. You should have recieved a copy of the text describing the FLOSS exception, and it is + * also available here: http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.web.bean.wcm; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.faces.component.UISelectOne; +import javax.faces.context.FacesContext; +import javax.faces.event.ActionEvent; +import javax.faces.model.DataModel; +import javax.faces.model.ListDataModel; +import javax.faces.model.SelectItem; + +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.security.AccessPermission; +import org.alfresco.web.app.Application; +import org.alfresco.web.bean.users.UserMembersBean.PermissionWrapper; +import org.alfresco.web.ui.common.component.UIActionLink; + +/** + * Class for EditPermissions dialog + * + * @author Sergei Gavrusev + */ +public class EditPermissionsDialog extends UpdatePermissionsDialog +{ + private static final long serialVersionUID = 670465612383178325L; + + private static final String MSG_EDIT_PERMS_FOR = "edit_permissions_title"; + + private boolean finishButtonDisabled = true; + + private List personPerms = null; + private transient DataModel personPermsDataModel = null; + private String personAuthority; + + /** + * @param event + */ + public void setupAction(ActionEvent event) + { + + UIActionLink link = (UIActionLink) event.getComponent(); + Map params = link.getParameterMap(); + personAuthority = params.get("userName"); + + } + + /* + * (non-Javadoc) + * + * @see org.alfresco.web.bean.wcm.UpdatePermissionsDialog#init(java.util.Map) + */ + @Override + public void init(Map parameters) + { + super.init(parameters); + setActiveNode(getAvmBrowseBean().getAvmActionNode()); + personPerms = new ArrayList(3); + personPermsDataModel = null; + + NodeRef actionNode = getAvmBrowseBean().getAvmActionNode().getNodeRef(); + NodeRef parentRef = getNodeService().getPrimaryParent(actionNode).getParentRef(); + Set parentPermission = getPermissionService().getAllSetPermissions(parentRef); + + Set permsForRemove = ManagePermissionsDialog.getPermissionsForType(); + Set allSetPerms = getPermissionService().getAllSetPermissions(getActiveNode().getNodeRef()); + for (AccessPermission perm : allSetPerms) + { + if (!parentPermission.contains(perm)) + { + if (perm.getAuthority().equals(personAuthority) && permsForRemove.contains(perm.getPermission())) + { + PermissionWrapper wraper = new PermissionWrapper(perm.getPermission(), perm.getPermission()); + personPerms.add(wraper); + } + } + } + + } + + /* + * (non-Javadoc) + * + * @see org.alfresco.web.bean.dialog.BaseDialogBean#getFinishButtonDisabled() + */ + @Override + public boolean getFinishButtonDisabled() + { + return finishButtonDisabled; + } + + /* + * (non-Javadoc) + * + * @see org.alfresco.web.bean.dialog.BaseDialogBean#getContainerTitle() + */ + @Override + public String getContainerTitle() + { + FacesContext fc = FacesContext.getCurrentInstance(); + String pattern = Application.getMessage(fc, MSG_EDIT_PERMS_FOR); + return MessageFormat.format(pattern, personAuthority); + } + + /* + * (non-Javadoc) + * + * @see org.alfresco.web.bean.wcm.BasePermissionsDialog#finishImpl(javax.faces.context.FacesContext, java.lang.String) + */ + @Override + protected String finishImpl(FacesContext context, String outcome) throws Exception + { + setPermissions(getActiveNode()); + createLock(getActiveNode()); + + finishButtonDisabled = true; + + return outcome; + } + + @Override + public String cancel() + { + finishButtonDisabled = true; + + return super.cancel(); + } + + /** + * Set permissions for current node + * + * @param node + */ + private void setPermissions(AVMNode node) + { + NodeRef nodeRef = node.getNodeRef(); + Set permsForRemove = ManagePermissionsDialog.getPermissionsForType(); + + // Set only those permissions that contains in personPerms + // Other permissions are removed + for (String perm : permsForRemove) + { + boolean needToSet = false; + for (PermissionWrapper wrapper : personPerms) + { + if (wrapper.getPermission().equals(perm)) + { + needToSet = true; + break; + } + } + + if (needToSet) + { + getPermissionService().setPermission(nodeRef, personAuthority, perm, true); + } + else + { + getPermissionService().deletePermission(nodeRef, personAuthority, perm); + } + } + } + + /** + * @return The list of available permissions for the users/groups + */ + public SelectItem[] getPerms() + { + + return WCMPermissionsUtils.getPermissions(); + } + + /** + * Action handler called when the Add Permission button is pressed to process the current selection + */ + public void addPermission(ActionEvent event) + { + UISelectOne permPicker = (UISelectOne) event.getComponent().findComponent("perms"); + + String permission = (String) permPicker.getValue(); + if (permission != null) + { + boolean foundExisting = false; + for (int n = 0; n < personPerms.size(); n++) + { + PermissionWrapper wrapper = personPerms.get(n); + if (wrapper.getPermission().equals(permission)) + { + foundExisting = true; + break; + } + } + + if (!foundExisting) + { + FacesContext context = FacesContext.getCurrentInstance(); + PermissionWrapper wrapper = new PermissionWrapper(permission, Application.getMessage(context, permission)); + this.personPerms.add(wrapper); + finishButtonDisabled = false; + } + } + + } + + /** + * Returns the properties for current Person permissions JSF DataModel + * + * @return JSF DataModel representing the current Person permissions + */ + public DataModel getPersonPermsDataModel() + { + if (this.personPermsDataModel == null) + { + this.personPermsDataModel = new ListDataModel(); + } + + if (this.personPermsDataModel.getWrappedData() == null) + { + this.personPermsDataModel.setWrappedData(this.personPerms); + } + + return this.personPermsDataModel; + } + + /** + * Action handler called when the Remove button is pressed to remove a permission from current user + */ + public void removePermission(ActionEvent event) + { + PermissionWrapper wrapper = (PermissionWrapper) getPersonPermsDataModel().getRowData(); + if (wrapper != null) + { + this.personPerms.remove(wrapper); + finishButtonDisabled = false; + } + } + +} diff --git a/source/java/org/alfresco/web/bean/wcm/ManagePermissionsDialog.java b/source/java/org/alfresco/web/bean/wcm/ManagePermissionsDialog.java new file mode 100644 index 0000000000..9cd4cae4bf --- /dev/null +++ b/source/java/org/alfresco/web/bean/wcm/ManagePermissionsDialog.java @@ -0,0 +1,609 @@ +/* + * Copyright (C) 2005-2008 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 as + * published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. As a special exception to the terms and conditions of version 2.0 of the GPL, you may redistribute this Program in connection with Free/Libre and + * Open Source Software ("FLOSS") applications as described in Alfresco's FLOSS exception. You should have recieved a copy of the text describing the FLOSS exception, and it is + * also available here: http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.web.bean.wcm; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.faces.context.FacesContext; +import javax.faces.event.ActionEvent; +import javax.faces.event.ValueChangeEvent; +import javax.transaction.UserTransaction; + +import org.alfresco.repo.avm.AVMNodeConverter; +import org.alfresco.service.cmr.repository.InvalidNodeRefException; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.security.AccessPermission; +import org.alfresco.service.cmr.security.AccessStatus; +import org.alfresco.service.cmr.security.AuthorityType; +import org.alfresco.service.cmr.security.PermissionService; +import org.alfresco.service.cmr.security.PersonService; +import org.alfresco.web.app.Application; +import org.alfresco.web.app.context.IContextListener; +import org.alfresco.web.bean.dialog.FilterViewSupport; +import org.alfresco.web.bean.repository.MapNode; +import org.alfresco.web.bean.repository.QNameNodeMap; +import org.alfresco.web.bean.repository.Repository; +import org.alfresco.web.bean.users.UserMembersBean; +import org.alfresco.web.ui.common.Utils; +import org.alfresco.web.ui.common.component.UIListItem; +import org.alfresco.web.ui.common.component.UIModeList; +import org.alfresco.web.ui.common.component.data.UIRichList; +import org.alfresco.web.ui.repo.WebResources; + +/** + * Class for ManagePermissions dialog + * + * @author Sergei Gavrusev + */ +public class ManagePermissionsDialog extends BasePermissionsDialog implements IContextListener, FilterViewSupport +{ + + private static final long serialVersionUID = -6980134441634707541L; + + private static final String MSG_MANAGE_PERMS_FOR = "manage_permissions_title"; + private static final String MSG_VIEW_PERMS_FOR = "view_permissions_title"; + + private static final String LOCAL = "local"; + + private static final String INHERITED = "inherited"; + + private final static String MSG_CLOSE = "close"; + + private String filterMode = INHERITED; + + + /** PersonService bean reference */ + transient private PersonService personService; + + private UIRichList usersRichList = null; + + private boolean inheritParenSpacePermissions; + + /** + * @param personService The personService to set. + */ + public void setPersonService(final PersonService personService) + { + this.personService = personService; + } + + /** + * Getter for personService + * + * @return personService + */ + protected PersonService getPersonService() + { + if (personService == null) + { + personService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getPersonService(); + } + return personService; + } + + /* + * (non-Javadoc) + * + * @see org.alfresco.web.bean.dialog.BaseDialogBean#init(java.util.Map) + */ + public void init(Map parameters) + { + super.init(parameters); + contextUpdated(); + inheritParenSpacePermissions = getPermissionService().getInheritParentPermissions(getAvmBrowseBean().getAvmActionNode().getNodeRef()); + } + + /* + * (non-Javadoc) + * + * @see org.alfresco.web.bean.dialog.BaseDialogBean#finishImpl(javax.faces.context.FacesContext, java.lang.String) + */ + protected String finishImpl(FacesContext context, String outcome) throws Exception + { + return null; + } + + /** + * @return the list of user nodes for list data binding + */ + public List getUsers() + { + + boolean includeInherited = true; + + if (this.filterMode.equals(LOCAL)) + { + includeInherited = false; + } + + FacesContext context = FacesContext.getCurrentInstance(); + + List personNodes = null; + + UserTransaction tx = null; + try + { + tx = Repository.getUserTransaction(context, true); + tx.begin(); + + // Return all the permissions set against the current node + // for any authentication instance (user/group). + // Then combine them into a single list for each authentication + // found. + + NodeRef actionNode = getAvmBrowseBean().getAvmActionNode().getNodeRef(); + // getPermissionService().setInheritParentPermissions(actionNode, inheritParenSpacePermissions); + + Map> permissionMap; + Map> parentPermissionMap; + Set permissions = getPermissionService().getAllSetPermissions(actionNode); + Set permsToDisplay = getPermissionsForType(); + + permissionMap = getPerson(permissions, permsToDisplay); + + NodeRef parentRef = getNodeService().getPrimaryParent(actionNode).getParentRef(); + // getPermissionService().getAllSetPermissions(parentRef); + parentPermissionMap = getPerson(getPermissionService().getAllSetPermissions(parentRef), permsToDisplay); + + // for each authentication (username/group key) found we get the + // Person + // node represented by it and use that for our list databinding + // object + personNodes = new ArrayList(permissionMap.size()); + List local = new ArrayList(); + List inh = new ArrayList(); + for (String authority : permissionMap.keySet()) + { + local.clear(); + inh.clear(); + + divisionPermissions(authority, permissionMap, parentPermissionMap, inh, local); + // check if we are dealing with a person (User Authority) + if (AuthorityType.getAuthorityType(authority) == AuthorityType.GUEST || getPersonService().personExists(authority)) + { + NodeRef nodeRef = getPersonService().getPerson(authority); + if (nodeRef != null) + { + // create our Node representation + MapNode node = new MapNode(nodeRef); + + // set data binding properties + // this will also force initialisation of the props now + // during the UserTransaction + // it is much better for performance to do this now + // rather than during page bind + + if (includeInherited) + { + addUserPermissions(node, context, inh, personNodes, nodeRef, true); + } + + addUserPermissions(node, context, local, personNodes, nodeRef, false); + } + } + else + { + // need a map (dummy node) to represent props for this Group + // Authority + + if (includeInherited) + { + addGroupPermissions(authority, context, personNodes, inh, true); + } + addGroupPermissions(authority, context, personNodes, local, false); + } + } + + // commit the transaction + tx.commit(); + } + catch (InvalidNodeRefException refErr) + { + Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, Repository.ERROR_NODEREF), new Object[] { refErr.getNodeRef() })); + personNodes = Collections. emptyList(); + try + { + if (tx != null) + { + tx.rollback(); + } + } + catch (Exception tex) + { + } + } + catch (Throwable err) + { + Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, Repository.ERROR_GENERIC), err.getMessage()), err); + personNodes = Collections. emptyList(); + try + { + if (tx != null) + { + tx.rollback(); + } + } + catch (Exception tex) + { + } + } + + return personNodes; + } + + /** + * Add group permissions + * + * @param authority + * @param context + * @param personNodes + * @param perms + * @param inherited + */ + private void addGroupPermissions(final String authority, FacesContext context, List personNodes, List perms, final boolean inherited) + { + if (perms == null || perms.size() == 0) + return; + Map node = new HashMap(5, 1.0f); + if (authority.startsWith(PermissionService.GROUP_PREFIX) == true) + { + node.put("fullName", authority.substring(PermissionService.GROUP_PREFIX.length())); + } + else + { + node.put("fullName", authority); + } + node.put("userName", authority); + node.put("id", authority); + node.put("perms", UserMembersBean.roleListToString(context, perms)); + node.put("icon", WebResources.IMAGE_GROUP); + node.put("inherited", inherited); + + personNodes.add(node); + } + + /** + * Add users permissions + * + * @param node + * @param context + * @param perms + * @param personNodes + * @param nodeRef + * @param inherited + */ + private void addUserPermissions(MapNode node, FacesContext context, List perms, List personNodes, NodeRef nodeRef, boolean inherited) + { + if (perms == null || perms.size() == 0) + return; + Map props = (Map) ((QNameNodeMap) node.getProperties()).clone(); + props.put("fullName", ((String) node.get("firstName")) + ' ' + ((String) node.get("lastName"))); + props.put("perms", UserMembersBean.roleListToString(context, perms)); + props.put("icon", WebResources.IMAGE_PERSON); + props.put("inherited", inherited); + + personNodes.add(props); + } + + /** + * Separate permissions on inherited and local + * + * @param authority + * @param person + * @param parentPerson + * @param inherited + * @param local + */ + private void divisionPermissions(String authority, Map> person, Map> parentPerson, List inherited, List local) + { + List parentPerms = parentPerson.get(authority); + List perms = person.get(authority); + if (parentPerms == null) + { + local.addAll(perms); + return; + } + if (perms.equals(parentPerms)) + { + inherited.addAll(perms); + return; + } + for (String perm : perms) + { + if (parentPerms.contains(perm)) + { + inherited.add(perm); + } + else + { + local.add(perm); + } + } + } + + /** + * @param permissions + * @param permsToDisplay + * @return + */ + private Map> getPerson(Set permissions, Set permsToDisplay) + { + Map> permissionMap = new HashMap>(8, 1.0f); + for (AccessPermission permission : permissions) + { + if (permsToDisplay.contains(permission.getPermission())) + { + // we are only interested in Allow and not groups/owner etc. + if (permission.getAccessStatus() == AccessStatus.ALLOWED + && (permission.getAuthorityType() == AuthorityType.USER || permission.getAuthorityType() == AuthorityType.GROUP + || permission.getAuthorityType() == AuthorityType.GUEST || permission.getAuthorityType() == AuthorityType.EVERYONE)) + { + String authority = permission.getAuthority(); + + List userPermissions = permissionMap.get(authority); + if (userPermissions == null) + { + // create for first time + userPermissions = new ArrayList(4); + permissionMap.put(authority, userPermissions); + } + // add the permission name for this authority + userPermissions.add(permission.getPermission()); + } + } + } + return permissionMap; + } + + /** + * Get available permissions + * + * @return Set of permissions + */ + public static Set getPermissionsForType() + { + Set permissions = new LinkedHashSet(3); + permissions.add(PermissionService.READ); + permissions.add(PermissionService.WRITE); + permissions.add(PermissionService.DELETE); + + return permissions; + } + + /* + * (non-Javadoc) + * + * @see org.alfresco.web.app.context.IContextListener#areaChanged() + */ + public void areaChanged() + { + // nothing to do + + } + + /* + * (non-Javadoc) + * + * @see org.alfresco.web.app.context.IContextListener#contextUpdated() + */ + public void contextUpdated() + { + if (this.usersRichList != null) + { + this.usersRichList.setValue(null); + } + + } + + /* + * (non-Javadoc) + * + * @see org.alfresco.web.app.context.IContextListener#spaceChanged() + */ + public void spaceChanged() + { + // nothing to do + + } + + /* + * (non-Javadoc) + * + * @see org.alfresco.web.bean.dialog.FilterViewSupport#filterModeChanged(javax.faces.event.ActionEvent) + */ + public void filterModeChanged(ActionEvent event) + { + UIModeList viewList = (UIModeList) event.getComponent(); + // this.filterModeMode = viewList.getValue().toString(); + setFilterMode(viewList.getValue().toString()); + // force the list to be re-queried when the page is refreshed + if (this.usersRichList != null) + { + this.usersRichList.setValue(null); + } + + } + + /* + * (non-Javadoc) + * + * @see org.alfresco.web.bean.dialog.FilterViewSupport#getFilterItems() + */ + public List getFilterItems() + { + FacesContext context = FacesContext.getCurrentInstance(); + List items = new ArrayList(2); + + UIListItem item1 = new UIListItem(); + item1.setValue(INHERITED); + item1.setLabel(Application.getMessage(context, INHERITED)); + items.add(item1); + + UIListItem item2 = new UIListItem(); + item2.setValue(LOCAL); + item2.setLabel(Application.getMessage(context, LOCAL)); + items.add(item2); + + return items; + } + + /* + * (non-Javadoc) + * + * @see org.alfresco.web.bean.dialog.FilterViewSupport#getFilterMode() + */ + public String getFilterMode() + { + return filterMode; + } + + /* + * (non-Javadoc) + * + * @see org.alfresco.web.bean.dialog.FilterViewSupport#setFilterMode(java.lang.String) + */ + public void setFilterMode(final String filterMode) + { + this.filterMode = filterMode; + + // clear datalist cache ready to change results based on filter setting + contextUpdated(); + + } + + /** + * Getter for usersRichList + * + * @return usersRichList + */ + public UIRichList getUsersRichList() + { + return usersRichList; + } + + /** + * Setter for usersRichList + * + * @param usersRichList + */ + public void setUsersRichList(final UIRichList usersRichList) + { + this.usersRichList = usersRichList; + } + + + + /* + * (non-Javadoc) + * + * @see org.alfresco.web.bean.dialog.BaseDialogBean#restored() + */ + @Override + public void restored() + { + super.restored(); + contextUpdated(); + } + + /* + * (non-Javadoc) + * + * @see org.alfresco.web.bean.dialog.BaseDialogBean#getCancelButtonLabel() + */ + @Override + public String getCancelButtonLabel() + { + return Application.getMessage(FacesContext.getCurrentInstance(), MSG_CLOSE); + } + + /* + * (non-Javadoc) + * + * @see org.alfresco.web.bean.dialog.BaseDialogBean#getFinishButtonDisabled() + */ + @Override + public boolean getFinishButtonDisabled() + { + + return false; + } + + /* + * (non-Javadoc) + * + * @see org.alfresco.web.bean.dialog.BaseDialogBean#getActionsContext() + */ + @Override + public Object getActionsContext() + { + return this; + } + + @Override + public String getContainerTitle() + { + FacesContext fc = FacesContext.getCurrentInstance(); + String pattern = Application.getMessage(fc, isRendered() ? MSG_MANAGE_PERMS_FOR : MSG_VIEW_PERMS_FOR); + + // avmBrowseBean.getAvmActionNode().getNodePath().toDisplayPath(getNodeService(), getPermissionService()); + return MessageFormat.format(pattern, getAvmBrowseBean().getAvmActionNode().getName()); + } + + /** + * @return true if node in Staging Sandbox + */ + public boolean isRendered() + { + boolean result = false; + final String path = AVMNodeConverter.ToAVMVersionPath(getAvmBrowseBean().getAvmActionNode().getNodeRef()).getSecond(); + if (!AVMUtil.isMainStore(AVMUtil.getStoreName(path))) + { + result = true; + } + return result; + + } + + /** + * Getter for inheritParenSpacePermissions + * + * @return inheritParenSpacePermissions + */ + public boolean isInheritParenSpacePermissions() + { + return inheritParenSpacePermissions; + } + + /** + * Setter for inheritParenSpacePermissions Set the global inheritance behaviour for permissions on a node. + * + * @param inheritParenSpacePermissions + */ + public void setInheritParenSpacePermissions(final boolean inheritParenSpacePermissions) + { + this.inheritParenSpacePermissions = inheritParenSpacePermissions; + getPermissionService().setInheritParentPermissions(getAvmBrowseBean().getAvmActionNode().getNodeRef(), inheritParenSpacePermissions); + contextUpdated(); + } + + public void inheritPermissionsValueChanged(ValueChangeEvent event) + { + boolean inheritPermissions = (Boolean)event.getNewValue(); + setInheritParenSpacePermissions(inheritPermissions); + } + +} diff --git a/source/java/org/alfresco/web/bean/wcm/RemovePermissionsDialog.java b/source/java/org/alfresco/web/bean/wcm/RemovePermissionsDialog.java new file mode 100644 index 0000000000..444f95793a --- /dev/null +++ b/source/java/org/alfresco/web/bean/wcm/RemovePermissionsDialog.java @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2005-2008 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 as + * published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. As a special exception to the terms and conditions of version 2.0 of the GPL, you may redistribute this Program in connection with Free/Libre and + * Open Source Software ("FLOSS") applications as described in Alfresco's FLOSS exception. You should have recieved a copy of the text describing the FLOSS exception, and it is + * also available here: http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.web.bean.wcm; + +import java.text.MessageFormat; +import java.util.Map; +import java.util.Set; + +import javax.faces.context.FacesContext; +import javax.faces.event.ActionEvent; + +import org.alfresco.service.cmr.security.AccessPermission; +import org.alfresco.web.app.Application; +import org.alfresco.web.ui.common.component.UIActionLink; + +/** + * Class for RemovePermissions dialog + * + * @author Sergei Gavrusev + */ +public class RemovePermissionsDialog extends UpdatePermissionsDialog +{ + private static final long serialVersionUID = 7804466683515156182L; + + private static final String MSG_YES = "yes"; + private static final String MSG_NO = "no"; + private static final String MSG_REMOVE_PERMS_FOR = "remove_permissions_title"; + private String personAuthority = null; + + @Override + public boolean getFinishButtonDisabled() + { + return false; + } + + @Override + public String getFinishButtonLabel() + { + return Application.getMessage(FacesContext.getCurrentInstance(), MSG_YES); + } + + @Override + public String getCancelButtonLabel() + { + + return Application.getMessage(FacesContext.getCurrentInstance(), MSG_NO); + } + + @Override + public String getContainerTitle() + { + + FacesContext fc = FacesContext.getCurrentInstance(); + String pattern = Application.getMessage(fc, MSG_REMOVE_PERMS_FOR); + return MessageFormat.format(pattern, personAuthority); + + } + + + @Override + public void init(Map parameters) + { + super.init(parameters); + setActiveNode(getAvmBrowseBean().getAvmActionNode()); + } + + + @Override + protected String finishImpl(FacesContext context, String outcome) throws Exception + { + + removePermissions(getActiveNode()); + createLock(getActiveNode()); + + return outcome; + } + + /** + * Remove permission from node + * + * @param node + */ + private void removePermissions(AVMNode node) + { + Set permsForRemove = ManagePermissionsDialog.getPermissionsForType(); + Set allSetPerms = getPermissionService().getAllSetPermissions(node.getNodeRef()); + for (AccessPermission perm : allSetPerms) + { + if (perm.getAuthority().equals(personAuthority) && permsForRemove.contains(perm.getPermission())) + { + getPermissionService().deletePermission(node.getNodeRef(), personAuthority, perm.getPermission()); + + } + } + } + + /** + * @param event + */ + public void setupAction(ActionEvent event) + { + + UIActionLink link = (UIActionLink) event.getComponent(); + Map params = link.getParameterMap(); + personAuthority = params.get("userName"); + } + +} diff --git a/source/java/org/alfresco/web/bean/wcm/SetPermissionsDialog.java b/source/java/org/alfresco/web/bean/wcm/SetPermissionsDialog.java new file mode 100644 index 0000000000..7f1c118867 --- /dev/null +++ b/source/java/org/alfresco/web/bean/wcm/SetPermissionsDialog.java @@ -0,0 +1,498 @@ +/* + * Copyright (C) 2005-2008 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 as + * published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. As a special exception to the terms and conditions of version 2.0 of the GPL, you may redistribute this Program in connection with Free/Libre and + * Open Source Software ("FLOSS") applications as described in Alfresco's FLOSS exception. You should have recieved a copy of the text describing the FLOSS exception, and it is + * also available here: http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.web.bean.wcm; + +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.Serializable; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.ResourceBundle; +import java.util.Set; + +import javax.faces.component.UISelectOne; +import javax.faces.context.FacesContext; +import javax.faces.event.ActionEvent; +import javax.faces.model.DataModel; +import javax.faces.model.ListDataModel; +import javax.faces.model.SelectItem; +import javax.transaction.UserTransaction; + +import org.alfresco.model.ContentModel; +import org.alfresco.repo.avm.AVMNodeConverter; +import org.alfresco.repo.search.impl.lucene.QueryParser; +import org.alfresco.service.cmr.avm.AVMNodeDescriptor; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.search.ResultSet; +import org.alfresco.service.cmr.search.SearchService; +import org.alfresco.service.cmr.security.AuthorityService; +import org.alfresco.service.cmr.security.AuthorityType; +import org.alfresco.service.cmr.security.PermissionService; +import org.alfresco.service.cmr.security.PersonService; +import org.alfresco.service.namespace.NamespaceService; +import org.alfresco.web.app.Application; +import org.alfresco.web.bean.repository.Repository; +import org.alfresco.web.ui.common.SortableSelectItem; +import org.alfresco.web.ui.common.Utils; +import org.alfresco.web.ui.common.component.UIGenericPicker; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * Class for SetPermissions dialog + * + * @author Sergei Gavrusev + */ +public class SetPermissionsDialog extends UpdatePermissionsDialog +{ + + private static final long serialVersionUID = -8139619811033232880L; + + /** logger */ + private static Log logger = LogFactory.getLog(SetPermissionsDialog.class); + + private static final String MSG_USERS = "users"; + private static final String MSG_GROUPS = "groups"; + + private static final String MSG_SET_PERMS_FOR = "set_permissions_title"; + + transient private AuthorityService authorityService; + transient private PersonService personService; + + transient private DataModel userPermsDataModel = null; + + private List childList = null; + private List userGroupPerms = null; + + /** + * @param authorityService The authorityService to set. + */ + public void setAuthorityService(final AuthorityService authorityService) + { + this.authorityService = authorityService; + } + + /** + * Getter for authorityService + * + * @return authorityService + */ + protected AuthorityService getAuthorityService() + { + if (authorityService == null) + { + authorityService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getAuthorityService(); + } + return authorityService; + } + + /** + * @param personService The PersonService to set. + */ + public void setPersonService(final PersonService personService) + { + this.personService = personService; + } + + /** + * Getter for personService + * + * @return personService + */ + + protected PersonService getPersonService() + { + if (personService == null) + { + personService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getPersonService(); + } + return personService; + } + + /* + * (non-Javadoc) + * + * @see org.alfresco.web.bean.wcm.UpdatePermissionsDialog#init(java.util.Map) + */ + @Override + public void init(Map parameters) + { + super.init(parameters); + + setActiveNode(getAvmBrowseBean().getAvmActionNode()); + userGroupPerms = new ArrayList(8); + userPermsDataModel = null; + childList = new ArrayList(); + } + + /* + * (non-Javadoc) + * + * @see org.alfresco.web.bean.dialog.BaseDialogBean#getFinishButtonDisabled() + */ + @Override + public boolean getFinishButtonDisabled() + { + if (userGroupPerms.size() == 0) + return true; + else + return false; + } + + /* + * (non-Javadoc) + * + * @see org.alfresco.web.bean.dialog.BaseDialogBean#getContainerTitle() + */ + @Override + public String getContainerTitle() + { + + FacesContext fc = FacesContext.getCurrentInstance(); + String pattern = Application.getMessage(fc, MSG_SET_PERMS_FOR); + return MessageFormat.format(pattern, getActiveNode().getName()); + + } + + /* + * (non-Javadoc) + * + * @see org.alfresco.web.bean.wcm.BasePermissionsDialog#finishImpl(javax.faces.context.FacesContext, java.lang.String) + */ + @Override + protected String finishImpl(FacesContext context, String outcome) throws Exception + { + // check if any permissions was selected + if (userGroupPerms.size() > 0) + { + childList.add(getActiveNode().getDescriptor()); + setPermissions(getActiveNode().getDescriptor()); + createLock(getActiveNode()); + } + + return outcome; + } + + /** + * Set permissions for current node + * + * @param node + */ + private void setPermissions(final AVMNodeDescriptor node) + { + + for (int i = 0; i < userGroupPerms.size(); i++) + { + UserGroupPerm userGroupPerm = userGroupPerms.get(i); + final String authority = userGroupPerm.getAuthority(); + // find the selected permission ref from it's name and apply for the specified user + Set perms = ManagePermissionsDialog.getPermissionsForType(); + for (final String permission : perms) + { + if (userGroupPerm.getPermission().equals(permission)) + { + getPermissionService().setPermission(AVMNodeConverter.ToNodeRef(-1, node.getPath()), authority, permission, true); + + if (logger.isDebugEnabled()) + logger.debug("permission setted:" + permission); + break; + } + } + } + + } + + /** + * Property accessed by the Generic Picker component. + * + * @return The array of filter options to show in the users/groups picker + */ + public SelectItem[] getFilters() + { + ResourceBundle bundle = Application.getBundle(FacesContext.getCurrentInstance()); + + return new SelectItem[] { new SelectItem("0", bundle.getString(MSG_USERS)), new SelectItem("1", bundle.getString(MSG_GROUPS)) }; + } + + /** + * Query callback method executed by the Generic Picker component. This method is part of the contract to the Generic Picker, it is up to the backing bean to execute whatever + * query is appropriate and return the results. + * + * @param filterIndex Index of the filter drop-down selection + * @param contains Text from the contains textbox + * @return An array of SelectItem objects containing the results to display in the picker. + */ + public SelectItem[] pickerCallback(int filterIndex, String contains) + { + FacesContext context = FacesContext.getCurrentInstance(); + + SelectItem[] items; + + UserTransaction tx = null; + try + { + tx = Repository.getUserTransaction(context, true); + tx.begin(); + + List results = new ArrayList(); + + if (filterIndex == 0) + { + // Use lucene search to retrieve user details + String term = QueryParser.escape(contains.trim()); + StringBuilder query = new StringBuilder(128); + query.append("@").append(NamespaceService.CONTENT_MODEL_PREFIX).append("\\:firstName:\"*"); + query.append(term); + query.append("*\" @").append(NamespaceService.CONTENT_MODEL_PREFIX).append("\\:lastName:\"*"); + query.append(term); + query.append("*\" @").append(NamespaceService.CONTENT_MODEL_PREFIX).append("\\:userName:"); + query.append(term); + query.append("*"); + ResultSet resultSet = Repository.getServiceRegistry(context).getSearchService().query(Repository.getStoreRef(), SearchService.LANGUAGE_LUCENE, query.toString()); + List nodes = resultSet.getNodeRefs(); + + for (int index = 0; index < nodes.size(); index++) + { + NodeRef personRef = nodes.get(index); + String firstName = (String) getNodeService().getProperty(personRef, ContentModel.PROP_FIRSTNAME); + String lastName = (String) getNodeService().getProperty(personRef, ContentModel.PROP_LASTNAME); + String username = (String) getNodeService().getProperty(personRef, ContentModel.PROP_USERNAME); + if (username != null) + { + SelectItem item = new SortableSelectItem(username, firstName + " " + lastName + " [" + username + "]", lastName); + results.add(item); + } + } + } + else + { + // groups - simple text based match on name + Set groups = getAuthorityService().getAllAuthorities(AuthorityType.GROUP); + groups.addAll(getAuthorityService().getAllAuthorities(AuthorityType.EVERYONE)); + + String containsLower = contains.trim().toLowerCase(); + int offset = PermissionService.GROUP_PREFIX.length(); + for (String group : groups) + { + if (group.toLowerCase().indexOf(containsLower, offset) != -1) + { + results.add(new SortableSelectItem(group, group.substring(offset), group)); + } + } + } + + items = new SelectItem[results.size()]; + results.toArray(items); + Arrays.sort(items); + + // commit the transaction + tx.commit(); + } + catch (Throwable err) + { + Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err); + try + { + if (tx != null) + { + tx.rollback(); + } + } + catch (Exception tex) + { + } + + items = new SelectItem[0]; + } + + return items; + } + + /** + * Action handler called when the Add button is pressed to process the current selection + */ + public void addSelection(ActionEvent event) + { + UIGenericPicker picker = (UIGenericPicker) event.getComponent().findComponent("picker"); + UISelectOne permissionPicker = (UISelectOne) event.getComponent().findComponent("permissions"); + + String[] results = picker.getSelectedResults(); + if (results != null) + { + String permission = (String) permissionPicker.getValue(); + if (permission != null) + { + for (int i = 0; i < results.length; i++) + { + addAuthorityWithPerm(results[i], permission); + } + } + } + } + + /** + * Add an authority with the specified permission to the list . + * + * @param authority Authority to add (cannot be null) + * @param permsission Permission for the authorities (cannot be null) + */ + public void addAuthorityWithPerm(String authority, String permsission) + { + // only add if authority not already present in the list with same role + boolean foundExisting = false; + for (int n = 0; n < userGroupPerms.size(); n++) + { + UserGroupPerm wrapper = userGroupPerms.get(n); + if (authority.equals(wrapper.getAuthority()) && (permsission.equals(wrapper.getPermission()))) + { + foundExisting = true; + break; + } + } + + if (foundExisting == false) + { + StringBuilder label = new StringBuilder(64); + + // build a display label showing the user and their role for the space + AuthorityType authType = AuthorityType.getAuthorityType(authority); + if (authType == AuthorityType.GUEST || authType == AuthorityType.USER) + { + if (authType == AuthorityType.GUEST || getPersonService().personExists(authority) == true) + { + // found a User authority + label.append(buildLabelForUserAuthorityPerm(authority, permsission)); + } + } + else + { + // found a group authority + label.append(buildLabelForGroupAuthorityPerm(authority, permsission)); + } + + userGroupPerms.add(new UserGroupPerm(authority, permsission, label.toString())); + } + } + + /** + * Action handler called when the Remove button is pressed to remove a user+permission + */ + public void removeSelection(ActionEvent event) + { + UserGroupPerm wrapper = (UserGroupPerm) getUserPermsDataModel().getRowData(); + if (wrapper != null) + { + userGroupPerms.remove(wrapper); + } + } + + /** + * Returns the properties for current user-roles JSF DataModel + * + * @return JSF DataModel representing the current user-permission + */ + public DataModel getUserPermsDataModel() + { + if (userPermsDataModel == null) + { + userPermsDataModel = new ListDataModel(); + } + + // only set the wrapped data once otherwise the rowindex is reset + if (userPermsDataModel.getWrappedData() == null) + { + userPermsDataModel.setWrappedData(userGroupPerms); + } + + return userPermsDataModel; + } + + /** + * Helper to build a label of the form: Firstname Lastname (permission) + */ + public String buildLabelForUserAuthorityPerm(String authority, String role) + { + // found a User authority + NodeRef ref = getPersonService().getPerson(authority); + String firstName = (String) getNodeService().getProperty(ref, ContentModel.PROP_FIRSTNAME); + String lastName = (String) getNodeService().getProperty(ref, ContentModel.PROP_LASTNAME); + + StringBuilder buf = new StringBuilder(100); + buf.append(firstName).append(" ").append(lastName != null ? lastName : "").append(" (").append(Application.getMessage(FacesContext.getCurrentInstance(), role)).append(")"); + + return buf.toString(); + } + + /** + * Helper to build a label for a Group authority of the form: Groupname (permission) + */ + public String buildLabelForGroupAuthorityPerm(String authority, String role) + { + StringBuilder buf = new StringBuilder(100); + buf.append(authority.substring(PermissionService.GROUP_PREFIX.length())).append(" (").append(Application.getMessage(FacesContext.getCurrentInstance(), role)).append(")"); + + return buf.toString(); + } + + private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException + { + in.defaultReadObject(); + + userPermsDataModel = new ListDataModel(); + userPermsDataModel.setWrappedData(userGroupPerms); + + } + + /** + * @return The list of available permissions for the users/groups + */ + public SelectItem[] getPermissions() + { + + return WCMPermissionsUtils.getPermissions(); + } + + /** + * Simple wrapper class to represent a user/group and a permission combination + */ + public static class UserGroupPerm implements Serializable + { + private static final long serialVersionUID = -1546705703700113861L; + + public UserGroupPerm(String authority, String permission, String label) + { + this.authority = authority; + this.permission = permission; + this.label = label; + } + + public String getAuthority() + { + return authority; + } + + public String getPermission() + { + return permission; + } + + public String getLabel() + { + return label; + } + + private String authority; + private String permission; + private String label; + } +} diff --git a/source/java/org/alfresco/web/bean/wcm/UpdatePermissionsDialog.java b/source/java/org/alfresco/web/bean/wcm/UpdatePermissionsDialog.java new file mode 100644 index 0000000000..3934f9fa44 --- /dev/null +++ b/source/java/org/alfresco/web/bean/wcm/UpdatePermissionsDialog.java @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2005-2008 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 as + * published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. As a special exception to the terms and conditions of version 2.0 of the GPL, you may redistribute this Program in connection with Free/Libre and + * Open Source Software ("FLOSS") applications as described in Alfresco's FLOSS exception. You should have recieved a copy of the text describing the FLOSS exception, and it is + * also available here: http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.web.bean.wcm; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.faces.context.FacesContext; + +import org.alfresco.service.cmr.avm.locking.AVMLock; +import org.alfresco.service.cmr.avm.locking.AVMLockingService; +import org.alfresco.service.cmr.security.AuthenticationService; +import org.alfresco.web.bean.repository.Repository; + +/** + * Base class for Remove,Set,Edit Permissions dialogs + * + * @author Sergei Gavrusev + */ +public class UpdatePermissionsDialog extends BasePermissionsDialog +{ + private static final long serialVersionUID = 7189321059584956816L; + transient private AVMLockingService avmLockingService; + transient private AuthenticationService authenticationService; + + private AVMNode activeNode; + + @Override + public void init(Map parameters) + { + + super.init(parameters); + } + + /** + * @param avmLockingService The AVMLockingService to set. + */ + public void setAvmLockingService(final AVMLockingService avmLockingService) + { + this.avmLockingService = avmLockingService; + } + + protected AVMLockingService getAvmLockingService() + { + if (avmLockingService == null) + { + avmLockingService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getAVMLockingService(); + } + return avmLockingService; + } + + /** + * @param authenticationService The AuthenticationService to set. + */ + protected void setAuthenticationService(final AuthenticationService authenticationService) + { + this.authenticationService = authenticationService; + } + + protected AuthenticationService getAuthenticationService() + { + if (authenticationService == null) + { + authenticationService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getAuthenticationService(); + } + + return authenticationService; + } + + /** + * Create lock for node if it is necessary. Also create lock for children, if they inherit parent permissions. + * + * @param node + */ + protected void createLock(AVMNode node) + { + if (getAvmLockingService().getLock(node.getWebProject().getStoreId(), node.getPath().substring(node.getPath().indexOf("/"))) == null && !node.isDirectory()) + { + String userName = getAuthenticationService().getCurrentUserName(); + List owners = new ArrayList(1); + owners.add(userName); + + String webProject = node.getWebProject().getStoreId(); + String[] storePath = node.getPath().split(":"); + + AVMLock lock = new AVMLock(webProject, storePath[0], storePath[1], AVMLockingService.Type.DISCRETIONARY, owners); + getAvmLockingService().lockPath(lock); + } + + } + + /** + * Getter for active node property + * + * @return activeNode + */ + public AVMNode getActiveNode() + { + return activeNode; + } + + /** + * Setter for active node property + * + * @param activeNode + */ + public void setActiveNode(final AVMNode activeNode) + { + this.activeNode = activeNode; + } + +} diff --git a/source/java/org/alfresco/web/bean/wcm/WCMPermissionsUtils.java b/source/java/org/alfresco/web/bean/wcm/WCMPermissionsUtils.java new file mode 100644 index 0000000000..526c079911 --- /dev/null +++ b/source/java/org/alfresco/web/bean/wcm/WCMPermissionsUtils.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2005-2008 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 as + * published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. As a special exception to the terms and conditions of version 2.0 of the GPL, you may redistribute this Program in connection with Free/Libre and + * Open Source Software ("FLOSS") applications as described in Alfresco's FLOSS exception. You should have recieved a copy of the text describing the FLOSS exception, and it is + * also available here: http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.web.bean.wcm; + +import java.util.ResourceBundle; +import java.util.Set; + +import javax.faces.context.FacesContext; +import javax.faces.model.SelectItem; + +import org.alfresco.web.app.Application; + +public class WCMPermissionsUtils +{ + /** + * @return The list of available permissions for the users/groups + */ + public static SelectItem[] getPermissions() + { + ResourceBundle bundle = Application.getBundle(FacesContext.getCurrentInstance()); + + Set perms = ManagePermissionsDialog.getPermissionsForType(); + SelectItem[] permissions = new SelectItem[perms.size()]; + int index = 0; + for (String permission : perms) + { + String displayLabel = bundle.getString(permission); + permissions[index++] = new SelectItem(permission, displayLabel); + } + + return permissions; + } + +} diff --git a/source/web/WEB-INF/faces-config-beans.xml b/source/web/WEB-INF/faces-config-beans.xml index 720a663cae..d50e46bd8f 100644 --- a/source/web/WEB-INF/faces-config-beans.xml +++ b/source/web/WEB-INF/faces-config-beans.xml @@ -43,6 +43,26 @@ #{DocumentDetailsDialog.translationDocument} + + + The bean for the Manage Permissions. + + ManagePermissionsDialog + + org.alfresco.web.bean.wcm.ManagePermissionsDialog + + session + + + personService + #{PersonService} + + + avmBrowseBean + #{AVMBrowseBean} + + + @@ -3673,27 +3693,27 @@ #{NodeService} - - - - The bean that backs up the Unlock File Dialog - - UnlockFileDialog - org.alfresco.web.bean.wcm.UnlockFileDialog - session - - avmService - #{AVMLockingAwareService} - - - avmLockingService - #{AVMLockingService} - - - avmBrowseBean - #{AVMBrowseBean} - - + + + + The bean that backs up the Unlock File Dialog + + UnlockFileDialog + org.alfresco.web.bean.wcm.UnlockFileDialog + session + + avmService + #{AVMLockingAwareService} + + + avmLockingService + #{AVMLockingService} + + + avmBrowseBean + #{AVMBrowseBean} + + @@ -5828,4 +5848,76 @@ + + + + + + + + The bean that backs up the view of the Set Permissions + + SetPermissionsDialog + + org.alfresco.web.bean.wcm.SetPermissionsDialog + + session + + authorityService + #{AuthorityService} + + + personService + #{PersonService} + + + avmBrowseBean + #{AVMBrowseBean} + + + + nodeService + #{NodeService} + + + + + + The bean that backs up the view of the Remove Permissions + + RemovePermissionsDialog + + org.alfresco.web.bean.wcm.RemovePermissionsDialog + + session + + avmBrowseBean + #{AVMBrowseBean} + + + avmLockingService + #{AVMLockingService} + + + + + + The bean that backs up the view of the Edit Permissions + + EditPermissionsDialog + + org.alfresco.web.bean.wcm.EditPermissionsDialog + + session + + avmBrowseBean + #{AVMBrowseBean} + + + avmLockingService + #{AVMLockingService} + + + + diff --git a/source/web/images/icons/manage_permissions.gif b/source/web/images/icons/manage_permissions.gif new file mode 100644 index 0000000000..45704b50bd Binary files /dev/null and b/source/web/images/icons/manage_permissions.gif differ diff --git a/source/web/jsp/wcm/edit-permissions.jsp b/source/web/jsp/wcm/edit-permissions.jsp new file mode 100644 index 0000000000..d2750b0824 --- /dev/null +++ b/source/web/jsp/wcm/edit-permissions.jsp @@ -0,0 +1,124 @@ +<%-- + * Copyright (C) 2005-2008 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 + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" +--%> +<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> +<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib uri="/WEB-INF/alfresco.tld" prefix="a" %> +<%@ taglib uri="/WEB-INF/repo.tld" prefix="r" %> + +<%@ page buffer="32kb" contentType="text/html;charset=UTF-8" %> +<%@ page isELIgnored="false" %> +<%@ page import="org.alfresco.web.ui.common.PanelGenerator" %> + + + + + + + + <%-- Details --%> + + + + + + + + + + + + + + + + + + + + + + + + + + + +
1. 
+ + + + + +
+ 2.  +
+ + + + + + + + + + + + + + + + + + + + + +
+
+
+ +
+ +
\ No newline at end of file diff --git a/source/web/jsp/wcm/manage-permissions.jsp b/source/web/jsp/wcm/manage-permissions.jsp new file mode 100644 index 0000000000..ffe0d0ab67 --- /dev/null +++ b/source/web/jsp/wcm/manage-permissions.jsp @@ -0,0 +1,138 @@ + +<%-- + * Copyright (C) 2005-2008 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 + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" +--%> +<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%> +<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> +<%@ taglib uri="/WEB-INF/alfresco.tld" prefix="a"%> +<%@ taglib uri="/WEB-INF/repo.tld" prefix="r"%> + +<%@ page buffer="32kb" contentType="text/html;charset=UTF-8"%> +<%@ page isELIgnored="false"%> +<%@ page import="org.alfresco.web.ui.common.PanelGenerator"%> + + +<%-- load a bundle of properties with I18N strings --%> + + + + + + + <%-- Primary column with full name --%> + + + + + + + + + + + <%-- Username column --%> + + + + + + + <%-- Created Date column for details view mode --%> + + <%-- Column to show whether the rule is local --%> + + + + + + + + + + <%-- Permission column --%> + + + + + + + + <%-- Actions column --%> + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +   +
+
diff --git a/source/web/jsp/wcm/remove-permissions.jsp b/source/web/jsp/wcm/remove-permissions.jsp new file mode 100644 index 0000000000..31dddc99de --- /dev/null +++ b/source/web/jsp/wcm/remove-permissions.jsp @@ -0,0 +1,55 @@ +<%-- + * Copyright (C) 2005-2008 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 + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" +--%> +<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> +<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> +<%@ taglib uri="/WEB-INF/alfresco.tld" prefix="a" %> +<%@ taglib uri="/WEB-INF/repo.tld" prefix="r" %> + +<%@ page buffer="32kb" contentType="text/html;charset=UTF-8" %> +<%@ page isELIgnored="false" %> + + + + + + + + + + diff --git a/source/web/jsp/wcm/set-permissions.jsp b/source/web/jsp/wcm/set-permissions.jsp new file mode 100644 index 0000000000..1ee3cb0dd6 --- /dev/null +++ b/source/web/jsp/wcm/set-permissions.jsp @@ -0,0 +1,92 @@ +<%-- + * Copyright (C) 2005-2008 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 + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" +--%> +<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> +<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> +<%@ taglib uri="/WEB-INF/alfresco.tld" prefix="a" %> +<%@ taglib uri="/WEB-INF/repo.tld" prefix="r" %> + +<%@ page buffer="32kb" contentType="text/html;charset=UTF-8" %> +<%@ page isELIgnored="false" %> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +