Skip to content

Commit

Permalink
Fixed use without any User management
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Christian committed Sep 20, 2013
1 parent 58f6fa3 commit 2f0b0ac
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
10 changes: 8 additions & 2 deletions Controller/DocumentManagerAppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
}

Expand Down
20 changes: 13 additions & 7 deletions Model/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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'],
);
}
}
Expand Down
10 changes: 8 additions & 2 deletions View/Helper/DocumentManagerHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
}
}
9 changes: 5 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@ 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.
- Add the right permissions so Users can access the plugin actions
- 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.
Expand Down

0 comments on commit 2f0b0ac

Please sign in to comment.