dba/users
library moduleUR
Summary
Edit user.
- Tags
Author: Christian Grün, BaseX Team 2005-21, BSD License
__source : users/user-edit.xqm
Imports
This module is imported by 0 modules. It imports 1 modules.
Variables
Functions
4.1 dba:user-edit
Arities: dba:user-edit#5UR
dba:user-edit
(
$name
as
xs:string
, $newname
as
xs:string
, $pw
as
xs:string
, $perm
as
xs:string
, $info
as
xs:string
)
as
empty-sequence()
- name
as
xs:string
user name - newname
as
xs:string
new name - pw
as
xs:string
password - perm
as
xs:string
permission - info
as
xs:string
empty-sequence()
redirection
Invokes 14 functions from 4 modules
- util:redirect#2
- {http://basex.org/modules/user}alter#2
- {http://basex.org/modules/user}exists#1
- {http://basex.org/modules/user}grant#2
- {http://basex.org/modules/user}info#1
- {http://basex.org/modules/user}list-details#1
- {http://basex.org/modules/user}password#2
- {http://basex.org/modules/user}update-info#2
- {http://www.w3.org/2001/XMLSchema}QName#1
- {http://www.w3.org/2005/xpath-functions}deep-equal#2
- {http://www.w3.org/2005/xpath-functions}error#1
- {http://www.w3.org/2005/xpath-functions}error#2
- {http://www.w3.org/2005/xpath-functions}not#1
- {http://www.w3.org/2005/xpath-functions}parse-xml#1
Invoked by 0 functions from 0 modules
Annotations
%updating | () |
%rest:POST | () |
%rest:path | ('/dba/user-edit') |
%rest:form-param | ('name','{$name}') |
%rest:form-param | ('newname','{$newname}') |
%rest:form-param | ('pw','{$pw}') |
%rest:form-param | ('perm','{$perm}') |
%rest:form-param | ('info','{$info}') |
Source ( 40 lines)
function dba:user-edit(
$name as xs:string,
$newname as xs:string,
$pw as xs:string,
$perm as xs:string,
$info as xs:string
) as empty-sequence() {
try {
let $old := user:list-details($name)
return (
(: change name of user :)
if($name = $newname) then () else (
if(user:exists($newname)) then (
error((), 'User already exists.')
) else (
user:alter($name, $newname)
)
),
(: change password :)
if($pw = '') then () else user:password($name, $pw),
(: change permissions :)
if($perm = $old/@permission) then () else user:grant($name, $perm),
(: change user info :)
let $xml := if($info) then (
parse-xml($info)/*[self::info or error(xs:QName(err:FORC0006))]
) else (
<info/>
)
where not(deep-equal(user:info($name), $xml))
return user:update-info($xml, $name)
),
util:redirect($dba:SUB, map { 'name': $newname, 'info': 'User was saved.' })
} catch * {
let $error := if ($err:code != xs:QName('err:FODC0006')) then $err:description else
'Information must be XML with an info root element.'
return util:redirect($dba:SUB, map {
'name': $name, 'newname': $newname, 'pw': $pw, 'perm': $perm, 'error': $error
})
}
}
Namespaces
The following namespaces are defined:
Prefix | Uri |
---|---|
ann | http://www.w3.org/2012/xquery |
dba | dba/users 2 3 4 5 6 7 |
rest | http://exquery.org/ns/restxq |
util | dba/util |
Source Code
(:~
: Edit user.
:
: @author Christian Grün, BaseX Team 2005-21, BSD License
:)
module namespace dba = 'dba/users';
import module namespace util = 'dba/util' at '../lib/util.xqm';
(:~ Sub category :)
declare variable $dba:SUB := 'user';
(:~
: Edits a user.
: @param $name user name
: @param $newname new name
: @param $pw password
: @param $perm permission
: @return redirection
:)
declare
%updating
%rest:POST
%rest:path('/dba/user-edit')
%rest:form-param('name', '{$name}')
%rest:form-param('newname', '{$newname}')
%rest:form-param('pw', '{$pw}')
%rest:form-param('perm', '{$perm}')
%rest:form-param('info', '{$info}')
function dba:user-edit(
$name as xs:string,
$newname as xs:string,
$pw as xs:string,
$perm as xs:string,
$info as xs:string
) as empty-sequence() {
try {
let $old := user:list-details($name)
return (
(: change name of user :)
if($name = $newname) then () else (
if(user:exists($newname)) then (
error((), 'User already exists.')
) else (
user:alter($name, $newname)
)
),
(: change password :)
if($pw = '') then () else user:password($name, $pw),
(: change permissions :)
if($perm = $old/@permission) then () else user:grant($name, $perm),
(: change user info :)
let $xml := if($info) then (
parse-xml($info)/*[self::info or error(xs:QName(err:FORC0006))]
) else (
<info/>
)
where not(deep-equal(user:info($name), $xml))
return user:update-info($xml, $name)
),
util:redirect($dba:SUB, map { 'name': $newname, 'info': 'User was saved.' })
} catch * {
let $error := if ($err:code != xs:QName('err:FODC0006')) then $err:description else
'Information must be XML with an info root element.'
return util:redirect($dba:SUB, map {
'name': $name, 'newname': $newname, 'pw': $pw, 'perm': $perm, 'error': $error
})
}
};