1 | <%-- $Id: view_role.jsp 4889 2009-04-06 12:52:39Z nicklas $ |
---|
2 | ------------------------------------------------------------------ |
---|
3 | Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson |
---|
4 | Copyright (C) 2007 Nicklas Nordborg |
---|
5 | |
---|
6 | This file is part of BASE - BioArray Software Environment. |
---|
7 | Available at http://base.thep.lu.se/ |
---|
8 | |
---|
9 | BASE is free software; you can redistribute it and/or |
---|
10 | modify it under the terms of the GNU General Public License |
---|
11 | as published by the Free Software Foundation; either version 3 |
---|
12 | of the License, or (at your option) any later version. |
---|
13 | |
---|
14 | BASE is distributed in the hope that it will be useful, |
---|
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | GNU General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU General Public License |
---|
20 | along with BASE. If not, see <http://www.gnu.org/licenses/>. |
---|
21 | ------------------------------------------------------------------ |
---|
22 | |
---|
23 | @author Nicklas |
---|
24 | @version 2.0 |
---|
25 | --%> |
---|
26 | <%@ page session="false" |
---|
27 | import="net.sf.basedb.core.SessionControl" |
---|
28 | import="net.sf.basedb.core.DbControl" |
---|
29 | import="net.sf.basedb.core.SystemItems" |
---|
30 | import="net.sf.basedb.core.Item" |
---|
31 | import="net.sf.basedb.core.ItemContext" |
---|
32 | import="net.sf.basedb.core.Permission" |
---|
33 | import="net.sf.basedb.core.Role" |
---|
34 | import="net.sf.basedb.core.User" |
---|
35 | import="net.sf.basedb.core.RoleKey" |
---|
36 | import="net.sf.basedb.core.PermissionDeniedException" |
---|
37 | import="net.sf.basedb.core.PluginDefinition" |
---|
38 | import="net.sf.basedb.core.ItemQuery" |
---|
39 | import="net.sf.basedb.core.ItemResultList" |
---|
40 | import="net.sf.basedb.core.Include" |
---|
41 | import="net.sf.basedb.core.query.Orders" |
---|
42 | import="net.sf.basedb.core.query.Hql" |
---|
43 | import="net.sf.basedb.core.plugin.GuiContext" |
---|
44 | import="net.sf.basedb.core.plugin.Plugin" |
---|
45 | import="net.sf.basedb.clients.web.Base" |
---|
46 | import="net.sf.basedb.clients.web.PermissionUtil" |
---|
47 | import="net.sf.basedb.clients.web.util.HTML" |
---|
48 | import="net.sf.basedb.util.Values" |
---|
49 | import="net.sf.basedb.util.formatter.Formatter" |
---|
50 | import="net.sf.basedb.clients.web.formatter.FormatterFactory" |
---|
51 | import="net.sf.basedb.clients.web.extensions.ExtensionsControl" |
---|
52 | import="net.sf.basedb.clients.web.extensions.JspContext" |
---|
53 | import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer" |
---|
54 | import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil" |
---|
55 | import="net.sf.basedb.util.extensions.ExtensionsInvoker" |
---|
56 | import="java.util.Date" |
---|
57 | import="java.util.Map" |
---|
58 | import="java.util.Set" |
---|
59 | import="java.util.List" |
---|
60 | %> |
---|
61 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
62 | <%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %> |
---|
63 | <%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %> |
---|
64 | <%@ taglib prefix="p" uri="/WEB-INF/path.tld" %> |
---|
65 | <%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %> |
---|
66 | <%! |
---|
67 | private static final Item itemType = Item.ROLE; |
---|
68 | private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.ITEM); |
---|
69 | |
---|
70 | private static final String getShortPermissions(Item itemType, Set<Permission> permissions) |
---|
71 | { |
---|
72 | Set<Permission> defined = itemType.getDefinedPermissions(); |
---|
73 | StringBuilder sb = new StringBuilder(); |
---|
74 | if (defined.contains(Permission.CREATE)) sb.append(permissions.contains(Permission.CREATE) ? "C" : "-"); |
---|
75 | if (defined.contains(Permission.READ)) sb.append(permissions.contains(Permission.READ) ? "R" : "-"); |
---|
76 | if (defined.contains(Permission.USE)) sb.append(permissions.contains(Permission.USE) ? "U" : "-"); |
---|
77 | if (defined.contains(Permission.WRITE)) sb.append(permissions.contains(Permission.WRITE) ? "W" : "-"); |
---|
78 | if (defined.contains(Permission.DELETE)) sb.append(permissions.contains(Permission.DELETE) ? "D" : "-"); |
---|
79 | if (defined.contains(Permission.SET_OWNER)) sb.append(permissions.contains(Permission.SET_OWNER) ? "O" : "-"); |
---|
80 | if (defined.contains(Permission.SET_PERMISSION)) sb.append(permissions.contains(Permission.SET_PERMISSION) ? "P" : "-"); |
---|
81 | return sb.toString(); |
---|
82 | } |
---|
83 | %> |
---|
84 | <% |
---|
85 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
86 | final String ID = sc.getId(); |
---|
87 | final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null); |
---|
88 | final int itemId = cc.getId(); |
---|
89 | final float scale = Base.getScale(sc); |
---|
90 | final DbControl dc = sc.newDbControl(); |
---|
91 | try |
---|
92 | { |
---|
93 | Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc); |
---|
94 | Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext); |
---|
95 | |
---|
96 | String title = null; |
---|
97 | Role role = Role.getById(dc, itemId); |
---|
98 | |
---|
99 | RoleKey system = RoleKey.getById(dc, SystemItems.getRoleKeyId(Item.SYSTEM)); |
---|
100 | final boolean hasShareToEveryone = system.getPermissions(role).contains(Permission.SHARE_TO_EVERYONE); |
---|
101 | final boolean hasActAsAnotherUser = system.getPermissions(role).contains(Permission.ACT_AS_ANOTHER_USER); |
---|
102 | final boolean hasSelectJobagent = system.getPermissions(role).contains(Permission.SELECT_JOBAGENT); |
---|
103 | |
---|
104 | final boolean writePermission = role.hasPermission(Permission.WRITE); |
---|
105 | final boolean deletePermission = role.hasPermission(Permission.DELETE); |
---|
106 | final boolean isRemoved = role.isRemoved(); |
---|
107 | final boolean isUsed = isRemoved && role.isUsed(); |
---|
108 | final boolean deletePermanentlyPermission = deletePermission && !isUsed; |
---|
109 | JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, role); |
---|
110 | ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext); |
---|
111 | %> |
---|
112 | <base:page title="<%=title%>"> |
---|
113 | <base:head scripts="table.js,tabcontrol.js" styles="toolbar.css,table.css,headertabcontrol.css,path.css"> |
---|
114 | <ext:scripts context="<%=jspContext%>" /> |
---|
115 | <ext:stylesheets context="<%=jspContext%>" /> |
---|
116 | <script language="JavaScript"> |
---|
117 | function editItem() |
---|
118 | { |
---|
119 | Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, true); |
---|
120 | } |
---|
121 | function deleteItem() |
---|
122 | { |
---|
123 | location.replace('index.jsp?ID=<%=ID%>&cmd=DeleteItem&item_id=<%=itemId%>'); |
---|
124 | } |
---|
125 | function restoreItem() |
---|
126 | { |
---|
127 | location.replace('index.jsp?ID=<%=ID%>&cmd=RestoreItem&item_id=<%=itemId%>'); |
---|
128 | } |
---|
129 | function deleteItemPermanently() |
---|
130 | { |
---|
131 | Main.deleteItemPermanently('<%=ID%>', true, '<%=itemType.name()%>', <%=itemId%>, '&callback=itemDeleted'); |
---|
132 | } |
---|
133 | function itemDeleted() |
---|
134 | { |
---|
135 | Main.listItems('<%=ID%>', '<%=itemType.name()%>'); |
---|
136 | } |
---|
137 | function showUsingItems() |
---|
138 | { |
---|
139 | Main.showUsingItems('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>); |
---|
140 | } |
---|
141 | function deleteItemPermanently() |
---|
142 | { |
---|
143 | Main.deleteItemPermanently('<%=ID%>', true, '<%=itemType.name()%>', <%=itemId%>, '&callback=itemDeleted'); |
---|
144 | } |
---|
145 | function itemDeleted() |
---|
146 | { |
---|
147 | Main.listItems('<%=ID%>', '<%=itemType.name()%>'); |
---|
148 | } |
---|
149 | function showUsingItems() |
---|
150 | { |
---|
151 | Main.showUsingItems('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>); |
---|
152 | } |
---|
153 | function runPlugin(cmd) |
---|
154 | { |
---|
155 | Main.openPopup('index.jsp?ID=<%=ID%>&cmd='+cmd+'&item_id=<%=itemId%>', 'RunPlugin'+cmd, 740, 540); |
---|
156 | } |
---|
157 | </script> |
---|
158 | </base:head> |
---|
159 | <base:body> |
---|
160 | <p> |
---|
161 | <p:path> |
---|
162 | <p:pathelement title="Roles" href="<%="index.jsp?ID="+ID%>" /> |
---|
163 | <p:pathelement title="<%=HTML.encodeTags(role.getName())%>" /> |
---|
164 | </p:path> |
---|
165 | |
---|
166 | <t:tabcontrol id="main" active="properties"> |
---|
167 | <t:tab id="properties" title="Properties"> |
---|
168 | |
---|
169 | <tbl:toolbar |
---|
170 | > |
---|
171 | <tbl:button |
---|
172 | disabled="<%=writePermission ? false : true%>" |
---|
173 | image="<%=writePermission ? "edit.gif" : "edit_disabled.gif"%>" |
---|
174 | onclick="editItem()" |
---|
175 | title="Edit…" |
---|
176 | tooltip="<%=writePermission ? "Edit this role" : "You do not have permission to edit this role"%>" |
---|
177 | /> |
---|
178 | <tbl:button |
---|
179 | disabled="<%=deletePermission ? false : true%>" |
---|
180 | image="<%=deletePermission ? "delete.gif" : "delete_disabled.gif"%>" |
---|
181 | onclick="deleteItem()" |
---|
182 | title="Delete" |
---|
183 | visible="<%=!role.isRemoved()%>" |
---|
184 | tooltip="<%=deletePermission ? "Delete this role" : "You do not have permission to delete this role"%>" |
---|
185 | /> |
---|
186 | <tbl:button |
---|
187 | disabled="<%=writePermission ? false : true%>" |
---|
188 | image="<%=writePermission ? "restore.gif" : "restore_disabled.gif"%>" |
---|
189 | onclick="restoreItem()" |
---|
190 | title="Restore" |
---|
191 | visible="<%=role.isRemoved()%>" |
---|
192 | tooltip="<%=writePermission ? "Restore this role" : "You do not have permission to restore this role"%>" |
---|
193 | /> |
---|
194 | <tbl:button |
---|
195 | image="import.gif" |
---|
196 | onclick="runPlugin('ImportItem')" |
---|
197 | title="Import…" |
---|
198 | tooltip="Import data" |
---|
199 | visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>" |
---|
200 | /> |
---|
201 | <tbl:button |
---|
202 | image="export.gif" |
---|
203 | onclick="runPlugin('ExportItem')" |
---|
204 | title="Export…" |
---|
205 | tooltip="Export data" |
---|
206 | visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>" |
---|
207 | /> |
---|
208 | <tbl:button |
---|
209 | image="runplugin.gif" |
---|
210 | onclick="runPlugin('RunPlugin')" |
---|
211 | title="Run plugin…" |
---|
212 | tooltip="Run a plugin" |
---|
213 | visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>" |
---|
214 | /> |
---|
215 | <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" |
---|
216 | wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/> |
---|
217 | <tbl:button |
---|
218 | image="help.gif" |
---|
219 | onclick="<%="Main.openHelp('" + ID +"', 'role.view.properties')"%>" |
---|
220 | title="Help…" |
---|
221 | tooltip="Get help about this page" |
---|
222 | /> |
---|
223 | </tbl:toolbar> |
---|
224 | <div class="boxedbottom"> |
---|
225 | <div class="itemstatus">Permissions on this item: <i><%=PermissionUtil.getFullPermissionNames(role)%></i></div> |
---|
226 | <% |
---|
227 | if (role.isRemoved()) |
---|
228 | { |
---|
229 | %> |
---|
230 | <div class="itemstatus"> |
---|
231 | <base:icon |
---|
232 | image="<%=deletePermanentlyPermission ? "deleted.gif" : "deleted_disabled.gif"%>" |
---|
233 | onclick="<%=deletePermanentlyPermission ? "deleteItemPermanently()" : null%>" |
---|
234 | tooltip="<%=deletePermanentlyPermission ? "Permanently delete this item" : null%>" |
---|
235 | visible="<%=isRemoved%>"> This item has been flagged for deletion<br></base:icon> |
---|
236 | <base:icon image="used.gif" |
---|
237 | onclick="showUsingItems()" |
---|
238 | tooltip="Show the items that are using this one" |
---|
239 | visible="<%=isUsed%>"> This item is used by other items and can't be permanently deleted<br></base:icon> |
---|
240 | </div> |
---|
241 | <% |
---|
242 | } |
---|
243 | %> |
---|
244 | <table class="form" cellspacing=0> |
---|
245 | <tr> |
---|
246 | <td class="prompt">Name</td> |
---|
247 | <td><%=HTML.encodeTags(role.getName())%></td> |
---|
248 | </tr> |
---|
249 | <tr> |
---|
250 | <td class="prompt">Registered</td> |
---|
251 | <td><%=dateFormatter.format(role.getEntryDate())%></td> |
---|
252 | </tr> |
---|
253 | <tr> |
---|
254 | <td class="prompt">System ID</td> |
---|
255 | <td><%=HTML.encodeTags(role.getSystemId())%></td> |
---|
256 | </tr> |
---|
257 | <tr> |
---|
258 | <td class="prompt">Is default</td> |
---|
259 | <td><%=role.isDefault() ? "yes" : "no"%></td> |
---|
260 | </tr> |
---|
261 | <tr> |
---|
262 | <td class="prompt">Description</td> |
---|
263 | <td><%=HTML.niceFormat(role.getDescription())%></td> |
---|
264 | </tr> |
---|
265 | </table> |
---|
266 | |
---|
267 | <h4>Permissions</h4> |
---|
268 | <table class="form" cellspacing=0> |
---|
269 | <tr> |
---|
270 | <td class="prompt">Share to everyone</td> |
---|
271 | <td><%=hasShareToEveryone ? "yes" : "no"%></td> |
---|
272 | <td class="prompt">Select job agent</td> |
---|
273 | <td><%=hasSelectJobagent ? "yes" : "no"%></td> |
---|
274 | </tr> |
---|
275 | <tr> |
---|
276 | <td class="prompt">Act as another user</td> |
---|
277 | <td><%=hasActAsAnotherUser ? "yes" : "no"%></td> |
---|
278 | </tr> |
---|
279 | </table> |
---|
280 | |
---|
281 | <div class="itemlist"> |
---|
282 | <div class="data"> |
---|
283 | <table border="0" cellspacing="0" cellpadding="0"> |
---|
284 | <tr> |
---|
285 | <% |
---|
286 | Map<String, List<Item>> permissionGroups = PermissionUtil.getPermissionGroups(); |
---|
287 | |
---|
288 | for (String name : permissionGroups.keySet()) |
---|
289 | { |
---|
290 | %> |
---|
291 | <th class="columnheader" colspan="2"><b><%=name%></b></th> |
---|
292 | <% |
---|
293 | } |
---|
294 | %> |
---|
295 | </tr> |
---|
296 | <% |
---|
297 | int newItems = 0; |
---|
298 | int index = 0; |
---|
299 | int i = 0; |
---|
300 | do |
---|
301 | { |
---|
302 | newItems = 0; |
---|
303 | StringBuilder sb = new StringBuilder(); |
---|
304 | sb.append("<tr valign=\"top\""); |
---|
305 | sb.append(" class=\"").append(i == 1 ? "oddrow" : "evenrow").append("\""); |
---|
306 | sb.append(">"); |
---|
307 | for (String name : permissionGroups.keySet()) |
---|
308 | { |
---|
309 | List<Item> items = permissionGroups.get(name); |
---|
310 | if (items.size() > index) |
---|
311 | { |
---|
312 | newItems++; |
---|
313 | Item item = items.get(index); |
---|
314 | int keyId = SystemItems.getRoleKeyId(item); |
---|
315 | RoleKey key = RoleKey.getById(dc, keyId); |
---|
316 | |
---|
317 | sb.append("<td class=\"cell\"><b>").append(key.getName()).append("</b></td>"); |
---|
318 | sb.append("<td class=\"cell\">"); |
---|
319 | |
---|
320 | if (keyId != 0) |
---|
321 | { |
---|
322 | Set<Permission> permissions = key.getPermissions(role); |
---|
323 | sb.append(getShortPermissions(item, permissions)); |
---|
324 | } |
---|
325 | else |
---|
326 | { |
---|
327 | sb.append("(undefined key)"); |
---|
328 | } |
---|
329 | sb.append("</td>"); |
---|
330 | } |
---|
331 | else |
---|
332 | { |
---|
333 | sb.append("<td class=\"cell\" colspan=\"2\"> </td>"); |
---|
334 | } |
---|
335 | } |
---|
336 | if (newItems > 0) |
---|
337 | { |
---|
338 | %> |
---|
339 | <%=sb.toString()%> |
---|
340 | <% |
---|
341 | } |
---|
342 | i = 1 - i; |
---|
343 | index++; |
---|
344 | } while (newItems > 0); |
---|
345 | %> |
---|
346 | <tr class="panel"> |
---|
347 | <td colspan="99" class="panel"> |
---|
348 | <b>C</b> = Create, <b>R</b> = Read, <b>U</b> = Use, |
---|
349 | <b>W</b> = Write, <b>D</b> = Delete, <b>O</b> = Change owner, <b>P</b> = Change permissions |
---|
350 | |
---|
351 | </td> |
---|
352 | </tr> |
---|
353 | </table> |
---|
354 | </div> |
---|
355 | </div> |
---|
356 | <br> |
---|
357 | <% |
---|
358 | ItemQuery<User> userQuery = role.getUsers(); |
---|
359 | userQuery.include(Include.ALL); |
---|
360 | userQuery.order(Orders.asc(Hql.property("name"))); |
---|
361 | ItemResultList<User> users = userQuery.list(dc); |
---|
362 | |
---|
363 | if (users.size() == 0) |
---|
364 | { |
---|
365 | %> |
---|
366 | <h4>Members</h4> |
---|
367 | There are no members of this role (or, you don't have permission to view them). |
---|
368 | <% |
---|
369 | } |
---|
370 | else |
---|
371 | { |
---|
372 | %> |
---|
373 | <h4 class="docked">Members</h4> |
---|
374 | <tbl:table |
---|
375 | id="members" |
---|
376 | clazz="itemlist" |
---|
377 | columns="all" |
---|
378 | > |
---|
379 | <tbl:columndef |
---|
380 | id="name" |
---|
381 | title="Name" |
---|
382 | /> |
---|
383 | <tbl:columndef |
---|
384 | id="type" |
---|
385 | title="Type" |
---|
386 | /> |
---|
387 | <tbl:columndef |
---|
388 | id="description" |
---|
389 | title="Description" |
---|
390 | /> |
---|
391 | <tbl:data> |
---|
392 | <tbl:columns> |
---|
393 | </tbl:columns> |
---|
394 | <tbl:rows> |
---|
395 | <% |
---|
396 | for (User user : users) |
---|
397 | { |
---|
398 | %> |
---|
399 | <tbl:row> |
---|
400 | <tbl:cell column="name"><base:icon |
---|
401 | image="deleted.gif" |
---|
402 | tooltip="This item has been scheduled for deletion" |
---|
403 | visible="<%=user.isRemoved()%>" |
---|
404 | /><%=Base.getLinkedName(ID, user, false, true)%></tbl:cell> |
---|
405 | <tbl:cell column="type">User</tbl:cell> |
---|
406 | <tbl:cell column="description"><%=HTML.encodeTags(user.getDescription())%></tbl:cell> |
---|
407 | </tbl:row> |
---|
408 | <% |
---|
409 | } |
---|
410 | %> |
---|
411 | </tbl:rows> |
---|
412 | </tbl:data> |
---|
413 | </tbl:table> |
---|
414 | <% |
---|
415 | } |
---|
416 | %> |
---|
417 | |
---|
418 | </div> |
---|
419 | </t:tab> |
---|
420 | </t:tabcontrol> |
---|
421 | |
---|
422 | </base:body> |
---|
423 | </base:page> |
---|
424 | <% |
---|
425 | } |
---|
426 | finally |
---|
427 | { |
---|
428 | if (dc != null) dc.close(); |
---|
429 | } |
---|
430 | |
---|
431 | %> |
---|