Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | 75x 1x 3x 3x 1x 3x 3x 3x 3x 102x 12x 1x 3x 3x 90x 3x 2x 1x 3x 1x 35x 35x 3x 3x 3x 35x 35x 35x 35x 35x 35x 35x 35x 35x 35x 35x 35x 35x 31x 17x 4x 4x 35x 38x 3x 3x 3x 3x 3x 5x 5x 4x 5x 5x 2x 9x 9x 9x 9x 9x 9x 9x 8x 8x 7x 7x 2x 9x | <template>
<div
v-if="report"
class="modal fade show d-block report-decision-modal"
role="dialog"
aria-modal="true"
aria-labelledby="report-decision-title"
tabindex="-1"
style="background-color: rgba(0, 0, 0, 0.5)"
@click.self="!submitting && emit('close')"
>
<div class="modal-dialog modal-dialog-centered">
<form class="modal-content" @submit.prevent="submit">
<div class="modal-header">
<h5 id="report-decision-title" class="modal-title">
<font-awesome-icon icon="fa-solid fa-gavel" class="me-2" />
{{ t('report.decision.title') }}
</h5>
<button
type="button"
class="btn-close"
:aria-label="t('common.close')"
:disabled="submitting"
@click="emit('close')"
></button>
</div>
<div class="modal-body">
<p class="text-muted small">{{ t('report.decision.intro') }}</p>
<fieldset class="mb-3">
<legend class="form-label fs-6">{{ t('report.decision.outcomeLabel') }}</legend>
<div v-for="option in OUTCOMES" :key="option" class="form-check">
<input
:id="`decision-outcome-${option}`"
v-model="outcome"
class="form-check-input"
type="radio"
name="decision-outcome"
:value="option"
:disabled="submitting"
/>
<label class="form-check-label" :for="`decision-outcome-${option}`">
{{ t(`report.decision.outcomes.${option}`) }}
</label>
</div>
</fieldset>
<template v-if="outcome === 'actioned'">
<div v-if="removable" class="form-check mb-3">
<input
id="decision-remove"
v-model="removeContent"
class="form-check-input"
type="checkbox"
:disabled="submitting"
/>
<label class="form-check-label" for="decision-remove">
{{ t(`report.decision.remove.${report.targetType}`) }}
</label>
</div>
<fieldset class="mb-3">
<legend class="form-label fs-6">{{ t('report.decision.sanctionLabel') }}</legend>
<p v-if="report.reportedUserStanding" class="small text-muted mb-2 decision-strikes">
{{
t('report.decision.strikes').replace(
'{count}',
String(report.reportedUserStanding.activeStrikes)
)
}}
</p>
<div v-for="option in SANCTIONS" :key="option" class="form-check">
<input
:id="`decision-sanction-${option}`"
v-model="sanction"
class="form-check-input"
type="radio"
name="decision-sanction"
:value="option"
:disabled="submitting"
/>
<label class="form-check-label" :for="`decision-sanction-${option}`">
{{ t(`report.decision.sanctions.${option}`) }}
</label>
</div>
<div v-if="sanction === 'restriction'" class="mt-2 ms-4">
<label for="decision-days" class="form-label small">
{{ t('report.decision.daysLabel') }}
</label>
<input
id="decision-days"
v-model.number="restrictionDays"
class="form-control form-control-sm w-auto"
type="number"
min="1"
:max="MAX_RESTRICTION_DAYS"
required
:disabled="submitting"
/>
</div>
</fieldset>
<label for="decision-note" class="form-label">{{
t('report.decision.noteLabel')
}}</label>
<textarea
id="decision-note"
v-model="note"
class="form-control"
rows="3"
:maxlength="MAX_DECISION_NOTE_LENGTH"
:placeholder="t('report.decision.notePlaceholder')"
:disabled="submitting"
/>
</template>
</div>
<div class="modal-footer">
<button
type="button"
class="btn btn-secondary"
:disabled="submitting"
@click="emit('close')"
>
<font-awesome-icon icon="fa-solid fa-xmark" class="me-2" />
{{ t('common.cancel') }}
</button>
<button
type="submit"
class="btn decision-submit"
:class="outcome === 'actioned' ? 'btn-danger' : 'btn-primary'"
:disabled="!canSubmit || submitting"
>
<span
v-if="submitting"
class="spinner-border spinner-border-sm me-2"
role="status"
aria-hidden="true"
/>
<font-awesome-icon v-else icon="fa-solid fa-gavel" class="me-2" />
{{ t('report.decision.submit') }}
</button>
</div>
</form>
</div>
</div>
</template>
<script setup lang="ts">
// @implements UC-REPORT-005.1
import { computed, ref, watch } from 'vue'
import api from '@/services/api'
import { useUILanguage } from '@/composables/useUILanguage'
import { useToastStore } from '@/stores/toast'
import {
useAdminStore,
type AdminContentReport,
type ReportOutcome,
type ReportSanction
} from '@/stores/admin'
import { getErrorMessage } from '@/utils/errors'
const OUTCOMES: ReportOutcome[] = ['actioned', 'dismissed']
const SANCTIONS: ReportSanction[] = ['warning', 'restriction', 'ban']
const MAX_RESTRICTION_DAYS = 365
const MAX_DECISION_NOTE_LENGTH = 1000
const DEFAULT_RESTRICTION_DAYS = 7
// Open while a report is set: deciding it decides every open report of its target
const props = defineProps<{ report: AdminContentReport | null }>()
const emit = defineEmits<{ close: []; decided: [] }>()
const { t } = useUILanguage()
const toastStore = useToastStore()
const adminStore = useAdminStore()
const outcome = ref<ReportOutcome | null>(null)
const removeContent = ref(true)
const sanction = ref<ReportSanction>('warning')
const restrictionDays = ref(DEFAULT_RESTRICTION_DAYS)
const note = ref('')
const submitting = ref(false)
// A conversation belongs to its participants: an admin sanctions, removes nothing
const removable = computed(() => props.report?.targetType !== 'conversation')
const canSubmit = computed(() => {
if (!outcome.value) return false
if (outcome.value === 'dismissed' || sanction.value !== 'restriction') return true
const days = restrictionDays.value
return Number.isInteger(days) && days >= 1 && days <= MAX_RESTRICTION_DAYS
})
// Every decision starts blank
watch(
() => props.report?.id,
() => {
outcome.value = null
removeContent.value = true
sanction.value = 'warning'
restrictionDays.value = DEFAULT_RESTRICTION_DAYS
note.value = ''
}
)
/** The existing delete route of the content, as a platform admin may use it */
function deletePath(report: AdminContentReport): string {
const { target } = report
if (report.targetType === 'pack') return `/v1/store/${target.packId}`
return target.packId
? `/v1/store/${target.packId}/comments/${target.commentId}`
: `/v1/entities/${target.entityId}/items/${target.itemId}/comments/${target.commentId}`
}
/** Removes the content first: the decision then tells its author it is gone. */
async function removeReportedContent(report: AdminContentReport) {
try {
await api.delete(deletePath(report))
} catch (err: any) {
// Gone already: that is what was wanted
if (err.response?.status !== 404) throw err
}
}
async function submit() {
const report = props.report
Iif (!report || !outcome.value || !canSubmit.value || submitting.value) return
submitting.value = true
try {
const actioned = outcome.value === 'actioned'
const removed = actioned && removable.value && removeContent.value
if (removed) await removeReportedContent(report)
const trimmedNote = note.value.trim()
await adminStore.decideContentReport({
targetKey: report.targetKey,
outcome: outcome.value,
...(actioned && {
removed,
sanction: sanction.value,
...(sanction.value === 'restriction' && { restrictionDays: restrictionDays.value }),
...(trimmedNote && { note: trimmedNote })
})
})
toastStore.success(t('report.decision.success'))
emit('decided')
} catch (err) {
toastStore.error(getErrorMessage(err, t('report.decision.error'), t))
} finally {
submitting.value = false
}
}
</script>
|