Skip to content

Commit

Permalink
Fix all calls to deprecated functions so the app works with eXist 5.0…
Browse files Browse the repository at this point in the history
…/develop
  • Loading branch information
wolfgangmm committed Apr 10, 2019
1 parent 2e24c2e commit d178001
Show file tree
Hide file tree
Showing 11 changed files with 503 additions and 515 deletions.
12 changes: 6 additions & 6 deletions controller.xql
Expand Up @@ -43,7 +43,7 @@ declare function local:fallback-login($domain as xs:string, $maxAge as xs:dayTim
if ($user) then
let $isLoggedIn := xmldb:login("/db", $user, $password, true())
return
if ($isLoggedIn and (not($asDba) or xmldb:is-admin-user($user))) then (
if ($isLoggedIn and (not($asDba) or sm:is-dba($user))) then (
session:set-attribute("eXide.user", $user),
session:set-attribute("eXide.password", $password),
request:set-attribute($domain || ".user", $user),
Expand Down Expand Up @@ -75,7 +75,7 @@ declare function local:query-execution-allowed() {
local:user-allowed()
)
or
xmldb:is-admin-user((request:get-attribute("org.exist.login.user"),request:get-attribute("xquery.user"), 'nobody')[1])
sm:is-dba((request:get-attribute("org.exist.login.user"),request:get-attribute("xquery.user"), 'nobody')[1])
};

if ($exist:path eq '') then
Expand Down Expand Up @@ -104,9 +104,9 @@ else if ($exist:resource = 'login') then
if (local:user-allowed()) then
<status>
<user>{request:get-attribute("org.exist.login.user")}</user>
<isAdmin json:literal="true">{ xmldb:is-admin-user((request:get-attribute("org.exist.login.user"),request:get-attribute("xquery.user"), 'nobody')[1]) }</isAdmin>
<isAdmin json:literal="true">{ sm:is-dba((request:get-attribute("org.exist.login.user"),request:get-attribute("xquery.user"), 'guest')[1]) }</isAdmin>
</status>
else
else
(
response:set-status-code(401),
<status>fail</status>
Expand Down Expand Up @@ -137,15 +137,15 @@ else if (starts-with($exist:path, "/check/")) then
</dispatch>

else if ($exist:resource = "index.html") then
if (local:user-allowed()) then
if (local:user-allowed()) then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<view>
<forward url="modules/view.xql">
<set-header name="Cache-Control" value="max-age=3600"/>
</forward>
</view>
</dispatch>
else
else
(
response:set-status-code(401),
<status>fail</status>
Expand Down
4 changes: 2 additions & 2 deletions modules/apply-config.xql
Expand Up @@ -24,7 +24,7 @@ let $collection := request:get-parameter("collection", ())
let $xconf := request:get-parameter("config", ())
let $target := "/db/system/config" || $collection
return
if (xmldb:is-admin-user(xmldb:get-current-user())) then
if (sm:is-dba(sm:id()//sm:real/sm:username/string())) then
try {
(
<response json:literal="true">true</response>,
Expand All @@ -51,4 +51,4 @@ return
else
<response>
<error>You need to have dba rights</error>
</response>
</response>
69 changes: 31 additions & 38 deletions modules/collections.xql
@@ -1,6 +1,6 @@
(:
: eXide - web-based XQuery IDE
:
:
: Copyright (C) 2011 Wolfgang Meier
:
: This program is free software: you can redistribute it and/or modify
Expand All @@ -26,7 +26,7 @@ declare option exist:serialize "method=json media-type=text/javascript";

declare function local:sub-collections($root as xs:string, $children as xs:string*, $user as xs:string) {
for $child in $children
let $processChild :=
let $processChild :=
local:collections(concat($root, '/', $child), $child, $user)
where exists($processChild)
order by $child ascending
Expand All @@ -36,11 +36,11 @@ declare function local:sub-collections($root as xs:string, $children as xs:strin
</children>
};

declare function local:collections($root as xs:string, $child as xs:string,
declare function local:collections($root as xs:string, $child as xs:string,
$user as xs:string) {
if (sm:has-access(xs:anyURI($root), "x")) then
let $children := xmldb:get-child-collections($root)
let $canWrite :=
let $canWrite :=
(: local:canWrite($root, $user) :)
sm:has-access(xs:anyURI($root), "w")
return
Expand All @@ -55,13 +55,13 @@ declare function local:collections($root as xs:string, $child as xs:string,
else
()
) else
()
()
else
()
};

declare function local:list-collection-contents($collection as xs:string, $user as xs:string) {
let $subcollections :=
let $subcollections :=
for $child in xmldb:get-child-collections($collection)
let $collpath := concat($collection, "/", $child)
where sm:has-access(xs:anyURI($collpath), "r") and config:access-allowed($collpath, $user)
Expand Down Expand Up @@ -109,7 +109,7 @@ declare function local:resources($collection as xs:string, $user as xs:string) {
{
for $resource in $subset
let $isCollection := starts-with($resource, "/")
let $path :=
let $path :=
if ($isCollection) then
concat($collection, $resource)
else
Expand All @@ -118,17 +118,9 @@ declare function local:resources($collection as xs:string, $user as xs:string) {
order by $resource ascending
return
let $permissions := sm:get-permissions(xs:anyURI($path))/sm:permission
let $owner :=
if ($isCollection) then
xmldb:get-owner($path)
else
xmldb:get-owner($collection, $resource)
let $group :=
if ($isCollection) then
xmldb:get-group($path)
else
xmldb:get-group($collection, $resource)
let $lastMod :=
let $owner := $permissions/@owner/string()
let $group := $permissions/@group/string()
let $lastMod :=
let $date :=
if ($isCollection) then
xmldb:created($path)
Expand Down Expand Up @@ -183,7 +175,7 @@ declare function local:delete-collection($collName as xs:string, $user as xs:str

declare function local:delete-resource($collection as xs:string, $resource as xs:string, $user as xs:string) {
let $resource-name := substring-after($resource, $collection || "/")
let $canWrite :=
let $canWrite :=
sm:has-access(xs:anyURI($resource), "w")
and
sm:has-access(xs:anyURI($collection), "w")
Expand Down Expand Up @@ -221,30 +213,30 @@ declare function local:delete($collection as xs:string, $selections as xs:string
<response status="ok"/>
};

declare function local:copyOrMove($operation as xs:string, $target as xs:string, $sources as xs:string+,
declare function local:copyOrMove($operation as xs:string, $target as xs:string, $sources as xs:string+,
$user as xs:string) {
if (sm:has-access(xs:anyURI($target), "w")) then
for $source in $sources
let $isCollection := xmldb:collection-available($source)
return
try {
if ($isCollection) then
let $null :=
let $null :=
switch ($operation)
case "move" return
xmldb:move($source, $target)
default return
xmldb:copy($source, $target)
xmldb:copy-collection($source, $target)
return
<response status="ok"/>
else
let $split := analyze-string($source, "^(.*)/([^/]+)$")//fn:group/string()
let $null :=
let $null :=
switch ($operation)
case "move" return
xmldb:move($split[1], $target, $split[2])
default return
xmldb:copy($split[1], $target, $split[2])
xmldb:copy-resource($split[1], $split[2], $target, $split[2])
return
<response status="ok"/>
} catch * {
Expand All @@ -264,7 +256,7 @@ declare function local:rename($collection as xs:string, $source as xs:string) {
return
try {
if ($isCollection) then
let $null :=
let $null :=
xmldb:rename($collection || "/" || $source, $target)
return
<response status="ok"/>
Expand All @@ -280,7 +272,7 @@ declare function local:rename($collection as xs:string, $source as xs:string) {
};

declare %private function local:merge-properties($maps as map(*)+) {
map:new(
map:merge(
for $key in map:keys($maps[1])
let $values := distinct-values(for $map in $maps return $map($key))
return
Expand All @@ -290,24 +282,25 @@ declare %private function local:merge-properties($maps as map(*)+) {

declare %private function local:get-property-map($resource as xs:string) as map(*) {
let $isCollection := xmldb:collection-available($resource)
let $permissions := sm:get-permissions(xs:anyURI($resource))/sm:permission
return
if ($isCollection) then
map {
"owner" : xmldb:get-owner($resource),
"group" : xmldb:get-group($resource),
"owner" : $permissions/@owner/string(),
"group" : $permissions/@group/string(),
"last-modified" : format-dateTime(xmldb:created($resource), "[MNn] [D00] [Y0000] [H00]:[m00]:[s00]"),
"permissions" : sm:get-permissions(xs:anyURI($resource))/sm:permission/string(@mode),
"permissions" : $permissions/string(@mode),
"mime" : xmldb:get-mime-type(xs:anyURI($resource))
}
else
let $components := analyze-string($resource, "^(.*)/([^/]+)$")//fn:group/string()
return
map {
"owner" : xmldb:get-owner($components[1], $components[2]),
"group" : xmldb:get-group($components[1], $components[2]),
"last-modified" :
"owner" : $permissions/@owner/string(),
"group" : $permissions/@group/string(),
"last-modified" :
format-dateTime(xmldb:last-modified($components[1], $components[2]), "[MNn] [D00] [Y0000] [H00]:[m00]:[s00]"),
"permissions" : sm:get-permissions(xs:anyURI($resource))/sm:permission/string(@mode),
"permissions" : $permissions/string(@mode),
"mime" : xmldb:get-mime-type(xs:anyURI($resource))
}
};
Expand Down Expand Up @@ -392,7 +385,7 @@ declare %private function local:get-permissions($perms as xs:string) {

declare %private function local:get-users() {
distinct-values(
for $group in sm:get-groups()
for $group in sm:list-groups()
return
try {
sm:get-group-members($group)
Expand Down Expand Up @@ -441,7 +434,7 @@ declare function local:edit-properties($resources as xs:string*) {
<label for="group">Group:</label>
<select name="group">
{
for $group in sm:get-groups()
for $group in sm:list-groups()
order by $group
return
<option value="{$group}">
Expand All @@ -465,14 +458,14 @@ declare function local:edit-properties($resources as xs:string*) {
};

declare %private function local:permissions-from-form() {
let $rwx :=

let $rwx :=
for $type in ("u", "g", "o")
for $perm in ("r", "w", "x")
let $param := request:get-parameter($type || $perm, ())
return
concat(
$type,
$type,
if($param)then "+" else "-",
$perm
)
Expand Down
24 changes: 12 additions & 12 deletions modules/deployment.xql
Expand Up @@ -171,27 +171,27 @@ declare function deploy:create-collection($collection as xs:string, $userData as
};

declare function deploy:check-group($group as xs:string) {
if (xmldb:group-exists($group)) then
if (sm:group-exists($group)) then
()
else
xmldb:create-group($group)
sm:create-group($group)
};

declare function deploy:check-user($repoConf as element()) as xs:string+ {
let $perms := $repoConf/repo:permissions
let $user := if ($perms/@user) then $perms/@user/string() else xmldb:get-current-user()
let $group := if ($perms/@group) then $perms/@group/string() else xmldb:get-user-groups($user)[1]
let $user := if ($perms/@user) then $perms/@user/string() else sm:id()//sm:real/sm:username/string()
let $group := if ($perms/@group) then $perms/@group/string() else sm:get-user-groups($user)[1]
let $create :=
if (xmldb:exists-user($user)) then
if (index-of(xmldb:get-user-groups($user), $group)) then
if (sm:user-exists($user)) then
if (index-of(sm:get-user-groups($user), $group)) then
()
else (
deploy:check-group($group),
xmldb:add-user-to-group($user, $group)
sm:add-group-member($user, $group)
)
else (
deploy:check-group($group),
xmldb:create-user($user, $perms/@password, $group, ())
sm:create-account($user, $perms/@password, $group, ())
)
return
($user, $group)
Expand All @@ -202,7 +202,7 @@ declare function deploy:target-permissions($repoConf as element()) as xs:string
return
if ($permissions) then
if ($permissions castable as xs:int) then
xmldb:permissions-to-string(util:base-to-integer(xs:int($permissions), 8))
sm:octal-to-mode($permissions)
else
$permissions
else
Expand All @@ -220,7 +220,7 @@ declare function deploy:copy-templates($target as xs:string, $source as xs:strin
for $resource in xmldb:get-child-resources($source)
let $targetPath := xs:anyURI(concat($target, "/", $resource))
return (
xmldb:copy($source, $target, $resource),
xmldb:copy-resource($source, $resource, $target, $resource),
let $mime := xmldb:get-mime-type($targetPath)
let $perms :=
if ($mime eq "application/xquery") then
Expand Down Expand Up @@ -620,7 +620,7 @@ let $collection :=
return
if ($root) then $root else $collectionParam
else
$target
repo:get-root() || "/" || $target
let $info := request:get-parameter("info", ())
let $deploy := request:get-parameter("deploy", ())
let $download := request:get-parameter("download", ())
Expand All @@ -635,7 +635,7 @@ return
else if ($info) then
apputil:get-info($info)
else if ($abbrev) then
deploy:create-app($collection, $expathConf)
deploy:create-app($target, $expathConf)
else
deploy:view($collection, $expathConf, $repoConf)
} catch exerr:EXXQDY0003 {
Expand Down

0 comments on commit d178001

Please sign in to comment.