Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow voting for anonymous users #541

Merged
merged 1 commit into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions frontend/app/common/static_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
1 change: 1 addition & 0 deletions frontend/app/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export interface Config {
readonly_age: number;
max_image_size: number;
simple_view: boolean;
anon_vote: boolean;
}

export interface RemarkConfig {
Expand Down
27 changes: 27 additions & 0 deletions frontend/app/components/comment/comment.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,33 @@ const DefaultProps: Partial<Props> = {

describe('<Comment />', () => {
describe('voting', () => {
it('should be disabled for an anonymous user', () => {
const props = { ...DefaultProps, user: { id: 'anonymous_1' } } as Props;
const wrapper = shallow(<Comment {...props} />);
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(<Comment {...props} />);
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(<Comment {...({ ...DefaultProps, view: 'user' } as Props)} />);

Expand Down
4 changes: 2 additions & 2 deletions frontend/app/components/comment/comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ export class Comment extends Component<Props, State> {
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;
};

Expand All @@ -367,7 +367,7 @@ export class Comment extends Component<Props, State> {
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;
};

Expand Down
1 change: 1 addition & 0 deletions frontend/app/testUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ beforeEach(() => {
readonly_age: 100,
version: 'jest-test',
simple_view: false,
anon_vote: false,
};
});