Skip to content

Instantly share code, notes, and snippets.

@sdumitriu
Last active December 5, 2016 16:23
Show Gist options
  • Save sdumitriu/79956920e3259ac563b081cdc72ee3c7 to your computer and use it in GitHub Desktop.
Save sdumitriu/79956920e3259ac563b081cdc72ee3c7 to your computer and use it in GitHub Desktop.
PhenoTips - Change permissions for all/some patient records

To change permissions for all/some patient records, including the template used for future patients, open /bin/edit/Sandbox/ChangePermissions in a browser while logged in with an administrative account, paste the following snippet, and press Preview.

WARNING: Pressing Preview doesn't preview the changes, it will actually modify the permissions!

Things you can adjust:

  • the target visibility, at line 2 replace private with the desired value (hidden, private, matchable, public, open)
  • the target owner, at line 4 replace groupname with the desired group name, or uncomment line 6 and replace username with the desired username
  • the target collaborator, at line 8 replace groupname with the desired group name, or uncomment line 10 and replace username with the desired username
  • the target access level, at line 11 replace edit with the desired value (view, edit, manage)
  • you can add more collaborators, just define new $collaboratorX and $accessLevelX variables and make additional addCollaborator calls
  • skip the patient template by replacing the query at line 13 with 'from doc.object(PhenoTips.PatientClass) as p where doc.name <> ''PatientTemplate'''
  • only include records of a certain user by replacing the query at line 13 with 'from doc.object(PhenoTips.PatientClass) as p, doc.object(PhenoTips.OwnerClass) as o where o.owner = ''xwiki:XWiki.username'''
  • only include records of a certain workgroup by replacing the query at line 13 with 'from doc.object(PhenoTips.PatientClass) as p, doc.object(PhenoTips.OwnerClass) as o where o.owner = ''xwiki:Groups.groupname'''
  • only include records with an external ID matching a specific substring by replacing the query at line 13 with 'from doc.object(PhenoTips.PatientClass) as p where p.external_id like ''GC%'''
  • modify a specific set of patient records by specifying it manually: #foreach ($i in ['P0000001', 'P0000005', 'P0000042'])
{{velocity}}
#set ($visibility = $services.permissions.resolveVisibility('private'))
#set ($owner = $services.model.createDocumentReference('', 'Groups', 'groupname'))
## Or for a specific user:
## #set ($owner = $services.model.createDocumentReference('', 'XWiki', 'username'))
#set ($collaborator = $services.model.createDocumentReference('', 'Groups', 'groupname'))
## Or for a specific user:
## #set ($collaborator = $services.model.createDocumentReference('', 'XWiki', 'username'))
#set ($accessLevel = $services.permissions.resolveAccessLevel('edit'))
#foreach ($i in $services.query.xwql('from doc.object(PhenoTips.PatientClass) as p').execute())
#set ($patientAccess = $services.permissions.getPatientAccess($services.patients.getPatientById($i)))
$patientAccess.setOwner($owner)
$patientAccess.setVisibility($visibility)
$patientAccess.addCollaborator($collaborator, $accessLevel)
#end
{{/velocity}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment