Skip to content

Commit

Permalink
Merge pull request #73 from SilbinaryWolf/fix-securitytoken
Browse files Browse the repository at this point in the history
fix(SecurityID): Change FileAttachmentField to get SecurityID from the relative <form>
  • Loading branch information
Aaron Carlino authored Mar 23, 2017
2 parents 2d117c6 + 0b47afa commit 733b1bf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
6 changes: 1 addition & 5 deletions code/FileAttachmentField.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,6 @@ protected function defineFieldHolderRequirements() {
$this->imagesOnly();
}
}

if($token = $this->getForm()->getSecurityToken()) {
$this->addParam($token->getName(), $token->getSecurityID());
}
}

/**
Expand Down Expand Up @@ -1180,7 +1176,7 @@ public function getConfigJSON() {
}
}

$data['params'] = $this->params;
$data['params'] = ($this->params) ? $this->params : null;
$data['thumbnailsDir'] = $this->ThumbnailsDir();
$data['thumbnailWidth'] = $this->getSelectedThumbnailWidth();
$data['thumbnailHeight'] = $this->getSelectedThumbnailHeight();
Expand Down
14 changes: 14 additions & 0 deletions javascript/file_attachment_field.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ var UploadInterface = function (node, backend) {
this.settings = JSON.parse(node.getAttribute('data-config'));
this.node = node;
this.droppedFiles = [];
if (!this.settings.params) {
this.settings.params = {};
}

if (!this.settings.params.SecurityID) {
var formNode = this.node;
do {
formNode = formNode.parentNode;
} while (formNode && formNode.tagName !== 'FORM' && formNode.nodeType !== 11);
var securityIDNode = formNode.querySelector("input[name=\"SecurityID\"]");
if (securityIDNode) {
this.settings.params.SecurityID = securityIDNode.value;
}
}

if(template) {
this.settings.previewTemplate = template.innerHTML;
Expand Down

0 comments on commit 733b1bf

Please sign in to comment.