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:
@@ -1027,6 +1027,24 @@ describe('PostForm', () => {
|
||||
expect(container.textContent).not.toContain('warning: posting as moderator');
|
||||
});
|
||||
|
||||
it('uses the 5chan dev label for known developer moderator posts', async () => {
|
||||
testState.account = {
|
||||
author: { address: 'plebeius.bso', displayName: 'Tom' },
|
||||
subscriptions: ['music-posting.eth'],
|
||||
};
|
||||
testState.resolvedCommunityAddress = 'music-posting.eth';
|
||||
testState.rolesByCommunity = {
|
||||
'music-posting.eth': {
|
||||
'plebeius.bso': { role: 'owner' },
|
||||
},
|
||||
};
|
||||
|
||||
await renderPostForm('/mu');
|
||||
await clickByText(container, 'start_new_thread');
|
||||
|
||||
expect(container.textContent).toContain('warning: posting as 5chan dev');
|
||||
});
|
||||
|
||||
it('shows the pasted file-link filename next to the upload button', async () => {
|
||||
testState.uploadedFileName = null;
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
} from '../../lib/utils/post-options-utils';
|
||||
import { truncateWithEllipsisInMiddle } from '../../lib/utils/string-utils';
|
||||
import { getPublishURLFilename, isValidPublishURL, isValidURL } from '../../lib/utils/url-utils';
|
||||
import { getModerationPostingRoleLabel } from '../../lib/utils/author-display-utils';
|
||||
import { hasModQueueAccessRole } from '../../lib/utils/mod-access';
|
||||
import { getBoardPath } from '../../lib/utils/route-utils';
|
||||
import { isAllView, isCatalogView, isModQueueView, isModView, isPostPageView, isSubscriptionsView } from '../../lib/utils/view-utils';
|
||||
@@ -536,6 +537,8 @@ const PostFormTable = ({ closeForm, postCid }: { closeForm: () => void; postCid:
|
||||
const roles = useCommunityField(effectiveBoardAddress, (community) => community?.roles);
|
||||
const accountRole = accountAddress ? roles?.[accountAddress]?.role : undefined;
|
||||
const showBbcodeToolbar = hasModQueueAccessRole(accountRole) || (!effectiveBoardAddress && isInModView && accountCommunityAddresses.length > 0);
|
||||
const moderationPostingRoleLabel = getModerationPostingRoleLabel({ address: accountAddress, role: accountRole });
|
||||
const moderationPostingWarning = showBbcodeToolbar && moderationPostingRoleLabel ? `warning: posting as ${moderationPostingRoleLabel}` : undefined;
|
||||
|
||||
const [lengthError, setLengthError] = useState<string | null>(null);
|
||||
const [formError, setFormError] = useState<string | PostOptionsValidationError | null>(null);
|
||||
@@ -877,7 +880,7 @@ const PostFormTable = ({ closeForm, postCid }: { closeForm: () => void; postCid:
|
||||
/>
|
||||
</tbody>
|
||||
</table>
|
||||
{showBbcodeToolbar ? <div className={`${styles.error} ${styles.formError}`}>warning: posting as moderator</div> : null}
|
||||
{moderationPostingWarning ? <div className={`${styles.error} ${styles.formError}`}>{moderationPostingWarning}</div> : null}
|
||||
{formError ? (
|
||||
<div className={`${styles.error} ${styles.formError}`}>
|
||||
{isPostOptionsValidationError(formError) ? <PostOptionsErrorMessage error={formError} directories={directories} /> : formError}
|
||||
|
||||
@@ -759,8 +759,8 @@ describe('ReplyModal', () => {
|
||||
expect(container.querySelector('select[aria-label="Text color"]')).toBeNull();
|
||||
expect(container.textContent).not.toContain('mods only');
|
||||
expect(container.textContent).not.toContain('Mod editor');
|
||||
expect(container.textContent).toContain('warning: posting as moderator');
|
||||
const moderatorWarning = Array.from(container.querySelectorAll('div')).find((element) => element.textContent === 'warning: posting as moderator');
|
||||
expect(container.textContent).toContain('warning: posting as admin');
|
||||
const moderatorWarning = Array.from(container.querySelectorAll('div')).find((element) => element.textContent === 'warning: posting as admin');
|
||||
expect(moderatorWarning?.className).toContain('error');
|
||||
expect(container.querySelector('button[aria-label="Quote"]')).toBeNull();
|
||||
|
||||
@@ -778,7 +778,7 @@ describe('ReplyModal', () => {
|
||||
|
||||
expect(container.querySelector('button[aria-label="Red text"]')).toBeNull();
|
||||
expect(container.textContent).not.toContain('mods only');
|
||||
expect(container.textContent).not.toContain('warning: posting as moderator');
|
||||
expect(container.textContent).not.toContain('warning: posting as admin');
|
||||
});
|
||||
|
||||
it('updates account state, applies upload completions, and closes once publishing succeeds', async () => {
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
} from '../../lib/utils/post-options-utils';
|
||||
import { getPublishURLFilename, isValidPublishURL } from '../../lib/utils/url-utils';
|
||||
import { hasModQueueAccessRole } from '../../lib/utils/mod-access';
|
||||
import { getModerationPostingRoleLabel } from '../../lib/utils/author-display-utils';
|
||||
import { isAllView, isModView, isSubscriptionsView } from '../../lib/utils/view-utils';
|
||||
import useSelectedTextStore from '../../stores/use-selected-text-store';
|
||||
import useReplyModalStore from '../../stores/use-reply-modal-store';
|
||||
@@ -81,6 +82,8 @@ const ReplyModal = ({ closeModal, showReplyModal, parentCid, parentNumber, threa
|
||||
const roles = useCommunityField(communityAddress, (community) => community?.roles);
|
||||
const accountRole = accountAddress ? roles?.[accountAddress]?.role : undefined;
|
||||
const showBbcodeToolbar = hasModQueueAccessRole(accountRole);
|
||||
const moderationPostingRoleLabel = getModerationPostingRoleLabel({ address: accountAddress, role: accountRole });
|
||||
const moderationPostingWarning = showBbcodeToolbar && moderationPostingRoleLabel ? `warning: posting as ${moderationPostingRoleLabel}` : undefined;
|
||||
const textRef = useRef<HTMLTextAreaElement | null>(null);
|
||||
const setTextRef = useRef((element: HTMLTextAreaElement | null) => {
|
||||
textRef.current = element;
|
||||
@@ -609,7 +612,7 @@ const ReplyModal = ({ closeModal, showReplyModal, parentCid, parentNumber, threa
|
||||
{t('post')}
|
||||
</button>
|
||||
</div>
|
||||
{showBbcodeToolbar ? <div className={styles.error}>warning: posting as moderator</div> : null}
|
||||
{moderationPostingWarning ? <div className={styles.error}>{moderationPostingWarning}</div> : null}
|
||||
{lengthError ? (
|
||||
<div className={styles.error}>{lengthError}</div>
|
||||
) : error ? (
|
||||
|
||||
Reference in New Issue
Block a user