Jump to:

23379 Posts in 18298 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » Control Permissions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 751 Views
  • cumquat
    Avatar
    Community Member
    191 Posts

    Control Permissions Link to this post

    Ok i'm sure this is simple, my head is fried so please be gentle. All i want to do is if a user is in group x then show a form/item on a page as well as the rest of the content if they aren't then just the content gets shown. Seems simple enough and probably is, i just don't seem to be able to get it to work. I'm using 2.4.5 and the code i'm using is below, the form is $UploadForm.

    Cheers

    Mick

    <div class="typography">
       <% if Menu(2) %>
          <% include SideBar %>
          <div id="Content">
       <% end_if %>
          <% if Level(2) %>
              <% include BreadCrumbs %>
          <% end_if %>
             $Content
                <% control CurrentMember %>
                   <% if inGroup(3) %>
                      $UploadForm
                   <% end_if %>
                <% end_control %>   
                <table id="Filelist">
             <thead>
          <tr>
          <th>File</th>
          <th>Last Updated</th>
       </tr>
             </thead>
                      <% control FilesInFolder(Uploads/Secure/SOP) %>
             <tbody>
          <tr >
       <td><a href="$URL">$Name</a></td>
       <td>$LastEdited</td>
    </tr>
              <% end_control %>
          </tbody>
          </table>
       <% if Menu(2) %>
          </div>
       <% end_if %>
    </div>

  • martimiz
    Avatar
    Forum Moderator
    1068 Posts

    Re: Control Permissions Link to this post

    Looks like you're doing it right: the code-snippet below should work - that is: if you are currently logged on to the group that has ID = 3, and if $UploadForm does in fact shows a form, and if the template was flushed after adding the code (tested it just now in 2.4.5):

    <% control CurrentMember %>
       <% if inGroup(3) %>
          $UploadForm
       <% end_if %>
    <% end_control %>

    Maybe test this by adding a bit of text, like

       <% if inGroup(3) %>   
          Show upload form: <br />
          $UploadForm
       ...

  • cumquat
    Avatar
    Community Member
    191 Posts

    Re: Control Permissions Link to this post

    Thanks for the response, the form is there when i don't have the control in place but the moment i add the control it refuses to appear, i added the snippet and that shows so obviously the code was right it's just something to do with the form not wanting to appear when in that control. The form is shown below, all i want is to have a file upload on a page. Sorry missed a bit out of the code. I'm sure it has to be to do with the form even though it works with out the control, the form code is 'adapted' from one somewhere else and only seems to work with that blank fieldset in which leads me to believe its probably wrong.

    public function UploadForm() {
          
          $form = new Form (
             $this,
             "UploadForm",
             new FieldSet (
                $Attachment = new FileUploadField('Attachment','Upload a PDF or Doc file')
             )
    new FieldSet ( )
    );
          $Attachment->setFileTypes(array(
             'pdf',
             'doc'
          ));
          $Attachment->setUploadFolder("Uploads/Secure/SOP");
          return $form;
          }

  • martimiz
    Avatar
    Forum Moderator
    1068 Posts

    Re: Control Permissions Link to this post

    Ah... I'm thinking again!

    $UploadForm wouldn't work within the control, since UploadForm() is a Page method, not a Member method. So within the control you should probably use something like $Top.UploadForm...

  • cumquat
    Avatar
    Community Member
    191 Posts

    Re: Control Permissions Link to this post

    You sir, are a star!!!!

    Man i was going mental here trying to find a way/hack to get this to work.

    Thanks again

    Mick

    751 Views
Page: 1
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.