diff --git a/.gitignore b/.gitignore index 1dd9d21664697f9214e6ce750511e887460502a0..3bc58fcba846eeac7e751425d6e6ef9c4dacefd7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ build/ test/ local.build.properties +expath-pkg.xml diff --git a/docs/forking.md b/docs/forking.md index 3fa3569c632c797cfbcfe0499c18713098778e71..92efd7059971c44a14e46d3aa79fe0a3f60354f4 100644 --- a/docs/forking.md +++ b/docs/forking.md @@ -14,16 +14,9 @@ in the first panel (1). ![Forking step 1](http://localhost:8080/exist/apps/sade/templates/img/publisher-1.png] Click on "create" (2) and wait until you get redirected to your own instance. -[Enter a new secure password!] -To continue you have to enter new credentials to the SADE Plugin configuration: - -* URL: append -ProjectName to "/sade -* User: ProjectName -* Password: - -The username will be the same as the project name and you have to enter the -formerly typed password here as well. +The resulting view should present new credentials at the top. Again you have to +set these credentials in the [preferences in TextGridLab](publish.md#configuration). # Download & Tracking changes You can download any application by clicking on the download button at the SADE diff --git a/modules/app.xqm b/modules/app.xqm index 5a3a7d17472097f2fd5644b103b1d829fca7c7c3..394395f109e696d8cc146a0d6a7415def721e322 100644 --- a/modules/app.xqm +++ b/modules/app.xqm @@ -28,6 +28,15 @@ declare function app:title($node as node(), $model as map(*)) { config:get("project-title") }; +(:~ + : Get the target of this app by using the repo.xml. + : @param $node the HTML node with the attribute which triggered this call + : @param $model a map containing arbitrary data - used to pass information between template calls + :) +declare function app:target($node as node(), $model as map(*)) { + config:repoget("target") +}; + (:~ : Provides dynamic CSS based on the requested resource name :) declare function app:css-injection($node as node(), $model as map(*), $exist-resource) { @@ -380,3 +389,15 @@ element { node-name($node) } { $model("function")/xqdoc:comment/xqdoc:return/text() } }; + +declare function app:fork-successfull($node as node(), $model as map(*), $newpw as xs:string?) { +if(not($newpw)) then () else +
+ Sucessfully created a new package. You may now set the following parameters in the TextGrid Laboratory: + +
+}; diff --git a/modules/config.xqm b/modules/config.xqm index ab1c62394dedef689f8d0bf1c7fee5c48171e3ec..eeb92d3b7a6eb3c74627d67783790eacd0c73a98 100644 --- a/modules/config.xqm +++ b/modules/config.xqm @@ -60,3 +60,11 @@ declare function config:get($key as xs:string, $module-key as xs:string?) { declare function config:key-available($key as xs:string) as xs:boolean { $config:file/cf:config//*/string(@key) = $key }; + +(:~ + : A function to query the app repo config. + : @param $key – the name of the element to query for + : :) +declare function config:repoget($key as xs:string){ + $config:repo-descriptor//*[local-name() = $key] ! string(.) +}; diff --git a/modules/fork.xq b/modules/fork.xq index b95c10b74cdd8e35577d10f49ec92de6cb071f7e..a2f3935dc8b5d45da0e04dda67836d70acc8540d 100644 --- a/modules/fork.xq +++ b/modules/fork.xq @@ -6,7 +6,7 @@ xquery version "3.1"; : but in the new application. : : @author Mathias Göbel - : @version 0.1 + : @version 0.2 : :) import module namespace dbutil="http://exist-db.org/xquery/dbutil"; @@ -16,7 +16,32 @@ declare namespace cf="https://sade.textgrid.de/ns/configfile"; declare namespace expath="http://expath.org/ns/pkg"; declare namespace repo="http://exist-db.org/xquery/repo"; +(:~ + : Generate a password in the given length. + : + : @param $length the length of the resulting password + : @author Mathias Göbel + : @since 0.2 + : :) +declare function local:passwordGenerator($length as xs:integer) { + if($length lt 10) + then error( QName("https://sade.textgrid.de/ns/error", "FORK04"), "Short password. use at least 10 chars") + else + (: charmap must not contain characters that do not evaluate against xs:anyURI + or a regular expression REPLACEMENT. :) + let $charset := string-to-codepoints('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz') => codepoints-to-string() + let $charsetLength := string-length($charset) + let $password := + for $i in 1 to $length + let $num := util:random($charsetLength) + return + substring($charset, $num, 1) + return + string-join($password) +}; + declare variable $target := request:get-parameter("target", "koma"); +declare variable $password := local:passwordGenerator(15); declare variable $referer := request:get-header("Referer"); declare variable $dry-run := request:get-parameter("dry", "false"); @@ -40,7 +65,7 @@ declare variable $repoConf := true application sade-{ $target } - + pre-install.xq post-install.xq { current-dateTime() } @@ -119,6 +144,8 @@ return return if( $complete/@result = "ok" ) then - let $uri := replace($referer, "apps/.+/publish\.html", "apps/"||replace($name, "SADE", "sade")||"/publish.html") - return response:redirect-to(xs:anyURI($uri)) + let $replacement := "apps/" || replace($name, "SADE", "sade") || "/publish.html?newpw=" || $password + let $uri := replace(tokenize($referer, "\?")[1], "apps/.+/publish\.html", $replacement) + return + response:redirect-to(xs:anyURI($uri)) else $complete diff --git a/post-install.xq b/post-install.xq index b686804653df6fc3e92937ffeea5eedf743a2c5f..02695cf5f726fdc10ee1834c615fdd415d190303 100644 --- a/post-install.xq +++ b/post-install.xq @@ -79,8 +79,6 @@ as xs:string { local:format-test-rate-output($coverage) }; - - let $project-name := tokenize($target, "/")[last()] let $log := util:log-system-out("installing " || $project-name) @@ -94,8 +92,8 @@ let $data-xconf := $target || "/textgrid/data/collection.xconf" (: prepare empty Lucene Config files :) let $prepare-config := ( - util:eval("file:serialize-binary( xs:base64Binary(util:base64-encode(""# empty config file ä,ae ö,oe ü,ue"")), $system-path || $project-name || '-charmap.txt')"), - util:eval("file:serialize-binary( xs:base64Binary(util:base64-encode(""# empty config file Backfisch, Tochter, Mädchen"")), $system-path || $project-name || '-synonyms.txt')") + util:eval("file:serialize-binary( xs:base64Binary(util:base64-encode(""# default config file ä,ae ö,oe ü,ue"")), $system-path || $project-name || '-charmap.txt')"), + util:eval("file:serialize-binary( xs:base64Binary(util:base64-encode(""# default config file Backfisch, Tochter, Mädchen"")), $system-path || $project-name || '-synonyms.txt')") ) let $print-message := if($project-name != "sade") then true() else @@ -115,12 +113,14 @@ let $rewrite-synonyms := update value //xconf:lucene/xconf:analyzer/xconf:param[@name="synonyms"] /@value with $system-path || $project-name || "-synonyms.txt" -let $store-xconf := xmldb:store("/db/system/config"||$target||"/textgrid/data", "collection.xconf", doc( $data-xconf )) -let $reindex := xmldb:reindex($target||"/textgrid/data") +let $store-xconf := xmldb:store("/db/system/config" || $target || "/textgrid/data", "collection.xconf", doc( $data-xconf )) +let $reindex := xmldb:reindex($target || "/textgrid/data") + (: we have to test for writable path :) -let $path := $system-path +let $path := $system-path let $user := util:system-property("user.name") -let $message1 := $path || " is not available. Create it and make sure "||$user||" can write there." +let $message1 := $path || " is not available. Create it and make sure " + || $user || " can write there." let $message2 := "Could not write to " || $path || "." return ( if diff --git a/templates/publish.html b/templates/publish.html index cd6981c78c721910d39a3bb68c6563b18cf98d1a..7b618bfd9df74d733d557d9cff148601ecc270c9 100644 --- a/templates/publish.html +++ b/templates/publish.html @@ -1,4 +1,5 @@
+
diff --git a/test.xqm b/test.xqm index fbf9a21bcb6cbd4ac476ca9bdf1f76d0e8db6882..e61b410743121d1f32ba2480a191eee67628ce95 100644 --- a/test.xqm +++ b/test.xqm @@ -108,9 +108,9 @@ function tests:multiviewer-idResolver($id) { }; declare - %test:arg("id", "/data/10qd4.xml") %test:assertEquals("/db/apps/sade/textgrid/data/10qd4.xml") - %test:arg("id", "/docs/about.md") %test:assertEquals("/db/apps/sade/docs/about.md") - %test:arg("id", "docs/about.md") %test:assertEquals("/db/apps/sade/docs/about.md") + %test:arg("id", "/data/10qd4.xml") %test:assertXPath(" matches( $result, '^/db/apps/sade-?[a-zA-Z0-9\-\.]*/textgrid/data/10qd4.xml')") + %test:arg("id", "/docs/about.md") %test:assertXPath(" matches( $result, '^/db/apps/sade-?[a-zA-Z0-9\-\.]*/docs/about.md')") + %test:arg("id", "docs/about.md") %test:assertXPath(" matches( $result, '^/db/apps/sade-?[a-zA-Z0-9\-\.]*/docs/about.md')") function tests:multiviewer-getPath($id) { util:eval("multiviewer:getPath($id)") }; @@ -127,14 +127,6 @@ function tests:multiviewer-markdown($docpath) { util:eval( "multiviewer:markdown($docpath)" ) }; -declare - %test:arg("id", "textgrid:10qd4") %test:assertXPath('$result/@class = "teixslt"') - %test:arg("id", "textgrid:10qd4") %test:assertXPath('$result//*:h1[@class="maintitle"]/text() = "480. Der Lieper Haidebaum bei Hohenrode"') - %test:arg("id", "docs/about.md") %test:assertXPath('$result/@class = "markdown"') -function tests:multiviewer-show($id) { - util:eval("multiviewer:show($tests:node, $tests:model, $id, ())") -}; - (: ************** :) (: * NAVIGATION * :) (: ************** :)