[EXTENSION] Rights

Thanks for your help, however I think you are too far ahead of me.

Let us try from scratch. I downloaded “yii-blog-with-rights-1.3.0.r147.zip” and extracted it to /extensions. That’s basically it because the configuration described in the rights manual doesn’t say how to get the blog (as module) to run. Sorry to bother you with these basic questions but the Yii Manual covers some fields really good and others (like this) are nearly uncovered.

Hi! i can’t seem to make it work. can you guys help me? i always get

"Server error

The website encountered an error while retrieving http://localhost/demorbac/index.php/rights. It may be down for maintenance or configured incorrectly."

here is what my main.php config looks like. hope to get this working through everyones help :D


<?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'=>'<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/biggrin.gif' class='bbc_emoticon' alt=':D' />',

                ),

				'rights'=>array(

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

        ),


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

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

        ),

);

I can immediately spot a syntax error in your main config’s ‘modules’ array.

oops sorry boout that >.< ok i changed it but i get a different error now when i try to go to http://191.100.81.15/npstryko/index.php/rights:

"PHP Error

include(User.php) [<a href=‘function.include’>function.include</a>]: failed to open stream: No such file or directory

C:\wamp\www\yii-1.1.8.r3324\framework\YiiBase.php(421)

409 {

410 foreach(self::$_includePaths as $path)

411 {

412 $classFile=$path.DIRECTORY_SEPARATOR.$className.’.php’;

413 if(is_file($classFile))

414 {

415 include($classFile);

416 break;

417 }

418 }

419 }

420 else

421 include($className.’.php’);

422 }

423 else // class name with namespace in PHP 5.3

424 {

425 $namespace=str_replace(’\\’,’.’,ltrim($className,’\\’));

426 if(($path=self::getPathOfAlias($namespace))!==false)

427 include($path.’.php’);

428 else

429 return false;

430 }

431 return class_exists($className,false) || interface_exists($className,false);

432 }

433 return true;

Stack Trace

#0

  • C:\wamp\www\yii-1.1.8.r3324\framework\YiiBase.php(421): YiiBase::autoload()

#1

unknown(0): YiiBase::autoload("User")

#2

  • C:\wamp\www\yii-1.1.8.r3324\framework\db\ar\CActiveRecord.php(371): spl_autoload_call("User")

#3

– C:\wamp\www\npstryko\protected\modules\rights\components\RAuthorizer.php(295): CActiveRecord::model("User")

290

291 $criteria = new CDbCriteria();

292 $criteria->addInCondition(Rights::module()->userIdColumn, $userIdList);

293

294 $userClass = Rights::module()->userClass;

295 $users = CActiveRecord::model($userClass)->findAll($criteria);

296 $users = $this->attachUserBehavior($users);

297

298 $superusers = array();

299 foreach( $users as $user )

300 $superusers[] = $user->name;

#4

– C:\wamp\www\npstryko\protected\modules\rights\controllers\InstallController.php(61): RAuthorizer->getSuperusers()

56 ‘confirm’,

57 ‘run’,

58 ‘error’,

59 ‘ready’,

60 ),

61 ‘users’=>$this->_authorizer->getSuperusers(),

62 ),

63 array(‘deny’, // Deny all users

64 ‘users’=>array(’*’),

65 ),

66 );

#5

  • C:\wamp\www\yii-1.1.8.r3324\framework\web\CController.php(1143): InstallController->accessRules()

#6

  • C:\wamp\www\yii-1.1.8.r3324\framework\web\filters\CInlineFilter.php(59): CController->filterAccessControl(CFilterChain)

#7

  • C:\wamp\www\yii-1.1.8.r3324\framework\web\filters\CFilterChain.php(131): CInlineFilter->filter(CFilterChain)

#8

  • C:\wamp\www\yii-1.1.8.r3324\framework\web\CController.php(283): CFilterChain->run()

#9

  • C:\wamp\www\yii-1.1.8.r3324\framework\web\CController.php(257): CController->runActionWithFilters(CInlineAction, array("accessControl"))

#10

  • C:\wamp\www\yii-1.1.8.r3324\framework\web\CWebApplication.php(277): CController->run("")

#11

  • C:\wamp\www\yii-1.1.8.r3324\framework\web\CWebApplication.php(136): CWebApplication->runController("rights")

#12

  • C:\wamp\www\yii-1.1.8.r3324\framework\base\CApplication.php(158): CWebApplication->processRequest()

#13

– C:\wamp\www\npstryko\index.php(13): CApplication->run()

08 defined(‘YII_DEBUG’) or define(‘YII_DEBUG’,true);

09 // specify how many levels of call stack should be shown in each log message

10 defined(‘YII_TRACE_LEVEL’) or define(‘YII_TRACE_LEVEL’,3);

11

12 require_once($yii);

13 Yii::createWebApplication($config)->run();

2011-12-08 07:15:56 Apache/2.0.63 (Win32) Yii Framework/1.1.8"

You need to have a user table and a user model. This is all mentioned in the Rights documentation.

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

Hey skeef,

Sorry for overlooking your question. For the time being you can only achieve this by themeing Rights.

Hi Chris (and others)

I have installed this module on a fresh install of Yii but with the yii-user module also installed. When I run the installer I get the following:

Can anyone help here?

My config file is included 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'=>'sitename',


	// preloading 'log' component

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


	// autoloading model and component classes

	'import'=>array(

		'application.models.*',

		'application.components.*',

		'application.modules.user.models.*',

        'application.modules.user.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'=>'gfhfghfghfghgf',

		 	// If removed, Gii defaults to localhost only. Edit carefully to taste.

			'ipFilters'=>array('127.0.0.1','::1'),

		),

		'user',

		'rights'=>array(

			'install'=>true,					// Enables the installer for rights module.

		),

		/*'message' => array(

            'userModel' => 'User',

            'getNameMethod' => 'getFullName',

            'getSuggestMethod' => 'getSuggest',

        ),*/

	),


	// application components

	'components'=>array(

	

		'user'=>array(

			// enable cookie-based authentication

			'allowAutoLogin'=>true,

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

			'class'=>'RWebUser', 				// Allows super users access implicitly - used by rights module.

		),

		

		'authManager'=>array(

			'class'=>'RDbAuthManager',			// Provides support authorization item sorting.

		),

		

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

			'emulatePrepare' => true,

			'username' => 'dfgdfgfdgdf',

			'password' => 'fgfdgfdg',

			'charset' => 'utf8',

			'tablePrefix' => '',

		),

		

		'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'=>'webmaster@example.com',

	),

);

@pompey_pete: Try dropping the Rights database tables and running the installer again. That should help.

Hi, Chris!

Something I can not understand how to do it. If this is do not have too much trouble for you, could you please show a little example? I would be very grateful … :)

Thanks Chris, really like your work here. Yii is a better environment because of you!

Thanks. I’m glad you enjoy my work. :)

Maybe you should check out my other extensions as well. You can find links to them in my signature. :D

Hey skeef,

First, please read the Yii doc about theming here:

Theming and Skin

You can override Rights’ views by adding a rights folder under your theme’s views folder. Keep in mind that the files need to be named exactly the same as the originals for Yii to find your views.

I hope this helps.

Hi - I’m getting this error when I try to assign a role to a user:


CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`appointments_development`.`authassignment`, CONSTRAINT `authassignment_ibfk_1` FOREIGN KEY (`itemname`) REFERENCES `AuthItem` (`name`) ON DELETE CASCADE ON UPDATE CASCADE). The SQL statement executed was: INSERT INTO `AuthAssignment` (`itemname`, `userid`, `bizrule`, `data`) VALUES (:itemname, :userid, :bizrule, :data)

I’m using Rights 1.3.0

any thoughts?

Hello, maybe I don’t understand a logic… this is my problem.

I have a MessageController with actions "view", "create", "delete". I want to add a rule(?) "viewOwn" to check if the message selected is own.

viewOwn what will be? An operation? An item? T_T [color=#333333][font=arial, sans-serif][size=2]It[/size][/font][/color][color=#333333][font=arial, sans-serif][size=2] [/size][/font][/color][color=#333333][font=arial, sans-serif][size=2]who is to[/size][/font][/color][color=#333333][font=arial, sans-serif][size=2] [/size][/font][/color][color=#333333][font=arial, sans-serif][size=2]inherit and[/size][/font][/color][color=#333333][font=arial, sans-serif][size=2] [/size][/font][/color][color=#333333][font=arial, sans-serif][size=2]be inherited[/size][/font][/color][color=#333333][font=arial, sans-serif][size=2] [/size][/font][/color][color=#333333][font=arial, sans-serif][size=2]by whom[/size][/font][/color][color=#333333][font=arial, sans-serif][size=2]?[/size][/font][/color][color=#333333][font=arial, sans-serif][size=2] [/size][/font][/color][color=#333333][font=arial, sans-serif][size=2](The[/size][/font][/color][color=#333333][font=arial, sans-serif][size=2] [/size][/font][/color][color=#333333][font=arial, sans-serif][size=2]default rule[/size][/font][/color][color=#333333][font=arial, sans-serif][size=2] [/size][/font][/color][color=#333333][font=arial, sans-serif][size=2]is[/size][/font][/color][color=#333333][font=arial, sans-serif][size=2] [/size][/font][/color][color=#333333][font=arial, sans-serif][size=2]authenticated[/size][/font][/color][color=#333333][font=arial, sans-serif][size=2] [/size][/font][/color][color=#333333][font=arial, sans-serif][size=2]…[/size][/font][/color][color=#333333][font=arial, sans-serif][size=2])[/size][/font][/color]

You can look at the source of the Blog demo with Rights that you can download on the project page. In the blog you can check whether users have access to update their own posts.

Rights installed the userid column in AuthAssignment as varchar(64) which caused my Integrity constraint violation

when i changed userid to reflect the column type in my user table to INT(11) everything worked fine

Hi!

It is a great extension (thank you so much) but I have a problem:

Everything about auth is workin ok. But, everytime someone has no permission to access some place, Rights throws an CHttpException 403 (default and ok behavior) that is not ‘catched’, so that my screen shows:

It would be ok if was not showed in a BLANK screen, with no layout.

Where could I change the "error" page to be the default one (site/error) or how can I catch those exceptions?

Thank you again.

I’m having some trouble with business rules. I have a “Company” model and am trying to restrict access to a given Company to its “Owner”. I have a “Company.View” operation setup with the Rights module but it doesn’t seem to be picking up my “$params” parameter in checkAcess.

This is my business rule:

return yii::app()->user->id==$params["company"]->owner->id;

And this is my code in "CompanyController.php":


	public function actionView($id)

	{

		$model=$this->loadModel($id);

		$params = array('company'=>$model);


		if(Yii::app()->user->checkAccess('Company.View',$params))

		{

			$this->render('view',array(

				'model'=>$model,

			));

		}

	}



any help?

Ok, fixed:

All I have done was add ‘error’ to function allowedActions() in Controller.

Thanks anyway.

hi … i know it’s the holidays … just wondering if anyone has thoughts on my business rules issue i posted a couple of days ago … is the “$params” argument actually passed through when using checkAccess with Rights?

thanks!