Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
25004cbc
Commit
25004cbc
authored
Jun 03, 2016
by
Z.J. van de Weg
Committed by
Fatih Acet
Sep 19, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Snippets get award emoji!
👍
parent
b94de5fd
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
52 additions
and
6 deletions
+52
-6
CHANGELOG
CHANGELOG
+1
-0
app/controllers/concerns/toggle_award_emoji.rb
app/controllers/concerns/toggle_award_emoji.rb
+6
-2
app/controllers/snippets_controller.rb
app/controllers/snippets_controller.rb
+3
-0
app/models/snippet.rb
app/models/snippet.rb
+1
-0
config/routes.rb
config/routes.rb
+2
-1
lib/api/award_emoji.rb
lib/api/award_emoji.rb
+1
-1
spec/controllers/snippets_controller_spec.rb
spec/controllers/snippets_controller_spec.rb
+29
-2
spec/models/snippet_spec.rb
spec/models/snippet_spec.rb
+2
-0
spec/requests/api/award_emoji_spec.rb
spec/requests/api/award_emoji_spec.rb
+7
-0
No files found.
CHANGELOG
View file @
25004cbc
...
@@ -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
...
...
app/controllers/concerns/toggle_award_emoji.rb
View file @
25004cbc
...
@@ -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
els
e
when
MergeRequest
,
Issu
e
awardable
awardable
when
Snippet
nil
end
end
end
end
...
...
app/controllers/snippets_controller.rb
View file @
25004cbc
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
)
...
...
app/models/snippet.rb
View file @
25004cbc
...
@@ -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
...
...
config/routes.rb
View file @
25004cbc
...
@@ -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
...
...
lib/api/award_emoji.rb
View file @
25004cbc
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
|
...
...
spec/controllers/snippets_controller_spec.rb
View file @
25004cbc
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
spec/models/snippet_spec.rb
View file @
25004cbc
...
@@ -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
...
...
spec/requests/api/award_emoji_spec.rb
View file @
25004cbc
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment