diff --git a/CHANGELOG.md b/CHANGELOG.md index 80a8693..1d54a8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 3.1.0 + +- Activity rows with no user behind them (failed logins, scheduled tasks) show a plain system icon instead of a generated pattern. +- New **System picture** setting: admins can upload a picture for those rows instead (Admin, Extensions, User Avatars). + ## 3.0.1 - Pictures now show in activity logs (a server's Activity tab, your account activity and the admin activity page). These lists drew a generated avatar and ignored the user's picture. diff --git a/README.md b/README.md index a6c08f5..0995891 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Pterodactyl 2.0 has no avatar uploads. Core draws a generated pattern in the nav - Lists that show a user's `image` (admin users, server owner, subusers) get the user's picture because this extension replaces the panel's user transformers with versions that swap in the uploaded URL. If another extension also replaces `Pterodactyl\Transformers\Api\Client\UserTransformer` or `Pterodactyl\Transformers\Api\Admin\UserTransformer`, only one of them will win. - The navigation bar avatar is not a replaceable component in 2.0, so the user's picture is laid over it with CSS that targets the "Account Settings" link. A panel update that changes that link could break it; the rest of the extension is unaffected. -- Activity rows draw a generated avatar from the username and are not replaceable either. The activity API already includes each actor's picture, so the extension matches rows to it by username and lays the picture over the generated avatar. A panel update that changes the activity row layout could break it. +- Activity rows draw a generated avatar from the username and are not replaceable either. The activity API already includes each actor's picture, so the extension matches rows to it by username and lays the picture over the generated avatar. Rows with no user (shown as "System") get the picture set in the extension's **System picture** setting, or a plain system icon when none is set. A panel update that changes the activity row layout could break it. ## API diff --git a/extension.json b/extension.json index 49d453f..ea4c6bd 100644 --- a/extension.json +++ b/extension.json @@ -2,7 +2,7 @@ "$schema": "./node_modules/@pterodactyl/sdk/manifest.schema.json", "id": "user-avatars", "name": "User Avatars", - "version": "3.0.1", + "version": "3.1.0", "description": "Let users upload their own profile picture, shown in the navigation bar, admin user lists, server subuser lists and activity logs.", "author": "RustixDev", "icon": "circle-user", diff --git a/package-lock.json b/package-lock.json index 22f41e5..e2833f1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "user-avatars", - "version": "3.0.1", + "version": "3.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "user-avatars", - "version": "3.0.1", + "version": "3.1.0", "devDependencies": { "@base-ui/react": "^1.6.0", "@pterodactyl/sdk": "file:./sdk/pterodactyl-sdk-2.0.0-beta.4.tgz", diff --git a/package.json b/package.json index 59a3aec..3568f8a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "user-avatars", "private": true, - "version": "3.0.1", + "version": "3.1.0", "type": "module", "scripts": { "build": "vite build", diff --git a/src/UserAvatarsProvider.php b/src/UserAvatarsProvider.php index a9b5bfb..2f22715 100644 --- a/src/UserAvatarsProvider.php +++ b/src/UserAvatarsProvider.php @@ -4,6 +4,7 @@ use Pterodactyl\Extensions\ExtensionProvider; use Pterodactyl\Services\Extensions\ExtensionSettingDefinition; +use Pterodactyl\Services\Extensions\ExtensionSettingFiles; use Pterodactyl\Services\Extensions\ExtensionSettingsDefinition; use Pterodactyl\Transformers\Api\Admin\UserTransformer as CoreAdminUserTransformer; use Pterodactyl\Transformers\Api\Client\UserTransformer as CoreClientUserTransformer; @@ -25,6 +26,11 @@ public function boot(): void ->field('number') ->label('Largest upload (KB)') ->help('Uploads are cropped to a square and resized to 256 pixels, so the stored file is much smaller than this.'), + ExtensionSettingDefinition::make('system_picture', 'system_picture', null) + ->file(ExtensionSettingFiles::IMAGES, 1024) + ->frontend() + ->label('System picture') + ->help('Shown in activity logs on rows with no user behind them, like failed logins and scheduled tasks. Leave empty for a plain system icon.'), ])); $this->app->scoped(AvatarService::class, fn () => new AvatarService($this->settings())); diff --git a/src/client/avatars.spec.tsx b/src/client/avatars.spec.tsx index c021125..1f8671d 100644 --- a/src/client/avatars.spec.tsx +++ b/src/client/avatars.spec.tsx @@ -2,7 +2,7 @@ import { afterEach, beforeEach, expect, test } from 'vitest'; import { cleanup, render, screen, waitFor } from '@testing-library/react'; import { createExtensionTestHost } from '@pterodactyl/sdk/testing'; import AccountAvatarCard from './components/AccountAvatarCard'; -import ActivityAvatars, { ACTIVITY_CLASS } from './components/ActivityAvatars'; +import ActivityAvatars, { ACTIVITY_CLASS, SYSTEM_CLASS, decorateActivityRows, setSystemPicture } from './components/ActivityAvatars'; import AdminUserAvatar from './components/AdminUserAvatar'; import NavAvatar, { ROOT_CLASS, ROOT_VARIABLE } from './components/NavAvatar'; import { myAvatarQuery, userAvatarQuery } from './api'; @@ -100,6 +100,30 @@ test('activity rows show the actor picture in place of the generated avatar', as await waitFor(() => expect(admin.classList.contains(ACTIVITY_CLASS)).toBe(true)); expect(admin.style.backgroundImage).toContain(UPLOADED.url); expect(system.classList.contains(ACTIVITY_CLASS)).toBe(false); + expect(system.classList.contains(SYSTEM_CLASS)).toBe(true); + expect(admin.classList.contains(SYSTEM_CLASS)).toBe(false); list.remove(); }); + +test('system rows use the admin system picture when one is set', () => { + const list = document.createElement('div'); + list.innerHTML = ` +
+
+
System
+
`; + const circle = list.querySelector('div.rounded-full')!; + + setSystemPicture('/extensions/user-avatars/files/system.png'); + decorateActivityRows(list, new Map()); + expect(circle.classList.contains(ACTIVITY_CLASS)).toBe(true); + expect(circle.classList.contains(SYSTEM_CLASS)).toBe(false); + expect(circle.style.backgroundImage).toContain('system.png'); + + setSystemPicture(null); + decorateActivityRows(list, new Map()); + expect(circle.classList.contains(ACTIVITY_CLASS)).toBe(false); + expect(circle.classList.contains(SYSTEM_CLASS)).toBe(true); + expect(circle.style.backgroundImage).toBe(''); +}); diff --git a/src/client/components/ActivityAvatars.tsx b/src/client/components/ActivityAvatars.tsx index 8566404..0bd2aff 100644 --- a/src/client/components/ActivityAvatars.tsx +++ b/src/client/components/ActivityAvatars.tsx @@ -2,6 +2,17 @@ import { useEffect } from 'react'; import { useQueryClient, type QueryClient } from '@tanstack/react-query'; export const ACTIVITY_CLASS = 'uavt-activity-avatar'; +export const SYSTEM_CLASS = 'uavt-activity-system'; + +/** The label core gives rows with no user behind them (failed logins, scheduled tasks). */ +const SYSTEM_LABEL = 'System'; + +/** The admin's "System picture" setting, if one was uploaded. */ +let systemPicture: string | undefined; + +export function setSystemPicture(value: unknown): void { + systemPicture = typeof value === 'string' && value.trim() !== '' ? value.trim() : undefined; +} interface ActorAttributes { username?: string; @@ -33,13 +44,19 @@ export function actorImages(client: QueryClient): Map { return images; } -/** Put each activity row's picture behind its generated avatar (hidden by styles.css). */ +/** + * Put each activity row's picture behind its generated avatar (hidden by styles.css). + * Rows with no user get the admin's system picture, or a plain system icon + * when none is set, instead of a generated pattern. + */ export function decorateActivityRows(root: ParentNode, images: Map): void { for (const svg of root.querySelectorAll('div.rounded-full > svg[role="img"]')) { const circle = svg.parentElement as HTMLElement; const row = circle.closest('.grid'); const username = row?.querySelector('.text-foreground > span:first-child')?.textContent?.trim(); - const image = username ? images.get(username) : undefined; + const image = (username ? images.get(username) : undefined) ?? (username === SYSTEM_LABEL ? systemPicture : undefined); + + circle.classList.toggle(SYSTEM_CLASS, !image && username === SYSTEM_LABEL); if (!image) { if (circle.classList.contains(ACTIVITY_CLASS)) { diff --git a/src/client/index.tsx b/src/client/index.tsx index d6e160b..ac15efb 100644 --- a/src/client/index.tsx +++ b/src/client/index.tsx @@ -1,12 +1,14 @@ import './styles.css'; import { definePterodactylExtension } from '@pterodactyl/sdk'; import AccountAvatarCard from './components/AccountAvatarCard'; -import ActivityAvatars from './components/ActivityAvatars'; +import ActivityAvatars, { setSystemPicture } from './components/ActivityAvatars'; import AdminUserAvatar from './components/AdminUserAvatar'; import NavAvatar from './components/NavAvatar'; export default definePterodactylExtension({ - setup({ slots }) { + setup({ slots, config }) { + setSystemPicture(config.system_picture); + slots.register('nav.items.after', NavAvatar); slots.register('account.overview.before', AccountAvatarCard); slots.register('panel.users.detail.actions', AdminUserAvatar); diff --git a/src/client/styles.css b/src/client/styles.css index 6f1a6c3..a3f0459 100644 --- a/src/client/styles.css +++ b/src/client/styles.css @@ -25,3 +25,22 @@ html.uavt-has-avatar a[aria-label='Account Settings'] > span > svg { .uavt-activity-avatar > svg { visibility: hidden; } + +/* Activity rows with no user (failed logins, tasks): a plain system icon, not a generated pattern. */ +.uavt-activity-system { + background-color: var(--popover); + justify-content: center; +} + +.uavt-activity-system > svg { + display: none; +} + +.uavt-activity-system::before { + content: ''; + width: 55%; + height: 55%; + background-color: var(--foreground); + opacity: 0.7; + mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect width='20' height='8' x='2' y='2' rx='2'/%3E%3Crect width='20' height='8' x='2' y='14' rx='2'/%3E%3Cline x1='6' x2='6.01' y1='6' y2='6'/%3E%3Cline x1='6' x2='6.01' y1='18' y2='18'/%3E%3C/svg%3E") center / contain no-repeat; +}