1 | <%-- $Id: view_role.jsp 7216 2016-10-19 20:17:37Z 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 pageEncoding="UTF-8" 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.RESTRICTED_WRITE)) sb.append(permissions.contains(Permission.RESTRICTED_WRITE) ? "A" : "-"); |
---|
78 | if (defined.contains(Permission.WRITE)) sb.append(permissions.contains(Permission.WRITE) ? "W" : "-"); |
---|
79 | if (defined.contains(Permission.DELETE)) sb.append(permissions.contains(Permission.DELETE) ? "D" : "-"); |
---|
80 | if (defined.contains(Permission.SET_OWNER)) sb.append(permissions.contains(Permission.SET_OWNER) ? "O" : "-"); |
---|
81 | if (defined.contains(Permission.SET_PERMISSION)) sb.append(permissions.contains(Permission.SET_PERMISSION) ? "P" : "-"); |
---|
82 | return sb.toString(); |
---|
83 | } |
---|
84 | %> |
---|
85 | <% |
---|
86 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
87 | final String ID = sc.getId(); |
---|
88 | final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null); |
---|
89 | final int itemId = cc.getId(); |
---|
90 | final float scale = Base.getScale(sc); |
---|
91 | final DbControl dc = sc.newDbControl(); |
---|
92 | try |
---|
93 | { |
---|
94 | Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc); |
---|
95 | Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext); |
---|
96 | |
---|
97 | String title = null; |
---|
98 | Role role = Role.getById(dc, itemId); |
---|
99 | |
---|
100 | RoleKey system = RoleKey.getById(dc, SystemItems.getRoleKeyId(Item.SYSTEM)); |
---|
101 | final boolean hasShareToEveryone = system.getPermissions(role).contains(Permission.SHARE_TO_EVERYONE); |
---|
102 | final boolean hasActAsAnotherUser = system.getPermissions(role).contains(Permission.ACT_AS_ANOTHER_USER); |
---|
103 | final boolean hasSelectJobagent = system.getPermissions(role).contains(Permission.SELECT_JOBAGENT); |
---|
104 | |
---|
105 | final boolean writePermission = role.hasPermission(Permission.WRITE); |
---|
106 | final boolean deletePermission = role.hasPermission(Permission.DELETE); |
---|
107 | final boolean isRemoved = role.isRemoved(); |
---|
108 | final boolean isUsed = isRemoved && role.isUsed(); |
---|
109 | final boolean deletePermanentlyPermission = deletePermission && !isUsed; |
---|
110 | JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, role); |
---|
111 | ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext); |
---|
112 | %> |
---|
113 | <base:page title="<%=title%>" id="view-page"> |
---|
114 | <base:head scripts="table.js,tabcontrol-2.js,~roles.js" styles="toolbar.css,table.css,headertabcontrol.css,path.css"> |
---|
115 | <ext:scripts context="<%=jspContext%>" /> |
---|
116 | <ext:stylesheets context="<%=jspContext%>" /> |
---|
117 | </base:head> |
---|
118 | <base:body> |
---|
119 | <p:path><p:pathelement |
---|
120 | title="Roles" href="<%="index.jsp?ID="+ID%>" |
---|
121 | /><p:pathelement title="<%=HTML.encodeTags(role.getName())%>" |
---|
122 | /></p:path> |
---|
123 | |
---|
124 | <div id="page-data" data-item-id="<%=itemId%>"></div> |
---|
125 | |
---|
126 | <t:tabcontrol |
---|
127 | id="main" |
---|
128 | subclass="content mastertabcontrol" |
---|
129 | active="properties"> |
---|
130 | <t:tab id="properties" title="Properties"> |
---|
131 | <div> |
---|
132 | <table class="fullform bottomborder"> |
---|
133 | <tr> |
---|
134 | <th class="itemstatus"> |
---|
135 | <base:icon |
---|
136 | id="btnDeletePermanently" |
---|
137 | image="deleted.png" |
---|
138 | tooltip="This item has been flagged for deletion. Click to delete it now." |
---|
139 | enabled="<%=deletePermanentlyPermission %>" |
---|
140 | visible="<%=isRemoved%>" |
---|
141 | /> |
---|
142 | <base:icon |
---|
143 | id="btnUsingItems" |
---|
144 | image="used.png" |
---|
145 | tooltip="This item is used by other items and can't be permanently deleted. Show the items that are using this one" |
---|
146 | visible="<%=isRemoved && isUsed%>" /> |
---|
147 | </th> |
---|
148 | <td style="padding: 0px;"> |
---|
149 | <tbl:toolbar subclass="bottomborder bg-filled-50"> |
---|
150 | <tbl:button |
---|
151 | id="btnEdit" |
---|
152 | disabled="<%=!writePermission%>" |
---|
153 | image="edit.png" |
---|
154 | title="Edit…" |
---|
155 | tooltip="<%=writePermission ? "Edit this role" : "You do not have permission to edit this role"%>" |
---|
156 | /> |
---|
157 | <tbl:button |
---|
158 | id="btnDelete" |
---|
159 | disabled="<%=!deletePermission%>" |
---|
160 | image="delete.png" |
---|
161 | title="Delete" |
---|
162 | visible="<%=!role.isRemoved()%>" |
---|
163 | tooltip="<%=deletePermission ? "Delete this role" : "You do not have permission to delete this role"%>" |
---|
164 | /> |
---|
165 | <tbl:button |
---|
166 | id="btnRestore" |
---|
167 | disabled="<%=!writePermission%>" |
---|
168 | image="restore.png" |
---|
169 | title="Restore" |
---|
170 | visible="<%=role.isRemoved()%>" |
---|
171 | tooltip="<%=writePermission ? "Restore this role" : "You do not have permission to restore this role"%>" |
---|
172 | /> |
---|
173 | <tbl:button |
---|
174 | id="btnImport" |
---|
175 | image="import.png" |
---|
176 | data-plugin-type="IMPORT" |
---|
177 | title="Import…" |
---|
178 | tooltip="Import data" |
---|
179 | visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>" |
---|
180 | /> |
---|
181 | <tbl:button |
---|
182 | id="btnExport" |
---|
183 | image="export.png" |
---|
184 | data-plugin-type="EXPORT" |
---|
185 | title="Export…" |
---|
186 | tooltip="Export data" |
---|
187 | visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>" |
---|
188 | /> |
---|
189 | <tbl:button |
---|
190 | id="btnRunPlugin" |
---|
191 | image="runplugin.png" |
---|
192 | data-plugin-type="OTHER" |
---|
193 | title="Run plugin…" |
---|
194 | tooltip="Run a plugin" |
---|
195 | visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>" |
---|
196 | /> |
---|
197 | <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" |
---|
198 | wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/> |
---|
199 | <tbl:button |
---|
200 | image="help.png" |
---|
201 | subclass="auto-init" |
---|
202 | data-auto-init="help" |
---|
203 | data-help-id="role.view.properties" |
---|
204 | title="Help…" |
---|
205 | tooltip="Get help about this page" |
---|
206 | /> |
---|
207 | </tbl:toolbar> |
---|
208 | </td> |
---|
209 | </tr> |
---|
210 | <tr> |
---|
211 | <th>Name</th> |
---|
212 | <td><%=HTML.encodeTags(role.getName())%></td> |
---|
213 | </tr> |
---|
214 | <tr> |
---|
215 | <th>Registered</th> |
---|
216 | <td><%=dateFormatter.format(role.getEntryDate())%></td> |
---|
217 | </tr> |
---|
218 | <tr> |
---|
219 | <th>System ID</th> |
---|
220 | <td><%=HTML.encodeTags(role.getSystemId())%></td> |
---|
221 | </tr> |
---|
222 | <tr> |
---|
223 | <th>Is default</th> |
---|
224 | <td><%=role.isDefault() ? "yes" : "no"%></td> |
---|
225 | </tr> |
---|
226 | <tr> |
---|
227 | <th>Permissions</th> |
---|
228 | <td><%=PermissionUtil.getFullPermissionNames(role)%></td> |
---|
229 | </tr> |
---|
230 | <tr> |
---|
231 | <th>Description</th> |
---|
232 | <td><%=HTML.niceFormat(role.getDescription())%></td> |
---|
233 | </tr> |
---|
234 | </table> |
---|
235 | </div> |
---|
236 | |
---|
237 | <base:section |
---|
238 | id="permissions" |
---|
239 | title="<%="Permissions"%>" |
---|
240 | context="<%=cc%>" |
---|
241 | > |
---|
242 | <% |
---|
243 | Map<String, List<Item>> permissionGroups = PermissionUtil.getPermissionGroups(); |
---|
244 | %> |
---|
245 | <table class="fullform fullborder"> |
---|
246 | <tbody class="sectionheader"> |
---|
247 | <tr> |
---|
248 | <th colspan="<%=permissionGroups.size() * 2 %>">System-level permissions</th> |
---|
249 | </tr> |
---|
250 | </tbody> |
---|
251 | <tr> |
---|
252 | <th>Share to everyone</th> |
---|
253 | <td><%=hasShareToEveryone ? "yes" : "no"%></td> |
---|
254 | <th class="leftborder">Select job agent</th> |
---|
255 | <td><%=hasSelectJobagent ? "yes" : "no"%></td> |
---|
256 | <th class="leftborder">Act as another user</th> |
---|
257 | <td><%=hasActAsAnotherUser ? "yes" : "no"%></td> |
---|
258 | <td colspan="<%=permissionGroups.size() * 2 - 6 %>"></td> |
---|
259 | </tr> |
---|
260 | <tbody class="sectionheader"> |
---|
261 | <tr> |
---|
262 | <% |
---|
263 | for (String name : permissionGroups.keySet()) |
---|
264 | { |
---|
265 | %> |
---|
266 | <th colspan="2"><%=name%></th> |
---|
267 | <% |
---|
268 | } |
---|
269 | %> |
---|
270 | </tr> |
---|
271 | </tbody> |
---|
272 | <% |
---|
273 | int newItems = 0; |
---|
274 | int rowIndex = 0; |
---|
275 | do |
---|
276 | { |
---|
277 | newItems = 0; |
---|
278 | int colIndex = 0; |
---|
279 | StringBuilder sb = new StringBuilder(); |
---|
280 | sb.append("<tr>"); |
---|
281 | for (String name : permissionGroups.keySet()) |
---|
282 | { |
---|
283 | List<Item> items = permissionGroups.get(name); |
---|
284 | if (items.size() > rowIndex) |
---|
285 | { |
---|
286 | newItems++; |
---|
287 | Item item = items.get(rowIndex); |
---|
288 | int keyId = SystemItems.getRoleKeyId(item); |
---|
289 | RoleKey key = RoleKey.getById(dc, keyId); |
---|
290 | |
---|
291 | sb.append("<th"); |
---|
292 | if (colIndex > 0) sb.append(" class=\"leftborder\""); |
---|
293 | sb.append(">").append(key.getName()).append("</th>"); |
---|
294 | sb.append("<td>"); |
---|
295 | |
---|
296 | if (keyId != 0) |
---|
297 | { |
---|
298 | Set<Permission> permissions = key.getPermissions(role); |
---|
299 | sb.append(getShortPermissions(item, permissions)); |
---|
300 | } |
---|
301 | else |
---|
302 | { |
---|
303 | sb.append("(undefined key)"); |
---|
304 | } |
---|
305 | sb.append("</td>"); |
---|
306 | } |
---|
307 | else |
---|
308 | { |
---|
309 | sb.append("<th class=\"subprompt"); |
---|
310 | if (colIndex > 0) sb.append(" leftborder"); |
---|
311 | sb.append("\"></th><td></td>"); |
---|
312 | } |
---|
313 | colIndex++; |
---|
314 | } |
---|
315 | if (newItems > 0) |
---|
316 | { |
---|
317 | %> |
---|
318 | <%=sb.toString()%> |
---|
319 | <% |
---|
320 | } |
---|
321 | rowIndex++; |
---|
322 | } while (newItems > 0); |
---|
323 | %> |
---|
324 | </table> |
---|
325 | <b>C</b> = Create, <b>R</b> = Read, <b>U</b> = Use, <b>A</b> = Annotate, |
---|
326 | <b>W</b> = Write, <b>D</b> = Delete, <b>O</b> = Change owner, <b>P</b> = Change permissions |
---|
327 | </base:section> |
---|
328 | <% |
---|
329 | ItemQuery<User> userQuery = role.getUsers(); |
---|
330 | userQuery.include(Include.ALL); |
---|
331 | userQuery.order(Orders.asc(Hql.property("name"))); |
---|
332 | ItemResultList<User> users = userQuery.list(dc); |
---|
333 | %> |
---|
334 | <base:section |
---|
335 | id="members" |
---|
336 | title="<%="Members (" + users.size() + ")"%>" |
---|
337 | context="<%=cc%>" |
---|
338 | > |
---|
339 | <% |
---|
340 | if (users.size() == 0) |
---|
341 | { |
---|
342 | %> |
---|
343 | <div class="messagecontainer note"> |
---|
344 | There are no members of this role (or, you don't have permission to view them). |
---|
345 | </div> |
---|
346 | <% |
---|
347 | } |
---|
348 | else |
---|
349 | { |
---|
350 | %> |
---|
351 | <tbl:table |
---|
352 | id="members" |
---|
353 | columns="all" |
---|
354 | > |
---|
355 | <tbl:columndef |
---|
356 | id="name" |
---|
357 | title="Name" |
---|
358 | /> |
---|
359 | <tbl:columndef |
---|
360 | id="type" |
---|
361 | title="Type" |
---|
362 | /> |
---|
363 | <tbl:columndef |
---|
364 | id="description" |
---|
365 | title="Description" |
---|
366 | /> |
---|
367 | <tbl:data> |
---|
368 | <tbl:headers> |
---|
369 | <tbl:headerrow> |
---|
370 | <tbl:columnheaders /> |
---|
371 | </tbl:headerrow> |
---|
372 | </tbl:headers> |
---|
373 | <tbl:rows> |
---|
374 | <% |
---|
375 | for (User user : users) |
---|
376 | { |
---|
377 | %> |
---|
378 | <tbl:row> |
---|
379 | <tbl:cell column="name"><base:icon |
---|
380 | image="deleted.png" |
---|
381 | tooltip="This item has been scheduled for deletion" |
---|
382 | visible="<%=user.isRemoved()%>" |
---|
383 | /><%=Base.getLinkedName(ID, user, false, true)%></tbl:cell> |
---|
384 | <tbl:cell column="type">User</tbl:cell> |
---|
385 | <tbl:cell column="description"><%=HTML.encodeTags(user.getDescription())%></tbl:cell> |
---|
386 | </tbl:row> |
---|
387 | <% |
---|
388 | } |
---|
389 | %> |
---|
390 | </tbl:rows> |
---|
391 | </tbl:data> |
---|
392 | </tbl:table> |
---|
393 | <% |
---|
394 | } |
---|
395 | %> |
---|
396 | </base:section> |
---|
397 | <jsp:include page="../../common/anytoany/list_anytoany.jsp"> |
---|
398 | <jsp:param name="ID" value="<%=ID%>" /> |
---|
399 | <jsp:param name="item_type" value="<%=itemType.name()%>" /> |
---|
400 | <jsp:param name="item_id" value="<%=itemId%>" /> |
---|
401 | <jsp:param name="title" value="Other items related to this role" /> |
---|
402 | </jsp:include> |
---|
403 | </t:tab> |
---|
404 | </t:tabcontrol> |
---|
405 | </base:body> |
---|
406 | </base:page> |
---|
407 | <% |
---|
408 | } |
---|
409 | finally |
---|
410 | { |
---|
411 | if (dc != null) dc.close(); |
---|
412 | } |
---|
413 | |
---|
414 | %> |
---|