[EXTENSION] Rights

I had a deeper look into rights and it seems it can (almost) work out of the box, when you dont use the same actions name in controllers that have the same name in backend and frontend.

Example:

controllers/back/FooController

controllers/front/FooController

Authitems can be generated for:

Foo.* (losing global rules because this is ambiguous)

Foo.admin (where actionAdmin is only definied in back)

Foo.show (where actionShow is only definied in front)

In order to generate items for back and front I had to change following method in RGenerator to:




	protected function getControllersInPath($path)

	{

		$controllers = array();


		if( file_exists($path)===true )

		{

			$controllerDirectory = scandir($path);

			foreach( $controllerDirectory as $entry )

			{

				if( $entry{0}!=='.' )

				{

					$entryPath = $path.DIRECTORY_SEPARATOR.$entry;

					if( strpos(strtolower($entry), 'controller')!==false )

					{

						$name = substr($entry, 0, -14);

						$controllers[ strtolower($entryPath)] = array( //CHANGED THIS LINE

							'name'=>$name,

							'file'=>$entry,

							'path'=>$entryPath,

						);

					}


					if( is_dir($entryPath)===true )

						foreach( $this->getControllersInPath($entryPath) as $controllerName=>$controller )

							$controllers[ $controllerName ] = $controller;

				}

			}

		}


		return $controllers;

	}



hi I’m assigning operations to task (MyTask) like this:


$auth_manager->addItemChild($parent_name, $child_name);

// $parent_name = 'MyTask'



in a for loop. I’m creating operations and next I’m assigning them to MyTask (install action) and revoking them and removing (uninstall action). Sometimes the assignment isn’t displayed properly in the Tasks list view. The operations whitch I’ve assigned to MyTask are displayed like they haven’t been assigned. After I’ve entered MyTask from Tasks list view to whitch I’ve assigned operations they are visible in the Children list and after switching back to the Tasks view everything looks ok. This situation is very rare but it is possible.

And one more question is there a way to do a checkAccess before redirecting based on something like this "controller/action"? For example:


if(Yii::app()->user->checkAccess(Yii::app()->user->returnUrl))

{

$this->redirect(Yii::app()->user->returnUrl);

}


else

{

$this->redirect('defaultURL');

}

I have a question about guests…

In the permissions module, you can set specific permissions for Guest users that are inherited to normal users and upwards.

However, it doesn’t work. A guest user does not have the permission to do that specific action. My current solution is to set the allowedActions() function in the controller, but I should be able to just set the right permissions I think?

Does anyone have a solution?

I too had the same issue and edited the rights code to fit with my requirement. Anyway you can generate controller actions for rights by commenting rights module checking part in getControllersInModules function in RGenarater.php. Don`t know is there any good way to doing it.

Modyfying the Rights code isn’t the best way because you have to remember to make same changes in future release of Rights - if you will be updating the module :).

Rights access is restricted for superusers and it’s fine. This way u can control access to the module for specific users. If you want to let a user access Rights just assign Superuser role to that user.

You can also take a look on yii-user module there’s a similar functionality - only users that have “Superuser” property set to “Yes” can create new users.

There’s no need to fix something that doesn’t need fixing I think ;).

Have you set this:


'authManager'=>array(

...

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

),

in the app main.php config file? If so try to set permission like this:


XYZController.*

assign it to Guest role and check if this works.

I managed to solve my problem by making some modifications to the source code. Now the extension works much faster!

I would suggest it was evaluated the possibility of incorporating the next official release.

Attached is the patch.

Exactly changing Rights code is not a good practice.But I want to give rights module access to end user except some actions such as "controller action generator", "permission deletion" etc…(these actions are related to developer and no need for end user). Let me know is there any way to do this without changing the code.

Thanks

Thanks, this is the solution!

Shouldn’t this be in the manual as well?

It’s mentioned here: authManager in “Using Default Roles” section.

Cheers

Perhaps this will do the job for you:

  1. Create a task called e.g. "View rights"

  2. Create operations that user should be able to access

  3. Assign created operations to "View rights" task

  4. Assign task to user.

Sometimes there’s no way to avoid code changing but I think that will work without modifying Rights code.

Hi!

How to use business rules to allow access only to records not published yet.

I tried to create a function in news–>models:

public function isPublished()


{


	return $this->published;


}

And in business rules:

return !News::model()->isPublished();

yii-1.1.5.r2654

yii-rights-1.3.0.r147

yii-user-0.3-r107

Thanks and congratulation for Rights!

maamarcos

was the same problem - look http://www.yiiframework.com/forum/index.php?/topic/13337-yii-user-with-rights/page__view__findpost__p__124047

i want to use business rules in module yii-rights, so i create such rule


return yii::app()->user->id==$params['record_id'];

but how can i pass parameter $params into this rule?

if i use manual cheching i can use such code


    $params=array('record_id'=>$id);

    if(Yii::app()->user->checkAccess('updateOwnPost',$params))

    {

        // update post

    } 

but how can i do such in module?

Hi!

After install Rights, I can't upload files (pictures, PDFs and DOCs) anymore.





Maybe some Models or Controllers don't have access permission for upload.





Is it an issue?

Hi everyone !

I would like to do search function like is in the User Management module but actually I don’t know how to start with it in “Rights Module”.

Search function is in User model and looks like this:


public function search($cr=0)

    {

        // Warning: Please modify the following code to remove attributes that

        // should not be searched.


        $criteria=new CDbCriteria;

        

        $criteria->compare('user_id',$this->user_id);

        $criteria->compare('username',$this->username,true);

        $criteria->compare('user_password',$this->user_password);

        $criteria->compare('user_email',$this->user_email,true);

        $criteria->compare('user_regdate',$this->user_regdate);

        $criteria->compare('user_lastvisit',$this->user_lastvisit);

        $criteria->compare('superuser',$this->superuser);

        $criteria->compare('user_active',$this->user_active);


        return new CActiveDataProvider(get_class($this), array(

            'criteria'=>$criteria,

        	'pagination'=>array(

		 'pageSize'=>Yii::app()->getModule('user')->user_page_size,

			),

        ));

    }

It’s using a model and then return dataprovider

In rights CGridView is used RAssignmentDataProvider stright away.

I’ve got a lot of users and search function would be really usefull for me.

Thanks

Chris, thank You for the great work!

There is a little problem: Unfortunately, when translating(particularly to Russian) phrases Assign and Revoke on different pages have the opposite meaning. How can I use icons instead of words. In addition, the icons are much visually and use less space on the screen.

Thanks and good luck

Hi All,

I’m searching for the same thing.

Tried this:

www.yiiframework.com/wiki/232/using-filters-with-cgridview-and-carraydataprovider/

link

But I hit the same problem using RAssignmentDataProvider and UserModel->search at the same time,

and I cant find a way to include a search filter in RAssignmentDataProvider.

How can this be done?

Hi,

I am new to Yii and especially to using its extensions. rights seems quite promising and I also managed to set it up. However I also need a blog for my project and just saw that there is a bundle with rights + blog. But I don’t really get these 2 working together. In the documentation PDF is also just a guide how to set up rights on its own and not with a blog.

Can anyone tell me what steps I have to do additionally, so I can use blog + rights?

Hi Tropi,

This is what I did:


class BlogModule extends CWebModule

{

	public function init()

	{

		// this method is called when the module is being created

		// you may place code here to customize the module or the application


				

				

		// import the module-level models and components

		$this->setImport(array(

			'blog.models.*',

			'blog.components.*',

			

			// for rights module

        	'application.modules.rights.*', 

   			'application.modules.rights.components.*',   

		));

		

	}

and then each of your controllers:

eg.


class SiteController extends Controller

{

	public $layout='column1';


	

	public function filters()

	{

		return array(

			'rights',

		);

	}