Skip to content

Commit

Permalink
Merge pull request #23331 from colemanw/post
Browse files Browse the repository at this point in the history
SearchKit - Use POST to send contact ids to action forms
  • Loading branch information
eileenmcnaughton authored May 20, 2022
2 parents 45e2237 + 1297a57 commit e9eb60f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
5 changes: 4 additions & 1 deletion CRM/Core/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,10 @@ public function key($name, $addSequence = FALSE, $ignoreKey = FALSE) {
// https://github.com/civicrm/civicrm-core/pull/17324
// and/or related get merged, then we should remove the REQUEST reference here.
$key = $_POST['qfKey'] ?? $_GET['qfKey'] ?? $_REQUEST['qfKey'] ?? NULL;
if (!$key && in_array($_SERVER['REQUEST_METHOD'], ['GET', 'HEAD'])) {
// Allow POST if `$_GET['reset'] == 1` because standalone search actions require a
// (potentially large) amount of data to the server and must make the page request using POST.
// See https://lab.civicrm.org/dev/core/-/issues/3222
if (!$key && (!empty($_GET['reset']) || in_array($_SERVER['REQUEST_METHOD'], ['GET', 'HEAD']))) {
// Generate a key if this is an initial request without one.
// We allow HEAD here because it is used by bots to validate URLs, so if
// we issue a 500 server error to them they may think the site is broken.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public function _run(\Civi\Api4\Generic\Result $result) {
'icon' => 'fa-file-excel-o',
'crmPopup' => [
'path' => "'civicrm/export/standalone'",
'query' => "{reset: 1, entity: '{$entity['name']}', id: ids.join(',')}",
'query' => "{reset: 1, entity: '{$entity['name']}'}",
'data' => "{id: ids.join(',')}",
],
];
}
Expand Down Expand Up @@ -104,7 +105,8 @@ public function _run(\Civi\Api4\Generic\Result $result) {
'icon' => $task['icon'] ?? 'fa-gear',
'crmPopup' => [
'path' => "'{$task['url']}'",
'query' => "{reset: 1, cids: ids.join(',')}",
'query' => "{reset: 1}",
'data' => "{cids: ids.join(',')}",
],
];
}
Expand Down Expand Up @@ -141,7 +143,7 @@ public function _run(\Civi\Api4\Generic\Result $result) {
'icon' => $task['icon'] ?? 'fa-gear',
'crmPopup' => [
'path' => "'{$task['url']}'",
'query' => "{id: ids.join(',')}",
'data' => "{id: ids.join(',')}",
],
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
if (action.crmPopup) {
var path = $scope.$eval(action.crmPopup.path, data),
query = action.crmPopup.query && $scope.$eval(action.crmPopup.query, data);
CRM.loadForm(CRM.url(path, query))
CRM.loadForm(CRM.url(path, query), {post: action.crmPopup.data && $scope.$eval(action.crmPopup.data, data)})
.on('crmFormSuccess', ctrl.refresh);
}
// If action uses dialogService
Expand Down
15 changes: 13 additions & 2 deletions js/crm.ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
options: {
url: null,
block: true,
post: null,
crmForm: null
},
_originalContent: null,
Expand Down Expand Up @@ -287,12 +288,22 @@
return false;
});
},
_ajax: function(url) {
if (!this.options.post || !this.isOriginalUrl()) {
return $.getJSON(url);
}
return $.post({
url: url,
dataType: 'json',
data: this.options.post
});
},
refresh: function() {
var that = this;
var url = this._formatUrl(this.options.url, 'json');
if (this.options.crmForm) $('form', this.element).ajaxFormUnbind();
if (this.options.block) this.element.block();
$.getJSON(url, function(data) {
this._ajax(url).then(function(data) {
if (data.status === 'redirect') {
that.options.url = data.userContext;
return that.refresh();
Expand Down Expand Up @@ -321,7 +332,7 @@
$('[name="'+formElement+'"]', that.element).crmError(msg);
});
}
}).fail(function(data, msg, status) {
}, function(data, msg, status) {
that._onFailure(data, status);
});
},
Expand Down

0 comments on commit e9eb60f

Please sign in to comment.