[EXTENSION] Rights

hi,

i used following code in modules/rights/views/layouts/main.php


<?php $this->beginContent('application.views.layouts.main'); ?>

as you said.its showing just default theme of yii.but i am using this theme.can you help in this.Rights should work in the theme that i mentioned.

Q1 : How to show the user’s role at user grid view?

Description : I’m using user and rights extension. I would like to show the user’s role at grid view of user/admin. and filter by user’s role. How can I?

this is my view


$this->widget('zii.widgets.grid.CGridView', array(

    	'id'=>'user-grid',

    	'dataProvider'=>$model->search(),

    	'filter'=>$model,

    	'columns'=>array(

    		array(

    			'name' => 'username',

    			'type'=>'raw',

    			'value' => 'CHtml::link(UHtml::markSearch($data,"username"),array("admin/view","id"=>$data->id))',

    		),

    		array(

    			'name'=>'email',

    			'type'=>'raw',

    			'value'=>'CHtml::link(UHtml::markSearch($data,"email"), "mailto:".$data->email)',

    		),

    		'create_at',

    		'lastvisit_at',

    		array(

    			'name'=>'status',

    			'value'=>'User::itemAlias("UserStatus",$data->status)',

    			'filter' => User::itemAlias("UserStatus"),

    		),

    		array(

    			'class'=>'CButtonColumn',

    		),

    	),

    ));

This is my controller


public function actionIndex()

    	{

    		$rasdataProvider = new RAssignmentDataProvider();

    		$dataProvider=new CActiveDataProvider('User', array(

    			'criteria'=>array(

    		        'condition'=>'status>'.User::STATUS_BANNED,

    		    ),

    				

    			'pagination'=>array(

    				'pageSize'=>Yii::app()->controller->module->user_page_size,

    			),

    		));

    

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

    			'dataProvider'=>$dataProvider,

    			'rasdataProvider'=>$rasdataProvider,

    		));

    	}

This is the relation of user.php


public function relations()

    	{

            $relations = Yii::app()->getModule('user')->relations;

            if (!isset($relations['profile']))

                $relations['profile'] = array(self::HAS_ONE, 'Profile', 'user_id');

            return $relations;

    	}

Q2 : How to check the user is logging in or not?

Q3: If the user is already logged in, the system do not allow same user. How can I do? I’m using rights and user modules.

Regards

T

Hi Chris83,

everything work fine for me with your extension but a new registered user doesn’t get the authenticated role assigned automatically (i set the default role as guest too)…so, about your issue, i don’t really understand where i should put this code in the user controller!

instead i modify RegistrationController action method here :




if ($model->save()) {

							

        $authenticatedName = Rights::module()->authenticatedName;

        Rights::assign($authenticatedName, $model->id);

        ...                                            



there is also an orphelin row in the authassignment table when the user is deleted, so i follow rob on this issue (cannot put the link :frowning: …) :

code.google.com/p/yii-rights/issues/detail?id=33

Thanks

Hi,

I’ve installed the rights extension even thou it gave me a 403 error. But i cannot access the module at mysite.com/rights

It issues a 403 error saying:

You are not authorized to perform this action.

The call stack for this exception is:


exception 'CHttpException' with message 'You are not authorized to perform this action.' in /var/www/vhosts/mywebsite.com/httpdocs/test/framework/web/auth/CAccessControlFilter.php:170

Stack trace:

#0 /var/www/vhosts/mywebsite.com/httpdocs/test/framework/web/auth/CAccessControlFilter.php(133): CAccessControlFilter->accessDenied(Object(RWebUser), 'You are not aut...')

#1 /var/www/vhosts/mywebsite.com/httpdocs/test/framework/web/filters/CFilter.php(39): CAccessControlFilter->preFilter(Object(CFilterChain))

#2 /var/www/vhosts/mywebsite.com/httpdocs/test/framework/web/CController.php(1146): CFilter->filter(Object(CFilterChain))

#3 /var/www/vhosts/mywebsite.com/httpdocs/test/framework/web/filters/CInlineFilter.php(59): CController->filterAccessControl(Object(CFilterChain))

#4 /var/www/vhosts/mywebsite.com/httpdocs/test/framework/web/filters/CFilterChain.php(131): CInlineFilter->filter(Object(CFilterChain))

#5 /var/www/vhosts/mywebsite.com/httpdocs/test/framework/web/CController.php(292): CFilterChain->run()

#6 /var/www/vhosts/mywebsite.com/httpdocs/test/framework/web/CController.php(266): CController->runActionWithFilters(Object(CInlineAction), Array)

#7 /var/www/vhosts/mywebsite.com/httpdocs/test/framework/web/CWebApplication.php(283): CController->run('')

#8 /var/www/vhosts/mywebsite.com/httpdocs/test/framework/web/CWebApplication.php(142): CWebApplication->runController('rights')

#9 /var/www/vhosts/mywebsite.com/httpdocs/test/framework/base/CApplication.php(162): CWebApplication->processRequest()

#10 /var/www/vhosts/mywebsite.com/httpdocs/test/index.php(14): CApplication->run()

#11 {main}

REQUEST_URI=/test/rights

---

I’m logged in as username “admin” with a user id equal to 1. In the AuthAssignment table there’s default entry fro Admin and userid = 1

Any clues?

I’ve managed to solve the problem. My UserIdentity component had stored the wrong variable in its $username and $_id members :)

Problem: Getting 403 you are not authorized error when trying to access: mydomain.com/index.php?r=rights

I have downloaded the rights module and following the yii-rights-doc-1.2.0 installation instructions.

Prior to installing rights, I have created some Rbac table structures and populated with some roles and permissions. (for reference, the sql create data included below)

My rights config is as follows: (a bit puzzled as to why ‘installed’ appears twice in this array?):

As you can see, my main super user role below is ‘chadmin’ … which is an item in my AuthItem table




        //rights, see p. 5 of yii-rights-doc-1.2.0

        'rights' => array(

            'superuserName' => 'chadmin',

            'authenticatedName'=>null,

//            'userIdColumn'=>'id',

            'userNameColumn'=>'first_name',

//            'enableBizRule'=>true,

//            'enableBizRuleData'=>false,

//            'displayDescription'=>true,

//            'flashSuccessKey'=>'RightsSuccess',

//            'flashErrorKey'=>'RightsError',

            'install'=>true,

//            'baseUrl'=>'/rights',

//            'layout'=>'rights.views.layouts.main',

//            'appLayout'=>'application.views.layouts.main',

//            'cssFile'=>'rights.css',

            'install'=>true,

//            'debug'=>true,

        ),



Sorry for this big one:

Any help on how to solve this / even where to start looking would be greatly appreciated.

Thanks

gvanto

why repeat twice


"install"=>true

line ? Only one …

Hi,

first of all thanks for sharing this module with us.

i have installed it and is working fine, but i have a problem changing the language.

The framework is recognizing the new language, pt_br, i have already create a folder in messages/pt_br with the translations.

But done all this in Rights it still using the default language.

Do you know any way to solve this problem, or i’m missing something i my configuration?

Thanks for your support.

best regards

You can use this:

	'rights'=&gt;array(


		'install'=&gt;false,


		'appLayout'=&gt;'[b]//layouts/main[/b]'


	),

please help me i think i lost track from scratch. i want to use this module for administration end

include(D:\wamp\www\app2\protected\modules\rights\components\RightsWebUser.php) [<a href=‘function.include’>function.include</a>]: failed to open stream: No such file or directory

be sure that your directories are readable by the apache process owner.

This is how it appears in the documentation … ? (I wondered about this myself)

Another thing I am unclear about is the authenticatedName - what is this?

"name of the role assigned to authenticated users"

-> but I have different roles? How can this be in the configuration section for Rights?

more Questions:

If there’s already a tbl_authassignments table which contains user<->role definitions, what is the purpose of the tbl_rights table?

when going to index.php/rights I get this message

Error 403

There must be at least one superuser!

The admin is the superuser. I’m not sure why I’m getting this error.

@cwhite: we could not help you without more informations about your config …

Hi Guys,

First off, Chris this module is fantastic.

I thought I would share a small alteration I made to the RGenerator Class, and apologies if someone has already done this, to account for external actions.

I added a function to instantiate the controller and return all declared external actions.




        /**

         * Returns a list of external actions

         * @param array $cInfo - controller information

         * @return array

         */

        protected function getExternalActions(array $cInfo)

        {

                require_once $cInfo['path'];

                $controllerName = ucfirst($cInfo['name']) . 'Controller';

                $controller = new $controllerName('');

                $actions = array();

                foreach(array_keys($controller->actions()) as $action)

                {

                        $actions[ strtolower($action) ] = array(

						'name'=>  ucfirst($action),

					);

                }

                return $actions;

        }



Then called it in the getControllerActions function as shown bellow.




public function getControllerActions($items=null)

	{

		if( $items===null )

			$items = $this->getAllControllers();


		foreach( $items['controllers'] as $controllerName=>$controller )

		{       

                        $actions = $this->getExternalActions($controller);  // change this line                      

			$file = fopen($controller['path'], 'r');

			$lineNumber = 0;

			while( feof($file)===false )

			{

				++$lineNumber;

				$line = fgets($file);

				preg_match('/public[ \t]+function[ \t]+action([A-Z]{1}[a-zA-Z0-9]+)[ \t]*\(/', $line, $matches);

				if( $matches!==array() )

				{

					$name = $matches[1];

					$actions[ strtolower($name) ] = array(

						'name'=>$name,

						'line'=>$lineNumber

					);

				}

			}


			$items['controllers'][ $controllerName ]['actions'] = $actions;

		}


		foreach( $items['modules'] as $moduleName=>$module )

			$items['modules'][ $moduleName ] = $this->getControllerActions($module);


		return $items;

	}



Now all external actions are listed.

Cheers

Ben

Hi all!

I have question :

How to config to mutilple user use rights?

Like : Admin -> admin role 1 -> create many role and role 1 can’t see admin role 2 and user in role 2

         -&gt; admin role 2 -&gt; create many role

hi friends after instaling the Rights module whan i want to access it, following error is accour. Error 403

There must be at least one superuser!

plz tell me how to fix it.

thanks in advance.

[solved]

in my authassignment table userid column value is not same as in user table.

hi Chris83

[size="4"]i am using this but no value is in return[/size]

in my authassignment table itemname column have the ‘AssignedTask.Admin’ value for the following user but no value in return.

here is code demo .





array('label'=>'Assign Tasks', 'url'=>array('/AssignedTask/admin'),'visible'=> Yii::app()->user->checkAccess('AssignedTask.Admin'),




plz tell me how can i solve it.

fix bug in rights/components/RAuthorizer.php -> public function getSuperusers()




foreach( $users as $user) 

	$superusers[] = $user->name;



to




$colname=Rights::module()->userNameColumn;

foreach($users as $user)

	$superusers[] = $user->$colname;



In the last received a new error:


Fatal error: [] operator not supported for strings in D:\OpenServer\domains\ffi\_fw\collections\CMap.php on line 291

After analysis of the code found that error in the getUniqueRoles() (RInstaller).

Solution: in configuration (main.php)




		'authManager' => array (

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

			'defaultRoles'=>'Guest',


		),

comment or delete this:


'defaultRoles'=>'Guest',

(My server: Apache-2.2.23, PHP-5.4.10, MySQL-5.1.67)