Uploaded image for project: 'Kernel'
  1. Kernel
  2. KNL-428

add isVisible method to determine tool visibility in a site for a user

    Details

    • Type: Contributed Patch
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.2.1
    • Component/s: API, Impl
    • Labels:
      None

      Description

      The portal implements it's own method to check whether a given tool Placement is hidden or not. Suggest this or a similar method is implemented in the Kernel as this is a useful feature.

      Current methods from:
      portal/portal-impl/impl/src/java/org/sakaiproject/portal/charon/ToolHelperImpl.java

      public static final String TOOLCONFIG_REQUIRED_PERMISSIONS = "functions.require";

      public boolean isHidden(Placement placement)

      { if (placement == null) return true; String requiredPermissionsString = StringUtils.trimToNull(placement.getConfig().getProperty(TOOLCONFIG_REQUIRED_PERMISSIONS)); if (requiredPermissionsString == null) return false; return requiredPermissionsString.contains("site.upd"); }

      /**

      • The optional tool configuration tag "functions.require" describes a
      • set of permission lists which decide the visibility of the tool link
      • for this site user. Lists are separated by "|" and permissions within a
      • list are separated by ",". Users must have all the permissions included in
      • at least one of the permission lists.
        *
      • For example, a value like "section.role.student,annc.new|section.role.ta"
      • would let a user with "section.role.ta" see the tool, and let a user with
      • both "section.role.student" AND "annc.new" see the tool, but not let a user
      • who only had "section.role.student" see the tool.
        *
      • If the configuration tag is not set or is null, then all users see the tool.
        */
        public boolean allowTool(Site site, Placement placement)
        {
        // No way to render an opinion
        if (placement == null || site == null) return true;

      String requiredPermissionsString = placement.getConfig().getProperty(TOOLCONFIG_REQUIRED_PERMISSIONS);
      if (log.isDebugEnabled()) log.debug("requiredPermissionsString=" + requiredPermissionsString + " for " + placement.getToolId());
      if (requiredPermissionsString == null)
      return true;
      requiredPermissionsString = requiredPermissionsString.trim();
      if (requiredPermissionsString.length() == 0)
      return true;

      String[] allowedPermissionSets = requiredPermissionsString.split("
      |");
      for (int i = 0; i < allowedPermissionSets.length; i++)
      {
      String[] requiredPermissions = allowedPermissionSets[i].split(",");
      if (log.isDebugEnabled()) log.debug("requiredPermissions=" + Arrays.asList(requiredPermissions));
      boolean gotAllInList = true;
      for (int j = 0; j < requiredPermissions.length; j++)
      {
      if (!SecurityService.unlock(requiredPermissions[j].trim(), site.getReference()))

      { gotAllInList = false; break; }

      }
      if (gotAllInList)

      { return true; }

      }

      // No permission sets were matched.
      return false;
      }

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  steve.swinsburg Steve Swinsburg
                  Reporter:
                  steve.swinsburg Steve Swinsburg
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  2 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:

                    Git Source Code