fix(mod-queue): show board button from live roles (#1079)

* fix(mod-queue): show board button from live roles

* fix(mod-queue): require live role for board access
This commit is contained in:
Tommaso Casaburi
2026-03-13 16:37:57 +08:00
committed by GitHub
parent 726522586c
commit fd9ab19de3
4 changed files with 104 additions and 7 deletions
@@ -0,0 +1,61 @@
import { describe, expect, it } from 'vitest';
import { canAccessBoardModQueue, hasModQueueAccessRole } from '../mod-access';
describe('hasModQueueAccessRole', () => {
it('accepts board moderation roles', () => {
expect(hasModQueueAccessRole('owner')).toBe(true);
expect(hasModQueueAccessRole('admin')).toBe(true);
expect(hasModQueueAccessRole('moderator')).toBe(true);
});
it('rejects missing and unrelated roles', () => {
expect(hasModQueueAccessRole(undefined)).toBe(false);
expect(hasModQueueAccessRole('viewer')).toBe(false);
});
});
describe('canAccessBoardModQueue', () => {
it('allows access to the global queue when at least one moderated board is cached', () => {
expect(
canAccessBoardModQueue({
accountCommunityAddresses: ['music-posting.eth'],
}),
).toBe(true);
});
it('rejects access to the global queue when no moderated boards are cached', () => {
expect(
canAccessBoardModQueue({
accountCommunityAddresses: [],
}),
).toBe(false);
});
it('allows access when the current board role is moderator even without cached board membership', () => {
expect(
canAccessBoardModQueue({
boardAddress: '12D3KooWNFgjQWX2EUEs7pixdjkWSLh21EZ9NeYnV8iMaCyYhLGJ',
accountCommunityAddresses: [],
accountRole: 'moderator',
}),
).toBe(true);
});
it('rejects board-scoped access when only the cached moderated board matches by alias', () => {
expect(
canAccessBoardModQueue({
boardAddress: 'music-posting.eth',
accountCommunityAddresses: ['music-posting.bso'],
}),
).toBe(false);
});
it('rejects access when neither the role nor moderated board list matches', () => {
expect(
canAccessBoardModQueue({
boardAddress: 'music-posting.eth',
accountCommunityAddresses: ['tech-posting.eth'],
}),
).toBe(false);
});
});
+19
View File
@@ -0,0 +1,19 @@
export const hasModQueueAccessRole = (role?: string): boolean => role === 'admin' || role === 'owner' || role === 'moderator';
interface BoardModQueueAccessArgs {
boardAddress?: string;
accountCommunityAddresses: string[];
accountRole?: string;
}
export const canAccessBoardModQueue = ({ boardAddress, accountCommunityAddresses, accountRole }: BoardModQueueAccessArgs): boolean => {
if (hasModQueueAccessRole(accountRole)) {
return true;
}
if (!boardAddress) {
return accountCommunityAddresses.length > 0;
}
return false;
};