Uploaded image for project: '{RETIRED} XWiki Enterprise'
  1. {RETIRED} XWiki Enterprise
  2. XE-1169

Add target attachment document support to XWiki.AttachmentSelector macro



    • keywords:
      attachmentSelector patch
    • Pull Request Status:
      Awaiting Committer feedback
    • Similar issues:


      I've added support to the attachmentSelector macro by adding a new macro parameter 'targetdocname'.

      Pull req: https://github.com/xwiki/xwiki-enterprise/pull/20

      When you specify the targetdocname as a different page, the macro will list/save/delete attachments from that document, instead of the current document.

      The current document will still receive the attachment name in the specified property as normal.
      The property will still only receive the attachment filename, and not the target document name.
      Eg. Filename.jpg, not TargetPage@Filename.jpg

      If you have custom view sheets, you will have to adjust your code to include the targetdocname as well as the propertyname to display an image / create a link.

      Users that can edit the current document that contains the macro, will either:

      a) Get an access denied message if they don't have the 'view' permission on the target documen, and 'choose an attachment' button will be hidden.
      b) 'Choose an attachment' button, and see all the attachments with 'view' on target document
      c) All of b) plus upload form is displayed if they have 'edit' permission on that target document.

      Hopefully you can include this as a enhancement.

      I've tested this on XE 3.5 and it works quite nicely, allowing you to adjust the permission on the target page to prevent users from downloading/displaying certain attachments.

      Example usage in XWiki class sheet:

      ## You can modify this page to customize the presentation of your object.
      ## At first you should keep the default presentation and just save the document.
      #set($class = $doc.getObject('Sandbox.TestClass').xWikiClass)
       ; image attachment test
       : {{attachmentSelector targetdocname="Sandbox.TestPage1" classname="Sandbox.TestClass" property="imagename" savemode="form" filter="jpg,png" displayImage="true" width="300" link="true"/}}
       ; file attachment test
       : {{attachmentSelector classname="Sandbox.TestClass" property="planname" savemode="form" filter="zip" displayImage="false" link="true"/}}




            sdumitriu Sergiu Dumitriu
            jamiem Jamie Maher
            0 Vote for this issue
            2 Start watching this issue


              Date of First Response: