Allow voting for anonymous users

This commit is contained in:
Pavel Mineev
2020-01-07 23:43:49 -06:00
committed by Umputun
parent 5ee76febf2
commit bfa308e8da
5 changed files with 32 additions and 2 deletions
+1
View File
@@ -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
View File
@@ -112,6 +112,7 @@ export interface Config {
readonly_age: number;
max_image_size: number;
simple_view: boolean;
anon_vote: boolean;
}
export interface RemarkConfig {
@@ -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)} />);
+2 -2
View File
@@ -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;
};
@@ -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;
};
+1
View File
@@ -22,5 +22,6 @@ beforeEach(() => {
readonly_age: 100,
version: 'jest-test',
simple_view: false,
anon_vote: false,
};
});