Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing csrf token to "set breaking" button. #2558

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 3 additions & 17 deletions tabbycat/templates/ajax/AjaxMixin.vue
Original file line number Diff line number Diff line change
@@ -1,31 +1,17 @@
<script>
import ModalErrorMixin from '../errors/ModalErrorMixin.vue'
import CookieMixin from './CookieMixin.vue'

export default {
mixins: [ModalErrorMixin],
mixins: [ModalErrorMixin, CookieMixin],
methods: {
ajaxSave: function (
url, payload, message, completeFunction, failFunction,
returnPayload, showErrorModal = true,
) {
const self = this
const dataPayload = JSON.stringify(payload)
function getCookie (name) {
let cookieValue = null
if (document.cookie && document.cookie !== '') {
const cookies = document.cookie.split(';')
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim()
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1))
break
}
}
}
return cookieValue
}
const csrftoken = getCookie('csrftoken')
const csrftoken = this.getCookie('csrftoken')
$.ajax({
type: 'POST',
url: url,
Expand Down
20 changes: 20 additions & 0 deletions tabbycat/templates/ajax/CookieMixin.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<script>
export default {
methods: {
getCookie: function (name) {
let cookieValue = null
if (document.cookie && document.cookie !== '') {
const cookies = document.cookie.split(';')
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim()
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1))
}
}
}
return cookieValue
},
},
}
</script>
7 changes: 6 additions & 1 deletion tabbycat/templates/tables/CheckboxTablesContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<form v-if="roundInfo.break === 'True' && roundInfo.model === 'participants.Adjudicator'"
:action="urls.breakingAdjs" method="post">
<button class="btn btn-primary" type="submit">
<input type="hidden" name="csrfmiddlewaretoken" :value="csrftoken">
<i data-feather="star"></i> {{ gettext("Set Breaking") }}
</button>
</form>
Expand Down Expand Up @@ -77,9 +78,10 @@ import _ from 'lodash'
import AutoSaveCounter from '../../templates/allocations/AutoSaveCounter.vue'
import TablesContainer from './TablesContainer.vue'
import AjaxMixin from '../ajax/AjaxMixin.vue'
import CookieMixin from '../ajax/CookieMixin.vue'

export default {
mixins: [AjaxMixin],
mixins: [AjaxMixin, CookieMixin],
components: { AutoSaveCounter, TablesContainer },
props: {
tablesData: Array,
Expand Down Expand Up @@ -111,6 +113,9 @@ export default {
})
return checked
},
csrftoken: function () {
return this.getCookie('csrftoken')
},
},
methods: {
saveChecks: function (type) {
Expand Down
Loading