|
42 | 42 | :key="category.name" |
43 | 43 | class="flex flex-col gap-1.5" |
44 | 44 | > |
45 | | - <h4 class="m-0 border-b border-divider text-base font-medium text-primary"> |
| 45 | + <h4 |
| 46 | + class="m-0 border-b border-divider text-base font-medium" |
| 47 | + :class="category.headingClass || 'text-primary'" |
| 48 | + > |
46 | 49 | {{ category.name }} |
47 | 50 | </h4> |
48 | 51 | <div class="flex flex-col gap-2"> |
49 | | - <Checkbox |
| 52 | + <span |
50 | 53 | v-for="scope in category.scopes" |
51 | 54 | :key="scope" |
52 | | - :label="scopesToLabels(getScopeValue(scope)).join(', ')" |
53 | | - :model-value="hasScope(scopesVal, scope)" |
54 | | - @update:model-value="scopesVal = toggleScope(scopesVal, scope)" |
55 | | - /> |
| 55 | + v-tooltip="impliedStaffTooltip(scope)" |
| 56 | + class="w-fit" |
| 57 | + > |
| 58 | + <Checkbox |
| 59 | + :label="scopesToLabels(getScopeValue(scope)).join(', ')" |
| 60 | + :label-class="category.labelClass" |
| 61 | + :disabled="category.disabled || !!impliedStaffTooltip(scope)" |
| 62 | + :model-value="hasScope(scopesVal, scope) || !!impliedStaffTooltip(scope)" |
| 63 | + @update:model-value="scopesVal = toggleScope(scopesVal, scope)" |
| 64 | + /> |
| 65 | + </span> |
56 | 66 | </div> |
57 | 67 | </div> |
58 | 68 | </div> |
|
247 | 257 | </p> |
248 | 258 | <div v-else :id="`pat-permissions-${pat.id}`" class="grid gap-1 sm:grid-cols-2"> |
249 | 259 | <div |
250 | | - v-for="(scope, index) in patScopes(pat)" |
251 | | - :key="`${pat.id}-scope-${index}`" |
| 260 | + v-for="scope in patScopes(pat)" |
| 261 | + :key="`${pat.id}-scope-${scope.id}`" |
252 | 262 | class="flex items-center gap-1" |
253 | 263 | > |
254 | 264 | <CheckIcon class="size-5 shrink-0 text-green" /> |
255 | | - {{ scope }} |
| 265 | + <span :class="scopeTextClass(scope.accent)">{{ scope.text }}</span> |
256 | 266 | </div> |
257 | 267 | </div> |
258 | 268 | </div> |
@@ -292,11 +302,17 @@ import { |
292 | 302 | useRelativeTime, |
293 | 303 | useVIntl, |
294 | 304 | } from '@modrinth/ui' |
| 305 | +import { isAdmin, isStaff } from '@modrinth/utils' |
295 | 306 | import { useQuery, useQueryClient } from '@tanstack/vue-query' |
296 | 307 |
|
| 308 | +import { useAuth } from '~/composables/auth' |
297 | 309 | import { |
| 310 | + adminScopeList, |
| 311 | + decodeScopes, |
298 | 312 | getScopeValue, |
299 | 313 | hasScope, |
| 314 | + moderationScopeList, |
| 315 | + scopeAccent, |
300 | 316 | scopeCategoryMessages, |
301 | 317 | scopeList, |
302 | 318 | toggleScope, |
@@ -425,6 +441,7 @@ useHead({ |
425 | 441 | }) |
426 | 442 |
|
427 | 443 | const data = useNuxtApp() |
| 444 | +const auth = await useAuth() |
428 | 445 | const { scopesToLabels, scopesToDefinitions } = useScopes() |
429 | 446 | const patModal = ref() |
430 | 447 | const minimumPatExpiry = data.$dayjs().add(1, 'day').format('YYYY-MM-DD') |
@@ -456,7 +473,7 @@ const displayPats = computed(() => { |
456 | 473 | }) |
457 | 474 |
|
458 | 475 | const scopeCategories = computed(() => { |
459 | | - return [ |
| 476 | + const categories = [ |
460 | 477 | { |
461 | 478 | name: formatMessage(scopeCategoryMessages.categoryUserAccount), |
462 | 479 | scopes: scopeList.filter((s) => s.startsWith('USER_')), |
@@ -507,7 +524,27 @@ const scopeCategories = computed(() => { |
507 | 524 | (s) => s.startsWith('ANALYTICS') || s.startsWith('PERFORM_ANALYTICS'), |
508 | 525 | ), |
509 | 526 | }, |
510 | | - ].filter((c) => c.scopes.length > 0) |
| 527 | + ] |
| 528 | +
|
| 529 | + if (isStaff(auth.value.user)) { |
| 530 | + categories.push( |
| 531 | + { |
| 532 | + name: 'Moderation', |
| 533 | + scopes: moderationScopeList, |
| 534 | + labelClass: 'text-orange', |
| 535 | + headingClass: 'text-orange', |
| 536 | + }, |
| 537 | + { |
| 538 | + name: 'Admin', |
| 539 | + scopes: adminScopeList, |
| 540 | + labelClass: 'text-red', |
| 541 | + headingClass: 'text-red', |
| 542 | + disabled: !isAdmin(auth.value.user), |
| 543 | + }, |
| 544 | + ) |
| 545 | + } |
| 546 | +
|
| 547 | + return categories.filter((c) => c.scopes.length > 0) |
511 | 548 | }) |
512 | 549 |
|
513 | 550 | function openCreatePat() { |
@@ -543,8 +580,38 @@ function isPatExpired(pat) { |
543 | 580 | return new Date(pat.expires) <= new Date() |
544 | 581 | } |
545 | 582 |
|
| 583 | +function impliedStaffTooltip(scope) { |
| 584 | + if (scope === 'MODERATION_READ' && hasScope(scopesVal.value, 'ADMIN_READ')) { |
| 585 | + return 'Included with Admin read' |
| 586 | + } |
| 587 | + if (scope === 'MODERATION_WRITE' && hasScope(scopesVal.value, 'ADMIN_WRITE')) { |
| 588 | + return 'Included with Admin write' |
| 589 | + } |
| 590 | +} |
| 591 | +
|
546 | 592 | function patScopes(pat) { |
547 | | - return scopesToDefinitions(BigInt(pat.scopes || 0)) |
| 593 | + const selected = decodeScopes(BigInt(pat.scopes || 0)) |
| 594 | + if (selected.includes('ADMIN_READ') && !selected.includes('MODERATION_READ')) { |
| 595 | + selected.push('MODERATION_READ') |
| 596 | + } |
| 597 | + if (selected.includes('ADMIN_WRITE') && !selected.includes('MODERATION_WRITE')) { |
| 598 | + selected.push('MODERATION_WRITE') |
| 599 | + } |
| 600 | + return selected.map((scope) => ({ |
| 601 | + id: scope, |
| 602 | + text: scopesToDefinitions(getScopeValue(scope))[0], |
| 603 | + accent: scopeAccent(scope), |
| 604 | + })) |
| 605 | +} |
| 606 | +
|
| 607 | +function scopeTextClass(accent) { |
| 608 | + if (accent === 'moderation') { |
| 609 | + return 'text-orange' |
| 610 | + } |
| 611 | + if (accent === 'admin') { |
| 612 | + return 'text-red' |
| 613 | + } |
| 614 | + return undefined |
548 | 615 | } |
549 | 616 |
|
550 | 617 | async function createPat() { |
|
0 commit comments