eZ Community » Forums » Developer » How to check that the user can read...
expandshrink

How to check that the user can read some content node? (in custom php-moudule)

How to check that the user can read some content node? (in custom php-moudule)

Monday 26 September 2011 6:42:15 pm - 4 replies

In my custom php-script I have two variables: the user object and the content object.

I need to know can this user read the object or not...

There is a method to check access for the current user: http://pubsvn.ez.no/doxygen/4.0/html/ezcontentobject_8php_source.html#l03630

But how can I check the same for any users? And how to use checkAccess results correctly?

NB: on my site many limitation roles/policies are used... (sections, subtrees etc., different user groups)

Monday 26 September 2011 8:09:45 pm

Hi,

how do you fetch the contentobject?

You wont be able to fetch it if you don't have access to it will you?

Tuesday 27 September 2011 8:41:56 am

>how do you fetch the contentobject?

My class extends the eZWorkflowEventType class.

The script is running after publishing some content objects and ObjectID is a parameter

 $object  = eZContentObject::fetch( $parameters['object_id'] );

So $current_user object is not a $user object that I need to check blunk.gif Emoticon BTW $current_user is an admin big-smile.gif Emoticon

Tuesday 27 September 2011 11:24:53 am

If your user is an admin, he can do and see everything. Nothing to check.

Tuesday 27 September 2011 12:00:04 pm

If your user is an admin, he can do and see everything. Nothing to check.

My user is an admin, but I need to check an access for another user(s)

For my project I copy the eZContentObject::checkAccess metod to my class and rewrite the code.

But my suggestion is to add UserID (contentobject_id) as parameter for the original eZContentObject::checkAccess function and fetch any user instead of the current user (if UserID is not empty)

Maybe is a good idea to use

if $UserID !== false
    $user =eZUser::fetch( $UserID );
else
    $user = eZUser::currentUser();

instead of

$user = eZUser::currentUser();

http://pubsvn.ez.no/doxygen/4.0/h...ontentobject_8php_source.html#l03633

Modified on Tuesday 27 September 2011 12:01:51 pm by Sergiy Gedeon

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from