Ignore:
Timestamp:
Feb 20, 2017, 8:09:27 AM (5 years ago)
Author:
Nicklas Nordborg
Message:

References #2043: Activating/deactivating roles on the fly in a login session

Added a "Inactive roles" tab in the "Preferences" dialog. This allows a user to set roles that should be inactive by default after logging in.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/www/my_base/user/preferences.jsp

    r7112 r7295  
    3939  import="net.sf.basedb.core.DbControl"
    4040  import="net.sf.basedb.core.User"
     41  import="net.sf.basedb.core.Role"
     42  import="net.sf.basedb.core.Type"
    4143  import="net.sf.basedb.core.Metadata"
    4244  import="net.sf.basedb.core.ItemContext"
     45  import="net.sf.basedb.core.ItemQuery"
    4346  import="net.sf.basedb.core.Permission"
     47  import="net.sf.basedb.core.query.Hql"
     48  import="net.sf.basedb.core.query.Restrictions"
     49  import="net.sf.basedb.core.query.Expressions"
     50  import="net.sf.basedb.core.query.Orders"
    4451  import="net.sf.basedb.util.ToStringComparator"
    4552  import="net.sf.basedb.clients.web.Base"
     
    5158  import="net.sf.basedb.clients.web.extensions.startpage.StartPageAction"
    5259  import="net.sf.basedb.util.Values"
     60  import="java.util.Collections"
    5361  import="java.util.List"
    5462  import="java.util.Set"
     
    95103  allItems.add(Item.BIOASSAYSET);
    96104 
     105  // Load roles
     106  List<Role> roles = null;
     107  Set<Integer> roleIds = sc.getAllRoles();
     108  Set<Integer> defaultInactive = Collections.emptySet();
     109  if (roleIds != null && roleIds.size() > 0)
     110  {
     111    ItemQuery<Role> roleQuery = Role.getQuery();
     112    roleQuery.restrict(Restrictions.in(Hql.property("id"), Expressions.parameter("roles")));
     113    roleQuery.setParameter("roles", roleIds, Type.INT);
     114    roleQuery.order(Orders.asc(Hql.property("name")));
     115    roles = roleQuery.list(dc);
     116   
     117    String tmp = Values.getStringOrNull(sc.getUserClientSetting("inactiveRoles"));
     118    if (tmp != null)
     119    {
     120      defaultInactive = new HashSet<Integer>(Arrays.asList(Values.getInt(tmp.split(":"))));
     121    }
     122  }
     123
    97124  JspContext context = ExtensionsControl.createContext(dc, pageContext, null, user);
    98125  ExtensionsInvoker<StartPageAction> invoker = (ExtensionsInvoker<StartPageAction>)ExtensionsControl.useExtensions(context, "net.sf.basedb.clients.web.start-page");
     
    505532        </table>
    506533      </t:tab>
     534      <t:tab
     535        id="inactiveRoles"
     536        title="Inactive roles"
     537        helpid="userpreferences.inactiveroles"
     538        tooltip="Select if any roles should be inactive by default after logging in"
     539        visible="<%=roles != null && roles.size() > 0%>"
     540        >
     541        <table class="fullform">
     542        <tr class="dynamic">
     543          <th>Default roles</th>
     544          <td>
     545            <b>Inactive at login</b><br>
     546            <%
     547            for (Role r : roles)
     548            {
     549              boolean inactive = defaultInactive.contains(r.getId());
     550              %>
     551              <label><input type="checkbox" id="role.<%=r.getId()%>"
     552                name="inactiveRoles" value="<%=r.getId()%>"
     553                <%=inactive ? "checked" : "" %>
     554                ><%=HTML.encodeTags(r.getName())%></label><br>
     555              <%
     556            }
     557            %>
     558            <div class="messagecontainer note" style="margin-top: 1em;">
     559            Select all roles that should be inactive by default
     560            after logging in. Note! This setting only applies when
     561            logging in via the web interface.
     562            </div>
     563          </td>
     564        </tr>
     565        </table>
     566       
     567      </t:tab>
    507568    </t:tabcontrol>
    508569    </form>
Note: See TracChangeset for help on using the changeset viewer.