Users and groups are defined using schemas and, as an Extensible Platform, Nuxeo gives you the ability to modify or add schemas.
Prerequisite
This page gives the step by step instructions to deploy new user information in Nuxeo Platform. For the UI configuration, it assumes you have the Nuxeo Web UI addon deployed.
Extending User Properties
Let's add a new user property called manager, corresponding to the current user's manager. This information would be helpful in the workflow context (for reassignment, escalation rules etc.)
Create the New User Property
Create a manager_user_field.xsd
file with the following content from the default user schema definition:
<?xml version="1.0"?>
<xs:schema targetNamespace="http://www.nuxeo.org/ecm/schemas/user"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:nxs="http://www.nuxeo.org/ecm/schemas/user">
<xs:include schemaLocation="base.xsd" />
<xs:element name="username" type="xs:string" />
<xs:element name="password" type="xs:string" />
<xs:element name="firstName" type="xs:string" />
<xs:element name="lastName" type="xs:string" />
<xs:element name="company" type="xs:string" />
<!-- here is my new user field -->
<xs:element name="manager" type="xs:string" />
<xs:element name="email">
<xs:simpleType>
<xs:restriction base="xs:string">
<!-- the same pattern is used in userinfo.xsd -->
<xs:pattern value="[^@]+@[^\.]+\..+" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<!-- inverse reference -->
<xs:element name="groups" type="nxs:stringList" />
<!-- tenant id for the user -->
<xs:element name="tenantId" type="xs:string" />
</xs:schema>
Deploy the New Field in Studio Modeler
- Open your Nuxeo Studio Project and Navigate to Studio Modeler > CONFIGURATION > Resources > Schemas.
- Upload the
manager_user_field.xsd
file. Go to CONFIGURATION > Content Model > Schemas and click on New. Fill in the popup window like this:
Click on Ok.
- Go to CONFIGURATION > Advanced Settings > XML Extensions and create a new XML extension (called for example
USER_SCHEMA_EXTENSION
) with the following content:<require>org.nuxeo.ecm.core.management.typesContrib</require> <extension point="schema" target="org.nuxeo.ecm.core.schema.TypeService"> <schema name="user" override="true" src="data/schemas/manager_user_field.xsd"/> </extension>
- To check that those steps were effective, check into your database that the fields are present in the users table after synching your project server-side and restarting Nuxeo.
Display the New Field in Web UI
This new field has to be displayed in all the pages related to the user information.
It includes:
- The user edition form to create and update the new property:
- The user information page to view the new property:
Edit Layout
- In Designer, go to Resources and create a folder under UI called
custom-user-fields
. We will create all the next elements in this folder. - Create a new element
nuxeo-edit-user
. - Replace the existing content by the element
nuxeo-edit-user.html
. - Add:
<nuxeo-user-suggestion value="{{user.manager}}" label="[[i18n('editUser.manager')]]" search-type="USER_TYPE" name="manager"></nuxeo-user-suggestion>
Create Layout
- Create a new element
nuxeo-create-user
. - Replace the existing content by the element create-user.html.
Add the line:
<link rel="import" href="nuxeo-edit-user.html">
Replace:
<nuxeo-layout id="layout" href="[[_layoutHref('nuxeo-edit-user.html')]]" model="[[_layoutModel(user, new)]]" on-element-changed="_layoutElementChanged"></nuxeo-layout>
by:
<nuxeo-layout id="layout" href="nuxeo-edit-user.html"
model="[[_layoutModel(user, new)]]"
on-element-changed="_layoutElementChanged"></nuxeo-layout>
User Management Layout
- Create a new element
nuxeo-user-group-management
. - Replace the existing content by the element
nuxeo-user-group-management.html
. - Add the following line:
<link rel="import" href="nuxeo-create-user.html">
- Comment the line:
<link rel="import" href="nuxeo-user-group-management/nuxeo-create-user.html">
User Management Page Layout
- Create a new element
nuxeo-user-group-management-page
. - Replace the existing content by the element
nuxeo-user-group-management-page.html
. Add the following line:
<link rel="import" href="nuxeo-user-group-management.html">
Comment the line:
<link rel="import" href="../../bower_components/nuxeo-ui-elements/nuxeo-user-group-management.html">
View Layout
- Create a folder called
nuxeo-user-group-management
under UI. - In this folder, create a new element
nuxeo-view-user
. - Replace the existing content by the element
nuxeo-view-user.html
. - Add the following lines:
<div class="layout vertical flex">
<label>[[i18n('user.manager')]]</label>
<nuxeo-user-tag user="[[user.properties.manager]]"></nuxeo-user-tag>
</div>
Update your Custom Bundle File
You need to reference these new elements in your *-custom.bundle.html
file. To do so, add the following lines:
<link rel="import" href="custom-user-fields/nuxeo-edit-user.html">
<link rel="import" href="custom-user-fields/nuxeo-create-user.html">
<link rel="import" href="custom-user-fields/nuxeo-user-group-management.html">
<link rel="import" href="custom-user-fields/nuxeo-user-group-management-page.html">
<link rel="import" href="nuxeo-user-group-management/nuxeo-view-user.html">
Translate the New Field
Add a new entry in your translation file (messages.json
by default) with:
{
...
"user.manager":"Manager"
...
}
Deploy Your Changes
- User Creation and Edition Layout
- User View Layout
User and Group References
Whenever you contribute to a schema referencing another schema or document, you must define the references and inverse references.
On that particular case, you also have to define directories to specify the way schemas are linked to each other.
The relation between user
and groups
uses a directory called groupDirectory is defined as follow:
<?xml version="1.0"?>
<component name="org.nuxeo.ecm.directory.storage">
<require>org.nuxeo.ecm.platform.digestauth.config</require>
<extension target="org.nuxeo.ecm.directory.GenericDirectory" point="directories">
<directory name="groupDirectory" extends="template-group">
<schema>group</schema>
<types>
<type>system</type>
</types>
<idField>groupname</idField>
<dataFile>groups.csv</dataFile>
<createTablePolicy>on_missing_columns</createTablePolicy>
<autoincrementIdField>false</autoincrementIdField>
<cacheEntryName>group-entry-cache</cacheEntryName>
<cacheEntryWithoutReferencesName>group-entry-cache-without-references</cacheEntryWithoutReferencesName>
<references>
<reference field="members" directory="userDirectory"
name="user2group" source="groupId" target="userId"
dataFile="user2group.csv"/>
<reference field="subGroups" directory="groupDirectory"
name="group2group" source="parentGroupId"
target="childGroupId"/>
<inverseReference field="parentGroups" directory="groupDirectory"
dualReferenceField="subGroups"/>
</references>
</directory>
</extension>
</component>
The customization of the groups is similar to the users.
The default group schema definition:
<?xml version="1.0"?>
<xs:schema targetNamespace="http://www.nuxeo.org/ecm/schemas/group"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:nxs="http://www.nuxeo.org/ecm/schemas/group">
<xs:include schemaLocation="base.xsd" />
<xs:element name="groupname" type="xs:string" />
<xs:element name="grouplabel" type="xs:string" />
<xs:element name="description" type="xs:string" />
<!-- references -->
<xs:element name="members" type="nxs:stringList" />
<xs:element name="subGroups" type="nxs:stringList" />
<!-- inverse reference -->
<xs:element name="parentGroups" type="nxs:stringList" />
<!-- multi tenant -->
<xs:element name="tenantId" type="xs:string" />
</xs:schema>
The group
schema can be extended as well using an extension:
<extension target="org.nuxeo.ecm.core.schema.TypeService" point="schema">
<schema name="group" src="schemas/my_custom_group_schema.xsd"/>
</extension>