Skip to content

Commit

Permalink
Merge pull request #53 from joewiz/separate-data-from-app
Browse files Browse the repository at this point in the history
version 2.0
  • Loading branch information
line-o authored Feb 25, 2021
2 parents 54198c6 + 118f19e commit 4b2ffa5
Show file tree
Hide file tree
Showing 56 changed files with 1,786 additions and 994 deletions.
82 changes: 64 additions & 18 deletions admin.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<div xmlns="http://www.w3.org/1999/xhtml" class="templates:surround?with=templates/page.html&amp;at=container-body">
<div xmlns="http://www.w3.org/1999/xhtml" data-template="templates:surround" data-template-with="templates/page.html" data-template-at="container-body">
<div class="row">
<div class="col-md-12">
<h1>Package Upload</h1>
<p>Upload xar packages to the public repository. New packages will not appear in the list of
available packages immediately. Instead you will have to trigger an update afterwards, using
the "publish" button below. This way you can upload multiple packages before publishing them.</p>
<h1>Admin</h1>
<p>View administrative information about packages and upload new ones.</p>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="col-md-8">
<div>
<h2>Statistics</h2>
<h3>Top 5 packages</h3>
<ol data-template="app:load-get-package-logs-for-admin-table" data-template-top-n="5">
<li data-template="templates:each" data-template-from="package-logs" data-template-to="package-log">
<span data-template="app:get-package-stats"/>
</li>
</ol>
</div>
<div data-template="app:load-package-groups">
<h2>All package groups</h2>
<div data-template="templates:each" data-template-from="package-groups" data-template-to="package-group">
<h3><span data-template="app:package-group-abbrev"/></h3>
<dl>
<dt>Abbrev</dt>
<dd><span data-template="app:package-group-abbrev"/></dd>
<dt>Name</dt>
<dd><span data-template="app:package-group-name"/></dd>
<dt>Title</dt>
<dd><span data-template="app:package-group-title"/></dd>
</dl>
<table data-template="app:load-packages" class="table table-bordered">
<thead>
<tr>
<th>Version</th>
<th>eXist Requirement</th>
<th>Date Published</th>
</tr>
</thead>
<tbody>
<tr data-template="templates:each" data-template-from="packages" data-template-to="package">
<td><span data-template="app:package-version"/></td>
<td><span data-template="app:package-requires"/></td>
<td><span data-template="app:package-date-published"/></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="col-md-4">
<p>
<a href="index.html" class="btn btn-primary">
<i class="glyphicon glyphicon-share"/> Return to list
</a>
</p>
<p>
<a href="?rebuild-package-groups-metadata=true" class="btn btn-default">
<i class="glyphicon glyphicon-repeat"/> Rebuild package-groups metadata
</a>
</p>
<a href="index.html?logout=true" class="btn btn-default">
<i class="glyphicon glyphicon-log-out"/> Log out</a>
<h2>Upload Packages</h2>
<p>Upload xar packages to the public repository. New packages will appear in the list of
available packages immediately upon upload.</p>
<p data-template="app:rebuild-package-groups-metadata"/>

<span class="btn btn-success fileinput-button">
<i class="glyphicon glyphicon-plus"/>
<span>Select files...</span>
Expand All @@ -28,16 +84,6 @@ <h1>Package Upload</h1>
<tbody id="files"/>
</table>
</div>
<div class="col-md-6">
<p>
<a href="index.html" class="btn btn-primary">
<i class="glyphicon glyphicon-share"/> Return to list
</a>
</p>
<p>Publishing will take a while to process apps.</p>
<a href="index.html?logout=true" class="btn btn-default">
<i class="glyphicon glyphicon-log-out"/> Log out</a>
</div>
</div>
<script type="text/javascript" src="resources/scripts/jquery.ui.widget.js"/>
<script type="text/javascript" src="resources/scripts/jquery.iframe-transport.js"/>
Expand All @@ -46,7 +92,7 @@ <h1>Package Upload</h1>
$(function () {
'use strict';
$('#fileupload').fileupload({
url: "modules/upload.xql",
url: "put-package",
dataType: 'json',
done: function (e, data) {
$.each(data.result.files, function (index, file) {
Expand All @@ -68,4 +114,4 @@ <h1>Package Upload</h1>
.parent().addClass($.support.fileInput ? undefined : 'disabled');
});
</script>
</div>
</div>
2 changes: 1 addition & 1 deletion build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
#

project.name=public-repo
project.version=1.1.0
project.version=2.0.0
6 changes: 0 additions & 6 deletions collection.xconf

This file was deleted.

72 changes: 34 additions & 38 deletions controller.xql
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
xquery version "3.1";

import module namespace config="http://exist-db.org/xquery/apps/config" at "modules/config.xqm";
import module namespace login="http://exist-db.org/xquery/login" at "resource:org/exist/xquery/modules/persistentlogin/login.xql";

declare namespace sm="http://exist-db.org/xquery/securitymanager";

declare variable $exist:path external;
declare variable $exist:resource external;
declare variable $exist:controller external;
declare variable $exist:prefix external;
declare variable $exist:root external;

declare variable $app-root-absolute-url :=
(request:get-header("X-Forwarded-Proto"), request:get-scheme())[1]
|| "://"
|| (request:get-header("X-Forwarded-Server"), request:get-server-name())[1]
|| request:get-context-path()
request:get-context-path()
|| $exist:prefix
|| $exist:controller
;
Expand All @@ -30,33 +30,21 @@ else if ($exist:path eq "/") then
<redirect url="index.html"/>
</dispatch>

else if ($exist:path eq "/public/apps.xml") then (
response:set-header('Content-Type', 'application/xml'),
else if ($exist:path eq "/public/apps.xml") then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/modules/list.xql"/>
<forward url="{$exist:controller}/modules/list.xq"/>
</dispatch>
)
else if ($exist:resource eq "update.xql") then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/modules/update.xql"/>
<view>
<forward url="{$exist:controller}/index.html"/>
<forward url="{$exist:controller}/modules/view.xql">
<set-header name="Cache-Control" value="no-cache"/>
</forward>
</view>
</dispatch>


(: Protected resource: user is required to log in with valid credentials.
If the login fails or no credentials were provided, the request is redirected
to the login.html page. :)
else if ($exist:path eq "/admin.html") then
let $user := request:get-attribute("org.exist.public-repo.login.user")
return
if ($user and (sm:is-dba($user) or "repo" = sm:get-user-groups($user))) then
if (exists($user) and sm:get-user-groups($user) = config:repo-permissions()?group) then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<view>
<forward url="{$exist:controller}/modules/view.xql">
<forward url="{$exist:controller}/modules/view.xq">
<set-header name="Cache-Control" value="no-cache"/>
</forward>
</view>
Expand All @@ -65,47 +53,62 @@ else if ($exist:path eq "/admin.html") then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="login.html"/>
<view>
<forward url="{$exist:controller}/modules/view.xql">
<forward url="{$exist:controller}/modules/view.xq">
<set-header name="Cache-Control" value="no-cache"/>
</forward>
</view>
</dispatch>

(: Protected resource :)
else if ($exist:path eq "/put-package") then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/modules/put-package.xq"/>
</dispatch>

else if (ends-with($exist:resource, ".html") and starts-with($exist:path, "/packages")) then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{concat($exist:controller, '/packages.html')}"/>
<view>
<forward url="{concat($exist:controller, '/modules/view.xql')}">
<forward url="{concat($exist:controller, '/modules/view.xq')}">
<add-parameter name="abbrev" value="{substring-before($exist:resource, '.html')}"/>
</forward>
</view>
</dispatch>

else if (ends-with($exist:resource, ".html")) then
(: the html page is run through view.xql to expand templates :)
(: the html page is run through view.xq to expand templates :)
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<view>
<forward url="modules/view.xql">
<forward url="modules/view.xq">
<set-header name="Cache-Control" value="no-cache"/>
</forward>
</view>
</dispatch>

else if (contains($exist:path, "/public/") and ends-with($exist:resource, ".zip")) then
else if (contains($exist:path, "/public/") and ends-with($exist:resource, ".xar") or ends-with($exist:resource, ".zip")) then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/modules/get-package.xq">
<add-parameter name="filename" value="{$exist:resource}"/>
</forward>
</dispatch>

else if (contains($exist:path, "/public/") and (ends-with($exist:resource, ".png") or ends-with($exist:resource, ".svg"))) then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="../modules/download-xar-zip.xq"/>
<forward url="{$exist:controller}/modules/get-icon.xq">
<add-parameter name="filename" value="{$exist:resource}"/>
</forward>
</dispatch>

else if ($exist:path eq "/find" or ends-with($exist:resource, ".zip")) then
else if ($exist:path eq "/find") then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="modules/find.xql">
<forward url="modules/find.xq">
<add-parameter name="app-root-absolute-url" value="{$app-root-absolute-url}"/>
</forward>
</dispatch>

else if ($exist:resource eq "feed.xml") then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="modules/feed.xql"/>
<forward url="modules/feed.xq"/>
</dispatch>

else if (contains($exist:path, "/$shared/")) then
Expand All @@ -117,16 +120,9 @@ else if (contains($exist:path, "/$shared/")) then

else if (contains($exist:path, "/resources/")) then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/resources/{substring-after($exist:path, '/resources/')}">
<set-header name="Cache-Control" value="max-age=3600, must-revalidate"/>
</forward>
<set-header name="Cache-Control" value="max-age=3600, must-revalidate"/>
</dispatch>

else if (ends-with($exist:path, ".xml")) then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<set-header name="Cache-Control" value="no-cache"/>
</dispatch>

else
(: everything else is passed through :)
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
Expand Down
4 changes: 2 additions & 2 deletions expath-pkg.xml.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://expath.org/ns/pkg" name="http://exist-db.org/apps/public-repo" abbrev="@project.name@" version="@project.version@" spec="1.0">
<title>eXist-db Public Application Repository</title>
<dependency processor="http://exist-db.org" semver-min="4.7.0"/>
<dependency package="http://expath.org/ns/crypto" semver-min="0.7"/>
<dependency processor="http://exist-db.org" semver-min="5.0.0"/>
<dependency package="http://exist-db.org/xquery/semver-xq" semver-min="2.2.1"/>
<dependency package="http://exist-db.org/apps/shared" semver-min="0.9.1"/>
</package>
8 changes: 4 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<div class="templates:surround?with=templates/page.html&amp;at=container-body">
<div data-template="templates:surround" data-template-with="templates/page.html" data-template-at="container-body">
<div class="row">
<div class="col-md-12">
<h1>Public Application Repository</h1>
Expand All @@ -10,7 +10,7 @@ <h1>Public Application Repository</h1>
Package Manager app.</li>
<li>Install the package directly from the Dashboard's Package Manager app. (By default the
Package Manager is configured to access the eXist-db public application repository feed,
at <a href="http://demo.exist-db.org/exist/apps/public-repo/public/apps.xml">http://demo.exist-db.org/exist/apps/public-repo/public/apps.xml</a>. To check or
at <a href="https://exist-db.org/exist/apps/public-repo/public/apps.xml">https://exist-db.org/exist/apps/public-repo/public/apps.xml</a>. To check or
edit the repository URL your Package Manager is using, go to your Dashboard, click on
the gear icon beneath the eXist-db icon, and you will see a field, "Public Repository
URL.")</li>
Expand All @@ -24,7 +24,7 @@ <h1>Public Application Repository</h1>
<div id="listWrapper" class="col-md-8">
<h2>Packages</h2>
<ul class="packages">
<li class="app:list-packages"/>
<li data-template="app:list-packages"/>
</ul>
</div>
<div class="col-md-4">
Expand All @@ -36,4 +36,4 @@ <h2>Admin</h2>
<p>(requires login)</p>
</div>
</div>
</div>
</div>
10 changes: 5 additions & 5 deletions login.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<div xmlns="http://www.w3.org/1999/xhtml" class="templates:surround?with=templates/page.html&amp;at=content">
<div xmlns="http://www.w3.org/1999/xhtml" data-template="templates:surround" data-template-with="templates/page.html" data-template-at="container-body">
<h1 class="rounded">Administrator Login</h1>
<div class="alert alert-success">
Please login. The user has to be a member of the "repo" or "dba" group.
Please login. The user has to be a member of the "repo" group.
</div>
<form method="POST" class="form form-horizontal">
<div class="form-group">
<label class="control-label col-md-1" for="user">User:</label>
<div class="col-md-3">
<input type="text" name="user" required="required" class="form-control" autofocus="autofocus"/>
<input type="text" name="user" required="required" autofocus="autofocus"/>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-1" for="password">Password:</label>
<div class="col-md-3">
<input type="password" name="password" class="form-control"/>
<input type="password" name="password"/>
</div>
</div>
<div class="form-group">
Expand All @@ -23,4 +23,4 @@ <h1 class="rounded">Administrator Login</h1>
</div>
</div>
</form>
</div>
</div>
1 change: 0 additions & 1 deletion meta/apps.xml

This file was deleted.

1 change: 0 additions & 1 deletion meta/packages.xml

This file was deleted.

Loading

0 comments on commit 4b2ffa5

Please sign in to comment.