Skip to content

Commit d6d53ff

Browse files
authored
Merge pull request #2001 from umputun/fix/admin-edit-frontend-1986
Fix frontend not respecting ADMIN_EDIT config
2 parents 195becc + a1215d8 commit d6d53ff

File tree

6 files changed

+27
-14
lines changed

6 files changed

+27
-14
lines changed

frontend/apps/remark42/app/__stubs__/static-config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ beforeEach(() => {
88
critical_score: -15,
99
low_score: -5,
1010
edit_duration: 300,
11+
admin_edit: false,
1112
max_comment_size: 3000,
1213
max_image_size: 5000,
1314
positive_score: false,

frontend/apps/remark42/app/common/static-store.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const StaticStore: StaticStoreType = {
1515
config: {
1616
version: '',
1717
edit_duration: 5000,
18+
admin_edit: false,
1819
max_comment_size: 5000,
1920
admins: [],
2021
admin_email: '',

frontend/apps/remark42/app/common/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ export interface Config {
109109
version: string;
110110
auth_providers: Provider[];
111111
edit_duration: number;
112+
admin_edit: boolean;
112113
max_comment_size: number;
113114
admins: string[];
114115
admin_email: string;

frontend/apps/remark42/app/components/comment/comment-actions.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,15 @@ export function CommentActions({
7373
<Button kind="link" size="sm" onClick={onToggleEditing}>
7474
{intl.formatMessage(editing ? messages.cancel : messages.edit)}
7575
</Button>
76-
<span
77-
role="timer"
78-
title={intl.formatMessage(messages.editCountdown)}
79-
className={clsx('comment-actions-countdown', styles.countdown)}
80-
>
81-
<Countdown timestamp={editDeadline} onTimePassed={onDisableEditing} />
82-
</span>
76+
{Number.isFinite(editDeadline) && (
77+
<span
78+
role="timer"
79+
title={intl.formatMessage(messages.editCountdown)}
80+
className={clsx('comment-actions-countdown', styles.countdown)}
81+
>
82+
<Countdown timestamp={editDeadline} onTimePassed={onDisableEditing} />
83+
</span>
84+
)}
8385
</>
8486
)}
8587
<div

frontend/apps/remark42/app/components/comment/comment.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,15 @@ export class Comment extends Component<CommentProps, State> {
102102

103103
// set comment edit timer
104104
if (this.isCurrentUser()) {
105-
const editDuration = StaticStore.config.edit_duration;
106-
const timeDiff = StaticStore.serverClientTimeDiff || 0;
107-
const editDeadline = new Date(props.data.time).getTime() + timeDiff + editDuration * 1000;
108-
109-
newState.editDeadline = editDeadline > Date.now() ? editDeadline : undefined;
105+
if (this.isAdmin() && StaticStore.config.admin_edit) {
106+
newState.editDeadline = Infinity;
107+
} else {
108+
const editDuration = StaticStore.config.edit_duration;
109+
const timeDiff = StaticStore.serverClientTimeDiff || 0;
110+
const editDeadline = new Date(props.data.time).getTime() + timeDiff + editDuration * 1000;
111+
112+
newState.editDeadline = editDeadline > Date.now() ? editDeadline : undefined;
113+
}
110114
}
111115

112116
return newState;
@@ -488,7 +492,10 @@ export class Comment extends Component<CommentProps, State> {
488492
copied={state.isCopied}
489493
editing={isEditing}
490494
replying={isReplying}
491-
editable={props.repliesCount === 0 && state.editDeadline !== undefined}
495+
editable={
496+
state.editDeadline !== undefined &&
497+
(props.repliesCount === 0 || (isAdmin && StaticStore.config.admin_edit))
498+
}
492499
editDeadline={state.editDeadline}
493500
readOnly={props.post_info?.read_only}
494501
onToggleReplying={this.toggleReplying}

frontend/packages/api/clients/public.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export interface Config {
66
version: string
77
auth_providers: Provider[]
88
edit_duration: number
9+
admin_edit: boolean
910
max_comment_size: number
1011
admins: string[]
1112
admin_email: string
@@ -103,7 +104,7 @@ export function createPublicClient({ siteId: site, baseUrl }: ClientParams) {
103104
async function getComments(url: string): Promise<CommentsTree>
104105
async function getComments(params: GetUserCommentsParams): Promise<Comment[]>
105106
async function getComments(
106-
params: string | GetUserCommentsParams
107+
params: string | GetUserCommentsParams,
107108
): Promise<Comment[] | CommentsTree> {
108109
if (typeof params === 'string') {
109110
return fetcher.get('/comments', { url: params })

0 commit comments

Comments
 (0)