[EXTENSION] Rights

Hi,

I am totally new to Yii. I was looking around for a RBAC solutions and was recommended to this module. I’ve managed to download the module and unzip it to the modules folder. Edited the main.php file into as below:




<?php


// uncomment the following to define a path alias

// Yii::setPathOfAlias('local','path/to/local-folder');


// This is the main Web application configuration. Any writable

// CWebApplication properties can be configured here.

return array(

	'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',

	'name'=>'Educare Foundation',


	// preloading 'log' component

	'preload'=>array('log'),


	// autoloading model and component classes

	'import'=>array(

		'application.models.*',

		'application.components.*',

		'application.modules.rights.*', 

		'application.modules.rights.components.*',

	),


	'modules'=>array(

		// uncomment the following to enable the Gii tool

		'gii'=>array(

			'class'=>'system.gii.GiiModule',

			'password'=>'1234',

		),

	),


	// application components

	'components'=>array(

		'user'=>array(

			'class'=>'RWebUser',

			// enable cookie-based authentication

			'allowAutoLogin'=>true,

		),

		// uncomment the following to enable URLs in path-format

		/*

		'urlManager'=>array(

			'urlFormat'=>'path',

			'rules'=>array(

				'<controller:\w+>/<id:\d+>'=>'<controller>/view',

				'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',

				'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

			),

		),

		'db'=>array(

			'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',

		),

		*/

		// uncomment the following to use a MySQL database

		'db'=>array(

			'connectionString' => 'mysql:host=localhost;dbname=testingdb',

			'emulatePrepare' => true,

			'username' => 'root',

			'password' => '',

			'charset' => 'utf8',

		),

		'authManager'=>array( 

			'class'=>'RDbAuthManager',

		),

		'modules'=>array( 'rights'=>array( 'install'=>true, // Enables the installer. 

		), ),

		'errorHandler'=>array(

			// use 'site/error' action to display errors

            'errorAction'=>'site/error',

        ),

		'log'=>array(

			'class'=>'CLogRouter',

			'routes'=>array(

				array(

					'class'=>'CFileLogRoute',

					'levels'=>'error, warning',

				),

				// uncomment the following to show log messages on web pages

				/*

				array(

					'class'=>'CWebLogRoute',

				),

				*/

			),

		),

	),


	// application-level parameters that can be accessed

	// using Yii::app()->params['paramName']

	'params'=>array(

		// this is used in contact page

		'adminEmail'=>'daniel@testing.com',

	),

);



and after this, I am totally lost. I have no idea how I can proceed to install the module. Can you advice me on the next step please?

Hello danieln,

Please read the documentation, there you should find all information necessary.

You can download the documentation here:

http://yii-rights.googlecode.com/files/yii-rights-doc-1.2.0.pdf

Hi,

Yup, I got the pdf and it’s where I got the info to edit the main.php file.

it says ‘install Rights using its installer component.’ but how do i do it?

I tried going to the address path/index.php?r=rights and i only got:

Error 404

Unable to resolve the request "rights"

You forgot to include rights in your modules:




//in your config/main.php:

'modules'=>array(

		// uncomment the following to enable the Gii tool

		'gii'=>array(

			'class'=>'system.gii.GiiModule',

			'password'=>'1234',

		),

                'rights'=>array(

			'install'=>true, // Enables the installer.

		),

	),




:)

I just updated to 1.2,and its a good thing I don’t have to edit the codes to select between description and names. Thanks Chris!

By the way, is it intentional that the headers of the tables, say assignment table, are not clickable to sort items? All the tables in my application are sortable with the click of the header, so I should configure your extension. Any hints on where should I start? ;)

Great! got to the installer page and it says ‘rights’ was installed successfully. now when ever I get back to this page, it gives me the installer only. so I tried to disable the install again (change the true to false, don’t delete the line as I tried deleting it and it sent me back to the error 403 page) then I was presented with the screen as shown in the screenshots --> the role manager page :)

Thanks a lot guys!!

Glad you got it rolling :)

well, now the next challenge is how to get it work with the authentication login.

any tips on that?

Hey macinville,

Well, the grid view displaying the assignments was done a while ago and it’s a custom data provider. I think the problem is that the data provider doesn’t have sorting implemented. Please let me know if you implement it and I might be able to add it to the module by default. :)

P.S. The authorization items are not sortable intentionally because they are always sorted according to their weights.

danieln,

Could you be a bit more specific on what you’re looking for? I’m pretty sure that you can find all necessary info by browsing this thread or reading the documentation.

Hi Chris,

Now that I got the RBAC working, but I’d like to know if there is any guide out there that teaches how to use the tables created to build the login script into the site.

danieln,

Are you referring to authorization and authentication using the database? If so, this should be helpful. It assumes that you already have a User model.

Hi,

Yup!

Thanks, will start my reading :)

The sorting I think is supposed to be constructed in the method fetchData, which was overriden by RAssignmentDataProvider. I’m afraid I might spend more time finding a way to sort the table like the usual behavior than I can afford, so I guess I’ll just use jQuery. :)

Hey again macinville,

I’ve added an enhancement issue of this on Google Code. I’ll look into when I have time. Thanks for the idea.

Hey Chris83,

Thanks for considering the idea. :)

Hi,

need some help again here.

After reading the authenticate article, I am now able to login with the usernames from the DB. So I am trying to get the rights module working by adding the line ‘public function filters() { return array( ‘rights’, ); }’ into the user controller to try it out. I changed the code




	public function filters()

	{

		return array(

			'accessControl', // perform access control for CRUD operations

		);

	}



to


public function filters() { return array( 'rights', ); }



as shown in the manual, but I got this error:





CException

Description


Filter "rights" is invalid. Controller "UserController" does have the filter method "filterrights".

Source File


D:\xampp\htdocs\yii\framework\web\filters\CInlineFilter.php(47)


00035:      * @return CInlineFilter the created instance

00036:      * @throws CException if the filter method does not exist

00037:      */

00038:     public static function create($controller,$filterName)

00039:     {

00040:         if(method_exists($controller,'filter'.$filterName))

00041:         {

00042:             $filter=new CInlineFilter;

00043:             $filter->name=$filterName;

00044:             return $filter;

00045:         }

00046:         else

00047: throw new CException(Yii::t('yii','Filter "{filter}" is invalid. Controller "{class}" does have the filter method "filter{filter}".',

00048:                 array('{filter}'=>$filterName, '{class}'=>get_class($controller))));

00049:     }

00050: 

00051:     /**

00052:      * Performs the filtering.

00053:      * This method calls the filter method defined in the controller class.

00054:      * @param CFilterChain $filterChain the filter chain that the filter is on.

00055:      */

00056:     public function filter($filterChain)

00057:     {

00058:         $method='filter'.$this->name;

00059:         $filterChain->controller->$method($filterChain);




can advise where did I went wrong?

Hey danieln,

You need to extend your application controller (normally called Controller) from RController and it will work.

Dear Cris,

I implemented the module rights according to manually version 1.2. Nevertheless, I had to install the database manually and the module is presenting the next bug while opening the url default (index.php?r=rights):




include(User.php): failed to open stream: No such file or directory 

...

/var/www/yiiRoot/framework/YiiBase.php(395)

...

...

395                 include($className.'.php');

...

...

The database user is root. does it have any hint of which it would be the problem?

I’m user database mysql, Module Rights version yii-rights-1.2.0.r142 and aplication default yii-1.1.6.r2877.

Thanks!

Hello Herbert,

If you’re getting that error it means that you do not have a user model correctly configured for your application, you can read more about this in the documentation under “Before you start”.

Hope this helps.