Yii 1.1: Troubleshooting Rights Extension

15 followers

Rights is one of user interface for Yii's Role Base Access Control extension. It is one of most downloaded extensions in Yii's Web.

Sometime developers might encounter errors or incomprehensive messages from Rights while implementing it. While there is a thread dedicated to solve the Rights problems, but because it already grown to big, I decide to collect common problems with their solutions into one wiki so it will be easier for everyone to check.

Things Need to Check First

  • UserIdentity class has been override to return user id instead username.
  • Make sure you have given CREATE TABLE access to the database user that are going to connect the Web App with the database. Rights needs to create table on first install.
  • Make sure you have signed in as superuser or admin before running Rights instalation.
  • You need a model named User. If you have a user table but with another name, change the Rights configuration
'rights'=>array(
    'userClass' => 'AnotherName',
),
  • The user table MUST NOT contain field named "name" or it will conflict with Rights
  • If you inherit CWebUser, make sure the class doesn't have a method named "getName()"

Troubleshoot

Problem

Need to change the table name for the sake of consistency

Solutions

Add the code to 'authManager' in the Yii configuration files:

'authManager' => array(
    'class' => 'RDbAuthManager',
    'assignmentTable' => 'authassignment',
    'itemTable' => 'authitem',
    'itemChildTable' => 'authitemchild',
    'rightsTable' => 'rights',
),

Problem

Got message: Filter "rights" is invalid. Controller "XyzController" does not have the filter method "filterrights"."

Solution

You must extend the controller class from RController. The easiest way is change the code at /protected/components/Controller.php

class Controller extends RController

Problem

Got message: "Property "CWebApplication.rights" is not defined."

Solution

It seems you have forgot to include "rights" in the Yii's module configuration. Please consult to documentation.


Problem

The Guest seems like not working.

Solution

Add following setting to the Yii configuration file:

'authManager' => array(
    'class'=>'RDbAuthManager',
    'defaultRoles'=>array('Guest'),
),

Total 6 comments

#18172 report it
cappadochian at 2014/09/19 11:03am
There must be at least one superuser!

There must be at least one superuser!

this happened to me, I could fix it by following a suggestion to delete all rights related db tables, create them once again, and then install rights (.../rights/install depending on your route config) once again.

hope this helps somebody out.

#15585 report it
Fire at 2013/11/26 09:49am
Managed to install yii-rights

Hi there,

I managed to install it by following a post on the yii-forums - here is a permalink to my post:

http://www.yiiframework.com/forum/index.php/topic/10556-extension-rights/page__view__findpost__p__229721

#12919 report it
Nur Rochim at 2013/04/20 11:05am
Error Assignments

I just tried my ext rights and succeed in the installation process. But when I choose the Assignments errors like this:

(sorry to my bad english. . )

CDbCommand failed to execute the SQL statement: SQLSTATE[42883]: Undefined function: 7 ERROR: operator does not exist: character varying = integer
LINE 5: WHERE userid=1
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.. The SQL statement executed was: SELECT name,t1.type,description,t1.bizrule,t1.data,weight
FROM authitem t1
LEFT JOIN authassignment t2 ON name=t2.itemname
LEFT JOIN rights t3 ON name=t3.itemname
WHERE userid=:userid
ORDER BY t1.type DESC, weight ASC
#12868 report it
Joemaxwell at 2013/04/17 02:02am
There must be at least one superuser!

Error 403

There must be at least one superuser!

Can someone give a hint on this one, anyone much appreciated.

#11309 report it
haseeb2k9 at 2013/01/05 04:39am
Error 403 There must be at least one superuser!

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.

#8579 report it
mohamadaliakbari at 2012/06/12 01:59pm
Very useful

Very useful Troubleshooting...

also its in documentation but in end of file:

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

Leave a comment

Please to leave your comment.

Write new article
  • Written by: junxiong
  • Category: Tips
  • Yii Version: 1.1
  • Votes: +8
  • Viewed: 18,216 times
  • Created on: Jan 3, 2012
  • Last updated: Jan 5, 2012
  • Tags: extension, Rights, RBAC