www/admin/users/edit_default_membership.jsp

Code
Comments
Other
Rev Date Author Line
3467 08 Jun 07 nicklas 1 <%-- $Id$
3467 08 Jun 07 nicklas 2   ------------------------------------------------------------------
3675 16 Aug 07 jari 3   Copyright (C) 2007 Nicklas Nordborg
3467 08 Jun 07 nicklas 4
3467 08 Jun 07 nicklas 5   This file is part of BASE - BioArray Software Environment.
3467 08 Jun 07 nicklas 6   Available at http://base.thep.lu.se/
3467 08 Jun 07 nicklas 7
3467 08 Jun 07 nicklas 8   BASE is free software; you can redistribute it and/or
3467 08 Jun 07 nicklas 9   modify it under the terms of the GNU General Public License
4476 05 Sep 08 jari 10   as published by the Free Software Foundation; either version 3
3467 08 Jun 07 nicklas 11   of the License, or (at your option) any later version.
3467 08 Jun 07 nicklas 12
3467 08 Jun 07 nicklas 13   BASE is distributed in the hope that it will be useful,
3467 08 Jun 07 nicklas 14   but WITHOUT ANY WARRANTY; without even the implied warranty of
3467 08 Jun 07 nicklas 15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
3467 08 Jun 07 nicklas 16   GNU General Public License for more details.
3467 08 Jun 07 nicklas 17
3467 08 Jun 07 nicklas 18   You should have received a copy of the GNU General Public License
4510 11 Sep 08 jari 19   along with BASE. If not, see <http://www.gnu.org/licenses/>.
3467 08 Jun 07 nicklas 20   ------------------------------------------------------------------
3467 08 Jun 07 nicklas 21
3467 08 Jun 07 nicklas 22
3467 08 Jun 07 nicklas 23   @author Nicklas
3467 08 Jun 07 nicklas 24   @version 2.0
3467 08 Jun 07 nicklas 25 --%>
5426 24 Sep 10 nicklas 26 <%@ page pageEncoding="UTF-8" session="false"
3467 08 Jun 07 nicklas 27   import="net.sf.basedb.core.SessionControl"
3467 08 Jun 07 nicklas 28   import="net.sf.basedb.core.DbControl"
3467 08 Jun 07 nicklas 29   import="net.sf.basedb.core.SystemItems"
3467 08 Jun 07 nicklas 30   import="net.sf.basedb.core.Item"
3467 08 Jun 07 nicklas 31   import="net.sf.basedb.core.Type"
3467 08 Jun 07 nicklas 32   import="net.sf.basedb.core.ItemContext"
3467 08 Jun 07 nicklas 33   import="net.sf.basedb.core.Permission"
3467 08 Jun 07 nicklas 34   import="net.sf.basedb.core.Group"
3467 08 Jun 07 nicklas 35   import="net.sf.basedb.core.User"
3467 08 Jun 07 nicklas 36   import="net.sf.basedb.core.Quota"
3467 08 Jun 07 nicklas 37   import="net.sf.basedb.core.Role"
3467 08 Jun 07 nicklas 38   import="net.sf.basedb.core.Directory"
3467 08 Jun 07 nicklas 39   import="net.sf.basedb.core.QuotaType"
3467 08 Jun 07 nicklas 40   import="net.sf.basedb.core.Location"
3467 08 Jun 07 nicklas 41   import="net.sf.basedb.core.Include"
3467 08 Jun 07 nicklas 42   import="net.sf.basedb.core.ItemQuery"
3467 08 Jun 07 nicklas 43   import="net.sf.basedb.core.ItemResultList"
3467 08 Jun 07 nicklas 44   import="net.sf.basedb.core.PermissionDeniedException"
3467 08 Jun 07 nicklas 45   import="net.sf.basedb.core.query.Orders"
3467 08 Jun 07 nicklas 46   import="net.sf.basedb.core.query.Hql"
3467 08 Jun 07 nicklas 47   import="net.sf.basedb.core.query.Restrictions"
3467 08 Jun 07 nicklas 48   import="net.sf.basedb.core.query.Expressions"
3467 08 Jun 07 nicklas 49   import="net.sf.basedb.clients.web.Base"
3467 08 Jun 07 nicklas 50   import="net.sf.basedb.clients.web.util.HTML"
3467 08 Jun 07 nicklas 51   import="net.sf.basedb.util.Values"
3467 08 Jun 07 nicklas 52   import="net.sf.basedb.util.formatter.Formatter"
6223 15 Jan 13 nicklas 53   import="net.sf.basedb.util.json.JsonUtil"
6223 15 Jan 13 nicklas 54   import="net.sf.basedb.util.json.NameableConverter"
3467 08 Jun 07 nicklas 55   import="net.sf.basedb.clients.web.formatter.FormatterFactory"
3467 08 Jun 07 nicklas 56   import="net.sf.basedb.clients.web.formatter.FormatterSettings"
3467 08 Jun 07 nicklas 57   import="java.util.Date"
6223 15 Jan 13 nicklas 58   import="org.json.simple.JSONArray"
6291 11 Jun 13 nicklas 59   import="org.json.simple.JSONObject"
3467 08 Jun 07 nicklas 60 %>
3467 08 Jun 07 nicklas 61 <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
3467 08 Jun 07 nicklas 62 <%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
3467 08 Jun 07 nicklas 63 <%
3467 08 Jun 07 nicklas 64 final Item itemType = Item.USER;
3467 08 Jun 07 nicklas 65 final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
3467 08 Jun 07 nicklas 66 final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
3467 08 Jun 07 nicklas 67 final int itemId = cc.getId();
3467 08 Jun 07 nicklas 68 final String ID = sc.getId();
3467 08 Jun 07 nicklas 69 final float scale = Base.getScale(sc);
7954 12 May 21 nicklas 70 final DbControl dc = sc.newDbControl(":Edit default groups and roles");
3467 08 Jun 07 nicklas 71 try
3467 08 Jun 07 nicklas 72 {
3467 08 Jun 07 nicklas 73   String title = "Default group and role membership";
3467 08 Jun 07 nicklas 74
3467 08 Jun 07 nicklas 75   // Query to retrieve default groups
3467 08 Jun 07 nicklas 76   ItemQuery<Group> groupQuery = Group.getQuery();
3890 30 Oct 07 nicklas 77   groupQuery.include(Include.ALL);
3467 08 Jun 07 nicklas 78   groupQuery.restrict(
3467 08 Jun 07 nicklas 79     Restrictions.eq(
3467 08 Jun 07 nicklas 80       Hql.property("default"), 
3467 08 Jun 07 nicklas 81       Expressions.parameter("isDefault", true, Type.BOOLEAN)
3467 08 Jun 07 nicklas 82     )
3467 08 Jun 07 nicklas 83   );
6223 15 Jan 13 nicklas 84   groupQuery.order(Orders.asc(Hql.property("name")));
6291 11 Jun 13 nicklas 85   JSONObject jsonGroups = new JSONObject();
6291 11 Jun 13 nicklas 86   jsonGroups.put("itemType", "GROUP");
6291 11 Jun 13 nicklas 87   jsonGroups.put("name", "Groups");
7604 25 Feb 19 nicklas 88   jsonGroups.put("items", JsonUtil.toArray(groupQuery.iterate(dc), new NameableConverter<Group>()));
3467 08 Jun 07 nicklas 89
3467 08 Jun 07 nicklas 90   // Query to retrieve default roles
3467 08 Jun 07 nicklas 91   ItemQuery<Role> roleQuery = Role.getQuery();
3890 30 Oct 07 nicklas 92   roleQuery.include(Include.ALL);
3467 08 Jun 07 nicklas 93   roleQuery.restrict(
3467 08 Jun 07 nicklas 94     Restrictions.eq(
3467 08 Jun 07 nicklas 95       Hql.property("default"), 
3467 08 Jun 07 nicklas 96       Expressions.parameter("isDefault", true, Type.BOOLEAN)
3467 08 Jun 07 nicklas 97     )
3467 08 Jun 07 nicklas 98   );
6223 15 Jan 13 nicklas 99   roleQuery.order(Orders.asc(Hql.property("name")));
6291 11 Jun 13 nicklas 100   JSONObject jsonRoles = new JSONObject();
6291 11 Jun 13 nicklas 101   jsonRoles.put("itemType", "ROLE");
6291 11 Jun 13 nicklas 102   jsonRoles.put("name", "Roles");
7604 25 Feb 19 nicklas 103   jsonRoles.put("items", JsonUtil.toArray(roleQuery.iterate(dc), new NameableConverter<Role>()));
3467 08 Jun 07 nicklas 104
6291 11 Jun 13 nicklas 105   JSONArray jsonMembers = new JSONArray();
6291 11 Jun 13 nicklas 106   jsonMembers.add(jsonGroups);
6291 11 Jun 13 nicklas 107   jsonMembers.add(jsonRoles);
6291 11 Jun 13 nicklas 108   
3467 08 Jun 07 nicklas 109   final boolean readGroups = sc.hasPermission(Permission.READ, Item.GROUP);
3467 08 Jun 07 nicklas 110   final boolean useGroups = sc.hasPermission(Permission.USE, Item.GROUP);
3467 08 Jun 07 nicklas 111   final boolean writeGroups = sc.hasPermission(Permission.WRITE, Item.GROUP);
3467 08 Jun 07 nicklas 112   final boolean writeRoles = sc.hasPermission(Permission.WRITE, Item.ROLE);
3467 08 Jun 07 nicklas 113   final boolean writeMembership = writeGroups && writeRoles;
3467 08 Jun 07 nicklas 114   %>
3467 08 Jun 07 nicklas 115   <base:page type="popup" title="<%=title%>">
6291 11 Jun 13 nicklas 116   <base:head scripts="linkitems-2.js,~default_membership.js" />
6223 15 Jan 13 nicklas 117   <base:body>
6223 15 Jan 13 nicklas 118     <h1><%=title%> <base:help helpid="user.edit.default_membership" /></h1>
3467 08 Jun 07 nicklas 119     
6387 18 Dec 13 nicklas 120     <div id="page-data" class="datacontainer"
6223 15 Jan 13 nicklas 121       data-everyone-id="<%=SystemItems.getId(Group.EVERYONE) %>"
6223 15 Jan 13 nicklas 122       ></div>
6223 15 Jan 13 nicklas 123     
6162 10 Oct 12 nicklas 124     <form action="index.jsp?ID=<%=ID%>" method="post" name="user">
3467 08 Jun 07 nicklas 125     <input type="hidden" name="cmd" value="UpdateDefaultMembership">
3467 08 Jun 07 nicklas 126
6610 20 Nov 14 nicklas 127     <div class="content">
5922 11 Jan 12 nicklas 128       <table class="fullform input100 smaller bottomborder">
5921 10 Jan 12 nicklas 129       <tr class="dynamic">
5921 10 Jan 12 nicklas 130       <th>Member in</th>
3467 08 Jun 07 nicklas 131       <td>
5921 10 Jan 12 nicklas 132         <div class="selectionlist">
5921 10 Jan 12 nicklas 133           <table>
5921 10 Jan 12 nicklas 134           <tr>
5921 10 Jan 12 nicklas 135             <td>
6291 11 Jun 13 nicklas 136               <select name="membership" id="membership"
6291 11 Jun 13 nicklas 137                 class="auto-init"
6291 11 Jun 13 nicklas 138                 data-auto-init="link-container"
6291 11 Jun 13 nicklas 139                 data-initial-items="<%=HTML.encodeTags(jsonMembers.toJSONString()) %>"
6291 11 Jun 13 nicklas 140                 size="16" multiple <%=!writeMembership ? "disabled readonly class=\"disabled\"" : ""%>>
5921 10 Jan 12 nicklas 141               </select>
5921 10 Jan 12 nicklas 142             </td>
5921 10 Jan 12 nicklas 143             <td style="vertical-align: top;">
5921 10 Jan 12 nicklas 144               <base:buttongroup vertical="true">
5921 10 Jan 12 nicklas 145                 <base:button 
6223 15 Jan 13 nicklas 146                   id="btnAddGroups"
6291 11 Jun 13 nicklas 147                   subclass="leftaligned auto-init"
6291 11 Jun 13 nicklas 148                   data-auto-init="add-link"
6291 11 Jun 13 nicklas 149                   data-list-id="membership"
6291 11 Jun 13 nicklas 150                   data-item-type="GROUP"
6291 11 Jun 13 nicklas 151                   data-exclude="<%=SystemItems.getId(Group.EVERYONE) %>"
5921 10 Jan 12 nicklas 152                   style="width: 12em;"
5921 10 Jan 12 nicklas 153                   title="Add&nbsp;groups&hellip;"  
5921 10 Jan 12 nicklas 154                   tooltip="Add groups to this user"
5921 10 Jan 12 nicklas 155                   disabled="<%=!writeMembership %>" 
5921 10 Jan 12 nicklas 156                 />
5921 10 Jan 12 nicklas 157                 <base:button 
6223 15 Jan 13 nicklas 158                   id="btnAddRoles"
6291 11 Jun 13 nicklas 159                   subclass="leftaligned auto-init"
6291 11 Jun 13 nicklas 160                   data-auto-init="add-link"
6291 11 Jun 13 nicklas 161                   data-list-id="membership"
6291 11 Jun 13 nicklas 162                   data-item-type="ROLE"
5921 10 Jan 12 nicklas 163                   style="width: 12em;"
5921 10 Jan 12 nicklas 164                   title="Add&nbsp;roles&hellip;"  
5921 10 Jan 12 nicklas 165                   tooltip="Add roles to this user"
5921 10 Jan 12 nicklas 166                   disabled="<%=!writeMembership %>" 
5921 10 Jan 12 nicklas 167                 />
5921 10 Jan 12 nicklas 168                 <base:button 
6223 15 Jan 13 nicklas 169                   id="btnRemoveMembership"
6291 11 Jun 13 nicklas 170                   subclass="leftaligned auto-init"
6291 11 Jun 13 nicklas 171                   data-auto-init="remove-link"
6291 11 Jun 13 nicklas 172                   data-list-id="membership"
6291 11 Jun 13 nicklas 173                   data-item-type="GROUP"
5921 10 Jan 12 nicklas 174                   style="width: 12em;"
5921 10 Jan 12 nicklas 175                   title="Remove" 
5921 10 Jan 12 nicklas 176                   tooltip="Remove the user from the selected items"
5921 10 Jan 12 nicklas 177                   disabled="<%=!writeMembership%>" 
5921 10 Jan 12 nicklas 178                 />
5921 10 Jan 12 nicklas 179               </base:buttongroup>
6610 20 Nov 14 nicklas 180               <div class="messagecontainer note">
6610 20 Nov 14 nicklas 181                 The selected roles and groups will automatically be assigned to new users.
6610 20 Nov 14 nicklas 182               </div>
5921 10 Jan 12 nicklas 183             </td>
5921 10 Jan 12 nicklas 184           </tr>
5921 10 Jan 12 nicklas 185           </table>
5921 10 Jan 12 nicklas 186         </div>
3467 08 Jun 07 nicklas 187       </td>
3467 08 Jun 07 nicklas 188       </tr>
3467 08 Jun 07 nicklas 189       </table>
5921 10 Jan 12 nicklas 190     </div>
3467 08 Jun 07 nicklas 191     </form>
5921 10 Jan 12 nicklas 192     <base:buttongroup subclass="dialogbuttons">
6223 15 Jan 13 nicklas 193       <base:button id="btnSave" title="Save" />
6223 15 Jan 13 nicklas 194       <base:button id="close" title="Cancel" />
5921 10 Jan 12 nicklas 195     </base:buttongroup>
3467 08 Jun 07 nicklas 196   </base:body>
3467 08 Jun 07 nicklas 197   </base:page>
3467 08 Jun 07 nicklas 198   <%
3467 08 Jun 07 nicklas 199 }
3467 08 Jun 07 nicklas 200 finally
3467 08 Jun 07 nicklas 201 {
3467 08 Jun 07 nicklas 202   if (dc != null) dc.close();
3467 08 Jun 07 nicklas 203 }
3467 08 Jun 07 nicklas 204 %>