diff options
author | Annabel Dunstone Gray <annabel.dunstone@gmail.com> | 2018-08-08 14:14:37 -0500 |
---|---|---|
committer | Annabel Dunstone Gray <annabel.dunstone@gmail.com> | 2018-08-08 14:14:37 -0500 |
commit | 9187e23e5a93e0031bc17be8b49edde89ee7f3da (patch) | |
tree | a220946a9fad872868d20aec0ac866f8b28f8918 | |
parent | 6f21652f0b79a614ad809dc028aaa28aee16732e (diff) | |
download | gitlab-ce-43283-upvote-your-own-stuff.tar.gz |
Allow users to upvote or downvote their own contributions43283-upvote-your-own-stuff
-rw-r--r-- | app/controllers/concerns/toggle_award_emoji.rb | 12 | ||||
-rw-r--r-- | app/models/concerns/awardable.rb | 22 | ||||
-rw-r--r-- | app/views/award_emoji/_awards_block.html.haml | 4 | ||||
-rw-r--r-- | app/views/projects/notes/_actions.html.haml | 3 | ||||
-rw-r--r-- | app/views/snippets/notes/_actions.html.haml | 3 | ||||
-rw-r--r-- | lib/api/award_emoji.rb | 6 | ||||
-rw-r--r-- | spec/requests/api/award_emoji_spec.rb | 14 |
7 files changed, 8 insertions, 56 deletions
diff --git a/app/controllers/concerns/toggle_award_emoji.rb b/app/controllers/concerns/toggle_award_emoji.rb index ba5b7d33f87..2bbb92869b6 100644 --- a/app/controllers/concerns/toggle_award_emoji.rb +++ b/app/controllers/concerns/toggle_award_emoji.rb @@ -5,16 +5,12 @@ module ToggleAwardEmoji authenticate_user! name = params.require(:name) - if awardable.user_can_award?(current_user, name) - awardable.toggle_award_emoji(name, current_user) + awardable.toggle_award_emoji(name, current_user) - todoable = to_todoable(awardable) - TodoService.new.new_award_emoji(todoable, current_user) if todoable + todoable = to_todoable(awardable) + TodoService.new.new_award_emoji(todoable, current_user) if todoable - render json: { ok: true } - else - render json: { ok: false } - end + render json: { ok: true } end private diff --git a/app/models/concerns/awardable.rb b/app/models/concerns/awardable.rb index dd07f389fa5..571041110a1 100644 --- a/app/models/concerns/awardable.rb +++ b/app/models/concerns/awardable.rb @@ -76,20 +76,6 @@ module Awardable true end - def awardable_votes?(name) - AwardEmoji::UPVOTE_NAME == name || AwardEmoji::DOWNVOTE_NAME == name - end - - def user_can_award?(current_user, name) - awardable_by_user?(current_user, name) && Ability.allowed?(current_user, :award_emoji, self) - end - - def user_authored?(current_user) - author = self.respond_to?(:author) ? self.author : self.user - - author == current_user - end - def awarded_emoji?(emoji_name, current_user) award_emoji.where(name: emoji_name, user: current_user).exists? end @@ -117,12 +103,4 @@ module Awardable def normalize_name(name) Gitlab::Emoji.normalize_emoji_name(name) end - - def awardable_by_user?(current_user, name) - if user_authored?(current_user) - !awardable_votes?(normalize_name(name)) - else - true - end - end end diff --git a/app/views/award_emoji/_awards_block.html.haml b/app/views/award_emoji/_awards_block.html.haml index 8ca9fb4512e..a758a63dfb3 100644 --- a/app/views/award_emoji/_awards_block.html.haml +++ b/app/views/award_emoji/_awards_block.html.haml @@ -1,9 +1,8 @@ - grouped_emojis = awardable.grouped_awards(with_thumbs: inline) -- user_authored = awardable.user_authored?(current_user) .awards.js-awards-block{ class: ("hidden" if !inline && grouped_emojis.empty?), data: { award_url: toggle_award_url(awardable) } } - awards_sort(grouped_emojis).each do |emoji, awards| %button.btn.award-control.js-emoji-btn.has-tooltip{ type: "button", - class: [(award_state_class(awardable, awards, current_user)), (award_user_authored_class(emoji) if user_authored)], + class: [(award_state_class(awardable, awards, current_user))], data: { placement: "bottom", title: award_user_list(awards, current_user) } } = emoji_icon(emoji) %span.award-control-text.js-counter @@ -13,7 +12,6 @@ .award-menu-holder.js-award-holder %button.btn.award-control.has-tooltip.js-add-award{ type: 'button', 'aria-label': _('Add reaction'), - class: ("js-user-authored" if user_authored), data: { title: _('Add reaction'), placement: "bottom" } } %span{ class: "award-control-icon award-control-icon-neutral" }= custom_icon('emoji_slightly_smiling_face') %span{ class: "award-control-icon award-control-icon-positive" }= custom_icon('emoji_smiley') diff --git a/app/views/projects/notes/_actions.html.haml b/app/views/projects/notes/_actions.html.haml index b4fe1cabdfd..74519aec4cc 100644 --- a/app/views/projects/notes/_actions.html.haml +++ b/app/views/projects/notes/_actions.html.haml @@ -38,9 +38,8 @@ - if can?(current_user, :award_emoji, note) - if note.emoji_awardable? - - user_authored = note.user_authored?(current_user) .note-actions-item - = button_tag title: 'Add reaction', class: "note-action-button note-emoji-button js-add-award js-note-emoji #{'js-user-authored' if user_authored} has-tooltip btn btn-transparent", data: { position: 'right', container: 'body' } do + = button_tag title: 'Add reaction', class: "note-action-button note-emoji-button js-add-award js-note-emoji has-tooltip btn btn-transparent", data: { position: 'right', container: 'body' } do = icon('spinner spin') %span{ class: 'link-highlight award-control-icon-neutral' }= custom_icon('emoji_slightly_smiling_face') %span{ class: 'link-highlight award-control-icon-positive' }= custom_icon('emoji_smiley') diff --git a/app/views/snippets/notes/_actions.html.haml b/app/views/snippets/notes/_actions.html.haml index 3a50324770d..220ba2b49e6 100644 --- a/app/views/snippets/notes/_actions.html.haml +++ b/app/views/snippets/notes/_actions.html.haml @@ -1,8 +1,7 @@ - if current_user - if note.emoji_awardable? - - user_authored = note.user_authored?(current_user) .note-actions-item - = link_to '#', title: 'Add reaction', class: "note-action-button note-emoji-button js-add-award js-note-emoji #{'js-user-authored' if user_authored} has-tooltip", data: { position: 'right' } do + = link_to '#', title: 'Add reaction', class: "note-action-button note-emoji-button js-add-award js-note-emoji has-tooltip", data: { position: 'right' } do = icon('spinner spin') %span{ class: 'link-highlight award-control-icon-neutral' }= custom_icon('emoji_slightly_smiling_face') %span{ class: 'link-highlight award-control-icon-positive' }= custom_icon('emoji_smiley') diff --git a/lib/api/award_emoji.rb b/lib/api/award_emoji.rb index c3d93996816..072312d8d2a 100644 --- a/lib/api/award_emoji.rb +++ b/lib/api/award_emoji.rb @@ -65,7 +65,7 @@ module API requires :name, type: String, desc: 'The name of a award_emoji (without colons)' end post endpoint do - not_found!('Award Emoji') unless can_read_awardable? && can_award_awardable? + not_found!('Award Emoji') unless can_read_awardable? award = awardable.create_award_emoji(params[:name], current_user) @@ -99,10 +99,6 @@ module API can?(current_user, read_ability(awardable), awardable) end - def can_award_awardable? - awardable.user_can_award?(current_user, params[:name]) - end - def awardable @awardable ||= begin diff --git a/spec/requests/api/award_emoji_spec.rb b/spec/requests/api/award_emoji_spec.rb index 0921fecb933..3238424304a 100644 --- a/spec/requests/api/award_emoji_spec.rb +++ b/spec/requests/api/award_emoji_spec.rb @@ -144,7 +144,6 @@ describe API::AwardEmoji do end describe "POST /projects/:id/awardable/:awardable_id/award_emoji" do - let(:issue2) { create(:issue, project: project, author: user) } context "on an issue" do it "creates a new award emoji" do @@ -167,12 +166,6 @@ describe API::AwardEmoji do expect(response).to have_gitlab_http_status(401) end - it "returns a 404 error if the user authored issue" do - post api("/projects/#{project.id}/issues/#{issue2.id}/award_emoji", user), name: 'thumbsup' - - expect(response).to have_gitlab_http_status(404) - end - it "normalizes +1 as thumbsup award" do post api("/projects/#{project.id}/issues/#{issue.iid}/award_emoji", user), name: '+1' @@ -204,7 +197,6 @@ describe API::AwardEmoji do end describe "POST /projects/:id/awardable/:awardable_id/notes/:note_id/award_emoji" do - let(:note2) { create(:note, project: project, noteable: issue, author: user) } it 'creates a new award emoji' do expect do @@ -215,12 +207,6 @@ describe API::AwardEmoji do expect(json_response['user']['username']).to eq(user.username) end - it "it returns 404 error when user authored note" do - post api("/projects/#{project.id}/issues/#{issue.iid}/notes/#{note2.id}/award_emoji", user), name: 'thumbsup' - - expect(response).to have_gitlab_http_status(404) - end - it "normalizes +1 as thumbsup award" do post api("/projects/#{project.id}/issues/#{issue.iid}/notes/#{note.id}/award_emoji", user), name: '+1' |