Skip to content

Commit dac2c85

Browse files
committed
Fix missing authentication (CSRF) when using related issues block (#90 and PR #93)
1 parent 750e602 commit dac2c85

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

assets/javascripts/issue_dynamic_edit.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,23 @@ if (_CONF_DISPLAY_EDIT_ICON === "block"){
3737
$('body.controller-issues.action-show .issue.details').addClass('showPencils');
3838
}
3939

40+
let updateCSRFToken = function(token){
41+
document.querySelectorAll('input[name="authenticity_token"]').forEach(elt => elt.value = token);
42+
document.querySelector('meta[name="csrf-token"]').setAttribute("content", token);
43+
}
44+
45+
let setCSRFTokenInput = function(token){
46+
document.querySelectorAll('form[method="post"]').forEach(elt => {
47+
if(!elt.querySelectorAll('input[name="authenticity_token"]').length){
48+
let input = document.createElement("input");
49+
input.setAttribute("type", "hidden");
50+
input.setAttribute("name", "authenticity_token");
51+
input.value = token;
52+
elt.insertBefore(input, null);
53+
}
54+
});
55+
}
56+
4057
/* Generate edit block */
4158
var getEditFormHTML = function(attribute){
4259
var formElement = $('#issue_' + attribute + "_id");
@@ -317,6 +334,8 @@ var sendData = function(serialized_data){
317334
$('body').find('input[type=date]').datepickerFallback(datepickerOptions);
318335
}
319336

337+
setCSRFTokenInput($(parsed).find('input[name="authenticity_token"]').val());
338+
updateCSRFToken($(parsed).find('input[name="authenticity_token"]').val());
320339
setCheckVersionInterval(true);
321340
},
322341
error: function(xhr, msg, error) {
@@ -354,4 +373,5 @@ var sendData = function(serialized_data){
354373
}
355374

356375
// Init plugin
357-
cloneEditForm();
376+
cloneEditForm();
377+
setCSRFTokenInput(document.querySelector('meta[name="csrf-token"]').getAttribute("content"));

init.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require 'redmine'
22

3-
require 'details_issue_hooks'
3+
require_relative './lib/details_issue_hooks.rb'
44

55
Redmine::Plugin.register :redmine_issue_dynamic_edit do
66
name 'Redmine Dynamic edit Issue plugin'

0 commit comments

Comments
 (0)