Files
AstralRinth/apps/frontend/src/components/ui/moderation/ModerationReportCard.vue
aecsocket 39f2b0ecb6 Technical review queue (#4775)
* chore: fix typo in status message

* feat(labrinth): overhaul malware scanner report storage and routes

* chore: address some review comments

* feat: add Delphi to Docker Compose `with-delphi` profile

* chore: fix unused import Clippy lint

* feat(labrinth/delphi): use PAT token authorization with project read scopes

* chore: expose file IDs in version queries

* fix: accept null decompiled source payloads from Delphi

* tweak(labrinth): expose base62 file IDs more consistently for Delphi

* feat(labrinth/delphi): support new Delphi report severity field

* chore(labrinth): run `cargo sqlx prepare` to fix Docker build errors

* tweak: add route for fetching Delphi issue type schema, abstract Labrinth away from issue types

* chore: run `cargo sqlx prepare`

* chore: fix typo on frontend generated state file message

* feat: update to use new Delphi issue schema

* wip: tech review endpoints

* wip: add ToSchema for dependent types

* wip: report issues return

* wip

* wip: returning more data

* wip

* Fix up db query

* Delphi configuration to talk to Labrinth

* Get Delphi working with Labrinth

* Add Delphi dummy fixture

* Better Delphi logging

* Improve utoipa for tech review routes

* Add more sorting options for tech review queue

* Oops join

* New routes for fetching issues and reports

* Fix which kind of ID is returned in tech review endpoints

* Deduplicate tech review report rows

* Reduce info sent for projects

* Fetch more thread info

* Address PR comments

* fix ci

* fix postgres version mismatch

* fix version creation

* Implement routes

* fix up tech review

* Allow adding a moderation comment to Delphi rejections

* fix up rebase

* exclude rejected projects from tech review

* add status change msg to tech review thread

* cargo sqlx prepare

* also ignore withheld projects

* More filtering on issue search

* wip: report routes

* Fix up for build

* cargo sqlx prepare

* fix thread message privacy

* New tech review search route

* submit route

* details have statuses now

* add default to drid status

* dedup issue details

* fix sqlx query on empty files

* fixes

* Dedupe issue detail statuses and message on entering tech rev

* Fix qa issues

* Fix qa issues

* fix review comments

* typos

* fix ci

* feat: tech review frontend (#4781)

* chore: fix typo in status message

* feat(labrinth): overhaul malware scanner report storage and routes

* chore: address some review comments

* feat: add Delphi to Docker Compose `with-delphi` profile

* chore: fix unused import Clippy lint

* feat(labrinth/delphi): use PAT token authorization with project read scopes

* chore: expose file IDs in version queries

* fix: accept null decompiled source payloads from Delphi

* tweak(labrinth): expose base62 file IDs more consistently for Delphi

* feat(labrinth/delphi): support new Delphi report severity field

* chore(labrinth): run `cargo sqlx prepare` to fix Docker build errors

* tweak: add route for fetching Delphi issue type schema, abstract Labrinth away from issue types

* chore: run `cargo sqlx prepare`

* chore: fix typo on frontend generated state file message

* feat: update to use new Delphi issue schema

* wip: tech review endpoints

* wip: add ToSchema for dependent types

* wip: report issues return

* wip

* wip: returning more data

* wip

* Fix up db query

* Delphi configuration to talk to Labrinth

* Get Delphi working with Labrinth

* Add Delphi dummy fixture

* Better Delphi logging

* Improve utoipa for tech review routes

* Add more sorting options for tech review queue

* Oops join

* New routes for fetching issues and reports

* Fix which kind of ID is returned in tech review endpoints

* Deduplicate tech review report rows

* Reduce info sent for projects

* Fetch more thread info

* Address PR comments

* fix ci

* fix ci

* fix postgres version mismatch

* fix version creation

* Implement routes

* feat: batch scan alert

* feat: layout

* feat: introduce surface variables

* fix: theme selector

* feat: rough draft of tech review card

* feat: tab switcher

* feat: batch scan btn

* feat: api-client module for tech review

* draft: impl

* feat: auto icons

* fix: layout issues

* feat: fixes to code blocks + flag labels

* feat: temp remove mock data

* fix: search sort types

* fix: intl & lint

* chore: re-enable mock data

* fix: flag badges + auto open first issue in file tab

* feat: update for new routes

* fix: more qa issues

* feat: lazy load sources

* fix: re-enable auth middleware

* feat: impl threads

* fix: lint & severity

* feat: download btn + switch to using NavTabs with new local mode option

* feat: re-add toplevel btns

* feat: reports page consistency

* fix: consistency on project queue

* fix: icons + sizing

* fix: colors and gaps

* fix: impl endpoints

* feat: load all flags on file tab

* feat: thread generics changes

* feat: more qa

* feat: fix collapse

* fix: qa

* feat: msg modal

* fix: ISO import

* feat: qa fixes

* fix: empty state basic

* fix: collapsible region

* fix: collapse thread by default

* feat: rough draft of new process/flow

* fix labrinth build

* fix thread message privacy

* New tech review search route

* feat: qa fixes

* feat: QA changes

* fix: verdict on detail not whole issue

* fix: lint + intl

* fix: lint

* fix: thread message for tech rev verdict

* feat: use anim frames

* fix: exports + typecheck

* polish: qa changes

* feat: qa

* feat: qa polish

* feat: fix malic modal

* fix: lint

* fix: qa + lint

* fix: pagination

* fix: lint

* fix: qa

* intl extract

* fix ci

---------

Signed-off-by: Calum H. <contact@cal.engineer>
Co-authored-by: Alejandro González <me@alegon.dev>
Co-authored-by: aecsocket <aecsocket@tutanota.com>

---------

Signed-off-by: Calum H. <contact@cal.engineer>
Co-authored-by: Alejandro González <me@alegon.dev>
Co-authored-by: Calum H. <contact@cal.engineer>
2025-12-20 11:43:04 +00:00

359 lines
9.9 KiB
Vue

<template>
<div class="overflow-hidden rounded-2xl">
<div class="bg-bg-raised p-4">
<div
class="flex w-full flex-col items-start justify-between gap-3 sm:flex-row sm:items-center sm:gap-0"
>
<span class="text-md flex flex-col gap-2 sm:flex-row sm:items-center">
<span class="flex items-center gap-2">
<span class="text-secondary">Reported for</span>
<span class="font-semibold text-contrast">
{{ formattedReportType }}
</span>
</span>
<span class="flex items-center gap-2">
<span class="hidden text-secondary sm:inline">By</span>
<span class="text-secondary sm:hidden">Reporter:</span>
<nuxt-link
:to="`/user/${report.reporter_user.username}`"
target="_blank"
class="inline-flex flex-row items-center gap-1 transition-colors duration-100 ease-in-out hover:text-brand"
>
<Avatar
:src="report.reporter_user.avatar_url"
circle
size="1.75rem"
class="flex-shrink-0"
/>
<span class="truncate">{{ report.reporter_user.username }}</span>
</nuxt-link>
</span>
</span>
<div class="flex flex-row items-center gap-2 self-end sm:self-auto">
<span class="whitespace-nowrap text-sm text-secondary">{{
formatRelativeTime(report.created)
}}</span>
<ButtonStyled circular>
<OverflowMenu :options="quickActions">
<template #default>
<EllipsisVerticalIcon class="size-4" />
</template>
<template #copy-id>
<ClipboardCopyIcon />
<span class="hidden sm:inline">Copy ID</span>
</template>
<template #copy-link>
<LinkIcon />
<span class="hidden sm:inline">Copy link</span>
</template>
</OverflowMenu>
</ButtonStyled>
</div>
</div>
<div class="my-4 h-px bg-surface-5" />
<div class="flex items-center justify-between">
<div class="flex items-center gap-4">
<Avatar
:src="reportItemAvatarUrl"
:circle="report.item_type === 'user'"
size="4rem"
:class="[
'flex-shrink-0 border border-surface-5 bg-surface-4 !shadow-none',
report.item_type !== 'user' && 'rounded-2xl',
]"
/>
<div v-if="report.item_type === 'user'" class="flex flex-col gap-1.5">
<NuxtLink
:to="`/user/${report.user?.username}`"
target="_blank"
class="text-base font-semibold text-contrast hover:underline"
>
{{ report.user?.username || 'Unknown User' }}
</NuxtLink>
<span
v-if="report.user?.created"
v-tooltip="formatExactDate(report.user.created)"
class="cursor-help text-sm text-secondary"
>
Joined {{ formatRelativeTime(report.user.created) }}
</span>
</div>
<div v-else class="flex flex-col gap-1.5">
<div class="flex items-center gap-2">
<NuxtLink
:to="reportItemUrl"
target="_blank"
class="text-base font-semibold text-contrast hover:underline"
>
{{ reportItemTitle }}
</NuxtLink>
<div
v-if="report.project?.project_type"
class="flex items-center gap-1 rounded-full border border-solid border-surface-5 bg-surface-4 px-2.5 py-1"
>
<component
:is="getProjectTypeIcon(report.project.project_type as any)"
aria-hidden="true"
class="h-4 w-4"
/>
<span class="text-sm font-medium text-secondary">
{{ formatProjectType(report.project.project_type, true) }}
</span>
</div>
<span
v-if="report.item_type === 'version' && report.version"
class="text-sm text-secondary"
>
{{ report.version.files.find((f) => f.primary)?.filename || 'Unknown Version' }}
</span>
</div>
<div v-if="report.target" class="flex items-center gap-1">
<Avatar
:src="report.target.avatar_url"
size="1.5rem"
circle
class="border border-surface-5 bg-surface-4 !shadow-none"
/>
<NuxtLink
:to="`/${report.target.type}/${report.target.slug}`"
target="_blank"
class="text-sm font-medium text-secondary hover:underline"
>
{{ report.target.name }}
</NuxtLink>
</div>
</div>
</div>
</div>
</div>
<CollapsibleRegion
v-model:collapsed="isThreadCollapsed"
:expand-text="expandText"
collapse-text="Collapse thread"
>
<div class="bg-surface-2 p-4 pt-2">
<ThreadView
v-if="report.thread"
ref="reportThread"
:thread="report.thread"
:quick-replies="reportQuickReplies"
:quick-reply-context="report"
:closed="reportClosed"
@update-thread="updateThread"
>
<template #closedActions>
<ButtonStyled v-if="isStaff(auth.user)" color="green" class="mt-2">
<button class="w-full gap-2 sm:w-auto" @click="reopenReport()">
<CheckCircleIcon class="size-4" />
Reopen Thread
</button>
</ButtonStyled>
</template>
<template #additionalActions="{ hasReply }">
<template v-if="isStaff(auth.user)">
<ButtonStyled v-if="hasReply" color="red">
<button class="w-full gap-2 sm:w-auto" @click="closeReport(true)">
<CheckCircleIcon class="size-4" />
Reply and close
</button>
</ButtonStyled>
<ButtonStyled v-else color="red">
<button class="w-full gap-2 sm:w-auto" @click="closeReport()">
<CheckCircleIcon class="size-4" />
Close report
</button>
</ButtonStyled>
</template>
</template>
</ThreadView>
</div>
</CollapsibleRegion>
</div>
</template>
<script setup lang="ts">
import {
CheckCircleIcon,
ClipboardCopyIcon,
EllipsisVerticalIcon,
LinkIcon,
} from '@modrinth/assets'
import { type ExtendedReport, reportQuickReplies } from '@modrinth/moderation'
import type { OverflowMenuOption } from '@modrinth/ui'
import {
Avatar,
ButtonStyled,
CollapsibleRegion,
getProjectTypeIcon,
injectNotificationManager,
OverflowMenu,
useRelativeTime,
} from '@modrinth/ui'
import { formatProjectType } from '@modrinth/utils'
import dayjs from 'dayjs'
import { computed } from 'vue'
import { isStaff } from '~/helpers/users.js'
import ThreadView from '../thread/ThreadView.vue'
const { addNotification } = injectNotificationManager()
const auth = await useAuth()
const props = defineProps<{
report: ExtendedReport
}>()
const reportThread = ref<{
setReplyContent: (content: string) => void
sendReply: (privateMessage?: boolean) => Promise<void>
} | null>(null)
const isThreadCollapsed = ref(true)
const didCloseReport = ref(false)
const reportClosed = computed(() => {
return didCloseReport.value || props.report.closed
})
const remainingMessageCount = computed(() => {
if (!props.report.thread?.messages) return 0
return Math.max(0, props.report.thread.messages.length - 1)
})
const expandText = computed(() => {
if (remainingMessageCount.value === 0) return 'Expand'
if (remainingMessageCount.value === 1) return 'Show 1 more message'
return `Show ${remainingMessageCount.value} more messages`
})
async function closeReport(reply = false) {
if (reply && reportThread.value) {
await reportThread.value.sendReply()
}
try {
await useBaseFetch(`report/${props.report.id}`, {
method: 'PATCH',
body: {
closed: true,
},
})
updateThread(props.report.thread)
didCloseReport.value = true
} catch (err: any) {
addNotification({
title: 'Error closing report',
text: err.data ? err.data.description : err,
type: 'error',
})
}
}
async function reopenReport() {
try {
await useBaseFetch(`report/${props.report.id}`, {
method: 'PATCH',
body: {
closed: false,
},
})
updateThread(props.report.thread)
didCloseReport.value = false
} catch (err: any) {
addNotification({
title: 'Error reopening report',
text: err.data ? err.data.description : err,
type: 'error',
})
}
}
const formatRelativeTime = useRelativeTime()
function formatExactDate(date: string): string {
return dayjs(date).format('MMMM D, YYYY [at] h:mm A')
}
function updateThread(newThread: any) {
if (props.report.thread) {
Object.assign(props.report.thread, newThread)
}
}
const quickActions: OverflowMenuOption[] = [
{
id: 'copy-link',
action: () => {
const base = window.location.origin
const reportUrl = `${base}/moderation/reports/${props.report.id}`
navigator.clipboard.writeText(reportUrl).then(() => {
addNotification({
type: 'success',
title: 'Report link copied',
text: 'The link to this report has been copied to your clipboard.',
})
})
},
},
{
id: 'copy-id',
action: () => {
navigator.clipboard.writeText(props.report.id).then(() => {
addNotification({
type: 'success',
title: 'Report ID copied',
text: 'The ID of this report has been copied to your clipboard.',
})
})
},
},
]
const reportItemAvatarUrl = computed(() => {
switch (props.report.item_type) {
case 'project':
case 'version':
return props.report.project?.icon_url || ''
case 'user':
return props.report.user?.avatar_url || ''
default:
return undefined
}
})
const reportItemTitle = computed(() => {
if (props.report.item_type === 'user') return props.report.user?.username || 'Unknown User'
return props.report.project?.title || 'Unknown Project'
})
const reportItemUrl = computed(() => {
switch (props.report.item_type) {
case 'user':
return `/user/${props.report.user?.username}`
case 'project':
return `/${props.report.project?.project_type}/${props.report.project?.slug}`
case 'version':
return `/${props.report.project?.project_type}/${props.report.project?.slug}/version/${props.report.version?.id}`
default:
return `/${props.report.item_type}/${props.report.id}`
}
})
const formattedReportType = computed(() => {
const reportType = props.report.report_type
// some are split by -, some are split by " "
const words = reportType.includes('-') ? reportType.split('-') : reportType.split(' ')
return words.map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(' ')
})
</script>