Skip to content

Instantly share code, notes, and snippets.

@tuurma
Created April 12, 2019 12:34
Show Gist options
  • Save tuurma/fe09263644fcec7fec14d99f66d1688b to your computer and use it in GitHub Desktop.
Save tuurma/fe09263644fcec7fec14d99f66d1688b to your computer and use it in GitHub Desktop.
moving from xmldb:change-user to sm
xquery version "3.1";
sm:create-group('boys'),
sm:create-group('girls'),
sm:create-group('existsol'),
(: create 3 accounts with personal groups and additional group :)
sm:create-account('magda', 'm-pass', ('girls', 'existsol')),
sm:create-account('lars', 'l-pass', ('boys', 'existsol')),
sm:create-account('joern', 'l-pass', ('boys', 'existsol')),
for $u in ('magda', 'lars', 'joern')
return
<get-user-groups>{$u} : {sm:get-user-groups($u)}</get-user-groups>
,
for $u in ('magda', 'lars', 'joern', 'boys', 'girls', 'existsol')
return
<get-group-members>{$u} : {sm:get-group-members($u)}</get-group-members>
@tuurma
Copy link
Author

tuurma commented Apr 12, 2019

Set up three groups and three accounts with personal groups. Produces lists of user groups and groups members like

<get-user-groups>magda : existsol girls magda</get-user-groups>
<get-user-groups>lars : boys existsol lars</get-user-groups>
<get-user-groups>joern : boys existsol joern</get-user-groups>

<get-group-members>magda : magda</get-group-members>
<get-group-members>lars : lars</get-group-members>
<get-group-members>joern : joern</get-group-members>
<get-group-members>boys : lars joern</get-group-members>
<get-group-members>girls : magda</get-group-members>
<get-group-members>existsol : magda lars joern</get-group-members>

@tuurma
Copy link
Author

tuurma commented Apr 12, 2019

xmldb:change-user($user, $password, $groups)

equivalent:

for $group in sm:get-user-groups($user) return sm:remove-group-member($group, $user),
for $group in $groups return sm:add-group-member($group, $user),
sm:passwd($user, $password)

@line-o
Copy link

line-o commented Apr 12, 2019

sm:passwd will then only work for the currently logged in user, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment