-
Notifications
You must be signed in to change notification settings - Fork 26
Table Permission Management (GRID)
From today (there's always a 'today') 25/08/2016 you can have a GRID TO MANAGE YOUR USERS FOR ANY TABLE OF YOUR DATABASE!!!!!!!!!! (ecc...!!)
Sorry but I'm very excited about that new tool because you can manage every permission for each of your table with just a line of code! Wow!
You can Create infinite groups, each group will have single permission to:
- See the All the Records
- See the Single Record
- Add a new Record
- Edit existing Records
- Delete existing Records
- !SEE JUST THE CONTENT THE USER HAS ADDED! based on the user ID
... FOR EACH TABLE! And the tables are Synced with your database AUTOMAGICALLY!
If you don't want to use this tool you can just ignore all this page, it's all optional!
All the content, even the GRID page, is all into these 3 files!
You must visit the page yourGroceryCrudURL.com/login/manage_permissions
and you're just ready to go!
To connect your user permission field to this tool you just need a line on you GC users page:
$crud->set_relation('permissions','crud_permissions','name');
Now the "permissions" field will show you a dropdown with ALL your permissions groups!
Create new groups and choose which tables they can have the permission for.
You just need to rewrite the $crud
variable that we use for Grocery_CRUD.
You MUST put that BEFORE the $output
VARIABLE!
$crud = $this->login_model->check($crud);
//before declaring the output variable!
$output = $crud->render;
If you mean that the user can see just the record they've added so you just need to add to that single line the field of the current table that contains the 'author' id.
// -- Just an example --
/* we have the table "articles" with an "author" field */
$crud = $this->login_model->check($crud,"author");
That's really it, you just have to check in the manage_permissions
page that the "ID ONLY" field!
Ok so the check() function is not enough for you and you want something more challenging. Ok, I'm with you!
6 numbers, that's all. Each number means something you don't need to care about.
ID RL RS A E D x x x x x x
- ID - only ID
- RL - Read List
- RS - Read Single Record
- A - Add
- E - Edit
- D - Delete
extractPermission($what,$permission=false,$table=false);
//example
//Check if the user can add a new record into the Article table
if(extractPermission("A",false,"article")){
echo "You can Add a record, so you're an Author!";
}else{
echo "You can't Add a thing here, sorry.";
}
We use "A" because (few lines above) the "A" is for the Add permission.
Check if a current logged user can make the relative action. Every function return a boolean.
- IDOnly($table_name)
- canSeeList($table_name)
- canSeeSingle($table_name)
- canAdd($table_name)
- canEdit($table_name)
- canDelete($table_name)
//example
if(IDOnly('articles')){
echo "You can see JUST your articles, ".$this->login_model->name();
if(canAdd('articles')){
echo ", and you can add a new article by clicking above.";
}else{
echo ", but you can't add a new article.";
}
}
/*
OUTPUT
if id only and can add:
'You can see JUST your articles, portapipe, and you can add a new article by clicking above.'
if id only but can't add:
'You can see JUST your articles, portapipe, but you can't add a new article.'
if not id only
''
*/