Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
Qpixel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
EIP
Answers
Qpixel
Commits
766d0afd
Commit
766d0afd
authored
Jun 9, 2020
by
ArtOfCode-
Browse files
Options
Downloads
Patches
Plain Diff
Add voting
parent
6e429592
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/models/vote.rb
+5
-2
5 additions, 2 deletions
app/models/vote.rb
db/seeds/site_settings.yml
+14
-0
14 additions, 0 deletions
db/seeds/site_settings.yml
with
19 additions
and
2 deletions
app/models/vote.rb
+
5
−
2
View file @
766d0afd
...
...
@@ -17,7 +17,8 @@ class Vote < ApplicationRecord
def
self
.
total_rep_change
(
col
)
col
=
col
.
includes
(
:post
)
settings
=
SiteSetting
.
where
(
name:
[
'QuestionUpVoteRep'
,
'QuestionDownVoteRep'
,
'AnswerUpVoteRep'
,
'AnswerDownVoteRep'
])
'AnswerUpVoteRep'
,
'AnswerDownVoteRep'
,
'ArticleUpVoteRep'
,
'ArticleDownVoteRep'
])
.
map
{
|
ss
|
[
ss
.
name
,
ss
.
value
]
}.
to_h
rep_changes
=
PostType
.
mapping
.
map
do
|
k
,
v
|
vote_types
=
{
1
=>
'Up'
,
-
1
=>
'Down'
}
...
...
@@ -45,7 +46,9 @@ class Vote < ApplicationRecord
[
post_type_ids
[
'Question'
],
1
]
=>
'QuestionUpVoteRep'
,
[
post_type_ids
[
'Question'
],
-
1
]
=>
'QuestionDownVoteRep'
,
[
post_type_ids
[
'Answer'
],
1
]
=>
'AnswerUpVoteRep'
,
[
post_type_ids
[
'Answer'
],
-
1
]
=>
'AnswerDownVoteRep'
[
post_type_ids
[
'Answer'
],
-
1
]
=>
'AnswerDownVoteRep'
,
[
post_type_ids
[
'Article'
],
1
]
=>
'ArticleUpVoteRep'
,
[
post_type_ids
[
'Article'
],
-
1
]
=>
'ArticleDownVoteRep'
}
rep_change
=
SiteSetting
[
setting_names
[[
post
.
post_type_id
,
vote_type
]]]
||
0
recv_user
.
update!
(
reputation:
recv_user
.
reputation
+
direction
*
rep_change
)
...
...
This diff is collapsed.
Click to expand it.
db/seeds/site_settings.yml
+
14
−
0
View file @
766d0afd
...
...
@@ -54,6 +54,20 @@
description
:
>
The reputation change to the post's author when an answer is downvoted.
-
name
:
ArticleUpVoteRep
value
:
10
value_type
:
integer
category
:
ReputationAndVoting
description
:
>
The reputation change to the post's author when an article is upvoted.
-
name
:
ArticleDownVoteRep
value
:
-2
value_type
:
integer
category
:
ReputationAndVoting
description
:
>
The reputation change to the post's author when an article is downvoted.
-
name
:
AllowSelfVotes
value
:
false
value_type
:
boolean
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment