]> 91.132.146.200 Git - bibliotheca-php.git/commitdiff
improvements in rights. Not finished yet but looks good
authorBanana <mail@bananas-playground.net>
Thu, 7 Jan 2021 12:02:58 +0000 (13:02 +0100)
committerBanana <mail@bananas-playground.net>
Thu, 7 Jan 2021 12:02:58 +0000 (13:02 +0100)
upgrade/from-version-1.0.txt
webclient/config/config.php.default
webclient/lib/manageentry.class.php
webclient/lib/trite.class.php
webclient/view/default/manageentry/manageentry.php
webclient/view/default/managetags/managetags.php

index 76ccad72c6185f4ee181ebd4e3cac343f616ca6c..c3d96be0a31e67fa95ab6ce02b2ea71c24dff951 100644 (file)
@@ -2,7 +2,11 @@
 Please copy the new config/config.php.default to config/config.php and adapt the settings which you
 have on the old config files. After that you can delete config/database|path|system files.
 
-# DB changes. Run each line against your bibliotheca DB
+# Deletion of config definition
+The definition of USER_DEFAULT_RIGHTS_STRING can be removed from config file.
+
+# DB changes. Run each line against your bibliotheca DB.
 UPDATE `bib_menu` SET `rights` = 'rw-rw----' WHERE `bib_menu`.`id` = 10;
 UPDATE `bib_menu` SET `group` = '2' WHERE `bib_menu`.`id` = 10;
 INSERT INTO `bib_menu` (`id`, `text`, `action`, `icon`, `owner`, `group`, `rights`, `position`, `category`) VALUES (NULL, 'Profile', 'profile', 'user', '1', '2', 'rw-rw----', '5', 'manage');
+DELETE FROM `bib_menu` WHERE `bib_menu`.`id` = 13;
index 8ed6cf640cd80f403b1eb1c28c2a9bebe81f1220..e6ef303c8fc7474924bec3adf0889029a4ec4d5c 100644 (file)
@@ -47,7 +47,6 @@ define('SESSION_NAME', "bibliotheca-session");
 define('SESSION_SAVE_PATH', PATH_SYSTEMOUT.'/session');
 
 # usersettings
-define('USER_DEFAULT_RIGHTS_STRING','rwxrwx---');
 define('ADMIN_GROUP_ID','1');
 define('ANON_USER_ID','2');
 define('ANON_GROUP_ID','3');
index ee08692eb09154c64e5357231f6c105409d2336c..d713d8ec056c46b2097aab35236bda3158b83b93 100644 (file)
@@ -66,7 +66,7 @@ class Manageentry {
        /**
         * Set the collection to manage entries from
         *
-        * @param sring $collectionId Number
+        * @param string $collectionId Number
         */
        public function setCollection($collectionId) {
                if(!empty($collectionId)) {
@@ -319,7 +319,7 @@ class Manageentry {
                        $queryStr = "SELECT `id`
                                                FROM `".DB_PREFIX."_collection_entry_".$this->_collectionId."`
                                                WHERE `id` = '".$this->_DB->real_escape_string($entryId)."'
-                                                       AND " . $this->_User->getSQLRightsString("write") . "";
+                                                       AND ".$this->_User->getSQLRightsString("write")."";
                        if(QUERY_DEBUG) error_log("[QUERY] ".__METHOD__." query: ".var_export($queryStr,true));
                        try {
                                $query = $this->_DB->query($queryStr);
index 59c35ca7efcd8ece5a306fb8c04c38517662f026..211142a14ae97c4edf34ed6f35f27272e44f3ed4 100644 (file)
@@ -156,14 +156,14 @@ class Trite {
         *
         * @return array
         */
-       public function getCollections() {
+       public function getCollections($rightsMode="read") {
                $ret = array();
 
                $queryStr = "SELECT `c`.`id`, `c`.`name`, `c`.`description`
                                        FROM `".DB_PREFIX."_collection` AS c
                                        LEFT JOIN `".DB_PREFIX."_user` AS u ON `c`.`owner` = `u`.`id`
                                        LEFT JOIN `".DB_PREFIX."_group` AS g ON `c`.`group` = `g`.`id`
-                                       WHERE ".$this->_User->getSQLRightsString("read", "c")."
+                                       WHERE ".$this->_User->getSQLRightsString($rightsMode, "c")."
                                        ORDER BY `c`.`name`";
                if(QUERY_DEBUG) error_log("[QUERY] ".__METHOD__." query: ".var_export($queryStr,true));
                try {
@@ -185,6 +185,8 @@ class Trite {
        /**
         * Fields for the loaded collection.
         *
+        * Works only if collection is already loaded and thus rights are validated
+        *
         * @return array
         */
        public function getCollectionFields() {
@@ -215,6 +217,8 @@ class Trite {
         * Possible optimization can be done here: Do not load everything at once, but per field
         * Needs also change in frontend to separate those calls
         *
+        * Works only if collection is already loaded and thus rights are validated
+        *
         * @param string $search String value to search value against
         * @return array
         */
@@ -257,6 +261,34 @@ class Trite {
                return $ret;
        }
 
+       /**
+        * Load the tools configured for the current loaded collection
+        *
+        * @return array
+        */
+       public function getAvailableTools() {
+               $ret = array();
+
+               $queryStr = "SELECT `t`.`id`, `t`.`name`, `t`.`description`, `t`.`action`, `t`.`target`
+                                       FROM `".DB_PREFIX."_tool2collection` AS t2c
+                                       LEFT JOIN `".DB_PREFIX."_tool` AS t ON t2c.fk_collection_id = t.id
+                                       WHERE t2c.fk_collection_id = '".$this->_DB->real_escape_string($this->_id)."'";
+               if(QUERY_DEBUG) error_log("[QUERY] ".__METHOD__." query: ".var_export($queryStr,true));
+               try {
+                       $query = $this->_DB->query($queryStr);
+                       if($query !== false && $query->num_rows > 0) {
+                               while(($result = $query->fetch_assoc()) != false) {
+                                       $ret[$result['id']] = $result;
+                               }
+                       }
+               }
+               catch (Exception $e) {
+                       error_log("[ERROR] ".__METHOD__." mysql catch: ".$e->getMessage());
+               }
+
+               return  $ret;
+       }
+
        /**
         * set some defaults by init of the class
         *
index 78bd33fd19c025c3ccf2b10b81ab749072212ea0..93c38bededfb8225b6af16cb8f3e28a4a58dea5a 100644 (file)
@@ -16,8 +16,8 @@
  * limitations under the License.
  */
 
-require_once 'lib/managecollections.class.php';
-$ManangeCollections = new ManageCollections($DB,$Doomguy);
+require_once 'lib/trite.class.php';
+$Trite = new Trite($DB,$Doomguy);
 require_once 'lib/manageentry.class.php';
 $ManangeEntry = new Manageentry($DB,$Doomguy);
 
@@ -42,14 +42,13 @@ if(isset($_GET['id']) && !empty($_GET['id'])) {
 }
 
 if(!empty($_collection)) {
-       $setCollection = $ManangeCollections->getCollection($_collection, "write");
+       $TemplateData['loadedCollection'] = $Trite->load($_collection, "write");
 
-       if(!empty($setCollection)) {
-               $ManangeEntry->setCollection($_collection);
-               $TemplateData['loadedCollection'] = $setCollection;
+       if(!empty($TemplateData['loadedCollection'])) {
+               $ManangeEntry->setCollection($Trite->param('id'));
 
                $TemplateData['editFields'] = $ManangeEntry->getEditFields();
-               $TemplateData['availableTools'] = $ManangeCollections->getAvailableTools($_collection);
+               $TemplateData['availableTools'] = $Trite->getAvailableTools();
 
                if(!empty($_id)) {
                        $TemplateData['storagePath'] = PATH_WEB_STORAGE . '/' . $_collection . '/' . $_id;
@@ -71,10 +70,10 @@ if(!empty($_collection)) {
                        }
                        $_fieldsToSave = array();
                        if (!empty($fdata)) {
-                               // @todo there is no setting for individual rights available yet
+                               // @todo there is no setting for individual rights available yet, use the collection rights for now.
                                $_owner = $Doomguy->param('id');
-                               $_group = $Doomguy->param('baseGroupId');
-                               $_rights = 'rwxrwxr--';
+                               $_group = $Trite->param('group');
+                               $_rights = $Trite->param('rights');
 
                                foreach ($TemplateData['editFields'] as $fieldId=>$fieldData) {
                                        if(isset($fdata[$fieldData['identifier']])) {
@@ -118,7 +117,7 @@ if(!empty($_collection)) {
                                        if (!empty($_fieldsToSave) && isset($_fieldsToSave['title'])) {
                                                $do = $ManangeEntry->create($_fieldsToSave, $_owner, $_group, $_rights);
                                                if (!empty($do)) {
-                                                       $TemplateData['message']['content'] = "New entry: <a href='index.php?p=manageentry&collection=".$_collection."&id=".$do."'>".$do."</a>";
+                                                       $TemplateData['message']['content'] = "<a href='index.php?p=manageentry&collection=".$_collection."&id=".$do."'>View your new entry</a>";
                                                        $TemplateData['message']['status'] = "success";
                                                } else {
                                                        // use editData to display given data
@@ -139,8 +138,9 @@ if(!empty($_collection)) {
        else {
                $TemplateData['message']['content'] = "Collection could not be loaded.";
                $TemplateData['message']['status'] = "error";
+               $TemplateData['existingCollections'] = $Trite->getCollections("write");
        }
 }
 else {
-       $TemplateData['existingCollections'] = $ManangeCollections->getCollections();
+       $TemplateData['existingCollections'] = $Trite->getCollections("write");
 }
index e7b8116d9a1419f96b381384af3665ac26e0dcaf..4560353905d5dcfc0d48eebefa41eed3dbcdf244 100644 (file)
@@ -37,7 +37,7 @@ $TemplateData['loadedCollection'] = array();
 $TemplateData['collections'] = array();
 
 if(!empty($_collection)) {
-       $TemplateData['loadedCollection'] = $Trite->load($_collection);
+       $TemplateData['loadedCollection'] = $Trite->load($_collection, "write");
        if(!empty($TemplateData['loadedCollection'])) {
                $ManageTags->setCollection($_collection);
                if(isset($_POST['submitForm'])) {
@@ -64,6 +64,10 @@ if(!empty($_collection)) {
                }
                else {
                        $TemplateData['tags'] = $Trite->getTags();
+                       if(empty($TemplateData['tags'])) {
+                               $TemplateData['message']['content'] = "No tags available or something went wrong.";
+                               $TemplateData['message']['status'] = "warning";
+                       }
                }
        }
        else {
@@ -72,5 +76,5 @@ if(!empty($_collection)) {
        }
 }
 else {
-       $TemplateData['collections'] = $Trite->getCollections();
+       $TemplateData['collections'] = $Trite->getCollections("write");
 }