[EXTENSION] Rights

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)

can anyone help me??

i have an error like this :

whats the solution??

sorry to my bad english. .

thanks before. …

Hi,

Thanks for your work in this module, it was very good when integrating in my projects.

Currently, we have upgraded to Yii v1.1.13, and we found the rights unable to use.

Previously we use Yii v1.1.12.

Please help to solve this problem, thanks a lot!

Hello, I’m having some issues with Rights.

Ok, so the authentication simply does not work. I realised that if I change the values of userid column in the authassignment table from user id to user name it will work…

Dear all

First of all thank you Chris for "rights" and users contributing in this forum to let people use it at best! need help, want to know the missing part in yii rights module implementation.

  • module successfully installed (both user & rights)

  • removed access rules from main controller

  • can view the panel with option

    Assignments

    Permissions

    Roles

    Tasks

    Operations

  • created roles, assigned to user.

for example: sub admin to create users, assigned that to newly created user.

  • the new user is not working with assigned rights.

Whats the missing step?

Thanks in Advance.

How do you manage to edit the userid column and set its value to 1 can you write the mysql code. for this.

Hi Chris

I have this error on my installation can you help me out on this please.

Anyone is much appreciated.

[b]

[/b]

Error 403

[color=#555555][font=Arial, Helvetica, sans-serif]There must be at least one superuser![/font][/color][color=#555555][font=Arial, Helvetica, sans-serif]

[/font][/color][color=#555555][font=Arial, Helvetica, sans-serif]Best Regards.[/font][/color]

I’m using phpmyAdmin ;)

I have a problem, please help me.

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 (demo.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)

it’s after adding assign item to roles.

Hello. I installed yii-rights, which created 4 db tables: AuthAssignment, AuthItem, AuthItemChild, Rights. First 3 dbtables: AuthAssignment, AuthItem, AuthItemChild are populated with data, but last table: Rights is always blank. Is this normal situation?

Thanks for reply

Tom

I have two Controllers

1.CustomercareController

2.ReportsController

And i have created some new role for account to reports and ccare to customercare.

Images are attached.

Problem:-

When logged in with Accountant i can access all the controller actions of both controllers.

Is there anything i have to change in Controllers?

OR should do some change in business rules.

Please guide me what i missed.

SOLVED:- Forgot to apply filters in controllers. and extend RController.

[size="3"][center]How to install the Rights without error 403![/center][/size]

  1. First of all, you must configure authentication using a database. You must configure the creation, deletion user using the database, as well as the login to the site. The users table must be named ‘users’.

I use a table users like this:


CREATE TABLE IF NOT EXISTS `users` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `login` varchar(50) NOT NULL,

  `pass` varchar(50) NOT NULL,

  `email` varchar(32) NOT NULL,

  `lang` varchar(2) NOT NULL DEFAULT '',

  `rememberme` int(1) NOT NULL DEFAULT '0',

  `regdate` datetime NOT NULL,

  `last_update` datetime NOT NULL,

  `last_comin` datetime NOT NULL,

  `active` int(1) NOT NULL,

  PRIMARY KEY (`id`)

) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

  1. Create a user with the username ‘admin’. His id should be 1 (id=1)

Install the Rights.

  1. Unpack the archive in protected/modules/rights

  2. Correct the config/main

in Import section:


'import'=>array(


'application.modules.rights.*',

'application.modules.rights.components.*',   // Correct paths if necessary. 

),

in Components section:


'components'=>array(


'user'=>array(

'class'=>'RWebUser',      // Allows super users access implicitly.

//'defaultRoles'=>'Guest',

),



in authManager section:


'authManager'=>array(

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


),

in modules section:


'modules'=>array(

		'rights' => array (

				'superuserName' => 'SuperAdmin',

				'authenticatedName' => 'Authenticated',

				'userClass' => 'Users',

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

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

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

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

				'displayDescription' => true, // Whether to use item description instead of name.

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

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

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

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

				'appLayout' => 'webroot.themes.office.views.layouts.main', // Application layout.

				//'appLayout' => 'application.modules.admin.views.layouts.main', // Application layout.

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


			'install' => false,

		),

),



  1. Make sure that

'install' => true,

  1. Entering a site under the ‘admin’ account

  2. Call mysite/index.php?r=rights or mysite/index.php/rights.

Get:

Congratulations! Rights has been installed succesfully…

or not … ;))

If you are use ‘login’ field in the table ‘users’ as I am, but not the field ‘name’ as conceived by the author,

You get famous Error 403 There must be at least one superuser!.

You have two ways:

1. Use a table ‘users’ like this


CREATE TABLE IF NOT EXISTS `users` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `user` varchar(50) NOT NULL,

  `pass` varchar(50) NOT NULL,

  `email` varchar(32) NOT NULL,

  `lang` varchar(2) NOT NULL DEFAULT '',

  `rememberme` int(1) NOT NULL DEFAULT '0',

  `regdate` datetime NOT NULL,

  `last_update` datetime NOT NULL,

  `last_comin` datetime NOT NULL,

  `active` int(1) NOT NULL,

  PRIMARY KEY (`id`)

) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

and run again.

2. Make such magical passes:

2.1. in components/RAuthorizer.php, around line 300, change


$superusers[] = $user->name;

to


$superusers[] = $user->{Rights::module()->userNameColumn};

2.2. in /protected/components/UserIdentity.php add lines:


$this->username = $rec->login;

$this->setState( 'userlogin', $rec->login );

$this->setState( 'name', $rec->name );

(my rquest is: $rec = Users::model()->findByAttributes( array ( ‘login’ => $this->username ) ); )

2.3. ALTER TABLE users ADD name VARCHAR( 64 ) NULL AFTER login;

2.4. Assign the "admin" value to the "name" field

2.5. Entering under the username ‘admin’ and call mysite/index.php?r=rights или mysite/index.php/rights

Get:

Congratulations! …

Now we return everything back

2.6. Delete the line


$this->setState( 'userlogin', $rec->login ); 

in /protected/components/UserIdentity.php

2.7. ALTER TABLE users DROP name

2.8. Set


'install' => false,

in config/main


And finally,

It is also important that the names of the tables had such this: (note the capital letters)

AuthAssignment, AuthItem, AuthItemChild and Rights

Regards, guys