Hi,
following Request for a new contrib repository for a user and group name formatter and cleaner , I would like to propose an API to format and clean users.
The idea is to provide an API that provides what we’ve been doing in the OIDC, LDAP and CONFLUENCE modules as far as user and group name formatting is concerned, but still have it generic enough for it to be generally useful and reusable.
Note that there is an idea of eventually integrating this API to xwiki-platform or xwiki-commons, it’d be nice to design it as unsurprisingly as possible for something that ought to live there.
Also note that this API is extracted from OIDC, LDAP and CONFLUENCE and some design constraints come from this extraction: it ought to be reusable at these places without too much disruption.
Here are some of the general ideas of the proposal:
- we add a
formattermodule to the newly createduser-commonrepository - This module provides a
UserFormatterinterface (and aDefaultUserFormatterimplementation) providing:- a format method that takes a placeholder and fills it with values the
UserFormatterobject was initialized with - a clean method that takes a user name or a group names and cleans it as per the configuration it was initialized with
- a format method that takes a placeholder and fills it with values the
- A
UserFormatterFactorycomponent would help createUserFormatterobjects, that are configurable (following a suggestion from @tmortagne)
Here’s a proposed implementation that we can use to discuss and refine more concretely. In this preliminary implementation, for UserFormatter, I wanted to imitate the way Query objects work, but in an immutable way.
Here’s how it would look like from the side of the API usage:
- OIDC-278: Use the user common formatter by raphj · Pull Request #118 · xwiki-contrib/oidc · GitHub
- LDAP-162: Use the user common formatter by raphj · Pull Request #49 · xwiki-contrib/ldap · GitHub
- CONFLUENCE-515: Use the user common formatter by raphj · Pull Request #82 · xwiki-contrib/confluence · GitHub
At this point pretty much any detail or architectural aspect can be discussed and changed, don’t hesitate to suggest / recommend any kind of change or provide any kind of nitpick (this is also an occasion for me to improve my designs in general).