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
06786aa5
Commit
06786aa5
authored
Jan 24, 2019
by
Mario de la Ossa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use a Serializer for related issues/epics
Use serializers for: - EpicLinks - EpicIssueLinks - IssueLinks
parent
c441a155
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
137 additions
and
92 deletions
+137
-92
ee/app/serializers/linked_epic_entity.rb
ee/app/serializers/linked_epic_entity.rb
+19
-0
ee/app/serializers/linked_epic_issue_entity.rb
ee/app/serializers/linked_epic_issue_entity.rb
+23
-0
ee/app/serializers/linked_epic_issue_serializer.rb
ee/app/serializers/linked_epic_issue_serializer.rb
+5
-0
ee/app/serializers/linked_epic_serializer.rb
ee/app/serializers/linked_epic_serializer.rb
+5
-0
ee/app/serializers/linked_issue_entity.rb
ee/app/serializers/linked_issue_entity.rb
+37
-0
ee/app/serializers/linked_project_issue_entity.rb
ee/app/serializers/linked_project_issue_entity.rb
+25
-0
ee/app/serializers/linked_project_issue_serializer.rb
ee/app/serializers/linked_project_issue_serializer.rb
+5
-0
ee/app/services/epic_issues/list_service.rb
ee/app/services/epic_issues/list_service.rb
+5
-16
ee/app/services/epic_links/list_service.rb
ee/app/services/epic_links/list_service.rb
+5
-21
ee/app/services/issuable_links/list_service.rb
ee/app/services/issuable_links/list_service.rb
+4
-34
ee/app/services/issue_links/list_service.rb
ee/app/services/issue_links/list_service.rb
+4
-21
No files found.
ee/app/serializers/linked_epic_entity.rb
0 → 100644
View file @
06786aa5
# frozen_string_literal: true
class
LinkedEpicEntity
<
Grape
::
Entity
include
RequestAwareEntity
expose
:id
,
:title
,
:state
expose
:reference
do
|
epic
|
epic
.
to_reference
(
request
.
issuable
.
group
)
end
expose
:path
do
|
epic
|
group_epic_path
(
epic
.
group
,
epic
)
end
expose
:relation_path
do
|
epic
|
group_epic_link_path
(
epic
.
group
,
request
.
issuable
.
iid
,
epic
.
id
)
end
end
ee/app/serializers/linked_epic_issue_entity.rb
0 → 100644
View file @
06786aa5
# frozen_string_literal: true
class
LinkedEpicIssueEntity
<
LinkedIssueEntity
include
RequestAwareEntity
expose
:relation_path
,
override:
true
do
|
issue
|
if
can_admin_issue_link?
(
issue
)
group_epic_issue_path
(
issuable
.
group
,
issuable
.
iid
,
issue
.
epic_issue_id
)
end
end
expose
:reference
,
override:
true
do
|
issue
|
issue
.
to_reference
(
full:
true
)
end
expose
:epic_issue_id
private
def
can_admin_issue_link?
(
issue
)
Ability
.
allowed?
(
current_user
,
:admin_epic_issue
,
issue
)
&&
Ability
.
allowed?
(
current_user
,
:admin_epic
,
issuable
)
end
end
ee/app/serializers/linked_epic_issue_serializer.rb
0 → 100644
View file @
06786aa5
# frozen_string_literal: true
class
LinkedEpicIssueSerializer
<
BaseSerializer
entity
LinkedEpicIssueEntity
end
ee/app/serializers/linked_epic_serializer.rb
0 → 100644
View file @
06786aa5
# frozen_string_literal: true
class
LinkedEpicSerializer
<
BaseSerializer
entity
LinkedEpicEntity
end
ee/app/serializers/linked_issue_entity.rb
0 → 100644
View file @
06786aa5
# frozen_string_literal: true
class
LinkedIssueEntity
<
Grape
::
Entity
include
RequestAwareEntity
expose
:id
,
:confidential
,
:title
expose
:assignees
,
using:
UserEntity
expose
:state
expose
:milestone
,
using:
API
::
Entities
::
Milestone
expose
:weight
expose
:reference
do
|
link
|
link
.
to_reference
(
issuable
.
project
)
end
expose
:path
do
|
link
|
project_issue_path
(
link
.
project
,
link
.
iid
)
end
expose
:relation_path
expose
:due_date
,
:created_at
,
:closed_at
private
def
current_user
request
.
current_user
end
def
issuable
request
.
issuable
end
end
ee/app/serializers/linked_project_issue_entity.rb
0 → 100644
View file @
06786aa5
# frozen_string_literal: true
class
LinkedProjectIssueEntity
<
LinkedIssueEntity
include
Gitlab
::
Utils
::
StrongMemoize
expose
:relation_path
,
override:
true
do
|
issue
|
# Make sure the user can admin both the current issue AND the
# referenced issue projects in order to return the removal link.
if
can_admin_issue_link_on_current_project?
&&
can_admin_issue_link?
(
issue
.
project
)
project_issue_link_path
(
issuable
.
project
,
issuable
.
iid
,
issue
.
issue_link_id
)
end
end
private
def
can_admin_issue_link_on_current_project?
strong_memoize
(
:can_admin_on_current_project
)
do
can_admin_issue_link?
(
issuable
.
project
)
end
end
def
can_admin_issue_link?
(
project
)
Ability
.
allowed?
(
current_user
,
:admin_issue_link
,
project
)
end
end
ee/app/serializers/linked_project_issue_serializer.rb
0 → 100644
View file @
06786aa5
# frozen_string_literal: true
class
LinkedProjectIssueSerializer
<
BaseSerializer
entity
LinkedProjectIssueEntity
end
ee/app/services/epic_issues/list_service.rb
View file @
06786aa5
...
...
@@ -2,6 +2,8 @@
module
EpicIssues
class
ListService
<
IssuableLinks
::
ListService
extend
::
Gitlab
::
Utils
::
Override
private
def
child_issuables
...
...
@@ -10,22 +12,9 @@ module EpicIssues
issuable
.
issues_readable_by
(
current_user
,
preload:
preload_for_collection
)
end
def
relation_path
(
issue
)
if
can_admin_issue_link?
(
issue
)
group_epic_issue_path
(
issuable
.
group
,
issuable
.
iid
,
issue
.
epic_issue_id
)
end
end
def
can_admin_issue_link?
(
issue
)
Ability
.
allowed?
(
current_user
,
:admin_epic_issue
,
issue
)
&&
Ability
.
allowed?
(
current_user
,
:admin_epic
,
issuable
)
end
def
reference
(
issue
)
issue
.
to_reference
(
full:
true
)
end
def
to_hash
(
issue
)
super
.
merge
(
epic_issue_id:
issue
.
epic_issue_id
)
override
:serializer
def
serializer
LinkedEpicIssueSerializer
end
end
end
ee/app/services/epic_links/list_service.rb
View file @
06786aa5
...
...
@@ -2,6 +2,8 @@
module
EpicLinks
class
ListService
<
IssuableLinks
::
ListService
extend
::
Gitlab
::
Utils
::
Override
private
def
child_issuables
...
...
@@ -10,27 +12,9 @@ module EpicLinks
EpicsFinder
.
new
(
current_user
,
parent_id:
issuable
.
id
,
group_id:
issuable
.
group
.
id
).
execute
end
def
reference
(
epic
)
epic
.
to_reference
(
issuable
.
group
)
end
def
issuable_path
(
epic
)
group_epic_path
(
epic
.
group
,
epic
)
end
def
relation_path
(
epic
)
group_epic_link_path
(
epic
.
group
,
issuable
.
iid
,
epic
.
id
)
end
def
to_hash
(
object
)
{
id:
object
.
id
,
title:
object
.
title
,
state:
object
.
state
,
reference:
reference
(
object
),
path:
issuable_path
(
object
),
relation_path:
relation_path
(
object
)
}
override
:serializer
def
serializer
LinkedEpicSerializer
end
end
end
ee/app/services/issuable_links/list_service.rb
View file @
06786aa5
...
...
@@ -11,47 +11,17 @@ module IssuableLinks
end
def
execute
child_issuables
.
map
do
|
referenced_object
|
to_hash
(
referenced_object
)
end
serializer
.
new
(
current_user:
current_user
,
issuable:
issuable
).
represent
(
child_issuables
)
end
private
def
preload_for_collection
[{
project: :namespace
},
:assignees
]
end
def
relation_path
(
object
)
def
serializer
raise
NotImplementedError
end
def
reference
(
object
)
object
.
to_reference
(
issuable
.
project
)
end
def
issuable_path
(
object
)
project_issue_path
(
object
.
project
,
object
.
iid
)
end
# rubocop: disable CodeReuse/Serializer
def
to_hash
(
object
)
{
id:
object
.
id
,
confidential:
object
.
confidential
,
title:
object
.
title
,
assignees:
UserSerializer
.
new
.
represent
(
object
.
assignees
),
state:
object
.
state
,
milestone:
MilestoneSerializer
.
new
.
represent
(
object
.
milestone
),
weight:
object
.
weight
,
reference:
reference
(
object
),
path:
issuable_path
(
object
),
relation_path:
relation_path
(
object
),
due_date:
object
.
due_date
,
created_at:
object
.
created_at
,
closed_at:
object
.
closed_at
}
def
preload_for_collection
[{
project: :namespace
},
:assignees
]
end
# rubocop: enable CodeReuse/Serializer
end
end
ee/app/services/issue_links/list_service.rb
View file @
06786aa5
...
...
@@ -2,7 +2,7 @@
module
IssueLinks
class
ListService
<
IssuableLinks
::
ListService
include
Gitlab
::
Utils
::
StrongMemoiz
e
extend
::
Gitlab
::
Utils
::
Overrid
e
private
...
...
@@ -10,26 +10,9 @@ module IssueLinks
issuable
.
related_issues
(
current_user
,
preload:
preload_for_collection
)
end
def
relation_path
(
issue
)
# Make sure the user can admin both the current issue AND the
# referenced issue projects in order to return the removal link.
if
can_admin_issue_link_on_current_project?
&&
can_admin_issue_link?
(
issue
.
project
)
project_issue_link_path
(
current_project
,
issuable
.
iid
,
issue
.
issue_link_id
)
end
end
def
can_admin_issue_link_on_current_project?
strong_memoize
(
:can_admin_on_current_project
)
do
can_admin_issue_link?
(
current_project
)
end
end
def
can_admin_issue_link?
(
project
)
Ability
.
allowed?
(
current_user
,
:admin_issue_link
,
project
)
end
def
current_project
issuable
.
project
override
:serializer
def
serializer
LinkedProjectIssueSerializer
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