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
248970ab
Commit
248970ab
authored
May 31, 2017
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Addresses aesthetic details on text and naming
parent
9d389de0
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
65 additions
and
68 deletions
+65
-68
app/controllers/projects/issue_links_controller.rb
app/controllers/projects/issue_links_controller.rb
+5
-5
app/models/issue_link.rb
app/models/issue_link.rb
+1
-1
app/models/system_note_metadata.rb
app/models/system_note_metadata.rb
+2
-1
app/services/issue_links/create_service.rb
app/services/issue_links/create_service.rb
+2
-2
app/services/issue_links/destroy_service.rb
app/services/issue_links/destroy_service.rb
+4
-4
spec/models/issue_link_spec.rb
spec/models/issue_link_spec.rb
+18
-5
spec/requests/projects/issue_links_controller_spec.rb
spec/requests/projects/issue_links_controller_spec.rb
+29
-46
spec/services/issue_links/create_service_spec.rb
spec/services/issue_links/create_service_spec.rb
+4
-4
No files found.
app/controllers/projects/issue_links_controller.rb
View file @
248970ab
...
@@ -7,10 +7,10 @@ module Projects
...
@@ -7,10 +7,10 @@ module Projects
end
end
def
create
def
create
opt
s
=
params
.
slice
(
:issue_references
)
create_param
s
=
params
.
slice
(
:issue_references
)
result
=
IssueLinks
::
CreateService
.
new
(
issue
,
current_user
,
opt
s
).
execute
result
=
IssueLinks
::
CreateService
.
new
(
issue
,
current_user
,
create_param
s
).
execute
render
json:
{
result:
result
,
issues:
issues
},
status:
result
[
:http_status
]
render
json:
{
message:
result
[
:message
]
,
issues:
issues
},
status:
result
[
:http_status
]
end
end
def
destroy
def
destroy
...
@@ -18,9 +18,9 @@ module Projects
...
@@ -18,9 +18,9 @@ module Projects
return
render_403
unless
can?
(
current_user
,
:admin_issue_link
,
issue_link
.
target
.
project
)
return
render_403
unless
can?
(
current_user
,
:admin_issue_link
,
issue_link
.
target
.
project
)
result
=
IssueLinks
::
DestroyService
.
new
(
issue_link
,
current_user
).
execute
IssueLinks
::
DestroyService
.
new
(
issue_link
,
current_user
).
execute
render
json:
{
result:
result
,
issues:
issues
}
render
json:
{
issues:
issues
}
end
end
private
private
...
...
app/models/issue_link.rb
View file @
248970ab
...
@@ -10,7 +10,7 @@ class IssueLink < ActiveRecord::Base
...
@@ -10,7 +10,7 @@ class IssueLink < ActiveRecord::Base
private
private
def
check_self_relation
def
check_self_relation
return
unless
source
||
target
return
unless
source
&&
target
if
source
==
target
if
source
==
target
errors
.
add
(
:source
,
'cannot be related to itself'
)
errors
.
add
(
:source
,
'cannot be related to itself'
)
...
...
app/models/system_note_metadata.rb
View file @
248970ab
...
@@ -2,7 +2,8 @@ class SystemNoteMetadata < ActiveRecord::Base
...
@@ -2,7 +2,8 @@ class SystemNoteMetadata < ActiveRecord::Base
ICON_TYPES
=
%w[
ICON_TYPES
=
%w[
commit description merge confidential visible label assignee cross_reference
commit description merge confidential visible label assignee cross_reference
title time_tracking branch milestone discussion task moved opened closed merged
title time_tracking branch milestone discussion task moved opened closed merged
outdated approved unapproved relate unrelate
outdated
approved unapproved relate unrelate
]
.
freeze
]
.
freeze
validates
:note
,
presence:
true
validates
:note
,
presence:
true
...
...
app/services/issue_links/create_service.rb
View file @
248970ab
...
@@ -9,13 +9,13 @@ module IssueLinks
...
@@ -9,13 +9,13 @@ module IssueLinks
return
error
(
'No Issue found for given reference'
,
401
)
return
error
(
'No Issue found for given reference'
,
401
)
end
end
create_issue_link
create_issue_link
s
success
success
end
end
private
private
def
create_issue_link
def
create_issue_link
s
referenced_issues
.
each
do
|
referenced_issue
|
referenced_issues
.
each
do
|
referenced_issue
|
create_notes
(
referenced_issue
)
if
relate_issues
(
referenced_issue
)
create_notes
(
referenced_issue
)
if
relate_issues
(
referenced_issue
)
end
end
...
...
app/services/issue_links/destroy_service.rb
View file @
248970ab
...
@@ -8,19 +8,19 @@ module IssueLinks
...
@@ -8,19 +8,19 @@ module IssueLinks
end
end
def
execute
def
execute
remove_relation
!
remove_relation
create_notes
!
create_notes
success
(
message:
'Relation was removed'
)
success
(
message:
'Relation was removed'
)
end
end
private
private
def
remove_relation
!
def
remove_relation
@issue_link
.
destroy!
@issue_link
.
destroy!
end
end
def
create_notes
!
def
create_notes
SystemNoteService
.
unrelate_issue
(
@issue
,
@referenced_issue
,
current_user
)
SystemNoteService
.
unrelate_issue
(
@issue
,
@referenced_issue
,
current_user
)
SystemNoteService
.
unrelate_issue
(
@referenced_issue
,
@issue
,
current_user
)
SystemNoteService
.
unrelate_issue
(
@referenced_issue
,
@issue
,
current_user
)
end
end
...
...
spec/models/issue_link_spec.rb
View file @
248970ab
...
@@ -18,12 +18,25 @@ describe IssueLink do
...
@@ -18,12 +18,25 @@ describe IssueLink do
end
end
context
'self relation'
do
context
'self relation'
do
it
'invalidates object'
do
let
(
:issue
)
{
create
:issue
}
issue
=
create
:issue
issue_link
=
build
:issue_link
,
source:
issue
,
target:
issue
expect
(
issue_link
).
to
be_invalid
context
'cannot be validated'
do
expect
(
issue_link
.
errors
[
:source
]).
to
include
(
'cannot be related to itself'
)
it
'does not invalidate object with self relation error'
do
issue_link
=
build
:issue_link
,
source:
issue
,
target:
nil
issue_link
.
valid?
expect
(
issue_link
.
errors
[
:source
]).
to
be_empty
end
end
context
'can be invalidated'
do
it
'invalidates object'
do
issue_link
=
build
:issue_link
,
source:
issue
,
target:
issue
expect
(
issue_link
).
to
be_invalid
expect
(
issue_link
.
errors
[
:source
]).
to
include
(
'cannot be related to itself'
)
end
end
end
end
end
end
end
...
...
spec/requests/projects/issue_links_controller_spec.rb
View file @
248970ab
...
@@ -19,17 +19,10 @@ describe Projects::IssueLinksController do
...
@@ -19,17 +19,10 @@ describe Projects::IssueLinksController do
login_as
user
login_as
user
end
end
subject
do
get
namespace_project_issue_links_path
(
namespace_id:
issue
.
project
.
namespace
,
project_id:
issue
.
project
,
issue_id:
issue
,
format: :json
)
end
it
'returns JSON response'
do
it
'returns JSON response'
do
list_service_response
=
IssueLinks
::
ListService
.
new
(
issue
,
user
).
execute
list_service_response
=
IssueLinks
::
ListService
.
new
(
issue
,
user
).
execute
subject
get
namespace_project_issue_links_path
(
issue_links_params
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
eq
(
list_service_response
.
as_json
)
expect
(
json_response
).
to
eq
(
list_service_response
.
as_json
)
...
@@ -38,87 +31,70 @@ describe Projects::IssueLinksController do
...
@@ -38,87 +31,70 @@ describe Projects::IssueLinksController do
describe
'POST /*namespace_id/:project_id/issues/:issue_id/links'
do
describe
'POST /*namespace_id/:project_id/issues/:issue_id/links'
do
let
(
:issue_b
)
{
create
:issue
,
project:
project
}
let
(
:issue_b
)
{
create
:issue
,
project:
project
}
let
(
:issue_references
)
{
[
issue_b
.
to_reference
]
}
let
(
:user_role
)
{
:developer
}
before
do
before
do
project
.
team
<<
[
user
,
user_role
]
project
.
team
<<
[
user
,
user_role
]
login_as
user
login_as
user
end
end
subject
do
post
namespace_project_issue_links_path
(
namespace_id:
issue
.
project
.
namespace
,
project_id:
issue
.
project
,
issue_id:
issue
,
issue_references:
issue_references
,
format: :json
)
end
context
'with success'
do
context
'with success'
do
let
(
:user_role
)
{
:developer
}
let
(
:issue_references
)
{
[
issue_b
.
to_reference
]
}
it
'returns success JSON'
do
it
'returns success JSON'
do
subject
post
namespace_project_issue_links_path
(
issue_links_params
(
issue_references:
issue_references
))
list_service_response
=
IssueLinks
::
ListService
.
new
(
issue
,
user
).
execute
list_service_response
=
IssueLinks
::
ListService
.
new
(
issue
,
user
).
execute
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'result'
]).
to
eq
(
'status'
=>
'success'
)
expect
(
json_response
).
to
eq
(
'message'
=>
nil
,
expect
(
json_response
[
'issues'
]).
to
eq
(
list_service_response
.
as_json
)
'issues'
=>
list_service_response
.
as_json
)
end
end
end
end
context
'with failure'
do
context
'with failure'
do
context
'when unauthorized'
do
context
'when unauthorized'
do
let
(
:user_role
)
{
:guest
}
let
(
:user_role
)
{
:guest
}
let
(
:issue_references
)
{
[
issue_b
.
to_reference
]
}
it
'returns 403'
do
it
'returns 403'
do
subject
post
namespace_project_issue_links_path
(
issue_links_params
(
issue_references:
issue_references
))
expect
(
response
).
to
have_http_status
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
end
end
context
'when failing service result'
do
context
'when failing service result'
do
let
(
:user_role
)
{
:developer
}
let
(
:issue_references
)
{
[
'#999'
]
}
let
(
:issue_references
)
{
[
'#999'
]
}
it
'returns failure JSON'
do
it
'returns failure JSON'
do
subject
post
namespace_project_issue_links_path
(
issue_links_params
(
issue_references:
issue_references
))
list_service_response
=
IssueLinks
::
ListService
.
new
(
issue
,
user
).
execute
list_service_response
=
IssueLinks
::
ListService
.
new
(
issue
,
user
).
execute
expect
(
response
).
to
have_http_status
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
expect
(
json_response
[
'result'
]).
to
eq
(
'message'
=>
'No Issue found for given reference'
,
expect
(
json_response
).
to
eq
(
'message'
=>
'No Issue found for given reference'
,
'issues'
=>
list_service_response
.
as_json
)
'status'
=>
'error'
,
'http_status'
=>
401
)
expect
(
json_response
[
'issues'
]).
to
eq
(
list_service_response
.
as_json
)
end
end
end
end
end
end
end
end
describe
'DELETE /*namespace_id/:project_id/issues/:issue_id/link/:id'
do
describe
'DELETE /*namespace_id/:project_id/issues/:issue_id/link/:id'
do
let
(
:referenced_issue
)
{
create
:issue
,
project:
project
}
let
(
:issue_link
)
{
create
:issue_link
,
target:
referenced_issue
}
let
(
:issue_link
)
{
create
:issue_link
,
target:
referenced_issue
}
let
(
:current_project_user_role
)
{
:developer
}
subject
do
delete
namespace_project_issue_link_path
(
namespace_id:
issue
.
project
.
namespace
,
project_id:
issue
.
project
,
issue_id:
issue
,
id:
issue_link
.
id
,
format: :json
)
end
before
do
before
do
project
.
team
<<
[
user
,
current_project_
user_role
]
project
.
team
<<
[
user
,
user_role
]
login_as
user
login_as
user
end
end
context
'when unauthorized'
do
context
'when unauthorized'
do
context
'when no authorization on current project'
do
context
'when no authorization on current project'
do
let
(
:current_project_user_role
)
{
:guest
}
let
(
:referenced_issue
)
{
create
:issue
,
project:
project
}
let
(
:user_role
)
{
:guest
}
it
'returns 403'
do
it
'returns 403'
do
subject
delete
namespace_project_issue_link_path
(
issue_links_params
(
id:
issue_link
.
id
))
expect
(
response
).
to
have_http_status
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
...
@@ -127,10 +103,10 @@ describe Projects::IssueLinksController do
...
@@ -127,10 +103,10 @@ describe Projects::IssueLinksController do
context
'when no authorization on the related issue project'
do
context
'when no authorization on the related issue project'
do
# unauthorized project issue
# unauthorized project issue
let
(
:referenced_issue
)
{
create
:issue
}
let
(
:referenced_issue
)
{
create
:issue
}
let
(
:
current_project_
user_role
)
{
:developer
}
let
(
:user_role
)
{
:developer
}
it
'returns 403'
do
it
'returns 403'
do
subject
delete
namespace_project_issue_link_path
(
issue_links_params
(
id:
issue_link
.
id
))
expect
(
response
).
to
have_http_status
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
...
@@ -138,16 +114,23 @@ describe Projects::IssueLinksController do
...
@@ -138,16 +114,23 @@ describe Projects::IssueLinksController do
end
end
context
'when authorized'
do
context
'when authorized'
do
let
(
:current_project_user_role
)
{
:developer
}
let
(
:referenced_issue
)
{
create
:issue
,
project:
project
}
let
(
:user_role
)
{
:developer
}
it
'returns success JSON'
do
it
'returns success JSON'
do
subject
delete
namespace_project_issue_link_path
(
issue_links_params
(
id:
issue_link
.
id
))
list_service_response
=
IssueLinks
::
ListService
.
new
(
issue
,
user
).
execute
list_service_response
=
IssueLinks
::
ListService
.
new
(
issue
,
user
).
execute
expect
(
json_response
[
'result'
]).
to
eq
(
'message'
=>
'Relation was removed'
,
'status'
=>
'success'
)
expect
(
json_response
).
to
eq
(
'issues'
=>
list_service_response
.
as_json
)
expect
(
json_response
[
'issues'
]).
to
eq
(
list_service_response
.
as_json
)
end
end
end
end
end
end
def
issue_links_params
(
opts
=
{})
opts
.
reverse_merge
(
namespace_id:
issue
.
project
.
namespace
,
project_id:
issue
.
project
,
issue_id:
issue
,
format: :json
)
end
end
end
spec/services/issue_links/create_service_spec.rb
View file @
248970ab
...
@@ -19,7 +19,7 @@ describe IssueLinks::CreateService, service: true do
...
@@ -19,7 +19,7 @@ describe IssueLinks::CreateService, service: true do
subject
{
described_class
.
new
(
issue
,
user
,
params
).
execute
}
subject
{
described_class
.
new
(
issue
,
user
,
params
).
execute
}
context
'when
empty reference list
'
do
context
'when
the reference list is empty
'
do
let
(
:params
)
do
let
(
:params
)
do
{
issue_references:
[]
}
{
issue_references:
[]
}
end
end
...
@@ -61,7 +61,7 @@ describe IssueLinks::CreateService, service: true do
...
@@ -61,7 +61,7 @@ describe IssueLinks::CreateService, service: true do
end
end
end
end
context
'when
any I
ssue to relate'
do
context
'when
there is an i
ssue to relate'
do
let
(
:issue_a
)
{
create
:issue
,
project:
project
}
let
(
:issue_a
)
{
create
:issue
,
project:
project
}
let
(
:another_project
)
{
create
:empty_project
,
namespace:
project
.
namespace
}
let
(
:another_project
)
{
create
:empty_project
,
namespace:
project
.
namespace
}
let
(
:another_project_issue
)
{
create
:issue
,
project:
another_project
}
let
(
:another_project_issue
)
{
create
:issue
,
project:
another_project
}
...
@@ -84,7 +84,7 @@ describe IssueLinks::CreateService, service: true do
...
@@ -84,7 +84,7 @@ describe IssueLinks::CreateService, service: true do
expect
(
IssueLink
.
find_by!
(
target:
another_project_issue
)).
to
have_attributes
(
source:
issue
)
expect
(
IssueLink
.
find_by!
(
target:
another_project_issue
)).
to
have_attributes
(
source:
issue
)
end
end
it
'returns success
message with Issue reference
'
do
it
'returns success
status
'
do
is_expected
.
to
eq
(
status: :success
)
is_expected
.
to
eq
(
status: :success
)
end
end
...
@@ -117,7 +117,7 @@ describe IssueLinks::CreateService, service: true do
...
@@ -117,7 +117,7 @@ describe IssueLinks::CreateService, service: true do
{
issue_references:
[
issue_b
.
to_reference
,
issue_a
.
to_reference
]
}
{
issue_references:
[
issue_b
.
to_reference
,
issue_a
.
to_reference
]
}
end
end
it
'returns success'
do
it
'returns success
status
'
do
is_expected
.
to
eq
(
status: :success
)
is_expected
.
to
eq
(
status: :success
)
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