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
0cdce852
Commit
0cdce852
authored
Nov 05, 2019
by
Vitali Tatarintev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check if user can comment on issue
Add extra check preventing create notes for issues with locked discussion
parent
ba9b746b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
34 deletions
+38
-34
lib/gitlab/slash_commands/issue_comment.rb
lib/gitlab/slash_commands/issue_comment.rb
+9
-4
spec/lib/gitlab/slash_commands/issue_comment_spec.rb
spec/lib/gitlab/slash_commands/issue_comment_spec.rb
+29
-30
No files found.
lib/gitlab/slash_commands/issue_comment.rb
View file @
0cdce852
...
...
@@ -11,15 +11,12 @@ module Gitlab
'issue comment <id> *`⇧ Shift`*+*`↵ Enter`* <comment>'
end
def
self
.
allowed?
(
issue
,
user
)
can?
(
user
,
:create_note
,
issue
)
end
def
execute
(
match
)
note_body
=
match
[
:note_body
].
to_s
.
strip
issue
=
find_by_iid
(
match
[
:iid
])
return
not_found
unless
issue
return
access_denied
unless
can_create_note?
(
issue
)
note
=
create_note
(
issue:
issue
,
note:
note_body
)
...
...
@@ -32,10 +29,18 @@ module Gitlab
private
def
can_create_note?
(
issue
)
Ability
.
allowed?
(
current_user
,
:create_note
,
issue
)
end
def
not_found
Gitlab
::
SlashCommands
::
Presenters
::
Access
.
new
.
not_found
end
def
access_denied
Gitlab
::
SlashCommands
::
Presenters
::
Access
.
new
.
generic_access_denied
end
def
create_note
(
issue
:,
note
:)
note_params
=
{
noteable:
issue
,
note:
note
}
...
...
spec/lib/gitlab/slash_commands/issue_comment_spec.rb
View file @
0cdce852
...
...
@@ -3,24 +3,43 @@
require
'spec_helper'
describe
Gitlab
::
SlashCommands
::
IssueComment
do
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:user
)
{
issue
.
author
}
describe
'#execute'
do
let
(
:project
)
{
create
(
:project
,
:public
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:user
)
{
issue
.
author
}
let
(
:chat_name
)
{
double
(
:chat_name
,
user:
user
)
}
let
(
:regex_match
)
{
described_class
.
match
(
"issue comment
#{
issue
.
iid
}
\n
Comment body"
)
}
subject
{
described_class
.
new
(
project
,
chat_name
).
execute
(
regex_match
)
}
context
'when the issue exists'
do
context
'when the user does not have permission'
do
context
'when project is private'
do
let
(
:project
)
{
create
(
:project
)
}
context
'when the user is not a member of the project'
do
let
(
:chat_name
)
{
double
(
:chat_name
,
user:
create
(
:user
))
}
it
'does not allow the user to comment'
do
expect
(
subject
[
:response_type
]).
to
be
(
:ephemeral
)
expect
(
subject
[
:text
]).
to
match
(
'not found'
)
expect
(
issue
.
reload
.
notes
.
count
).
to
be_zero
end
end
end
context
'when the user is not a member of the project'
do
let
(
:chat_name
)
{
double
(
:chat_name
,
user:
create
(
:user
))
}
it
'does not allow the user to comment'
do
expect
(
subject
[
:response_type
]).
to
be
(
:ephemeral
)
expect
(
subject
[
:text
]).
to
match
(
'not found'
)
expect
(
issue
.
reload
.
notes
.
count
).
to
be_zero
context
'when the discussion is locked in the issue'
do
before
do
issue
.
update!
(
discussion_locked:
true
)
end
it
'does not allow the user to comment'
do
expect
(
subject
[
:response_type
]).
to
be
(
:ephemeral
)
expect
(
subject
[
:text
]).
to
match
(
'You are not allowed'
)
expect
(
issue
.
reload
.
notes
.
count
).
to
be_zero
end
end
end
...
...
@@ -52,7 +71,7 @@ describe Gitlab::SlashCommands::IssueComment do
end
end
context
'the issue does not exist'
do
context
'
when
the issue does not exist'
do
let
(
:regex_match
)
{
described_class
.
match
(
"issue comment 2343242
\n
Comment body"
)
}
it
'returns not found'
do
...
...
@@ -95,24 +114,4 @@ describe Gitlab::SlashCommands::IssueComment do
end
end
end
describe
'.allowed?'
do
subject
{
described_class
.
allowed?
(
issue
,
user
)
}
before
do
allow
(
Ability
).
to
receive
(
:allowed?
).
with
(
user
,
:create_note
,
issue
).
and_return
(
is_allowed
)
end
context
'when the user can create a note'
do
let
(
:is_allowed
)
{
true
}
it
{
is_expected
.
to
be_truthy
}
end
context
'when the user cannot create a note'
do
let
(
:is_allowed
)
{
false
}
it
{
is_expected
.
to
be_falsey
}
end
end
end
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