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
a2f93a75
Commit
a2f93a75
authored
Apr 27, 2017
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return proper relation removal path on RelatedIssues::ListService
parent
ee743909
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
11 deletions
+50
-11
app/services/related_issues/list_service.rb
app/services/related_issues/list_service.rb
+11
-1
spec/services/related_issues/list_service_spec.rb
spec/services/related_issues/list_service_spec.rb
+39
-10
No files found.
app/services/related_issues/list_service.rb
View file @
a2f93a75
...
@@ -12,7 +12,8 @@ module RelatedIssues
...
@@ -12,7 +12,8 @@ module RelatedIssues
title:
referenced_issue
.
title
,
title:
referenced_issue
.
title
,
state:
referenced_issue
.
state
,
state:
referenced_issue
.
state
,
reference:
referenced_issue
.
to_reference
(
@issue
.
project
),
reference:
referenced_issue
.
to_reference
(
@issue
.
project
),
path:
namespace_project_issue_path
(
referenced_issue
.
project
.
namespace
,
referenced_issue
.
project
,
referenced_issue
.
iid
)
path:
namespace_project_issue_path
(
referenced_issue
.
project
.
namespace
,
referenced_issue
.
project
,
referenced_issue
.
iid
),
destroy_relation_path:
destroy_relation_path
(
referenced_issue
)
}
}
end
end
end
end
...
@@ -39,5 +40,14 @@ module RelatedIssues
...
@@ -39,5 +40,14 @@ module RelatedIssues
# TODO: Try to use SQL instead Array#select
# TODO: Try to use SQL instead Array#select
@issues
=
Ability
.
issues_readable_by_user
(
@issues
,
@current_user
)
@issues
=
Ability
.
issues_readable_by_user
(
@issues
,
@current_user
)
end
end
def
destroy_relation_path
(
issue
)
return
unless
Ability
.
allowed?
(
@current_user
,
:admin_related_issue
,
issue
.
project
)
namespace_project_issue_related_issue_path
(
issue
.
project
.
namespace
,
issue
.
project
,
issue
.
iid
,
issue
.
related_issues_id
)
end
end
end
end
end
spec/services/related_issues/list_service_spec.rb
View file @
a2f93a75
...
@@ -20,27 +20,24 @@ describe RelatedIssues::ListService, service: true do
...
@@ -20,27 +20,24 @@ describe RelatedIssues::ListService, service: true do
let!
(
:related_issue_c
)
do
let!
(
:related_issue_c
)
do
create
(
:related_issue
,
id:
999
,
create
(
:related_issue
,
id:
999
,
issue:
issue_d
,
issue:
issue_d
,
related_issue:
issue
,
related_issue:
issue
)
created_at:
Date
.
today
)
end
end
let!
(
:related_issue_b
)
do
let!
(
:related_issue_b
)
do
create
(
:related_issue
,
id:
998
,
create
(
:related_issue
,
id:
998
,
issue:
issue
,
issue:
issue
,
related_issue:
issue_c
,
related_issue:
issue_c
)
created_at:
1
.
day
.
ago
)
end
end
let!
(
:related_issue_a
)
do
let!
(
:related_issue_a
)
do
create
(
:related_issue
,
id:
997
,
create
(
:related_issue
,
id:
997
,
issue:
issue
,
issue:
issue
,
related_issue:
issue_b
,
related_issue:
issue_b
)
created_at:
2
.
days
.
ago
)
end
end
it
'verifies number of queries'
do
it
'verifies number of queries'
do
recorded
=
ActiveRecord
::
QueryRecorder
.
new
{
subject
}
recorded
=
ActiveRecord
::
QueryRecorder
.
new
{
subject
}
expect
(
recorded
.
count
).
to
be_within
(
1
).
of
(
25
)
expect
(
recorded
.
count
).
to
be_within
(
1
).
of
(
39
)
end
end
it
'returns related issues JSON'
do
it
'returns related issues JSON'
do
...
@@ -51,7 +48,8 @@ describe RelatedIssues::ListService, service: true do
...
@@ -51,7 +48,8 @@ describe RelatedIssues::ListService, service: true do
title:
issue_b
.
title
,
title:
issue_b
.
title
,
state:
issue_b
.
state
,
state:
issue_b
.
state
,
reference:
issue_b
.
to_reference
(
project
),
reference:
issue_b
.
to_reference
(
project
),
path:
"/
#{
project
.
full_path
}
/issues/
#{
issue_b
.
iid
}
"
path:
"/
#{
project
.
full_path
}
/issues/
#{
issue_b
.
iid
}
"
,
destroy_relation_path:
"/
#{
project
.
full_path
}
/issues/
#{
issue_b
.
iid
}
/related_issues/
#{
related_issue_a
.
id
}
"
}
}
)
)
...
@@ -60,7 +58,8 @@ describe RelatedIssues::ListService, service: true do
...
@@ -60,7 +58,8 @@ describe RelatedIssues::ListService, service: true do
title:
issue_c
.
title
,
title:
issue_c
.
title
,
state:
issue_c
.
state
,
state:
issue_c
.
state
,
reference:
issue_c
.
to_reference
(
project
),
reference:
issue_c
.
to_reference
(
project
),
path:
"/
#{
project
.
full_path
}
/issues/
#{
issue_c
.
iid
}
"
path:
"/
#{
project
.
full_path
}
/issues/
#{
issue_c
.
iid
}
"
,
destroy_relation_path:
"/
#{
project
.
full_path
}
/issues/
#{
issue_c
.
iid
}
/related_issues/
#{
related_issue_b
.
id
}
"
}
}
)
)
...
@@ -69,7 +68,8 @@ describe RelatedIssues::ListService, service: true do
...
@@ -69,7 +68,8 @@ describe RelatedIssues::ListService, service: true do
title:
issue_d
.
title
,
title:
issue_d
.
title
,
state:
issue_d
.
state
,
state:
issue_d
.
state
,
reference:
issue_d
.
to_reference
(
project
),
reference:
issue_d
.
to_reference
(
project
),
path:
"/
#{
project
.
full_path
}
/issues/
#{
issue_d
.
iid
}
"
path:
"/
#{
project
.
full_path
}
/issues/
#{
issue_d
.
iid
}
"
,
destroy_relation_path:
"/
#{
project
.
full_path
}
/issues/
#{
issue_d
.
iid
}
/related_issues/
#{
related_issue_c
.
id
}
"
}
}
)
)
end
end
...
@@ -96,5 +96,34 @@ describe RelatedIssues::ListService, service: true do
...
@@ -96,5 +96,34 @@ describe RelatedIssues::ListService, service: true do
end
end
end
end
end
end
context
'remove relations'
do
let!
(
:related_issue
)
do
create
(
:related_issue
,
issue:
issue
,
related_issue:
referenced_issue
)
end
context
'when user can admin related issues on one project'
do
let
(
:unauthorized_project
)
{
create
:empty_project
}
let
(
:referenced_issue
)
{
create
:issue
,
project:
unauthorized_project
}
before
do
# User can just see related issues
unauthorized_project
.
team
<<
[
user
,
:guest
]
end
it
'returns no destroy relation path'
do
expect
(
subject
.
first
[
:destroy_relation_path
]).
to
be_nil
end
end
context
'when user can admin related issues on both projects'
do
let
(
:referenced_issue
)
{
create
:issue
,
project:
project
}
it
'returns related issue destroy relation path'
do
expect
(
subject
.
first
[
:destroy_relation_path
])
.
to
eq
(
"/
#{
project
.
full_path
}
/issues/
#{
referenced_issue
.
iid
}
/related_issues/
#{
related_issue
.
id
}
"
)
end
end
end
end
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