Commit 25004cbc authored by Z.J. van de Weg's avatar Z.J. van de Weg Committed by Fatih Acet

Snippets get award emoji! 👍

parent b94de5fd
...@@ -508,6 +508,7 @@ v 8.10.0 ...@@ -508,6 +508,7 @@ v 8.10.0
- Updated project header design - Updated project header design
- Issuable collapsed assignee tooltip is now the users name - Issuable collapsed assignee tooltip is now the users name
- Fix compare view not changing code view rendering style - Fix compare view not changing code view rendering style
- Emoji can be awarded on Snippets !4456
- Exclude email check from the standard health check - Exclude email check from the standard health check
- Updated layout for Projects, Groups, Users on Admin area. !4424 - Updated layout for Projects, Groups, Users on Admin area. !4424
- Fix changing issue state columns in milestone view - Fix changing issue state columns in milestone view
......
...@@ -10,7 +10,9 @@ module ToggleAwardEmoji ...@@ -10,7 +10,9 @@ module ToggleAwardEmoji
if awardable.user_can_award?(current_user, name) if awardable.user_can_award?(current_user, name)
awardable.toggle_award_emoji(name, current_user) awardable.toggle_award_emoji(name, current_user)
TodoService.new.new_award_emoji(to_todoable(awardable), current_user)
todoable = to_todoable(awardable)
TodoService.new.new_award_emoji(todoable, current_user) if todoable
render json: { ok: true } render json: { ok: true }
else else
...@@ -24,8 +26,10 @@ module ToggleAwardEmoji ...@@ -24,8 +26,10 @@ module ToggleAwardEmoji
case awardable case awardable
when Note when Note
awardable.noteable awardable.noteable
else when MergeRequest, Issue
awardable awardable
when Snippet
nil
end end
end end
......
class SnippetsController < ApplicationController class SnippetsController < ApplicationController
include ToggleAwardEmoji
before_action :snippet, only: [:show, :edit, :destroy, :update, :raw] before_action :snippet, only: [:show, :edit, :destroy, :update, :raw]
# Allow read snippet # Allow read snippet
...@@ -85,6 +87,7 @@ class SnippetsController < ApplicationController ...@@ -85,6 +87,7 @@ class SnippetsController < ApplicationController
PersonalSnippet.find(params[:id]) PersonalSnippet.find(params[:id])
end end
end end
alias_method :awardable, :snippet
def authorize_read_snippet! def authorize_read_snippet!
authenticate_user! unless can?(current_user, :read_personal_snippet, @snippet) authenticate_user! unless can?(current_user, :read_personal_snippet, @snippet)
......
...@@ -4,6 +4,7 @@ class Snippet < ActiveRecord::Base ...@@ -4,6 +4,7 @@ class Snippet < ActiveRecord::Base
include Participable include Participable
include Referable include Referable
include Sortable include Sortable
include Awardable
default_value_for :visibility_level, Snippet::PRIVATE default_value_for :visibility_level, Snippet::PRIVATE
......
...@@ -101,6 +101,7 @@ Rails.application.routes.draw do ...@@ -101,6 +101,7 @@ Rails.application.routes.draw do
resources :snippets do resources :snippets do
member do member do
get 'raw' get 'raw'
post :toggle_award_emoji
end end
end end
...@@ -110,7 +111,6 @@ Rails.application.routes.draw do ...@@ -110,7 +111,6 @@ Rails.application.routes.draw do
# #
# Invites # Invites
# #
resources :invites, only: [:show], constraints: { id: /[A-Za-z0-9_-]+/ } do resources :invites, only: [:show], constraints: { id: /[A-Za-z0-9_-]+/ } do
member do member do
post :accept post :accept
...@@ -665,6 +665,7 @@ Rails.application.routes.draw do ...@@ -665,6 +665,7 @@ Rails.application.routes.draw do
resources :snippets, constraints: { id: /\d+/ } do resources :snippets, constraints: { id: /\d+/ } do
member do member do
get 'raw' get 'raw'
post :toggle_award_emoji
end end
end end
......
module API module API
class AwardEmoji < Grape::API class AwardEmoji < Grape::API
before { authenticate! } before { authenticate! }
AWARDABLES = [Issue, MergeRequest] AWARDABLES = [Issue, MergeRequest, Snippet]
resource :projects do resource :projects do
AWARDABLES.each do |awardable_type| AWARDABLES.each do |awardable_type|
......
require 'spec_helper' require 'spec_helper'
describe SnippetsController do describe SnippetsController do
describe 'GET #show' do let(:user) { create(:user) }
let(:user) { create(:user) }
describe 'GET #show' do
context 'when the personal snippet is private' do context 'when the personal snippet is private' do
let(:personal_snippet) { create(:personal_snippet, :private, author: user) } let(:personal_snippet) { create(:personal_snippet, :private, author: user) }
...@@ -230,4 +230,31 @@ describe SnippetsController do ...@@ -230,4 +230,31 @@ describe SnippetsController do
end end
end end
end end
context 'award emoji on snippets' do
let(:personal_snippet) { create(:personal_snippet, :private, author: user) }
before do
sign_in(user)
end
describe 'POST #toggle_award_emoji' do
it "toggles the award emoji" do
expect do
post(:toggle_award_emoji, id: personal_snippet.to_param, name: "thumbsup")
end.to change { personal_snippet.award_emoji.count }.by(1)
expect(response.status).to eq(200)
end
it "removes the already awarded emoji" do
post(:toggle_award_emoji, id: personal_snippet.to_param, name: "thumbsup")
expect do
post(:toggle_award_emoji, id: personal_snippet.to_param, name: "thumbsup")
end.to change { personal_snippet.award_emoji.count }.by(-1)
expect(response.status).to eq(200)
end
end
end
end end
...@@ -9,12 +9,14 @@ describe Snippet, models: true do ...@@ -9,12 +9,14 @@ describe Snippet, models: true do
it { is_expected.to include_module(Participable) } it { is_expected.to include_module(Participable) }
it { is_expected.to include_module(Referable) } it { is_expected.to include_module(Referable) }
it { is_expected.to include_module(Sortable) } it { is_expected.to include_module(Sortable) }
it { is_expected.to include_module(Awardable) }
end end
describe 'associations' do describe 'associations' do
it { is_expected.to belong_to(:author).class_name('User') } it { is_expected.to belong_to(:author).class_name('User') }
it { is_expected.to belong_to(:project) } it { is_expected.to belong_to(:project) }
it { is_expected.to have_many(:notes).dependent(:destroy) } it { is_expected.to have_many(:notes).dependent(:destroy) }
it { is_expected.to have_many(:award_emoji).dependent(:destroy) }
end end
describe 'validation' do describe 'validation' do
......
...@@ -14,6 +14,9 @@ describe API::API, api: true do ...@@ -14,6 +14,9 @@ describe API::API, api: true do
describe "GET /projects/:id/awardable/:awardable_id/award_emoji" do describe "GET /projects/:id/awardable/:awardable_id/award_emoji" do
context 'on an issue' do context 'on an issue' do
let(:issue) { create(:issue, project: project, author: user) }
let!(:award_emoji) { create(:award_emoji, awardable: issue, user: user) }
it "returns an array of award_emoji" do it "returns an array of award_emoji" do
get api("/projects/#{project.id}/issues/#{issue.id}/award_emoji", user) get api("/projects/#{project.id}/issues/#{issue.id}/award_emoji", user)
...@@ -39,6 +42,10 @@ describe API::API, api: true do ...@@ -39,6 +42,10 @@ describe API::API, api: true do
end end
end end
context 'on a snippet' do
it 'returns the awarded '
end
context 'when the user has no access' do context 'when the user has no access' do
it 'returns a status code 404' do it 'returns a status code 404' do
user1 = create(:user) user1 = create(:user)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment