[EXTENSION] Rights

The rights module is really good. But I lack one feature, and that is that it doesn’t scan subfolders in the controllers folders.

@saiful: Interesting benchmarks, thanks for sharing. I’m glad to help if you require further assistance.

@krillzip: You make a very good point! I’ll fix that as soon as possible. I already have a lot of improvements in the development branch but I think I can fit this minor fix in as well. Have you written the additional code for the RightsGenerator already or?

Edit:

I’ve done the changes and in the next version that is planned to be released within a few days the generator will also find controllers in subfolders.

Version 0.9.10 is now available.

New features are:

  • Most views now user grid view and data providers

  • Authorization items are now properly sorted according to weights

  • Rights now has its own user behavior

  • Generator now looks for controllers in subfolders

There has been quite a lot of changes made and I’ve tested also the module quite a lot. However, in case you happen to find a bug please report it on Google Code.

The documentation has also been updated and can be found at:

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

Enjoy!

Great… :)

Should I reinstall or just overwrite the module scripts?

Maybe you write some guide to do it.

You should read the updated documentation and either reinstall the module or recreate all authorization items you’ve created for the filter. This is because the naming conventions has been changed to support case-sensitive authorization item names.

hi…i m new to yii…

i have installed the rights module…but when i write the url

[color="#FF0000"]"http://localhost/pdf/index.php?r=rights"[/color]

in the browser to get the rights…it throws an exception that

[color="#FF0000"]"Property "CWebApplication.rights" is not defined."[/color]

plz tell me its solution as soon as possible…i am new to yii…i will b very thank full to u…

waiting for response

@sufard: You haven’t probably added rights to your module configuration. Please refer to the documentation for more information.

ok…let me see it…

thanks for reply…

this is my main.php file…

plz see it i have done all the work from start but the problem ids same

<?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'=&gt;dirname(__FILE__).DIRECTORY_SEPARATOR.'..',


'name'=&gt;'My Web Application',





// preloading 'log' component


'preload'=&gt;array('log'),





// autoloading model and component classes


'import'=&gt;array(


	'application.models.*',


	'application.components.*',


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


),





// application components


'components'=&gt;array(


	'user'=&gt;array(


		// enable cookie-based authentication


		'allowAutoLogin'=&gt;true,


	),


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


	/*


	'urlManager'=&gt;array(


		'urlFormat'=&gt;'path',


		'rules'=&gt;array(


			'&lt;controller:&#092;w+&gt;/&lt;id:&#092;d+&gt;'=&gt;'&lt;controller&gt;/view',


			'&lt;controller:&#092;w+&gt;/&lt;action:&#092;w+&gt;/&lt;id:&#092;d+&gt;'=&gt;'&lt;controller&gt;/&lt;action&gt;',


			'&lt;controller:&#092;w+&gt;/&lt;action:&#092;w+&gt;'=&gt;'&lt;controller&gt;/&lt;action&gt;',


		),


	),


	*/


	/*


	'db'=&gt;array(


		'connectionString' =&gt; 'sqlite:'.dirname(__FILE__).'/&#46;&#46;/data/testdrive.db',


	),


	*/


	// uncomment the following to use a MySQL database


	


	'db'=&gt;array(


		'connectionString' =&gt; 'mysql:host=localhost;dbname=rights',


		'emulatePrepare' =&gt; true,


		'username' =&gt; 'root',


		'password' =&gt; '',


		'charset' =&gt; 'utf8',


	),


	


	'errorHandler'=&gt;array(


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


        'errorAction'=&gt;'site/error',


    ),


	'log'=&gt;array(


		'class'=&gt;'CLogRouter',


		'routes'=&gt;array(


			array(


				'class'=&gt;'CFileLogRoute',


				'levels'=&gt;'error, warning',


			),


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


			/*


			array(


				'class'=&gt;'CWebLogRoute',


			),


			*/


		),


	),


),


[color=&quot;#FF0000&quot;]'import'=&gt;array( 


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


),


'components'=&gt;array( 


	  'user'=&gt;array( 


	  'class'=&gt;'RightsWebUser',


), 


'authManager'=&gt;array( 


	  'class'=&gt;'RightsAuthManager',


      'connectionID'=&gt;'db',


    ),


), 


'modules'=&gt;array( 


		'rights'=&gt;array( 


		'install'=&gt;true, // Add this line only if you wish to use the installer.


	),


),


'rights'=&gt;array( 


'superuserName'=&gt;'Admin', // Name of the role with super user privileges. 


'authenticatedName'=&gt;'Authenticated', // Name of the authenticated user role. 


'guestName'=&gt;'Guest', // Name of the guest role. 


'defaultRoles'=&gt;null, // List of role names that are assigned to all users. 


'userClass'=&gt;'User', // Name of the User model class. 


'userIdColumn'=&gt;'id_number', // Name of the user id column in the database. 


'userNameColumn'=&gt;'username', // Name of the user name column in the database. 


'enableBizRule'=&gt;true, // Whether to enable authorization item business rules. 


'enableBizRuleData'=&gt;false, // Whether to enable data for business rules. 


'flashSuccessKey'=&gt;'RightsSuccess', // Key to use for setting success flash messages. 


'flashErrorKey'=&gt;'RightsError', // Key to use for setting error flash messages. 


'layout'=&gt;'rights.views.layouts.rights', // Layout to use for displaying Rights. 


'baseUrl'=&gt;'/rights', // Base URL for Rights. Change if module is nested. 


'cssFile'=&gt;'rights.css', // Style sheet file to use for Rights. 


'install'=&gt;false, // Whether to enable installer. 


),[/color]





// application-level parameters that can be accessed


// using Yii::app()-&gt;params['paramName']


'params'=&gt;array(


	// this is used in contact page


	'adminEmail'=&gt;'webmaster@example.com',


),

);

please compare with this config:


<?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'=>'My Web Application',

        

// preloading 'log' component

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

        

// autoloading model and component classes

        'import'=>array(

                'application.models.*',

                'application.components.*',

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

        ),

        

// application components

        'components'=>array(

                'user'=>array(

// enable cookie-based authentication

                        'allowAutoLogin'=>true,

                        'class'=>'RightsWebUser',

                ),

// 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=rights',

                        'emulatePrepare' => true,

                        'username' => 'root',

                        'password' => '',

                        'charset' => 'utf8',

                ),

                'authManager'=>array( 

                        'class'=>'RightsAuthManager',

                        'connectionID'=>'db',

                ),

                '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',

),

                        */

                        ),

                ),

        ),

        'modules'=>array( 

                'rights'=>array( 

                        'superuserName'=>'Admin', // Name of the role with super user privileges. 

                        'authenticatedName'=>'Authenticated', // Name of the authenticated user role. 

                        'guestName'=>'Guest', // Name of the guest role. 

                        'defaultRoles'=>null, // List of role names that are assigned to all users. 

                        'userClass'=>'User', // Name of the User model class. 

                        'userIdColumn'=>'id_number', // Name of the user id column in the database. 

                        'userNameColumn'=>'username', // Name of the user name column in the database. 

                        'enableBizRule'=>true, // Whether to enable authorization item business rules. 

                        'enableBizRuleData'=>false, // Whether to enable data for business rules. 

                        'flashSuccessKey'=>'RightsSuccess', // Key to use for setting success flash messages. 

                        'flashErrorKey'=>'RightsError', // Key to use for setting error flash messages. 

                        'layout'=>'rights.views.layouts.rights', // Layout to use for displaying Rights. 

                        'baseUrl'=>'/rights', // Base URL for Rights. Change if module is nested. 

                        'cssFile'=>'rights.css', // Style sheet file to use for Rights. 

                        'install'=>true, // Whether to enable installer. 

                ),

        ),

        

// application-level parameters that can be accessed

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

        'params'=>array(

// this is used in contact page

                'adminEmail'=>'webmaster@example.com',

        ),

); 

Please note that you don’t need to set any configurations for rights unless they are different from the default values.

@sufard: You have the rights module configuration twice.

Hi Chris,

it looks like you have created a great piece of code however I am having some difficulties in make it to work.

I’ve the user model and table created and filled with a user account (‘admin’), the main layout has the full path in it (application.views.layouts.main), the config file includes


	

        'components'=>array(

		'user'=>array(

			// enable cookie-based authentication

			'allowAutoLogin'=>true,

            'loginUrl'=>array('/user/login'),

            'class'=>'RightsWebUser',

		),

        'authManager'=>array(

            'class'=>'RightsAuthManager',

        ),



and




    'modules'=>array(

        'rights'=>array(

            'superuserName'=>'admin', // Name of the role with super user privileges. 

            'authenticatedName'=>'Authenticated', // Name of the authenticated user role. 

            'guestName'=>'Guest', // Name of the guest role. 

            'defaultRoles'=>null, // List of role names that are assigned to all users. 

            'userClass'=>'User', // Name of the User model class. 

            'userIdColumn'=>'id', // Name of the user id column in the database. 

            'userNameColumn'=>'username', // Name of the user name column in the database. 

            'enableBizRule'=>true, // Whether to enable authorization item business rules. 

            'enableBizRuleData'=>false, // Whether to enable data for business rules. 

            'flashSuccessKey'=>'RightsSuccess', // Key to use for setting success flash messages. 

            'flashErrorKey'=>'RightsError', // Key to use for setting error flash messages. 

            'layout'=>'rights.views.layouts.rights', // Layout to use for displaying Rights. 

            'baseUrl'=>'/rights', // Base URL for Rights. Change if module is nested. 

            'cssFile'=>'rights.css', // Style sheet file to use for Rights. 

            'install'=>true, // Whether to enable installer.            

        ),




however when i load http://localhost/myapp/index.php/rights or http://localhost/myapp/index.php/rights/install

it does redirect me to the main page http://localhost/myapp/index.php. I’m logged in as user ‘admin’ and I don’t have any of the Auth* tables in the database

do you have any idea on what it is missing here?

appreciate your help :)

@pingala

try to add connectionId


'authManager'=>array( 

                        'class'=>'RightsAuthManager',

                        'connectionID'=>'db',

                ),

cheers mate, actually that’s not it but you reminded me to check the db settings and what I’ve found is that the user I’ve created on MySQL didn’t have the privileges to create tables … pity I didn’t get any error message in regards I would have saved a lot of time.

So I would add in the documentation a note specifying that the db user must have privileges to create tables, as check point so the developer is forced to check :)

thanks.

Thanks for pointing this out. Sorry for the inconvenience, I will add this to the documentation. Weird that you didn’t get any errors. I have to try denying the create privileges on one of my test installations and try to figure out why you didn’t get any errors when trying to install the module.

So now you got it up and running? :)

I have one problen on a fresh install of yii (database of my own desing)

Whe i try to use the system on any controller i get this error:


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

To fix this i must modify the controller class from


class Controller extends CController

to


class Controller extends RightsBaseController



I am pretty new to yii so i must be making a mistake, if there are a better way please tell me. If this change is a must, then it should be good to add to the docs of yii-rights.

You’re absolutely right and there is no other way to do it. It’s mentioned in the documentation. This is because the filter method (RightsFilter) is in the RightsBaseController-class so you must extend you application base controller (normally Controller) from that class in order to use the rights ACAC filter.

I read the docs again and found it…

I was looking on all the examples and i must have pass that. Sorry for the question.

On the example blog we use the:


    /**

    * Returns a specific Rights configuration variable.

    * @param string the name of the variable to get.

    * @return mixed the value of the variable or null if not set.

    */

    public static function getConfig($name)

    {

        $module = self::module();

        if( isset($module->$name)===true )

            return $module->$name;

        else

            return null;

    }

This function do not exist anymore on the last revision, how can i check on a view if a user is the superuser:

(on the blog of rev 9.10 we use):


array('label'=>'Rights', 'url'=>array('/rights'), 'visible'=>Yii::app()->user->checkAccess(Rights::getConfig('superuserRole'))),

thanks for the previus reply and keep doing this amazing module

Edit:

Using


array('label'=>'Rights', 'url'=>array('/rights'), 'visible'=>Rights::getAuthorizer()->isSuperuser()),

instead of the previus way the system works ok. So do not reply my question

@angelus_ira: The Rights::getConfig()-method was removed because you can achieve the same by calling e.g.


Rights::module()->superuserName.

It’s alright to ask. I’m glad to answer any questions or explain why some things have been done in a certain way.

Version 0.9.11 is now available.

Rights has undergone a major user interface review and it should be more user-friendly now.

Important note:

Operations for the Automatic Controller Access Controller filter are now case-sensitive.

Read the updated documentation before you install. It can be found at:

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

Updating your current Rights-installation is easily done by re-installing.

Please remember that re-installing the module will result in loss of data.

[i]The translations aren’t complete at the moment because they haven’t been updated.

I’ll try to get them updated as soon as possible. Sorry for the inconvenience.[/i]

Enjoy!