Class PeopleDirectoryService

java.lang.Object
io.meeds.social.people.service.PeopleDirectoryService

@Service public class PeopleDirectoryService extends Object
Rules of the People Directory application instances (EXO-93255, EXO-93256, EXO-93257): who may change an instance's settings or list its users, which stored values are valid, and the users an instance lists. The portlet is glue: it reads the page, the site and its own window id from the portal context and its preferences from the portlet container, and every decision is taken here.
  • Field Details

    • DEFAULT_PAGE_SIZE

      public static final int DEFAULT_PAGE_SIZE
      See Also:
    • MIN_PAGE_SIZE

      public static final int MIN_PAGE_SIZE
      See Also:
    • MAX_PAGE_SIZE

      public static final int MAX_PAGE_SIZE
      See Also:
    • MAX_HEADER_LENGTH

      public static final int MAX_HEADER_LENGTH
      See Also:
    • EMPTY_HEADER_TRANSLATIONS

      public static final String EMPTY_HEADER_TRANSLATIONS
      See Also:
    • PAGE_SIZE_OUT_OF_RANGE_MESSAGE

      public static final String PAGE_SIZE_OUT_OF_RANGE_MESSAGE
      See Also:
    • HEADER_TRANSLATIONS_INVALID_MESSAGE

      public static final String HEADER_TRANSLATIONS_INVALID_MESSAGE
      See Also:
    • HEADER_TOO_LONG_MESSAGE

      public static final String HEADER_TOO_LONG_MESSAGE
      See Also:
    • MAX_ATTRIBUTES

      public static final int MAX_ATTRIBUTES
      See Also:
    • MAX_VALUES_PER_ATTRIBUTE

      public static final int MAX_VALUES_PER_ATTRIBUTE
      See Also:
    • MAX_VALUE_LENGTH

      public static final int MAX_VALUE_LENGTH
      See Also:
    • MAX_ATTRIBUTE_VALUES_SUGGESTED

      public static final int MAX_ATTRIBUTE_VALUES_SUGGESTED
      See Also:
    • MAX_LIMIT

      public static final int MAX_LIMIT
      See Also:
    • EMPTY_JSON_OBJECT

      public static final String EMPTY_JSON_OBJECT
      See Also:
    • UNKNOWN_ATTRIBUTE_MESSAGE

      public static final String UNKNOWN_ATTRIBUTE_MESSAGE
      See Also:
    • ATTRIBUTE_FILTER_INVALID_MESSAGE

      public static final String ATTRIBUTE_FILTER_INVALID_MESSAGE
      See Also:
    • TOO_MANY_ATTRIBUTES_MESSAGE

      public static final String TOO_MANY_ATTRIBUTES_MESSAGE
      See Also:
    • TOO_MANY_VALUES_MESSAGE

      public static final String TOO_MANY_VALUES_MESSAGE
      See Also:
    • VALUE_TOO_LONG_MESSAGE

      public static final String VALUE_TOO_LONG_MESSAGE
      See Also:
    • INVALID_RANGE_MESSAGE

      public static final String INVALID_RANGE_MESSAGE
      See Also:
    • MAX_GROUPS

      public static final int MAX_GROUPS
      See Also:
    • MAX_GROUPS_SUGGESTED

      public static final int MAX_GROUPS_SUGGESTED
      See Also:
    • MAX_GROUP_QUERY_LENGTH

      public static final int MAX_GROUP_QUERY_LENGTH
      See Also:
    • EMPTY_JSON_ARRAY

      public static final String EMPTY_JSON_ARRAY
      See Also:
    • GROUP_FILTER_INVALID_MESSAGE

      public static final String GROUP_FILTER_INVALID_MESSAGE
      See Also:
    • GROUP_NOT_SELECTABLE_MESSAGE

      public static final String GROUP_NOT_SELECTABLE_MESSAGE
      See Also:
    • TOO_MANY_GROUPS_MESSAGE

      public static final String TOO_MANY_GROUPS_MESSAGE
      See Also:
    • userAcl

      @Autowired protected org.exoplatform.portal.config.UserACL userAcl
    • layoutService

      @Autowired protected org.exoplatform.portal.mop.service.LayoutService layoutService
    • userPortalConfigService

      @Autowired protected org.exoplatform.portal.config.UserPortalConfigService userPortalConfigService
    • profilePropertyService

      @Autowired protected org.exoplatform.social.core.profileproperty.ProfilePropertyService profilePropertyService
    • translationService

      @Autowired protected io.meeds.social.translation.service.TranslationService translationService
    • identityManager

      @Autowired protected org.exoplatform.social.core.manager.IdentityManager identityManager
    • relationshipManager

      @Autowired protected org.exoplatform.social.core.manager.RelationshipManager relationshipManager
    • profileSearchConnector

      @Autowired protected ProfileSearchConnector profileSearchConnector
    • userPermissionService

      @Autowired protected UserPermissionService userPermissionService
    • organizationService

      @Autowired protected org.exoplatform.services.organization.OrganizationService organizationService
    • spaceService

      @Autowired protected org.exoplatform.social.core.space.spi.SpaceService spaceService
  • Constructor Details

    • PeopleDirectoryService

      public PeopleDirectoryService()
  • Method Details

    • canEditSettings

      public boolean canEditSettings(org.exoplatform.portal.mop.page.PageKey pageKey, org.exoplatform.portal.mop.SiteKey siteKey, String windowId, String username)
      Whether a user may change the settings of one People Directory window.

      The right is bound to the window, never to the page the URL routes to: the portlet-viewer page renders any stored window by its id, so the page of the portal context does not necessarily hold the window. The window is looked up first in the stored layout of that page, whose edit right then applies, then in the layout the portal renders for the site (the meta site's when the site is displayed), whose edit right then applies. A window held by neither, such as a catalogue instance previewed in the portlet editor, has no editable settings.

      The edit right is the portal's. On a space page, the members of the page's own space that its edit permission names, as a single <membership type>:<space group> expression, get it too; an edit permission naming everyone, another group or several groups grants nothing more. On a site layout, the right is the portal's only.

      Parameters:
      pageKey - the page resolved from the portal context, may be null
      siteKey - the rendering site, may be null
      windowId - the storage id of the window being rendered
      username - the user asking
      Returns:
      true when the user may store the window's settings
    • canViewDirectory

      public boolean canViewDirectory(org.exoplatform.portal.mop.page.PageKey pageKey, org.exoplatform.portal.mop.SiteKey siteKey, String windowId, String username)
      Whether a user may see the users a People Directory window lists: the view right of the page, or of the rendered site layout, that holds the window, found as canEditSettings(PageKey, SiteKey, String, String) finds it.
      Parameters:
      pageKey - the page resolved from the portal context, may be null
      siteKey - the rendering site, may be null
      windowId - the storage id of the window
      username - the user asking
      Returns:
      true when the user may list the directory
    • normalizeAttributeFilter

      public String normalizeAttributeFilter(String value)
      Validates a posted attribute filter: a JSON object mapping a profile property name to the values a listed user must hold one of. An empty object means the directory is not filtered by attribute.
      Parameters:
      value - the posted value
      Returns:
      the value to store, re-serialized, each attribute's values de-duplicated
      Throws:
      IllegalArgumentException - with UNKNOWN_ATTRIBUTE_MESSAGE when a name is not the name of a directory attribute (a visible, active, top-level setting, other than email), TOO_MANY_ATTRIBUTES_MESSAGE, TOO_MANY_VALUES_MESSAGE or VALUE_TOO_LONG_MESSAGE beyond a bound, and ATTRIBUTE_FILTER_INVALID_MESSAGE when the value is not such an object, or an attribute has no value or a value that is not a non-blank text
    • getAttributeFilter

      public Map<String, List<String>> getAttributeFilter(String storedValue)
      The stored attribute filter as the directory applies it. A value that fails normalizeAttributeFilter(String), because another writer of the window's preferences stored it or because an attribute is no longer a directory attribute, gives null: the directory then lists nobody.
      Parameters:
      storedValue - the stored preference value, may be null
      Returns:
      the values per attribute, empty when the directory is not filtered by attribute, null when it lists nobody
    • getDirectoryAttributeNames

      public List<String> getDirectoryAttributeNames(String storedValue)
      The names of the profile attributes the directory filters on, which a viewer's advanced filter shows greyed out: the names only, never the values. A stored filter the directory cannot read gives none.
      Parameters:
      storedValue - the stored preference value, may be null
      Returns:
      the attribute names, in their stored order
    • getEditorAttributes

      public List<io.meeds.social.people.model.PeopleDirectoryAttribute> getEditorAttributes(String storedValue, Locale locale)
      The stored attribute filter as the settings drawer shows it: each entry with its values labelled, and flagged when the attribute is no longer available. Values the directory refuses are left to the drawer to flag; an entry stored with an invalid shape comes back with no value.
      Parameters:
      storedValue - the stored preference value, may be null
      locale - the editor's language, for the option labels
      Returns:
      the attributes, in their stored order
    • search

      public io.meeds.social.people.model.PeopleDirectoryPage search(org.exoplatform.portal.mop.page.PageKey pageKey, org.exoplatform.portal.mop.SiteKey siteKey, String windowId, String storedAttributeFilter, String storedAttributeFilterToSet, String storedGroupFilter, String storedGroupsToSet, String storedGuestRestriction, String query, Map<String,String> viewerAttributes, boolean connectionsOnly, String username, int offset, int limit) throws IllegalAccessException
      One page of the users a People Directory window lists to a viewer: the users matching the window's attribute and group filters and the viewer's own criteria, of all the users or of the viewer's connections. The directory's filter is read from the window's stored preferences, never from the request; the viewer's criteria on an attribute the directory filters are ignored, since the directory wins.
      Parameters:
      pageKey - the page resolved from the portal context, may be null
      siteKey - the rendering site, may be null
      windowId - the storage id of the window
      storedAttributeFilter - the window's stored attribute filter
      storedAttributeFilterToSet - the window's stored marker of a directory made from a template, whose attribute filter must be set again (isAttributeFilterToSet(String)): it then lists nobody
      storedGroupFilter - the window's stored group filter
      storedGroupsToSet - the window's stored marker of a directory whose groups must be set again (isGroupsToSet(String)): it then lists nobody
      storedGuestRestriction - the window's stored "Guests see only connections and space members" setting: any value but false, a missing one included, restricts a guest viewer to the users whose profile they can open (isGuestRestriction(String))
      query - the viewer's name search, may be blank
      viewerAttributes - the viewer's advanced filter, one text per attribute, may be null
      connectionsOnly - whether only the viewer's connections are listed
      username - the viewer
      offset - the index of the first user
      limit - the number of users, from 1 to MAX_LIMIT
      Returns:
      the users of the page and their total number
      Throws:
      IllegalAccessException - when the viewer may not view the page or site holding the window
      IllegalArgumentException - with UNKNOWN_ATTRIBUTE_MESSAGE when a viewer attribute is not a visible, active, top-level setting, or INVALID_RANGE_MESSAGE for an offset or a limit out of range
    • canSetFilterOptions

      public boolean canSetFilterOptions(String username)
      Whether a user may change the filter options of a People Directory window (the guest restriction, the attribute filter and the group filter): any user but an external one, a member of /platform/externals, who keeps the display options only, whatever grants them the edit right.
      Parameters:
      username - the user asking, may be null
      Returns:
      true when the filter options are offered to the user
    • canSetGroupFilter

      public boolean canSetGroupFilter(String username)
      Whether a user may set the group filter of a People Directory window: a user who may set its filter options (canSetFilterOptions(String)) and is a platform administrator, or a manager of at least one group, space or organizational unit (see getManagedGroupIds(String)).
      Parameters:
      username - the user asking, may be null
      Returns:
      true when the group filter is offered to the user
    • getSelectableGroups

      public List<io.meeds.social.people.model.PeopleDirectoryGroup> getSelectableGroups(org.exoplatform.portal.mop.page.PageKey pageKey, org.exoplatform.portal.mop.SiteKey siteKey, String windowId, String query, Collection<String> excludedGroupIds, String username) throws IllegalAccessException
      The groups an editor can select for a People Directory window's group filter: any group for a platform administrator, the groups the editor manages otherwise, each matched on its label or its id, ignoring case; at most MAX_GROUPS_SUGGESTED, the groups the drawer already holds left out before the bound applies.
      Parameters:
      pageKey - the page resolved from the portal context, may be null
      siteKey - the rendering site, may be null
      windowId - the storage id of the window
      query - a text the groups must contain, may be blank
      excludedGroupIds - the groups the drawer already holds, at most MAX_GROUPS of them read, may be null
      username - the editor
      Returns:
      the groups, labelled
      Throws:
      IllegalAccessException - when the user may not edit the window's settings or may not set its group filter
    • normalizeGroupFilter

      public String normalizeGroupFilter(String posted, String stored, String username)
      Validates a posted group filter and merges it with the stored one, for the editor saving it. The filter of an editor who may not set it is kept as stored, whatever is posted. For an editor who may, the stored groups the editor cannot select stay applied, and the posted ones replace the others; an empty post turns the editor's part of the filter OFF. Either way the stored groups that no longer exist are dropped. A space's group is stored with its space's id, resolved here, never posted.
      Parameters:
      posted - the posted value: a JSON array of group ids, [] when the editor's group filter is OFF
      stored - the stored preference value, may be null
      username - the editor
      Returns:
      the value to store: a JSON array of {groupId, spaceId}
      Throws:
      IllegalArgumentException - with GROUP_FILTER_INVALID_MESSAGE when the post is not such an array, GROUP_NOT_SELECTABLE_MESSAGE when a posted group is not one the editor can select, or TOO_MANY_GROUPS_MESSAGE beyond MAX_GROUPS existing groups
      IllegalStateException - when a stored group the editor cannot select cannot be looked up, never for an administrator: it is kept by refusing the save
    • getGroupFilter

      public List<String> getGroupFilter(String storedValue, String storedGroupsToSet)
      The stored group filter as the directory applies it: the ids of the stored groups that still exist. A stored group that no longer exists, or a space's group whose space was deleted, matches nobody, and a value that is not a stored group filter lists nobody. A window carrying the marker of a directory whose groups must be set again (isGroupsToSet(String)), a directory made from a template, lists nobody until a user who may set groups saves its group filter.
      Parameters:
      storedValue - the stored group filter, may be null
      storedGroupsToSet - the stored marker, may be null
      Returns:
      null when the directory is not filtered by group, the ids of the groups a listed user must belong to one of otherwise, empty when it lists nobody
    • getEditorGroups

      public io.meeds.social.people.model.PeopleDirectoryEditorGroups getEditorGroups(String storedValue, String storedGroupsToSet, String username)
      The stored group filter as the settings drawer shows it to an editor: the groups the editor can select, as chips, whether other groups are applied, never named, for an editor who may set the filter how many, which count against MAX_GROUPS, and whether stored groups no longer exist or the stored value cannot be read, so that the filter shows as set although no chip remains, and turning it OFF clears it. The marker of a directory whose groups must be set again (isGroupsToSet(String)) shows to an editor who may set groups as stored groups that no longer exist. Every editor, whether or not they may set groups, is told when the directory misses groups, never which.
      Parameters:
      storedValue - the stored group filter, may be null
      storedGroupsToSet - the stored marker, may be null
      username - the editor
      Returns:
      the editor's groups
      Throws:
      IllegalStateException - when a stored group cannot be looked up: the drawer then gets no group filter to post
    • isGroupsToSet

      public boolean isGroupsToSet(String storedValue)
      Parameters:
      storedValue - the stored marker of a directory whose groups must be set again, may be null
      Returns:
      whether the marker is set: a directory made from a template carries it, since a template does not keep the groups of its directories
    • clearsGroupsToSet

      public boolean clearsGroupsToSet(String postedGroupFilter, String username)
      Whether a save clears the marker of a directory whose groups must be set again: only a save by an editor who may set groups that posts a group filter, groups or the filter OFF, clears it; any other save keeps it, so that the directory keeps listing nobody.
      Parameters:
      postedGroupFilter - the posted group filter, null when none is posted
      username - the editor saving
      Returns:
      true when the marker is to be removed
    • isAttributeFilterToSet

      public boolean isAttributeFilterToSet(String storedValue)
      Parameters:
      storedValue - the stored marker of a directory whose attribute filter must be set again, may be null
      Returns:
      whether the marker is set: a directory made from a template that filtered by profile attribute carries it, since a template does not keep the attribute filter of its directories
    • clearsAttributeFilterToSet

      public boolean clearsAttributeFilterToSet(String postedAttributeFilter, String username)
      Whether a save of the app's settings clears the marker of a directory whose attribute filter must be set again: only a save by an editor who may set the filter options that posts an attribute filter clears it; any other save keeps it, so that the directory keeps listing nobody. The marker is not a protected preference: a page editor who rewrites the window's preferences through the layout API can drop it, as they can add an unfiltered directory to the page anyway.
      Parameters:
      postedAttributeFilter - the posted attribute filter, null when none is posted
      username - the editor saving
      Returns:
      true when the marker is to be removed
    • getManagedGroupIds

      public Set<String> getManagedGroupIds(String username)
      Parameters:
      username - a user
      Returns:
      the ids of the groups the user directly holds the manager membership type, or *, of: a membership inherited through a nested-group link does not make a manager
    • getAttributeValues

      public List<io.meeds.social.people.model.PeopleDirectoryAttributeValue> getAttributeValues(org.exoplatform.portal.mop.page.PageKey pageKey, org.exoplatform.portal.mop.SiteKey siteKey, String windowId, String attribute, String query, String username, Locale locale) throws IllegalAccessException
      The values an editor can select for an attribute of a People Directory window's filter: a dropdown property's options, or the distinct values the enabled users hold, owner-hidden values excluded, at most MAX_ATTRIBUTE_VALUES_SUGGESTED.
      Parameters:
      pageKey - the page resolved from the portal context, may be null
      siteKey - the rendering site, may be null
      windowId - the storage id of the window
      attribute - the profile property name
      query - a text the values must contain, may be blank
      username - the editor
      locale - the editor's language, for the option labels
      Returns:
      the values
      Throws:
      IllegalAccessException - when the user may not edit the window's settings or may not set its filter options: the values are those of all users, an external user's visible ones or not
      IllegalArgumentException - with UNKNOWN_ATTRIBUTE_MESSAGE when the attribute is not a directory attribute
    • isDirectoryAttribute

      public static boolean isDirectoryAttribute(org.exoplatform.social.core.profileproperty.model.ProfilePropertySetting setting)
      Parameters:
      setting - a profile property setting, may be null
      Returns:
      whether a directory can filter on the property: a visible, active, top-level setting, other than email, whose value stays indexed for the name search when its owner hides it
    • normalizePageSize

      public String normalizePageSize(String value)
      Validates a posted number of items per page.
      Parameters:
      value - the posted value
      Returns:
      the value to store
      Throws:
      IllegalArgumentException - with PAGE_SIZE_OUT_OF_RANGE_MESSAGE when the value is not an integer from MIN_PAGE_SIZE to MAX_PAGE_SIZE
    • normalizeHeaderTranslations

      public String normalizeHeaderTranslations(String value)
      Validates a posted header: a JSON object mapping a language to its label. Blank labels are dropped, so an empty result means the header is OFF.
      Parameters:
      value - the posted value
      Returns:
      the value to store, re-serialized
      Throws:
      IllegalArgumentException - with HEADER_TRANSLATIONS_INVALID_MESSAGE when the value is not such an object, or HEADER_TOO_LONG_MESSAGE when a label exceeds MAX_HEADER_LENGTH characters
    • isGuestRestriction

      public boolean isGuestRestriction(String storedValue)
      Whether the stored "Guests see only connections and space members" setting restricts guest viewers. It fails closed: any value but the literal false, a missing or unreadable one included, is ON.
      Parameters:
      storedValue - the stored preference value, may be null
      Returns:
      true unless the setting is OFF
    • normalizeGuestRestriction

      public String normalizeGuestRestriction(String value)
      Validates a posted "Guests see only connections and space members" setting, stored as true or false.
      Parameters:
      value - the posted value
      Returns:
      false for a posted false, true otherwise
    • getPageSize

      public int getPageSize(String storedValue)
      The stored number of items per page as the directory uses it. A value stored by another writer of the window's preferences (the layout editor stores any value) is brought back within the bounds; a missing or unreadable one gives the default.
      Parameters:
      storedValue - the stored preference value, may be null
      Returns:
      a page size from MIN_PAGE_SIZE to MAX_PAGE_SIZE
    • getHeaderTranslations

      public String getHeaderTranslations(String storedValue)
      The stored header as the directory uses it. A value another writer stored and that is not valid is read as no header.
      Parameters:
      storedValue - the stored preference value, may be null
      Returns:
      a valid JSON object of language to label, {} when none