Welcome Guest, Not a member yet? Register   Sign In
Tendoo CMS : Users, Groups and Permissions (Part I)
#1

(This post was last modified: 07-30-2015, 07:06 PM by Blair2004.)

As you may already know, Tendoo uses Aauth class as Auth module for users as default.
This module handle users, groups and theirs permissions.

In this small tutorial, i'm going to show you how to create a module which works with permissions.

I : Before we start

You should know that Aauth module has pre-installed group which is designed to be used for simple module. Thoses groups are "Master" and "Administrators".

- "Master" is the main group with all permissions. Actually, he can : "manage_options", "manage_modules", "manage_users"
- "Administrators" follows the previous but he cannot "manage_users".

There is a UI to create group manually but this feature is in the way to be removed. Since default group are enough and if not, module can create their own group with specific permissions.

II - First steps

i assume that you already know how to create a simple module with Tendoo.
now it's time to create group using User class

Note : You sould probably update your tendoo installation. Those following code are supposed to be use within your main module file and after adding action to "after_app_init" hook.

1. Create a group

You can create unlimited group using Aauth module through User Class like this : 

PHP Code:
<?php
User
::create_group$group_name $group_description $is_admin ); 

we use create group method statically. This method accepts 3 parameters : 
  • Group name
  • Group description
  • Is admin (this parameter allow this group's member to access dashboard), must be set as boolean.

a notice code is returned.

2. Update Group

You can change group details like this :

PHP Code:
<?php
User
::update_group$group_id $name $group_description $is_admin ); 

this method use the same parameters than the previous, the exception here is that the first parameters is the group id which is used to identify the group.

3. Delete Group

If you desire, you can delete a group. Beware this method does'nt check if the group has users to block deletion. If a group with members is deleted, those user won't have any group and dashboard maybe locked for them.

Here is how you can proceed : 

PHP Code:
<?php
User
::delete_group$group_id ); 

the only parameter here let you provide group id

4. Create permission

Default group wont be enough for enhanced module with several features, that's why you'll need to create your own group and permissions. Now i'll show you how to create a permission : 

PHP Code:
<?php
User
::create_permission$permision_namespace $permission_descripion ); 

this method accepts two parameters :

- Permission namespace (a string without spaces, special chars, underscore is supported and recommended)
- Permission description (talks about himself)

5. Update permission

This method let you update an existent permission :

PHP Code:
<?php
User
::update_permission$permission_id $permission_namespace $permission_details); 

This method looks like the previous one, but starts with permission id

6. Delete permission

I'll show you how to delete permission.
Note: If a permission is deleted and some script try to validate user's group permission, it will always returns false if the permission doesn't exists.

Here is how you can proceed :

PHP Code:
<?php
User
::delete_permission$permission_id ); 


7 . Give a permission to a group

This is surely the most important part of group section. You can create unlimited type of group, but you'll need to give permission to those groups.

It's recommended for simple module to use default group instead of creating new group with special permission (but if it's required go ahead..  Wink ).

Here is an example :

PHP Code:
<?php
User
::allow_group$group_id $permission_id ); 

8. How to get them all

A - For users
since Aauth module is included on tendoo, it's load Users_model class which has several method (all of those listed before), it's always available for hook which follows "after_app_init". You can call it directly within your "model" but using "$this->users" directly.
So to retreive Users here is the code : 

PHP Code:
<?php
$this
->users->get$user_id ); 

You can use var_dump to see object returned

B - For Groups

PHP Code:
<?php
$this
->users->auth->get_group_name($group_id); 

As you can see, auth library is included withing "users" model. You can use defined method directly this way.
That's almost all. Those methods are hold for the R.C.

Thanks for reading this.  Smile
NexoPOS 2.6.2 available on CodeCanyon.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB