From 2f0b0ac49b870e1dca9f6f85ba323fe2b67d0711 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 20 Sep 2013 12:11:22 +0200 Subject: [PATCH] Fixed use without any User management Using the plugin without any User management has been made much easier. It is the default behavior and it works out of the box without any need to tinker files or configuration. --- Controller/DocumentManagerAppController.php | 10 ++++++++-- Model/Document.php | 20 +++++++++++++------- View/Helper/DocumentManagerHelper.php | 10 ++++++++-- readme.md | 9 +++++---- 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/Controller/DocumentManagerAppController.php b/Controller/DocumentManagerAppController.php index 6d62040..d340fbd 100644 --- a/Controller/DocumentManagerAppController.php +++ b/Controller/DocumentManagerAppController.php @@ -22,7 +22,7 @@ public function hasAdminRights() { * Checks if a folder belongs to a User, i.e. all files in thise folder belongts to him */ public function folderBelongsToUser($path) { - if( !Configure::read('DocumentManager.authentification') || $this->Document->checkFolder($path, $this->getUserId())) {// file can be changed by current user + if($this->Document->checkFolder($path, $this->getUserId())) {// file can be changed by current user return true; }; return false; @@ -32,7 +32,7 @@ public function folderBelongsToUser($path) { * Checks if the file belongs to a User */ public function fileBelongsToUser($user_id) { - if( !Configure::read('DocumentManager.authentification') || $this->getUserId() == $user_id) {// file can be changed by current user + if($this->getUserId() == $user_id) {// file can be changed by current user return true; }; return false; @@ -42,10 +42,16 @@ public function fileBelongsToUser($user_id) { * Returns the logged user id, if not logged, return null */ public function getUserId() { + if(!Configure::read('DocumentManager.authentification')) {// If there is no authentification, user_id is null + return null; + } return $this->Authake->getUserId(); } public function isAdmin() { + if(!Configure::read('DocumentManager.authentification')) {// If there is no authentification, everyone has all the rights + return true; + } return $this->Authake->isMemberOf(1); } diff --git a/Model/Document.php b/Model/Document.php index fb0d109..ec4a9fc 100644 --- a/Model/Document.php +++ b/Model/Document.php @@ -9,12 +9,18 @@ */ class Document extends DocumentManagerAppModel { - public $belongsTo = array( - 'User' => array( - 'className' => 'Authake.User', - 'foreignKey' => 'user_id', - ), - ); + public function __construct($id = false, $table = null, $ds = null) { + if(Configure::read('DocumentManager.authentification')) {// If there is an authentification system, bind Documents to the right User model + $this->belongsTo = array( + 'User' => array( + 'className' => 'Authake.User', + 'foreignKey' => 'user_id', + ), + ); + } + parent::__construct($id, $table, $ds); + } + public function beforeValidate() { $this->validate = array( @@ -65,7 +71,7 @@ function readFolder($pathFolderNames) { $files[$i] = array( 'name' => $file, 'Document' => empty($document) ? null : $document['Document'], - 'User' => empty($document) ? null : $document['User'], + 'User' => (empty($document) || empty($document['User'])) ? null : $document['User'], ); } } diff --git a/View/Helper/DocumentManagerHelper.php b/View/Helper/DocumentManagerHelper.php index 8f12ecc..c7d5be8 100644 --- a/View/Helper/DocumentManagerHelper.php +++ b/View/Helper/DocumentManagerHelper.php @@ -10,7 +10,7 @@ class DocumentManagerHelper extends AppHelper { public $helpers = array('Html', 'Authake.Authake'); public function hasAdminRights() { - if( !Configure::read('DocumentManager.authentification') || $this->isAdmin()) {// User has admin rights + if($this->isAdmin()) {// User has admin rights return true; }; return false; @@ -20,7 +20,7 @@ public function hasAdminRights() { * Checks if the file belongs to a User */ public function fileBelongsToUser($user_id) { - if( !Configure::read('DocumentManager.authentification') || $this->getUserId() == $user_id) {// file can be changed by current user + if($this->getUserId() == $user_id) {// file can be changed by current user return true; }; return false; @@ -30,10 +30,16 @@ public function fileBelongsToUser($user_id) { * Returns the logged user id, if not logged, return null */ public function getUserId() { + if(!Configure::read('DocumentManager.authentification')) {// If there is no authentification, user_id is null + return null; + } return $this->Authake->getUserId(); } public function isAdmin() { + if(!Configure::read('DocumentManager.authentification')) {// If there is no authentification, everyone has all the rights + return true; + } return $this->Authake->isMemberOf(1); } } diff --git a/readme.md b/readme.md index 134a990..3bd639d 100644 --- a/readme.md +++ b/readme.md @@ -23,9 +23,10 @@ echo $this->fetch('script'); *** Dependencies *** -This plugin uses the following scripts: jquery, jquery-ui. http://jquery.com/ , http://jqueryui.com/ +This plugin uses jQuery : http://jquery.com/ +Be sure to load jQuery before including the scripts of this plugin. Otherwise while the plugin will still work, AJAX calls won't be possible. -For display purposes this plugins uses the following graphic library: Bootstrap. http://twitter.github.io/bootstrap/ +For a better display install Bootstrap. http://twitter.github.io/bootstrap/ For users permissions this plugin is meant to be used with the Authake plugin : https://github.com/mtkocak/authake Authake.User should declare it hasMany DocumentManager.Document. @@ -33,8 +34,8 @@ Authake.User should declare it hasMany DocumentManager.Document. - Users should have fields id, email, first_name and last_name. - Users can have field picture (displayed with Documents). -If you have another users management system, change the $belongsTo in Document.php according to your User class, and change the functions getUserId() and isAdmin() -in DocumentManager/Controller/DocumentManagerAppController.php and DocumentManager/View/Helper/DocumentManagerHelper.php to retrieve the right information. +If you have another users management system, change the $belongsTo in Document.php, __construct() function, according to your User class, and change the functions +getUserId() and isAdmin() in DocumentManager/Controller/DocumentManagerAppController.php and DocumentManager/View/Helper/DocumentManagerHelper.php to retrieve the right information. Using this plugin without Authake and without modifying these two functions will only work if you disable permission management to allow any user to access any action and any file as explained below.