diff --git a/frontend/app/common/static_store.ts b/frontend/app/common/static_store.ts index f01295ea..5c464722 100644 --- a/frontend/app/common/static_store.ts +++ b/frontend/app/common/static_store.ts @@ -27,6 +27,7 @@ export const StaticStore: StaticStoreType = { readonly_age: 0, max_image_size: 0, simple_view: false, + anon_vote: false, }, query: querySettings as QuerySettingsType, }; diff --git a/frontend/app/common/types.ts b/frontend/app/common/types.ts index 58ed9a8d..125486b4 100644 --- a/frontend/app/common/types.ts +++ b/frontend/app/common/types.ts @@ -112,6 +112,7 @@ export interface Config { readonly_age: number; max_image_size: number; simple_view: boolean; + anon_vote: boolean; } export interface RemarkConfig { diff --git a/frontend/app/components/comment/comment.test.tsx b/frontend/app/components/comment/comment.test.tsx index 1ddfc38e..00d683e7 100644 --- a/frontend/app/components/comment/comment.test.tsx +++ b/frontend/app/components/comment/comment.test.tsx @@ -32,6 +32,33 @@ const DefaultProps: Partial = { describe('', () => { describe('voting', () => { + it('should be disabled for an anonymous user', () => { + const props = { ...DefaultProps, user: { id: 'anonymous_1' } } as Props; + const wrapper = shallow(); + const voteButtons = wrapper.find('.comment__vote'); + + expect(voteButtons.length).toEqual(2); + + voteButtons.forEach(button => { + expect(button.prop('aria-disabled')).toEqual('true'); + expect(button.prop('title')).toEqual("Anonymous users can't vote"); + }); + }); + + it('should be enabled for an anonymous user when it was allowed from server', () => { + StaticStore.config.anon_vote = true; + + const props = { ...DefaultProps, user: { id: 'anonymous_1' } } as Props; + const wrapper = shallow(); + const voteButtons = wrapper.find('.comment__vote'); + + expect(voteButtons.length).toEqual(2); + + voteButtons.forEach(button => { + expect(button.prop('aria-disabled')).toEqual('false'); + }); + }); + it('disabled on user info widget', () => { const element = mount(); diff --git a/frontend/app/components/comment/comment.tsx b/frontend/app/components/comment/comment.tsx index 1576ed12..bfd55012 100644 --- a/frontend/app/components/comment/comment.tsx +++ b/frontend/app/components/comment/comment.tsx @@ -354,7 +354,7 @@ export class Comment extends Component { if (this.isCurrentUser()) return "Can't vote for your own comment"; if (StaticStore.config.positive_score && this.props.data.score < 1) return 'Only positive score allowed'; if (this.isGuest()) return 'Sign in to vote'; - if (this.isAnonymous()) return "Anonymous users can't vote"; + if (this.isAnonymous() && !StaticStore.config.anon_vote) return "Anonymous users can't vote"; return null; }; @@ -367,7 +367,7 @@ export class Comment extends Component { if (this.props.data.delete) return "Can't vote for deleted comment"; if (this.isCurrentUser()) return "Can't vote for your own comment"; if (this.isGuest()) return 'Sign in to vote'; - if (this.isAnonymous()) return "Anonymous users can't vote"; + if (this.isAnonymous() && !StaticStore.config.anon_vote) return "Anonymous users can't vote"; return null; }; diff --git a/frontend/app/testUtils/index.ts b/frontend/app/testUtils/index.ts index a5bd6733..1177b387 100644 --- a/frontend/app/testUtils/index.ts +++ b/frontend/app/testUtils/index.ts @@ -22,5 +22,6 @@ beforeEach(() => { readonly_age: 100, version: 'jest-test', simple_view: false, + anon_vote: false, }; });