Hi devs,
Context
-
In the new User API we have the concept of User. In practice a User object holds only a UserReference. When calling
User#getProperty(propName)
it gets the user property on the fly. Thus we don’t really need to have an Object holding aUserReference
since we could simply store theUserReference
directly and then calls a service to get the user properties. -
We need to get the user configuration properties with two use cases:
- the direct user properties (resolved from the
XWiki.XWikiUsers
xobject for ex) - the user properties with fallbacks on the space preferences, wiki preferences and xwiki.properties config file. For example when asking for the user editor. FTR this is what
XWiki#getUserPreferences()
currently does but we need we new API for it.
- the direct user properties (resolved from the
Thus I’m proposing the following new proposal.
New Proposal
- We keep the concept of
UserReference
andUserReferenceResolver
. - We drop the
User
object andUserResolver
- We introduce the
UserConfiguration
object (which represents a typed Configuration Source for user properties). - We use the
UserManager
to access everything.public interface UserManager { UserConfiguration createUser(UserReference userReference); void deleteUser(UserReference userReference); boolean exists(UserReference userReference); UserConfiguration getXWikiPropertiesUserConfiguration(UserReference userReference); UserConfiguration getWikiUserConfiguration(UserReference userReference, boolean inherits); UserConfiguration getSpaceUserConfiguration(UserReference userReference, boolean inherits); UserConfiguration getUserConfiguration(UserReference userReference, boolean inherits); }
- The Script service
$services.user
will provide theUserManager
API for scripts. It’ll also add aUserReference getCurrentUserReference()
API. - We modify the
ConfigurationSource
API to addsetProperty()
andsave()
methods so that the API is not just readonly but also write (and exceptions are thrown for CS that don’t implement the write part such as Composite CS and “xwikipropeties” or “xwikicfg” CS. The implementation should cache the modified properties and keep a list of modified properties and only persist them whensave()
is called. This allows for batch updates. - Since
UserConfiguration
implementsConfigurationSource
, it’ll also have the write methods. It’ll add typed methods for write (e.g.setDefaultEditor(Editor editor)
). - Note: a CS can have parents but when using the write methods, it only affects the curent level (and not the parent).
- We continue to allow getting a
UserConfiguration
object even when theUserReference
points to a non-existent user. In this caseUserManager#exists()
and all theUserConfiguration
write methods will throw aUserNotFoundException
.