[EXTENSION] Rights

You must extends your default controller Controller to RController, enable the filters on the controller

public function filters() { 


	


	return array(


		'rights'


	);


	


}

set the default roles on your config file like

	'authManager'=>array(


		'class'=>'RDbAuthManager',


		'connectionID'=>'db',


		'defaultRoles'=>array('Guest'),


	),

then you need to create the permissions on the rights module.

Remenber that the admin account has full access to the rights module.

Hi folks. I just started to work with rbac and I’m still learning. So sorry the dumb questions.

Scenario:

I have a portlet with a lot of links to controllers actions. I can toggle the visibility of links by checking the access to that controller action like

Yii::app()->user->checkAccess(‘Controller.Action’).

It’s working fine. But some users won’t have access to the portlet. I know i can create a new task or operation to define whatever the user will see the portlet. (I know my client wont be able to do this.) I dealing with a lot o portlets and I need to check if the user has access to some controller/action and if yes render the portlet otherwise no.

So how can I check if the user has access to one permission?

Check if any link has permission and then render portlet.

My problem is: I have created operation called Admin.Default.*.

Everything works fine with Admin module Default controller all actions.

However, when I check for access result is FALSE.


Yii::app()->user->checkAccess('Admin.Default.Index')

There is nothing special, because checking for access is very simple (name must be the same). Sample from RDbAuthManager:




public function getAuthItem($name, $allowCaching=true)

	{

		// Get all items if necessary and cache them.

		if( $allowCaching && $this->_items===array() )

			$this->_items = $this->getAuthItems();


		// Get the items from cache if possible.

		if( $allowCaching && isset($this->_items[ $name ]) )

		{

			return $this->_items[ $name ];

		}

		// Attempt to get the item.

		else if( ($item = parent::getAuthItem($name))!==null )

		{

			return $item;

		}


		// Item does not exist.

		return null;

	}



Is there any easy way to solve my problem without creating new operations?

Also I think this feature should be implemented in following Rights releases, because now there is no consistency between RightsFilter and checkAccess checking . First one supports ‘*’, second not.

Thanks in advance.

I’m not sure if I understand what you mean but if you add the other operations under Admin.Default as children to your Admin.Default.* operation it will work.

Yes, it will. But if I don’t create and add these child operations it won’t, however RightsFilter will work correctly. So this is what I am trying to tell, that behaviour of these two is not the same. Shouldn’t it be identical?

Oh now I see what you mean.

The thing with that is that Rights doesn’t alter the implementation of the web user checkAccess except that it returns true implicitly if the user is a super user. Of course I could add the functionality your requested but it would affect the performance of checkAccess which I’d be very careful with.

Somehow I completely broke everything.

I have a role named "Developer." If I edit "Developer" in the Rules system under Rights, Developer has rights to "User.Admin".

User "TestDev" is assigned the role "Developer."

If I log in as TestDev and attempt to load /user/admin I’m given a 403.

In UserController.php, I have:




	public function filters()

	{

		return array(

			'rights',

		);

	}

My understanding is: If I’m logged in as a user (TestDev) who has been given a role (Developer) which has a task assigned to it (User.Admin), and I go to a controller’s method (/user/admin) which is tied with the task assigned, I’ll have permission to do that task, OTHERWISE I get a 403.

I’m so toasted on this code, been working on it all day and simply can’t look anymore. Highly possible I skimmed right over my solution in this thread as well trying to track it down. Am I just misunderstanding how roles go together, or have I broken something listed above, or is there somewhere else I should be looking where I might have introduced the bug?

regarding ‘Undefined variable: permissions’ error.

MySQL 5.5 no longer supports create table … TYPE innodb;

type apparently was deprecated since mysql 4;

use create table… ENGINE desired_engine;

so, modify ‘rights/components/RInstaller.php’ and change type to engine;

after that, it should install

Hello slybaby,

Next version of Rights installer doesn’t specify an engine anymore so this should not be a problem.

Thanks for reporting this problem nevertheless.

Hi,

i use the latest version r142.

I defined ‘userIdColumn’ to my id (autoincrement integer ) of my useraccount table and

‘userNameColumn’ to username. Rights work, but everbody have access to rights-module and can

change permissions. if i change userIdColumn also to username all works as expected, only admins

have access to rights module.

The problem is in RAuthorizer in function getSuperusers: with an id column defined an empty array

will be returned and the accessControllFilter for the admin will therefore allways fire.

So what is the userIdColumn used for? Or may be its a bug?!

Greetings from Germany.

me23

Thank you for replying.

Admin account has full access. And the Admin role.

I see there is an Admin role that cannot be modified.

How can I assign this role to other roles?

For instance I want to make a role Developer and this role be allowed access to Rights module.

I thought I can make the Admin role a child of Developer, but Admin role doesn’t show in Add Child dropdown.

Hey me23,

I have to look into this, I haven’t encountered it before but I created an issue on GC about it.

I’ll report back when I know more.

Thanks for reporting this.

Hey again slybaby,

The superuser role always lies on the top of the authorization hierarchy and cannot be assigned as a child to another authorization item. The correct approach is to give your developers the superuser role if they absolutely need to access Rights.

I understand.

I still think it would be better if a predefined role (who cannot be deleted) with permissions to access Rights could be attributed to other roles. And I think it should not be named Admin, as this is too generic (Admin for Rights, Admin for Users, Admin for the developed system) - maybe AdminRights, or something.

Just my 2 cents.

On another note, about translation:

Could you allow ‘Rights’ to be translated in views? I mean, instead:




<?php $this->breadcrumbs = array(

	'Rights'=>Rights::getBaseUrl(),

	Rights::t('core', 'Permissions'),

); ?>



you could do:




<?php $this->breadcrumbs = array(

	Rights::t('core', 'Rights')=>Rights::getBaseUrl(),

	Rights::t('core', 'Permissions'),

); ?>



In a similar note, I have attached the translations for Rights (1248

core.php
) in Romanian(ro). Hope they are ok.

tablePrefix I need… or php file authmanager

but I don’t know how to do like that .

Hey All & Chris,

First of all Chris, this is really great. I tried lot of other extensions and I shortlisted this in one of my SaaS projects. I am relatively new to Yii, so I really need a help on my proposed implementation.

SuperAdmin (SaaS site owner)

[indent]Admin_1 (Tenant)[/indent]

[indent][indent]Manager Role[/indent][/indent]

[indent][indent]Team Lead Role[/indent][/indent]

[indent][indent][indent]Xyz Task[/indent][/indent][/indent]

[indent][indent][indent][indent]Operation 1[/indent][/indent][/indent][/indent]

[indent]Admin_2[/indent]

[indent][indent]CEO[/indent][/indent]

[indent][indent][indent]Ceo’s Tasks[/indent][/indent][/indent]

How about I keep track/set context for my user? So, if I belong to “Admin_1”, my checkAccess method should check only for permissions only for “Admin_1” hierarchy.

Some help would be really great.

Thanks

Please tell me how to implement a registration? Or suppose a share yii-user (extension yii-user)?

hi chris,

thanks for your extensions…

how can i modify the /authItem/permissions interface??

i want to add filter to the CGridview,.

i want to add filter to Item column with dropdownlist of my controller list,

for example : dropdownlist(‘Site’,‘Post’,‘Comment’),

if I choose ‘Post’ then will show ‘Post.*’,‘Post.index’,‘Post.create’,‘Post.update’ to assign to each role.

so i can assign permissions easily,because i have many controller ,

it will be nice if i can filter and assign permissions per controller…

guys can you help me to modify it?

thanks chris & all

Hey ressaince,

You could modify the RPermissionDataProvider to support this functionality.

When you’re done please show me what you did and maybe I could include something similar in future versions.