Forums / Developer / Access an object containing a file, but not the file itself.

Access an object containing a file, but not the file itself.

Author Message

Atle Pedersen

Thursday 04 January 2007 5:29:57 am

Hello!

A customer needs to upload files. The name and information about the files should be visible to all users, including anonymous users. However, it is required to log in before being allowed to download one of the uploaded files. That means I need partial access to an object. Or I need to allow reading of the object, men not downloading of files.

Is there a mechanism that allows this in eZ?

-----

I haven't been able to find one, so I went about making an extension with a new module containing a fetch function, thinking that the access restrictions were on module level. The function is very simple and looks like this:

  function get_Attrib( $nodeID ){
    $rootNode = eZContentObjectTreeNode::fetch( $nodeID);
    if ($rootNode===null) return false;
    $list =& $rootNode->subTree( );
    if ( $list === null ) return false;
    return array( 'result' => &$list );
  }

Even though I've granted all users full access to my new module including this function, it seems that the fetch function is still limited by the restrictions set for the content module. Am I doing something wrong, or is this a bug/feature?

Claudia Kosny

Thursday 04 January 2007 1:37:26 pm

Hi Atle

If you want to fetch a subtree no matter the permissions, you need add a parameter array(Limitation => array()) to the subtree function. Have a look at the code ofeZContentObjectTreeNode::subtree for clarification.

If you are not adverse to a bit of kernel hacking, you could try to change the module.php in kernel/content. Change the value of functions in the variable $ViewList['download'] to e.g 'my_download'. In the functionList below copy the entry for $FunctionList['read'] and change the key to 'my_download'. Now you can set the permissions for access to the download view the way you want. Please note that I have never tried this for the download, so test this first and keep a backup of the original module.php!

Claudia

Atle Pedersen

Friday 05 January 2007 5:41:21 am

Thank you Claudia, you give valuable help. My extension now works as required.

Betsy Gamrat

Saturday 20 January 2007 9:06:46 pm

Different idea:

Use a template to check if the user is logged in, and allow only authorized users to download the files.

eZ debug

Timing: Jan 31 2025 01:36:09
Script start
Timing: Jan 31 2025 01:36:09
Module start 'content'
Timing: Jan 31 2025 01:36:09
Module end 'content'
Timing: Jan 31 2025 01:36:09
Script end

Main resources:

Total runtime0.2018 sec
Peak memory usage8,192.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0086 589.3203370.2578
Module start 'content' 0.00870.0132 959.57811,005.6563
Module end 'content' 0.02190.1799 1,965.23443,894.8359
Script end 0.2018  5,860.0703 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00522.5644200.0003
Check MTime0.00150.7244200.0001
Mysql Total
Database connection0.00070.352810.0007
Mysqli_queries0.102150.57111410.0007
Looping result0.00140.69311390.0000
Template Total0.179388.810.1793
Template load0.00090.455810.0009
Template processing0.178488.373010.1784
Override
Cache load0.00060.304710.0006
Sytem overhead
Fetch class attribute can translate value0.00160.776910.0016
XML
Image XML parsing0.00020.121410.0002
General
dbfile0.00723.5573200.0004
String conversion0.00000.004630.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.0002 secs