1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.exoplatform.ecm.webui.component.explorer.popup.info;
18
19 import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer;
20 import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorerPortlet;
21 import org.exoplatform.ecm.webui.core.UIPermissionInfoBase;
22 import org.exoplatform.ecm.webui.utils.PermissionUtil;
23 import org.exoplatform.ecm.webui.utils.Utils;
24 import org.exoplatform.services.cms.link.LinkManager;
25 import org.exoplatform.services.cms.link.LinkUtils;
26 import org.exoplatform.services.jcr.access.PermissionType;
27 import org.exoplatform.services.jcr.core.ExtendedNode;
28 import org.exoplatform.services.log.ExoLogger;
29 import org.exoplatform.services.log.Log;
30 import org.exoplatform.services.security.IdentityConstants;
31 import org.exoplatform.services.wcm.core.NodetypeConstant;
32 import org.exoplatform.web.application.ApplicationMessage;
33 import org.exoplatform.webui.config.annotation.ComponentConfig;
34 import org.exoplatform.webui.config.annotation.EventConfig;
35 import org.exoplatform.webui.core.UIApplication;
36 import org.exoplatform.webui.core.UIGrid;
37 import org.exoplatform.webui.core.UIPopupContainer;
38 import org.exoplatform.webui.core.lifecycle.UIContainerLifecycle;
39 import org.exoplatform.webui.event.Event;
40 import org.exoplatform.webui.event.EventListener;
41
42 import javax.jcr.AccessDeniedException;
43 import javax.jcr.Node;
44 import java.util.List;
45
46 @ComponentConfig(lifecycle = UIContainerLifecycle.class, events = {
47 @EventConfig(listeners = UIPermissionInfo.DeleteActionListener.class,
48 confirm = "UIPermissionInfo.msg.confirm-delete-permission"),
49 @EventConfig(listeners = UIPermissionInfo.EditActionListener.class) })
50 public class UIPermissionInfo extends UIPermissionInfoBase {
51
52 public UIPermissionInfo() throws Exception {
53 super();
54 }
55
56 private static final Log LOG = ExoLogger.getLogger(UIPermissionInfo.class.getName());
57
58 static public class DeleteActionListener extends EventListener<UIPermissionInfo> {
59 public void execute(Event<UIPermissionInfo> event) throws Exception {
60 UIPermissionInfo uicomp = event.getSource() ;
61 UIJCRExplorer uiJCRExplorer = uicomp.getAncestorOfType(UIJCRExplorer.class) ;
62 Node currentNode = uiJCRExplorer.getCurrentNode() ;
63 uiJCRExplorer.addLockToken(currentNode);
64 ExtendedNode node = (ExtendedNode)currentNode;
65 String owner = IdentityConstants.SYSTEM ;
66 int iSystemOwner = 0;
67 if (uicomp.getExoOwner(node) != null) owner = uicomp.getExoOwner(node);
68 if (owner.equals(IdentityConstants.SYSTEM)) iSystemOwner = -1;
69 UIApplication uiApp = uicomp.getAncestorOfType(UIApplication.class) ;
70 if (uicomp.getSizeOfListPermission() < 2 + iSystemOwner) {
71 uiApp.addMessage(new ApplicationMessage("UIPermissionInfo.msg.no-permission-remove",
72 null, ApplicationMessage.WARNING));
73
74 return;
75 }
76 String name = event.getRequestContext().getRequestParameter(OBJECTID) ;
77 if(!currentNode.isCheckedOut()) {
78 uiApp.addMessage(new ApplicationMessage("UIActionBar.msg.node-checkedin", null,
79 ApplicationMessage.WARNING)) ;
80
81 return ;
82 }
83 String nodeOwner = Utils.getNodeOwner(node);
84 if(name.equals(nodeOwner)) {
85 uiApp.addMessage(new ApplicationMessage("UIPermissionInfo.msg.no-permission-remove", null,
86 ApplicationMessage.WARNING)) ;
87 return ;
88 }
89 if(PermissionUtil.canChangePermission(node)) {
90 if(node.canAddMixin("exo:privilegeable")) {
91 node.addMixin("exo:privilegeable");
92 node.setPermission(nodeOwner,PermissionType.ALL);
93 }
94 try {
95 node.removePermission(name) ;
96 node.save() ;
97 } catch(AccessDeniedException ace) {
98 node.getSession().refresh(false) ;
99 uiApp.addMessage(new ApplicationMessage("UIPermissionInfo.msg.access-denied", null,
100 ApplicationMessage.WARNING)) ;
101
102 return ;
103 }
104 if(uiJCRExplorer.getRootNode().equals(node)) {
105 if(!PermissionUtil.canRead(currentNode)) {
106 uiJCRExplorer.getAncestorOfType(UIJCRExplorerPortlet.class).reloadWhenBroken(uiJCRExplorer) ;
107 return ;
108 }
109 }
110 node.getSession().save() ;
111 } else {
112 uiApp.addMessage(new ApplicationMessage("UIPermissionInfo.msg.no-permission-tochange", null,
113 ApplicationMessage.WARNING)) ;
114
115 return ;
116 }
117 UIPopupContainer uiPopup = uicomp.getAncestorOfType(UIPopupContainer.class) ;
118 if(!PermissionUtil.canRead(node)) {
119 uiJCRExplorer.setSelectNode(LinkUtils.getParentPath(uiJCRExplorer.getCurrentPath()));
120 uiPopup.deActivate() ;
121 } else {
122 uicomp.updateGrid(uicomp.getChild(UIGrid.class).getUIPageIterator().getCurrentPage());
123 event.getRequestContext().addUIComponentToUpdateByAjax(uicomp.getParent()) ;
124 }
125 Node realNode = uiJCRExplorer.getRealCurrentNode();
126 LinkManager linkManager = uiJCRExplorer.getApplicationComponent(LinkManager.class);
127 if (linkManager.isLink(realNode)) {
128
129 linkManager.updateLink(realNode, currentNode);
130 }
131
132 if(currentNode.isNodeType(NodetypeConstant.MIX_REFERENCEABLE)){
133 List<Node> symlinks = linkManager.getAllLinks(currentNode, "exo:symlink");
134 for (Node symlink : symlinks) {
135 try {
136 linkManager.updateLink(symlink, currentNode);
137 } catch (Exception e) {
138 if (LOG.isWarnEnabled()) {
139 LOG.warn(e.getMessage());
140 }
141 }
142 }
143 }
144 currentNode.getSession().save();
145 uiJCRExplorer.setIsHidePopup(true) ;
146 if(!PermissionUtil.canRead(currentNode)){
147 uiPopup.cancelPopupAction();
148 uiJCRExplorer.refreshExplorer(currentNode.getSession().getRootNode(), true);
149 }else {
150 uiJCRExplorer.refreshExplorer(currentNode, false);
151 }
152 event.getRequestContext().addUIComponentToUpdateByAjax(uiJCRExplorer) ;
153 }
154 }
155
156 public Node getCurrentNode() throws Exception {
157 return this.getAncestorOfType(UIJCRExplorer.class).getCurrentNode();
158 }
159 }
160