Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "user-avatars",
"private": true,
"version": "3.0.1",
"version": "3.1.0",
"type": "module",
"scripts": {
"build": "vite build",
Expand Down
6 changes: 6 additions & 0 deletions src/UserAvatarsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()));
Expand Down
26 changes: 25 additions & 1 deletion src/client/avatars.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 = `
<div class="grid grid-cols-10">
<div><div class="w-10 h-10 rounded-full overflow-hidden"><svg role="img"></svg></div></div>
<div><div class="flex items-center text-foreground"><span>System</span></div></div>
</div>`;
const circle = list.querySelector<HTMLElement>('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('');
});
21 changes: 19 additions & 2 deletions src/client/components/ActivityAvatars.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -33,13 +44,19 @@ export function actorImages(client: QueryClient): Map<string, string> {
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<string, string>): void {
for (const svg of root.querySelectorAll<SVGElement>('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)) {
Expand Down
6 changes: 4 additions & 2 deletions src/client/index.tsx
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
19 changes: 19 additions & 0 deletions src/client/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Loading