Users Module

Version 13.4 by Silvia Macovei on 2010/08/16 11:31

The need is to develop the Users module of the XWiki platform, i.e. the module that provides the APIs allowing to manage XWiki Users.

Requirements & Use cases

We display lists of users in multiple places: user administration, user directory (to be commited), user suggests, rights UI.

  • UC1: Being able to restrict the list of users to local users in a wiki instance
  • UC2: Being able to restrict the list of users to global users in a wiki instance
  • UC2: Being able to mix local and global users in the lists available in a wiki instance

Implementation Proposal

Configuration (xwiki.properties)

#-# [Since 2.5M1]
#-# Define at which level users and groups should be handled in the farm. Available modes: 
#-#
#-# mixed (default):
#-# - user registration available in the main wiki and local wikis
#-# - users from the current wiki and the main wiki will be displayed in the rights interface and user suggests
#-# - user administration is present in all the wikis
#-#
#-# local:
#-# - user registration available in the main wiki and local wikis
#-# - only users from the current wiki will be displayed in the rights interface and user suggests
#-# - user administration is present in all the wikis
#-#
#-# global:
#-# - user registration available in the main wiki only, the register link in local wikis will point to the main wiki
#-# - only users from the main wiki will be displayed in the rights interface and user suggests
#-# - user administration is present in the main wiki only
core.virtual.users=mixed

Users Component

Hierarchy:

|- xwiki-users/
|-- xwiki-users-api/
|-- xwiki-users-default/ : some standard implementations
           * default (proxy that determine the implementation to use from the configuration)
           * global (only global users)
           * local (only local users)
           * mixed (both global and local users)

Minimalistic UserManager API :

API proposals

Information

Starting points meant to be extended in the future

Proposal 1

package org.xwiki.users;

import java.util.List;

import org.xwiki.model.reference.DocumentReference;

/**
 * User Manager interface.  
 * 
 * @version $Id: $
 */
public interface UserManager
{
    /**
     * Get users documents references.
     * 
     * @param limit Number of references to get
     * @param offset The offset to use in the results set 
     * @return A list of users documents references
     */
    List<DocumentReference> getUsers(int limit, int offset);
    
    /**
     * Get users documents references for users matching the given text fragment. The matching is performed on three
     * different fields: the name of the user document itself, the user firstname and the user lastname.
     * 
     * @param limit Number of references to get
     * @param offset The offset to use in the results set 
     * @return A list of users documents references matching the given text fragment
     */
    List<DocumentReference> getUsers(String match, int limit, int offset);
    
    /**
     * @return The number of users.
     */
    int getUsersNumber();
}

Proposal 2

package org.xwiki.users;

import org.xwiki.model.reference.DocumentReference;

/**
 * Class representing a XWiki User.
 * 
 * @version $Id:$
 */
public class User
{
    /**
     * Reference of the user profile document.
     */
    private DocumentReference documentReference;
    
    /**
     * User first name.
     */
    private String firstName;
    
    /**
     * User last name.
     */
    private String lastName;
    
    /**
     * Constructor.
     * 
     * @param documentReference Reference of the user profile document
     * @param firstName User first name
     * @param lastName User last name
     */
    public User(DocumentReference documentReference, String firstName, String lastName)
    {
        this.documentReference = documentReference;
        this.firstName = firstName;
        this.lastName = lastName;
    }
    
    /**
     * @return Reference of the user profile document
     */
    public DocumentReference getDocumentReference()
    {
        return documentReference;
    }
    
    /**
     * @return User first name
     */
    public String getFirstName()
    {
        return firstName;
    }
    
    /**
     * @return User last name
     */
    public String getLastName()
    {
        return lastName;
    }
package org.xwiki.users;

import java.util.List;

import org.xwiki.component.annotation.ComponentRole;

/**
 * User Manager interface.
 * 
 * @version $Id: $
 */
@ComponentRole
public interface UserManager
{    
    /**
     * Get users.
     * 
     * @param number Number of results to get
     * @param offset The offset to use in the results set
     * @return A list of users
     */
    List<User> getUsers(int number, int offset);

    /**
     * Get users matching the given text fragment. The matching is performed on three different fields: the name of the 
     * user document itself, the user first name and the user last name. The matching is not case sensitive.
     * 
     * @param match Text fragment to match
     * @param number Number of results to get
     * @param offset The offset to use in the results set
     * @return A list of users matching the given text fragment
     */
    List<User> getUsers(String match, int number, int offset);

    /**
     * @return The number of users.
     */
    int getUsersNumber();
}

Notes about the current implementation

The current implementation uses a named query to retrieve all the users (+info) at once from a given wiki. It caches them. The size of the cache is currently hardcoded to 20 wikis, which means that if each wiki contains 1000 users the cache will hold 20000 User objects.

  <query name="getAllUsersInfo">
    select distinct doc.fullName, firstName.value, lastName.value from XWikiDocument as doc, BaseObject as obj, 
    StringProperty as firstName, StringProperty as lastName where obj.name=doc.fullName 
    and obj.className='XWiki.XWikiUsers' and firstName.id.id=obj.id and firstName.name='first_name' 
    and lastName.id.id=obj.id and lastName.name='last_name'
  </query>

Get Connected