source: trunk/www/admin/roles/view_role.jsp @ 6605

Last change on this file since 6605 was 6605, checked in by Nicklas Nordborg, 8 years ago

References #1890: Improve skinnability of BASE

Updated regular view pages and edit dialogs.

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