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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
009c4f7f
Commit
009c4f7f
authored
Aug 24, 2018
by
Chantal Rollison
Committed by
Sean McGivern
Aug 24, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allows author to vote on their own issue
parent
f4d18201
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
31 additions
and
91 deletions
+31
-91
app/assets/javascripts/awards_handler.js
app/assets/javascripts/awards_handler.js
+10
-23
app/assets/javascripts/notes/components/note_awards_list.vue
app/assets/javascripts/notes/components/note_awards_list.vue
+6
-18
app/controllers/concerns/toggle_award_emoji.rb
app/controllers/concerns/toggle_award_emoji.rb
+1
-1
app/helpers/issues_helper.rb
app/helpers/issues_helper.rb
+0
-8
app/models/concerns/awardable.rb
app/models/concerns/awardable.rb
+2
-14
app/services/quick_actions/interpret_service.rb
app/services/quick_actions/interpret_service.rb
+1
-1
app/views/award_emoji/_awards_block.html.haml
app/views/award_emoji/_awards_block.html.haml
+1
-2
app/views/projects/notes/_actions.html.haml
app/views/projects/notes/_actions.html.haml
+1
-1
app/views/snippets/notes/_actions.html.haml
app/views/snippets/notes/_actions.html.haml
+1
-1
changelogs/unreleased/ccr-43283_allow_author_upvote.yml
changelogs/unreleased/ccr-43283_allow_author_upvote.yml
+5
-0
lib/api/award_emoji.rb
lib/api/award_emoji.rb
+1
-1
spec/models/concerns/awardable_spec.rb
spec/models/concerns/awardable_spec.rb
+2
-9
spec/requests/api/award_emoji_spec.rb
spec/requests/api/award_emoji_spec.rb
+0
-12
No files found.
app/assets/javascripts/awards_handler.js
View file @
009c4f7f
...
...
@@ -109,8 +109,6 @@ export class AwardsHandler {
}
const
$menu
=
$
(
`.
${
this
.
menuClass
}
`
);
const
$thumbsBtn
=
$menu
.
find
(
'
[data-name="thumbsup"], [data-name="thumbsdown"]
'
).
parent
();
const
$userAuthored
=
this
.
isUserAuthored
(
$addBtn
);
if
(
$menu
.
length
)
{
if
(
$menu
.
is
(
'
.is-visible
'
))
{
$addBtn
.
removeClass
(
'
is-active
'
);
...
...
@@ -134,9 +132,6 @@ export class AwardsHandler {
},
200
);
});
}
$thumbsBtn
.
toggleClass
(
'
disabled
'
,
$userAuthored
);
$thumbsBtn
.
prop
(
'
disabled
'
,
$userAuthored
);
}
// Create the emoji menu with the first category of emojis.
...
...
@@ -364,10 +359,6 @@ export class AwardsHandler {
return
$emojiButton
.
hasClass
(
'
active
'
);
}
isUserAuthored
(
$button
)
{
return
$button
.
hasClass
(
'
js-user-authored
'
);
}
decrementCounter
(
$emojiButton
,
emoji
)
{
const
counter
=
$
(
'
.js-counter
'
,
$emojiButton
);
const
counterNumber
=
parseInt
(
counter
.
text
(),
10
);
...
...
@@ -474,20 +465,16 @@ export class AwardsHandler {
}
postEmoji
(
$emojiButton
,
awardUrl
,
emoji
,
callback
)
{
if
(
this
.
isUserAuthored
(
$emojiButton
))
{
this
.
userAuthored
(
$emojiButton
);
}
else
{
axios
.
post
(
awardUrl
,
{
name
:
emoji
,
})
.
then
(({
data
})
=>
{
if
(
data
.
ok
)
{
callback
();
}
})
.
catch
(()
=>
flash
(
__
(
'
Something went wrong on our end.
'
)));
}
axios
.
post
(
awardUrl
,
{
name
:
emoji
,
})
.
then
(({
data
})
=>
{
if
(
data
.
ok
)
{
callback
();
}
})
.
catch
(()
=>
flash
(
__
(
'
Something went wrong on our end.
'
)));
}
findEmojiIcon
(
votesBlock
,
emoji
)
{
...
...
app/assets/javascripts/notes/components/note_awards_list.vue
View file @
009c4f7f
...
...
@@ -82,29 +82,17 @@ export default {
getAwardHTML
(
name
)
{
return
glEmojiTag
(
name
);
},
getAwardClassBindings
(
awardList
,
awardName
)
{
getAwardClassBindings
(
awardList
)
{
return
{
active
:
this
.
hasReactionByCurrentUser
(
awardList
),
disabled
:
!
this
.
canInteractWithEmoji
(
awardList
,
awardName
),
disabled
:
!
this
.
canInteractWithEmoji
(),
};
},
canInteractWithEmoji
(
awardList
,
awardName
)
{
let
isAllowed
=
true
;
const
restrictedEmojis
=
[
'
thumbsup
'
,
'
thumbsdown
'
];
// Users can not add :+1: and :-1: to their own notes
if
(
this
.
getUserData
.
id
===
this
.
noteAuthorId
&&
restrictedEmojis
.
indexOf
(
awardName
)
>
-
1
)
{
isAllowed
=
false
;
}
return
this
.
getUserData
.
id
&&
isAllowed
;
canInteractWithEmoji
()
{
return
this
.
getUserData
.
id
;
},
hasReactionByCurrentUser
(
awardList
)
{
return
awardList
.
filter
(
award
=>
award
.
user
.
id
===
this
.
getUserData
.
id
)
.
length
;
return
awardList
.
filter
(
award
=>
award
.
user
.
id
===
this
.
getUserData
.
id
).
length
;
},
awardTitle
(
awardsList
)
{
const
hasReactionByCurrentUser
=
this
.
hasReactionByCurrentUser
(
...
...
@@ -197,7 +185,7 @@ export default {
v-tooltip
v-for=
"(awardList, awardName, index) in groupedAwards"
:key=
"index"
:class=
"getAwardClassBindings(awardList
, awardName
)"
:class=
"getAwardClassBindings(awardList)"
:title=
"awardTitle(awardList)"
class=
"btn award-control"
data-boundary=
"viewport"
...
...
app/controllers/concerns/toggle_award_emoji.rb
View file @
009c4f7f
...
...
@@ -5,7 +5,7 @@ module ToggleAwardEmoji
authenticate_user!
name
=
params
.
require
(
:name
)
if
awardable
.
user_can_award?
(
current_user
,
name
)
if
awardable
.
user_can_award?
(
current_user
)
awardable
.
toggle_award_emoji
(
name
,
current_user
)
todoable
=
to_todoable
(
awardable
)
...
...
app/helpers/issues_helper.rb
View file @
009c4f7f
...
...
@@ -92,14 +92,6 @@ module IssuesHelper
end
end
def
award_user_authored_class
(
award
)
if
award
==
'thumbsdown'
||
award
==
'thumbsup'
'user-authored js-user-authored'
else
''
end
end
def
awards_sort
(
awards
)
awards
.
sort_by
do
|
award
,
award_emojis
|
if
award
==
"thumbsup"
...
...
app/models/concerns/awardable.rb
View file @
009c4f7f
...
...
@@ -76,12 +76,8 @@ 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
)
def
user_can_award?
(
current_user
)
Ability
.
allowed?
(
current_user
,
:award_emoji
,
self
)
end
def
user_authored?
(
current_user
)
...
...
@@ -117,12 +113,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
app/services/quick_actions/interpret_service.rb
View file @
009c4f7f
...
...
@@ -402,7 +402,7 @@ module QuickActions
match
[
1
]
if
match
end
command
:award
do
|
name
|
if
name
&&
issuable
.
user_can_award?
(
current_user
,
name
)
if
name
&&
issuable
.
user_can_award?
(
current_user
)
@updates
[
:emoji_award
]
=
name
end
end
...
...
app/views/award_emoji/_awards_block.html.haml
View file @
009c4f7f
...
...
@@ -3,7 +3,7 @@
.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 +13,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'
)
...
...
app/views/projects/notes/_actions.html.haml
View file @
009c4f7f
...
...
@@ -40,7 +40,7 @@
-
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'
)
...
...
app/views/snippets/notes/_actions.html.haml
View file @
009c4f7f
...
...
@@ -2,7 +2,7 @@
-
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'
)
...
...
changelogs/unreleased/ccr-43283_allow_author_upvote.yml
0 → 100644
View file @
009c4f7f
---
title
:
Allow author to vote on their own issue and MRs
merge_request
:
21203
author
:
type
:
changed
lib/api/award_emoji.rb
View file @
009c4f7f
...
...
@@ -100,7 +100,7 @@ module API
end
def
can_award_awardable?
awardable
.
user_can_award?
(
current_user
,
params
[
:name
]
)
awardable
.
user_can_award?
(
current_user
)
end
def
awardable
...
...
spec/models/concerns/awardable_spec.rb
View file @
009c4f7f
...
...
@@ -53,21 +53,14 @@ describe Awardable do
issue
.
project
.
add_guest
(
user
)
end
it
'does not allow upvoting or downvoting your own issue'
do
issue
.
update!
(
author:
user
)
expect
(
issue
.
user_can_award?
(
user
,
AwardEmoji
::
DOWNVOTE_NAME
)).
to
be_falsy
expect
(
issue
.
user_can_award?
(
user
,
AwardEmoji
::
UPVOTE_NAME
)).
to
be_falsy
end
it
'is truthy when the user is allowed to award emoji'
do
expect
(
issue
.
user_can_award?
(
user
,
AwardEmoji
::
UPVOTE_NAME
)).
to
be_truthy
expect
(
issue
.
user_can_award?
(
user
)).
to
be_truthy
end
it
'is falsy when the project is archived'
do
issue
.
project
.
update!
(
archived:
true
)
expect
(
issue
.
user_can_award?
(
user
,
AwardEmoji
::
UPVOTE_NAME
)).
to
be_falsy
expect
(
issue
.
user_can_award?
(
user
)).
to
be_falsy
end
end
...
...
spec/requests/api/award_emoji_spec.rb
View file @
009c4f7f
...
...
@@ -167,12 +167,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'
...
...
@@ -215,12 +209,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'
...
...
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