From 27b3784acd91dc843ca6e9d8993fa89afb91627d Mon Sep 17 00:00:00 2001
From: shinobu
Date: Sat, 20 Aug 2016 20:03:31 +0200
Subject: [PATCH] repairs the non-share version of saving queries, though it
isn't fully supported right now. This creates a db for users (with AC check)
who are allowed to creade them, the checkbox is prechecked as most user won't
have the permission to create their own dbs. Fixes Wrong Parameters and some
Typos as well.
---
extensions/queries/QueriesController.php | 34 +++++++++++++++-----
extensions/queries/resources/savepartial.js | 7 ++--
extensions/queries/templates/savequery.phtml | 2 +-
3 files changed, 30 insertions(+), 13 deletions(-)
diff --git a/extensions/queries/QueriesController.php b/extensions/queries/QueriesController.php
index ead13e3dc..410af8f19 100644
--- a/extensions/queries/QueriesController.php
+++ b/extensions/queries/QueriesController.php
@@ -404,17 +404,33 @@ public function savequeryAction()
$store = $this->_erfurt->getStore();
$storeGraph = $this->_owApp->selectedModel;
$graphUri = (string)$this->_owApp->selectedModel;
-
$res = "json or desc missing";
// checking for post data to save queries
$params = $this->_request->getParams();
- if (isset($params['json']) && isset($params['json'])) {
- if ($this->_request->getParam('share') == "true") {
+ if (isset($params['json'])) {
+ if ($this->_request->getParam('share') == 'true') {
+ //The User wants to story the Query in the DB he is querying -> check if he can edit it
+ if (!$this->_owApp->selectedModel->isEditable()) {
+ $res = "The Query cannot be shared, because the Model is not editable.";
+ $response->setBody($res);
+ return;
+ }
// store in the model itself - everybody can see it
$storeGraph = $this->_owApp->selectedModel;
} else {
- //private db - should be configured so only the user can see it
- $storeGraph = $this->getUserQueryDB();
+ //the User wants to Store the Query in his private DB -> check rights/if it already exists
+ if (!Erfurt_App::getInstance()->isActionAllowed('ModelManagement')) {
+ if ($this->findDB($this->_userDbUri) == null) {
+ $res = 'You dont have the Permission to create a DB for your Queries,'
+ . ' ask your Admin about it.';
+ $response->setBody($res);
+ return;
+ } else {
+ $storeGraph = $this->getUserQueryDB();
+ }
+ } else {
+ $storeGraph = $this->getUserQueryDB();
+ }
}
// checking whether any queries exist yet in this store
@@ -581,6 +597,8 @@ public function savequeryAction()
} else {
$res = 'Save failed. (Query with same pattern exists)';
}
+ } else {
+ $res = 'You dont have the permissions to save your Queries non-shared.';
}
$response->setBody($res);
}
@@ -693,12 +711,12 @@ private function createUserQueryDB()
$proposedDBname = $this->_userDbUri;
$store = $this->_erfurt->getStore();
- $newModel = $store->getNewModel($proposedDBname);
+ $newModel = $store->getNewModel($proposedDBname, null, null, true);
$object = array();
// add english label for this db
- $object['object_type'] = Erfurt_Store::TYPE_LITERAL;
+ $object['type'] = 'literal';
$object['value'] = 'GQB Query DB of ' . $this->_userName;
$newModel->addStatement($proposedDBname, EF_RDFS_LABEL, $object);
@@ -714,7 +732,7 @@ private function createUserQueryDB()
//domain of this db (needed?)
$object['value'] = $this->_privateConfig->saving->baseQueryDbUri;
- $object['object_type'] = Erfurt_Store::TYPE_IRI;
+ $object['type'] = 'uri';
$newModel->addStatement($proposedDBname, EF_RDFS_DOMAIN, $object);
//add owner/maker of this db
diff --git a/extensions/queries/resources/savepartial.js b/extensions/queries/resources/savepartial.js
index 9f3d3bfa3..280307efb 100644
--- a/extensions/queries/resources/savepartial.js
+++ b/extensions/queries/resources/savepartial.js
@@ -22,7 +22,7 @@ $(document).ready(function() {
success: function(msg){
//TODO check for status
if(msg != "All OK")
- alert("Fehler "+msg);
+ alert("Error "+msg);
//open(urlBase + "querybuilding/listquery");
}
});
@@ -46,8 +46,7 @@ $(document).ready(function() {
name: $('#qname').val(),
"query": editor.getValue(),
generator: "qe",
- //share: $("#savequerysharecheckbox").is(':checked') ? "true" : "false"
- share: "true"
+ share: $("#savequerysharecheckbox").is(':checked') ? "true" : "false"
}),
dataType: "text",
error: function(xmlHttpObj, type, error){
@@ -56,7 +55,7 @@ $(document).ready(function() {
success: function(msg){
//TODO check for status
if (msg != "All OK") {
- alert("Fehler " + msg);
+ alert("Error " + msg);
} else {
$('.innercontent').prepend("