Forums / Developer / eZContentObject::checkAccess strangeness

eZContentObject::checkAccess strangeness

Author Message

Bruce Morrison

Tuesday 23 November 2010 11:16:32 pm

Hi all

I'm working on some code that needs to identify if a particular user has edit access to a eZContentObject and have been running some tests using eZContentObject::checkAccess.

I found some strange code at the end of this method that modifies the result after the polices have been checked:

if ( $access == 'denied' )
{
    if ( $functionName == 'edit' )
    {
     // Check if we have 'create' access under the main parent
         if ( $this->attribute( 'current_version' ) == 1 && !$this->attribute( 'status' ) )
        {
             $mainNode = eZNodeAssignment::fetchForObject($this->attribute( 'id' ), $this->attribute( 'current_version' ) );
             $parentObj = $mainNode[0]->attribute('parent_contentobject' );
             $result = $parentObj->checkAccess( 'create',$this->attribute( 'contentclass_id' ),
                                                $parentObj->attribute( 'contentclass_id' ), false, $originalLanguage );
              if ( $result )              {
                 $access = 'allowed';
             }
              return $result;
         }
    }
}

This is my interpretation:

If a user doesn't have edit access to the object and the current version = 1 and the object has a status of draft then
If the user can create an object of the same type under the same node then user can edit that object.

Can anyone let me know why/if this code is required?

Cheers
Bruce

P.S. It would also be great if the method could take a additional parameter $user that defaulted to false. The method could check if it was a eZUser type and use it or get the current user if not. This would make is a lot more flexible :)

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Nicolas Pastorino

Wednesday 24 November 2010 5:17:59 am

"

 

if ( $access == 'denied' )
{
    if ( $functionName == 'edit' )
    {
     // Check if we have 'create' access under the main parent
         if ( $this->attribute( 'current_version' ) == 1 && !$this->attribute( 'status' ) )
        {
             $mainNode = eZNodeAssignment::fetchForObject($this->attribute( 'id' ), $this->attribute( 'current_version' ) );
             $parentObj = $mainNode[0]->attribute('parent_contentobject' );
             $result = $parentObj->checkAccess( 'create',$this->attribute( 'contentclass_id' ),
                                                $parentObj->attribute( 'contentclass_id' ), false, $originalLanguage );
              if ( $result )              {
                 $access = 'allowed';
             }
              return $result;
         }
    }
}

This is my interpretation:

If a user doesn't have edit access to the object and the current version = 1 and the object has a status of draft then
If the user can create an object of the same type under the same node then user can edit that object.

Can anyone let me know why/if this code is required?

"

Hi Bruce !

From the comment in the code, reading through it several times, and knowing that the 'edit' and 'create' functions of the 'content' module were often confusing, here is what i would understand :
If a user is trying to edit an object in its first version (ie : create a new one) and was denied access to the the 'edit' function, transform the access check into : "is she allowed to create an object of the given content class at this place in the content tree ?" and bubble-up the result. We are talking about object creation only here.

"

P.S. It would also be great if the method could take a additional parameter $user that defaulted to false. The method could check if it was a eZUser type and use it or get the current user if not. This would make is a lot more flexible

"

Yup, 100% agree here. Could you file this there : http://issues.ez.no/ezpublish ?

Cheers !

--
Nicolas Pastorino
Director Community - eZ
Member of the Community Project Board

eZ Publish Community on twitter: http://twitter.com/ezcommunity

t : http://twitter.com/jeanvoye
G+ : http://plus.tl/jeanvoye

Bruce Morrison

Wednesday 24 November 2010 3:40:13 pm

Hi Nicolas

Thanks for the input. The issue is that you can get a false positive from this code. If you have 2 policies

  1. Create Article
  2. Edit Article if you are owner

and there is an article, version 1 and in draft mode. Then checking if the user can edit will return true even in the user is not the owner of the object. (Policy 1 overrides 2)

This isn't an issue with the normal operation of eZ as editing via the admin interface uses eZContentObjectVersion::checkAccess which checks status & ownership before the policies.

The issue I have is that you can't rely on eZContentObject::checkAccess or eZContentObject::canEdit to determine if a user can edit an object.

It seems this is a "hack" to get around having to have both a create & edit policy to allow object creation. (i.e. create = create + edit version 1).

I can't decide if this is a feature or a bug. Given the situation where the false positive can occur I'm starting to think this is a bug. Any one else want to weigh in?

Cheers
Bruce

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

eZ debug

Timing: Jan 29 2025 13:37:54
Script start
Timing: Jan 29 2025 13:37:54
Module start 'content'
Timing: Jan 29 2025 13:37:54
Module end 'content'
Timing: Jan 29 2025 13:37:54
Script end

Main resources:

Total runtime0.2620 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0085 588.0469180.8359
Module start 'content' 0.00860.0051 768.8828102.9609
Module end 'content' 0.01370.2482 871.8438533.3594
Script end 0.2619  1,405.2031 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00341.3099200.0002
Check MTime0.00120.4688200.0001
Mysql Total
Database connection0.00090.351910.0009
Mysqli_queries0.216182.46731410.0015
Looping result0.00130.50591390.0000
Template Total0.247994.610.2479
Template load0.00090.327210.0009
Template processing0.247094.285210.2470
Override
Cache load0.00060.221810.0006
Sytem overhead
Fetch class attribute can translate value0.00070.253010.0007
XML
Image XML parsing0.00030.096610.0003
General
dbfile0.00401.5103200.0002
String conversion0.00000.001830.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs