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
929ff01a
Commit
929ff01a
authored
Sep 20, 2016
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure we have a user before checking for their permission in Notes::SlashCommandsService
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
3970640b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
0 deletions
+70
-0
app/services/notes/slash_commands_service.rb
app/services/notes/slash_commands_service.rb
+1
-0
spec/services/notes/slash_commands_service_spec.rb
spec/services/notes/slash_commands_service_spec.rb
+69
-0
No files found.
app/services/notes/slash_commands_service.rb
View file @
929ff01a
...
@@ -11,6 +11,7 @@ module Notes
...
@@ -11,6 +11,7 @@ module Notes
def
self
.
supported?
(
note
,
current_user
)
def
self
.
supported?
(
note
,
current_user
)
noteable_update_service
(
note
)
&&
noteable_update_service
(
note
)
&&
current_user
&&
current_user
.
can?
(
:"update_
#{
note
.
noteable_type
.
underscore
}
"
,
note
.
noteable
)
current_user
.
can?
(
:"update_
#{
note
.
noteable_type
.
underscore
}
"
,
note
.
noteable
)
end
end
...
...
spec/services/notes/slash_commands_service_spec.rb
View file @
929ff01a
...
@@ -122,6 +122,75 @@ describe Notes::SlashCommandsService, services: true do
...
@@ -122,6 +122,75 @@ describe Notes::SlashCommandsService, services: true do
end
end
end
end
describe
'.noteable_update_service'
do
include_context
'note on noteable'
it
'returns Issues::UpdateService for a note on an issue'
do
note
=
create
(
:note_on_issue
,
project:
project
)
expect
(
described_class
.
noteable_update_service
(
note
)).
to
eq
(
Issues
::
UpdateService
)
end
it
'returns Issues::UpdateService for a note on a merge request'
do
note
=
create
(
:note_on_merge_request
,
project:
project
)
expect
(
described_class
.
noteable_update_service
(
note
)).
to
eq
(
MergeRequests
::
UpdateService
)
end
it
'returns nil for a note on a commit'
do
note
=
create
(
:note_on_commit
,
project:
project
)
expect
(
described_class
.
noteable_update_service
(
note
)).
to
be_nil
end
end
describe
'.supported?'
do
include_context
'note on noteable'
let
(
:note
)
{
create
(
:note_on_issue
,
project:
project
)
}
context
'with no current_user'
do
it
'returns false'
do
expect
(
described_class
.
supported?
(
note
,
nil
)).
to
be_falsy
end
end
context
'when current_user cannot update the noteable'
do
it
'returns false'
do
user
=
create
(
:user
)
expect
(
described_class
.
supported?
(
note
,
user
)).
to
be_falsy
end
end
context
'when current_user can update the noteable'
do
it
'returns true'
do
expect
(
described_class
.
supported?
(
note
,
master
)).
to
be_truthy
end
context
'with a note on a commit'
do
let
(
:note
)
{
create
(
:note_on_commit
,
project:
project
)
}
it
'returns false'
do
expect
(
described_class
.
supported?
(
note
,
nil
)).
to
be_falsy
end
end
end
end
describe
'#supported?'
do
include_context
'note on noteable'
it
'delegates to the class method'
do
service
=
described_class
.
new
(
project
,
master
)
note
=
create
(
:note_on_issue
,
project:
project
)
expect
(
described_class
).
to
receive
(
:supported?
).
with
(
note
,
master
)
service
.
supported?
(
note
)
end
end
describe
'#execute'
do
describe
'#execute'
do
let
(
:service
)
{
described_class
.
new
(
project
,
master
)
}
let
(
:service
)
{
described_class
.
new
(
project
,
master
)
}
...
...
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