Implement event listeners that:
Assign specific owner, visibility, collaborators, or studies when a user creates a patient record, based on the user's preferences
Assign specific visibility, collaborators or studies when a workgroup becomes the owner of a patient record, based on the workgroup's preferences
Assign specific visibility or collaborators when a record is placed into a study.
The preferences will be stored in XWiki.ConfigurationClass objects in the user profile pages, workgroup pages or study pages.
XWiki.ConfigurationClass has two free-text (String) fields: property and value. For our purposes here, the following are valid property/value pairs:
Property=defaultOwner / value = <a user or workgroup referece>. Example: defaultOwner / xwiki:XWiki:John . Not valid on study pages.
Property=defaultCollaborator / value = <a user or workgroup referece>[^<access level]. Level can be view, edit, manage. If level is missing or is invalid, the default is view. Examples:
defaultCollaborator / xwiki:Groups.BloodDisorders^manage
defaultCollaborator / xwiki:XWiki.Mary
Property=defaultVisibility / value = <a visibility level configured on the current installation>. Example: defaultVisibility / matchable
Property=defaultStudy / value = <a study reference>. Example: defaultStudy / xwiki:Studies:TheGreatStudy. Not valid on study pages.
Property=defaultWorkgroup / value = <a workgroup reference>. Example: defaultWorkgroup / xwiki:Groups.BloodDisorders . Only on user profile pages. Allows to use preferences from one of the user’s workgroups IF they are not set in the user’s profile.
There can be any number of XWiki.ConfigurationClass objects in a user profile, workgroup profile or study page.
When a user creates a patient record, or when a user or workgroup becomes the owner of a patient record, a listener (see relevant sub-tasks below) reads the configuration objects in the user /workgroup profile and sets the specified permissions/studies. When a patient record is placed into a study, a listener reads the configuration objects in the study page and sets the specified permissions. These changes may activate several listeners in cascade. The process should stop when no more changes need to be made.
Listeners should only save the patient record document (and create a new version) if changes were actually made. E.g. if the patient record is public by default on the entire database, and the user's preference says their records should be public, the listener does not actually change the visibility. Do not create another version.
Retrieving one of the preferences defaultOwner, defaultCollaborator, defaultVisibility, defaultStudy for a User:
Look for XWiki.ConfigurationClass object with property=defaultWorkgoup in the user profile document
If it exists AND the workgroup reference is valid AND it’s one of this user’s workgroups, get all the defaults from that workgroup page (ignore any defaults that are set in the user profile)
Otherwise, look for XWiki.ConfigurationClass objects with that property in the user profile document
If the configuration does not exist, do nothing, as that configuration does not exist for the user.
All configuration objects with invalid values (as per the description above) will be skipped, and their encounter will be logged as a warning in the terminal.