Jump to:

10851 Posts in 2517 Topics by 1793 members

All other Modules

SilverStripe Forums » All other Modules » Secure Files: securing personal files

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2 3
Go to End
Author Topic: 2450 Views
  • Cano
    Avatar
    Community Member
    14 Posts

    Re: Secure Files: securing personal files Link to this post

    Thanks very much for getting back to me, I have added in another closing bracket that seemed to be throwing a spanner in the works so the code now shows,

    $result->push(new ArrayData(array('Folder' => $folder['Folder'], $files => $files)));

    I am now getting the following error message,

    [User Error] Bad class to singleton() - Files
    GET /silverstripe/investor-login/investor-area/

    Line 334 in C:\wamp\www\silverstripe\sapphire\core\Core.php
    Source

    325 *
    326 * @param string $className
    327 * @return Object
    328 */
    329 function singleton($className) {
    330    global $_SINGLETONS;
    331    if(!isset($className)) user_error("singleton() Called without a class", E_USER_ERROR);
    332    if(!is_string($className)) user_error("singleton() passed bad class_name: " . var_export($className,true), E_USER_ERROR);
    333    if(!isset($_SINGLETONS[$className])) {
    334     if(!class_exists($className)) user_error("Bad class to singleton() - $className", E_USER_ERROR);
    335       $_SINGLETONS[$className] = Object::strong_create($className,null, true);
    336       if(!$_SINGLETONS[$className]) user_error("singleton() Unknown class '$className'", E_USER_ERROR);
    337    }
    338    return $_SINGLETONS[$className];
    339 }
    340

    Trace

    * Bad class to singleton() - Files
    Line 334 of Core.php
    * singleton(Files)
    Line 2714 of DataObject.php
    * DataObject::get(Files)
    Line 22 of InvestorPage.php
    * InvestorPage->getFilesUserCanAccess()
    * call_user_func_array(Array,Array)
    Line 693 of Object.php
    * Object->__call(getFilesUserCanAccess,Array)
    * InvestorPage_Controller->getFilesUserCanAccess()
    Line 112 of ViewableData.php
    * ViewableData->__get(FilesUserCanAccess)
    Line 371 of ViewableData.php
    * ViewableData->obj(FilesUserCanAccess)
    Line 6 of .cacheC..wamp.www.silverstripe.themes.Vitruvian.templates.Layout.InvestorPage.ss
    * include(C:\WINDOWS\Temp\silverstripe-cacheC--wamp-www-silverstripe\.cacheC..wamp.www.silverstripe.themes.Vitruvian.templates.Layout.InvestorPage.ss)
    Line 420 of SSViewer.php
    * SSViewer->process(InvestorPage_Controller,Zend_Cache_Frontend_Output)
    Line 411 of SSViewer.php
    * SSViewer->process(InvestorPage_Controller)
    Line 202 of Controller.php
    * Controller->handleAction(SS_HTTPRequest)
    Line 137 of RequestHandler.php
    * RequestHandler->handleRequest(SS_HTTPRequest)
    Line 147 of Controller.php
    * Controller->handleRequest(SS_HTTPRequest)
    Line 199 of ContentController.php
    * ContentController->handleRequest(SS_HTTPRequest)
    Line 184 of ContentController.php
    * ContentController->handleRequest(SS_HTTPRequest)
    Line 67 of ModelAsController.php
    * ModelAsController->handleRequest(SS_HTTPRequest)
    Line 281 of Director.php
    * Director::handleRequest(SS_HTTPRequest,Session)
    Line 124 of Director.php
    * Director::direct(/investor-login/investor-area/)
    Line 127 of main.php


    Any thoughts on the problem?

    I really do appreciate your help with this, sorry to keep coming back with fresh problems! (I'm midway through a Lynda course on PHP and im diving in at the deepend here!) However, once i get this sorted, it will be somthing i can use again and again, and hopefully understand how/why im gettign these errors!

    Cano.

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Secure Files: securing personal files Link to this post

    Yep, that's an easy one. The following line is incorrect:

    $files = DataObject::get('Files');

    There is no "Files" object, only "File" objects.

  • Digital-Punk.co.uk
    Avatar
    Community Member
    51 Posts

    Re: Secure Files: securing personal files Link to this post

    Hi Hamish

    I'm using this code to get secured files and display on the frontend:

    function getViewableFiles() {
              $files = new DataObjectSet();
              $folders = DataObject::get('Folder');
              if(!$folders) return $files;
              foreach($folders as $folder)
                   if(!$folder->Secured && !$folder->InheritSecured())
                   continue;
                    if($folder->CanView())
                       if($subFiles = DataObject::get('File', "ClassName != 'Folder' && ParentID = {$folder->ID}"))
                   $files->merge($subFiles);
              return $files; // Should contain all files that the member can view.
          }

    But I have an issue with this code as it is grabbing only last created folder by ID. It means, if I have 2 different users with 2 separated folders, only one user will see files, because I'm getting only one folder. Where could be a problem?

    Best regards
    Digital Punk

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Secure Files: securing personal files Link to this post

    You seem to be missing braces after the foreach loop. Probably the cause of your problem because it's looping through every folder before moving to the CanView check - so only the last folder in the set gets analysed.

  • Cano
    Avatar
    Community Member
    14 Posts

    Re: Secure Files: securing personal files Link to this post

    Hamish = Legend.

    Thanks for helping out Silverstripe beginners, you're an asset to it's uptake.

  • Digital-Punk.co.uk
    Avatar
    Community Member
    51 Posts

    Re: Secure Files: securing personal files Link to this post

    To Hamish

    Thanks for your point! It helped to finalize solution.

    Best regards
    Digital Punk

    2450 Views
Page: 1 2 3
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.