All files / src/components AdminReportUserCell.vue

100% Statements 19/19
100% Branches 39/39
100% Functions 8/8
100% Lines 15/15

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  60x           58x                                                                                                                       1x                 1x                         3x                                                 52x                   52x         52x 52x   99x     52x 52x     52x 4x 4x      
<template>
  <div class="admin-report-user">
    <template v-if="user">
      <router-link
        :to="{ name: 'user-profile', params: { userId: user.id } }"
        class="text-decoration-none"
      >
        {{ user.name || (user.nickname ? `@${user.nickname}` : t('report.admin.deletedUser')) }}
      </router-link>
      <div v-if="user.email" class="text-muted small">{{ user.email }}</div>
 
      <div v-if="standing" class="mt-1 d-flex flex-wrap gap-1 align-items-center small">
        <span
          v-if="standing.activeStrikes > 0"
          class="badge bg-warning text-dark report-user-strikes"
        >
          {{ t('report.admin.strikes').replace('{count}', String(standing.activeStrikes)) }}
        </span>
        <span v-if="standing.bannedAt" class="badge bg-danger report-user-banned">
          {{ t('report.admin.banned') }}
        </span>
        <span v-else-if="restricted" class="badge bg-secondary report-user-restricted">
          {{
            t('report.admin.restrictedUntil').replace(
              '{date}',
              formatDateTime(standing.restrictedUntil!)
            )
          }}
        </span>
      </div>
 
      <!-- The reporter's record: reports often dismissed may be filed in bad faith -->
      <div v-if="reporterStanding" class="mt-1 d-flex flex-wrap gap-1 align-items-center small">
        <span
          class="badge report-user-record"
          :class="mostlyDismissed ? 'bg-warning text-dark' : 'bg-light text-dark border'"
        >
          {{
            t('report.admin.reporting.record')
              .replace('{reports}', String(reporterStanding.reports))
              .replace('{dismissed}', String(reporterStanding.dismissed))
          }}
        </span>
        <span v-if="reportingSuspended" class="badge bg-secondary report-user-suspended">
          {{
            t('report.admin.reporting.suspendedUntil').replace(
              '{date}',
              formatDateTime(reporterStanding.reportingSuspendedUntil!)
            )
          }}
        </span>
        <span
          v-else-if="reporterStanding.reportingWarnedAt"
          class="badge bg-info text-dark report-user-warned"
        >
          {{
            t('report.admin.reporting.warnedOn').replace(
              '{date}',
              formatDateTime(reporterStanding.reportingWarnedAt)
            )
          }}
        </span>
        <template v-if="!reportingSuspended">
          <button
            v-if="!reporterStanding.reportingWarnedAt"
            type="button"
            class="btn btn-link btn-sm p-0 report-user-warn"
            @click="emit('reporting', user.id, 'warn')"
          >
            <font-awesome-icon icon="fa-solid fa-triangle-exclamation" class="me-1" />
            {{ t('report.admin.reporting.warn') }}
          </button>
          <button
            v-else
            type="button"
            class="btn btn-link btn-sm p-0 report-user-suspend"
            @click="emit('reporting', user.id, 'suspend')"
          >
            <font-awesome-icon icon="fa-solid fa-ban" class="me-1" />
            {{ t('report.admin.reporting.suspend') }}
          </button>
        </template>
      </div>
 
      <button
        v-if="standing?.bannedAt || restricted || reportingSuspended"
        type="button"
        class="btn btn-link btn-sm p-0 mt-1 report-user-lift"
        :disabled="lifting"
        @click="emit('lift', user.id)"
      >
        <font-awesome-icon icon="fa-solid fa-unlock" class="me-1" />
        {{ t('report.admin.lift') }}
      </button>
    </template>
    <span v-else class="text-muted">—</span>
  </div>
</template>
 
<script setup lang="ts">
// @implements UC-REPORT-004.1, UC-REPORT-008.1, UC-REPORT-011.1
import { computed } from 'vue'
import type {
  AdminReportUser,
  AdminReportedUserStanding,
  AdminReporterStanding,
  ReportingAction
} from '@/stores/admin'
import { useUILanguage } from '@/composables/useUILanguage'
import { useDateFormat } from '@/composables/useDateFormat'
 
// A deleted account keeps only its id: no name, no email. The standing
// (strikes, sanctions) is the reported user's; the reporter's record, the
// reporter's.
const props = withDefaults(
  defineProps<{
    user: AdminReportUser | null
    standing?: AdminReportedUserStanding | null
    reporterStanding?: AdminReporterStanding | null
    lifting?: boolean
  }>(),
  { standing: null, reporterStanding: null, lifting: false }
)
 
const emit = defineEmits<{
  lift: [userId: string]
  reporting: [userId: string, action: ReportingAction]
}>()
 
const { t } = useUILanguage()
const { formatDateTime } = useDateFormat()
 
const isFuture = (date: string | null | undefined) => !!date && Date.parse(date) > Date.now()
 
// A restriction whose end is past no longer holds anything back
const restricted = computed(() => isFuture(props.standing?.restrictedUntil))
const reportingSuspended = computed(() => isFuture(props.reporterStanding?.reportingSuspendedUntil))
 
// Worth a look: at least 3 reports, most of them dismissed
const mostlyDismissed = computed(() => {
  const record = props.reporterStanding
  return !!record && record.reports >= 3 && record.dismissed * 2 > record.reports
})
</script>