Chris83
(Cniska)
July 28, 2010, 11:21am
10
joeysantiago:
Hello,
sorry for bothering you…
i freshly installed Yii and tried to add the rights module… this is my main.php file:
when i try to go to http://digitaldealer.wdev.wedoo.local/index.php?r=rights i get this:
can you please help me out?
should i add a user model… how? thanks a lot
(removed code from quote.)
Hello joeysantiago,
Seems that you haven’t configured your authManager, you can do that by adding the following code to your component configuration:
'authManager'=>array(
'class'=>'CDbAuthManager',
'connectionID'=>'db', // as in your database configuraiton
),
Let me know if this helps.
As a side note, you should remove or comment out the sqlite-configuration.
Chris83:
(removed code from quote.)
Hello joeysantiago,
Seems that you haven’t configured your authManager, you can do that by adding the following code to your component configuration:
'authManager'=>array(
'class'=>'CDbAuthManager',
'connectionID'=>'db', // as in your database configuraiton
),
Let me know if this helps.
As a side note, you should remove or comment out the sqlite-configuration.
Helo!
Hope everything’s ok in Helsinki. love that city.
anyhow:
i set up the DB connection and added the code you gave me under components array (hope it’s right!). now i get this error:
PHP Error
Description
YiiBase::include(User.php) [<a href='yiibase.include'>yiibase.include</a>]: failed to open stream: No such file or directory
Source File
/home/digitaldealer/public_html/www/framework/YiiBase.php(338)
00326: * @param string class name
00327: * @return boolean whether the class has been loaded successfully
00328: */
00329: public static function autoload($className)
00330: {
00331: // use include so that the error PHP file may appear
00332: if(isset(self::$_coreClasses[$className]))
00333: include(YII_PATH.self::$_coreClasses[$className]);
00334: else if(isset(self::$_classes[$className]))
00335: include(self::$_classes[$className]);
00336: else
00337: {
00338: include($className.'.php');
00339: return class_exists($className,false) || interface_exists($className,false);
00340: }
00341: return true;
00342: }
00343:
00344: /**
00345: * Writes a trace message.
00346: * This method will only log a message when the application is in debug mode.
00347: * @param string message to be logged
00348: * @param string category of the message
00349: * @see log
00350: */
Stack Trace
#0 /home/digitaldealer/public_html/www/framework/YiiBase.php(338): autoload()
#1 unknown(0): autoload()
#2 unknown(0): spl_autoload_call()
#3 /home/digitaldealer/public_html/www/protected/modules/rights/components/RightsAuthorizer.php(549): class_exists()
#4 /home/digitaldealer/public_html/www/framework/base/CComponent.php(152): RightsAuthorizer->setUser()
#5 /home/digitaldealer/public_html/www/protected/modules/rights/RightsModule.php(77): RightsAuthorizer->__set()
#6 /home/digitaldealer/public_html/www/framework/base/CModule.php(73): RightsModule->init()
#7 /home/digitaldealer/public_html/www/framework/YiiBase.php(194): RightsModule->__construct()
#8 /home/digitaldealer/public_html/www/framework/base/CModule.php(258): createComponent()
#9 /home/digitaldealer/public_html/www/framework/web/CWebApplication.php(379): CWebApplication->getModule()
#10 /home/digitaldealer/public_html/www/framework/web/CWebApplication.php(318): CWebApplication->createController()
#11 /home/digitaldealer/public_html/www/framework/web/CWebApplication.php(121): CWebApplication->runController()
#12 /home/digitaldealer/public_html/www/framework/base/CApplication.php(135): CWebApplication->processRequest()
#13 /home/digitaldealer/public_html/www/index.php(13): CWebApplication->run()
2010-07-28 14:42:01 Apache/2.2.9 (Debian) Yii Framework/1.1.3
kiitos paljon!
well, toivottavasti got it. hope it’s the right way.
created a User table on my db:
CREATE TABLE `yii_digitaldealer`.`User` (
`idUser` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`username` VARCHAR( 120 ) NOT NULL ,
`email` VARCHAR( 240 ) NOT NULL ,
`password` VARCHAR( 40 ) NOT NULL
) ENGINE = MYISAM
then in my folder through ssh i set up the User model:
php yiic shell config/main.php
model User
crud User
now it goes… is it the right way?
Chris83
(Cniska)
July 28, 2010, 4:04pm
12
Yes that’s the correct way of doing it.
It’s now mentioned in the docs that an User model is required to run this module.
I’ve also added the schema for the user table in the schema.sql found under data. It will be included in future releases.
So now it’s working fine?
edwaa
(Edo)
July 29, 2010, 4:18am
13
Chris83,
I think I followed the directions correctly in the PDF but things weren’t working. To get things to work I had to import all of these files:
'import'=>array(
...
'application.modules.rights.components.Rights',
'application.modules.rights.components.RightsBaseController',
'application.modules.rights.components.RightsFilter',
'application.modules.rights.components.RightsWebUser',
),
…and the documentation says to just import:
'import'=>array(
...
'application.modules.rights.components.RightsWebUser',
),
Any idea what I’m doing wrong?
Chris83:
Yes that’s the correct way of doing it.
It’s now mentioned in the docs that an User model is required to run this module.
I’ve also added the schema for the user table in the schema.sql found under data. It will be included in future releases.
So now it’s working fine?
kiitoksia! nyt se toimii hyvin!
in the docs it said that creating a webapp with yii command it would have run, so i didn’t think about it. Anyhow, thanks a lot, this extension’s great.
@edwaa : in my main.php i wrote:
'import'=>array(
'application.modules.rights.components.*'
),
and it goes smoothly…
greetings
i’m translating the module. In order to have the label for Auth Item translated in the user form i had to change the code of models/AssignmentForm.php:
public function attributeLabels()
{
return array(
'authItem' => Yii::t('RightsModule.tr', 'Auth Item'),
);
}
and in file controllers/AssignmentController.php
'buttons'=>array(
'submit'=>array(
'type'=>'submit',
'label'=>Yii::t('RightsModule.tr', 'Assign'),
),
),
now looks like everything’s translated
Ok, now that it works, i’m trying to use it learning curves are funny
i figured out that in my controllers i have to extend RightsBaseController…
ex:
class PostController extends RightsBaseController
{
public function filters()
{
return array(
'rights',
);
}
ok… now how can i check permissions? i created an Operation called PostController_actionCreate (tried also PostController_Create) and assigned it to a user (fredo). but when logged in with this user i navigate to http://digitaldealer.wdev.wedoo.local/index.php?r=post/create it says "You are not authorized to perform this action."…
what’s the matter? when i’ll get it, i promise you a beer (i’ll be in Helsinki in August!)
thanks a lot
Chris83
(Cniska)
July 29, 2010, 10:54pm
17
joeysantiago:
Ok, now that it works, i’m trying to use it learning curves are funny
i figured out that in my controllers i have to extend RightsBaseController…
ok… now how can i check permissions? i created an Operation called PostController_actionCreate (tried also PostController_Create) and assigned it to a user (fredo). but when logged in with this user i navigate to http://digitaldealer.wdev.wedoo.local/index.php?r=post/create it says "You are not authorized to perform this action."…
what’s the matter? when i’ll get it, i promise you a beer (i’ll be in Helsinki in August!)
thanks a lot
(removed code from quote.)
Hello joeysantiago,
The naming policy is the following: Post_Create (if the controller is PostController and the action is actionCreate()).
This is thoroughly documented in the doc, read the section about ACAC and see if that helps to understand how it works.
quangle
(Quanglv)
July 30, 2010, 3:20am
18
Hi Chris,
For instance I have 10 Controllers and each Controller has about 10 Actions.
Controller always has some same Actions like: Index, View, Create, Delete,…
I think I could make task *_Index or *_View for all Controllers that have Index or View action.
What you say?
Chris83:
(removed code from quote.)
Hello joeysantiago,
The naming policy is the following: Post_Create (if the controller is PostController and the action is actionCreate()).
This is thoroughly documented in the doc, read the section about ACAC and see if that helps to understand how it works.
Sorry… the problem was my server kind of cached operations and assignements… i restarted apache2 for other stuff and now magically everything works.
i attached the italian translation… were my yesterday’s findings ok?
thanks a lot,
federico
PS: in my main php i set
'modules'=>array(
'rights'=>array(
//'install'=>true, // Remove this row after running the module the first time.
'superUserRole'=>'Admin', // Only an example, this is the default value.
'defaultRoles'=>array('Guest'), // Only an example, this is the default value.
'superUsers'=>array(
1=>'admin',
),
),
),
is ‘admin’ user’s username? i feel quite dumb… i tried to assign superUser to my username, but it doesn’t work…
thanks
quangle
(Quanglv)
July 30, 2010, 3:14pm
20
What are difference between Operations and Tasks?
I create a role as below but it doesn’t work:
Name: Authorized_User
Description: authorized user
Bizrule: return Yii::app()->user->id
Controller:
public function filters() {
return array( 'rights', );
}
public function accessRules() {
return array('index', 'view', 'create', 'update', 'delete', 'admin', 'topAuthors', 'articles', 'setdefault');
}
I assigned Authorized_User has ability to Create new author.
Hope i understood it well:
a task is a set of operations. I think about them as something like:
task (name = "forum management"){
operation (name = "create posts"),
operation (name = "update posts"),
operation (name = "delete posts"),
}
hope it helps!
Chris83
(Cniska)
July 31, 2010, 2:58pm
22
quangle:
What are difference between Operations and Tasks?
I create a role as below but it doesn’t work:
Name: Authorized_User
Description: authorized user
Bizrule: return Yii::app()->user->id
Controller:
public function filters() {
return array( 'rights', );
}
public function accessRules() {
return array('index', 'view', 'create', 'update', 'delete', 'admin', 'topAuthors', 'articles', 'setdefault');
}
I assigned Authorized_User has ability to Create new author.
Hello quangle,
You don’t need the Yii’s accessControl-method if you don’t use the accessControl-filter.
Also, in normal cases like yours, you don’t need to set any business rules.
Please read the “Role-Based Access Control”-section in Yii’s guide to Authentication and Authorization here:
http://www.yiiframework.com/doc/guide/topics.auth
Chris83
(Cniska)
July 31, 2010, 7:09pm
23
Version 0.9.7 is now available.
New features are:
Flash messages
Support for module nesting
Sorting of authorization items
Hover functionality for the tables
Improved Installer
German translation (thanks g3ck0)
Italian translation (thanks joeysantiago)
I did a major code review during which I improved the code quality a bunch and even rewrote almost all comments. The overall quality of the module’s source code should now be pretty good.
The module documentation has also been updated and can be found at:
http://yii-rights.googlecode.com/files/yii-rights-doc.0.9.7.pdf
Enjoy!
Chris83
(Cniska)
August 1, 2010, 12:25pm
24
quangle:
Hi Chris,
For instance I have 10 Controllers and each Controller has about 10 Actions.
Controller always has some same Actions like: Index, View, Create, Delete,…
I think I could make task *_Index or *_View for all Controllers that have Index or View action.
What you say?
Hello quangle,
This is an interesting idea but it could result in a potential security risk and would you really want to assign all index and view actions to one role/user instead of assigning them separately?
I could think of making a operation for accessing all actions within a controller, but I’m not sure that is needed either. What do you think?
speedster
(Mkarazeev)
August 4, 2010, 4:45pm
25
Hi,
Maybe I’m doing something wrong, but installer fails with error Property “CDbAuthManager.itemWeightTable” is not defined.
And I’ve searched for this in google, no luck… Could tell me what am I doing wrong?
Chris83
(Cniska)
August 4, 2010, 5:43pm
26
speedster:
Hi,
Maybe I’m doing something wrong, but installer fails with error Property “CDbAuthManager.itemWeightTable” is not defined.
And I’ve searched for this in google, no luck… Could tell me what am I doing wrong?
Hello speedster,
As noted on the project page there is an error in the documentation. Please change your authManager to use the class RightsAuthManager and it should work. I’ve already corrected this in the documentation and it will be corrected in the next version.
Chris83
(Cniska)
August 5, 2010, 1:49am
27
Version 0.9.8 is now available.
New features are:
Authorization item generator
Automated installer
Improved support for module nesting
Sorting of all types of authorization items
I’ve been working pretty hard on getting it ready so I hope it work well. In case you happen to find a bug please report it on google code. The authorization item generator should be of assistance when installing the module so that you don’t need to create all the items for the filter by hand.
The generator can be accessed from:
rights/setup/generate
The documentation has again been updated and can be found at:
http://yii-rights.googlecode.com/files/yii-rights-doc.0.9.8.pdf
Enjoy!
Great job, Chris!
I love the generator feature! It will save a lot of time to set up the whole access control.
I am very new to yii and I am trying to do something as bellow:
I have a button that calls to a action. Instead of user going to the page display the decline message, I try to hide the button from displaying.
e.g. on Post/Admin page, every record has "View", "Edit", "Delete" buttons. If user has no permission to "Edit", then this user can not see the "Edit" button at all.
I’m not sure how can it be done normally, but this is just my thought. Maybe there can be a API that returns true or false value, like:
Yii::app()->rights->isPermit
Or references of other approaches or tutorials will be highly appreciated.
Thanks again for your great effort.
Jun
Chris83
(Cniska)
August 5, 2010, 10:14am
29
Great job, Chris!
I love the generator feature! It will save a lot of time to set up the whole access control.
I am very new to yii and I am trying to do something as bellow:
I have a button that calls to a action. Instead of user going to the page display the decline message, I try to hide the button from displaying.
e.g. on Post/Admin page, every record has "View", "Edit", "Delete" buttons. If user has no permission to "Edit", then this user can not see the "Edit" button at all.
I’m not sure how can it be done normally, but this is just my thought. Maybe there can be a API that returns true or false value, like:
Yii::app()->rights->isPermit
Or references of other approaches or tutorials will be highly appreciated.
Thanks again for your great effort.
Jun
We actually have that built in Yii’s access control.
With CMenu you can use:
'visible'=>Yii::app()->user->checkAccess('User.View')
or then you can of course put the link in an if-clause with a call to checkAccess.
You can read more about the checkAccess-method here:
http://www.yiiframework.com/doc/guide/topics.auth
If you wish to see how to use checkAccess in practice check out Yii’s blog demo with Rights which can be downloaded at:
http://yii-rights.googlecode.com/files/yii-blog-with-rights-0.9.8.r56.zip
Hopefully this helps.