Skip to content

Commit

Permalink
Include the csrf-token when deleting locks
Browse files Browse the repository at this point in the history
  • Loading branch information
taylor-steve committed Jan 24, 2025
1 parent 03adad6 commit c6eba43
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 15 deletions.
18 changes: 14 additions & 4 deletions app/assets/javascripts/spotlight/spotlight.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/assets/javascripts/spotlight/spotlight.esm.js.map

Large diffs are not rendered by default.

18 changes: 14 additions & 4 deletions app/assets/javascripts/spotlight/spotlight.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/assets/javascripts/spotlight/spotlight.js.map

Large diffs are not rendered by default.

20 changes: 15 additions & 5 deletions app/javascript/spotlight/admin/locks.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
export default class {
delete_lock(el) {
$.ajax({ url: $(el).data('lock'), type: 'POST', data: { _method: "delete" }, async: false});
$(el).removeAttr('data-lock');
const csrfToken = document.querySelector('meta[name="csrf-token"]')?.content;

fetch(el.dataset.lock, {
method: 'DELETE',
headers: {
'X-CSRF-Token': csrfToken
}
});

el.removeAttribute('data-lock');
}

connect() {
$('[data-lock]').on('click', (e) => {
this.delete_lock(e.target);
})
document.querySelectorAll('[data-lock]').forEach(element => {
element.addEventListener('click', (e) => {
this.delete_lock(e.target);
});
});
}
}

0 comments on commit c6eba43

Please sign in to comment.