mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(post): show specific role in moderation posting warning
Replace the generic "posting as moderator" label with the effective role (5chan dev, owner, admin, or moderator) in post and reply forms.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { KNOWN_5CHAN_DEVELOPER_ENTRIES, get5chanDeveloperBadge, getAuthorBadge, isKnown5chanDeveloper } from '../author-display-utils';
|
||||
import { KNOWN_5CHAN_DEVELOPER_ENTRIES, get5chanDeveloperBadge, getAuthorBadge, getModerationPostingRoleLabel, isKnown5chanDeveloper } from '../author-display-utils';
|
||||
|
||||
describe('author display utils', () => {
|
||||
it('recognizes the hardcoded 5chan developer addresses', () => {
|
||||
@@ -61,4 +61,12 @@ describe('author display utils', () => {
|
||||
title: 'administrator_of_this_board',
|
||||
});
|
||||
});
|
||||
|
||||
it('returns the posting warning label for the effective moderator role', () => {
|
||||
expect(getModerationPostingRoleLabel({ address: 'plebeius.bso', role: 'owner' })).toBe('5chan dev');
|
||||
expect(getModerationPostingRoleLabel({ address: 'other.bso', role: 'owner' })).toBe('owner');
|
||||
expect(getModerationPostingRoleLabel({ address: 'other.bso', role: 'admin' })).toBe('admin');
|
||||
expect(getModerationPostingRoleLabel({ address: 'other.bso', role: 'moderator' })).toBe('moderator');
|
||||
expect(getModerationPostingRoleLabel({ address: 'other.bso', role: 'viewer' })).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -51,3 +51,12 @@ export const getAuthorBadge = ({ address, role }: { address?: string; role?: str
|
||||
title: isMod ? 'moderator_of_this_board' : 'administrator_of_this_board',
|
||||
};
|
||||
};
|
||||
|
||||
export const getModerationPostingRoleLabel = ({ address, role }: { address?: string; role?: string }): string | undefined => {
|
||||
if (isKnown5chanDeveloper(address)) return '5chan dev';
|
||||
|
||||
const normalizedRole = role?.trim().toLowerCase();
|
||||
if (normalizedRole === 'owner' || normalizedRole === 'admin' || normalizedRole === 'moderator') return normalizedRole;
|
||||
|
||||
return undefined;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user