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
e2b53b5f
Commit
e2b53b5f
authored
Feb 12, 2020
by
Rajendra Kadam
Committed by
Stan Hu
Feb 12, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Separate service entities into own class files
parent
1af54d75
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
97 additions
and
72 deletions
+97
-72
changelogs/unreleased/refactoring-entities-file-16.yml
changelogs/unreleased/refactoring-entities-file-16.yml
+5
-0
lib/api/entities.rb
lib/api/entities.rb
+0
-72
lib/api/entities/global_notification_setting.rb
lib/api/entities/global_notification_setting.rb
+11
-0
lib/api/entities/project_service.rb
lib/api/entities/project_service.rb
+17
-0
lib/api/entities/project_service_basic.rb
lib/api/entities/project_service_basic.rb
+17
-0
lib/api/entities/project_with_access.rb
lib/api/entities/project_with_access.rb
+47
-0
No files found.
changelogs/unreleased/refactoring-entities-file-16.yml
0 → 100644
View file @
e2b53b5f
---
title
:
Separate service entities into own class files
merge_request
:
24936
author
:
Rajendra Kadam
type
:
added
lib/api/entities.rb
View file @
e2b53b5f
...
...
@@ -163,78 +163,6 @@ module API
end
end
class
GlobalNotificationSetting
<
NotificationSetting
expose
:notification_email
do
|
notification_setting
,
options
|
notification_setting
.
user
.
notification_email
end
end
class
ProjectServiceBasic
<
Grape
::
Entity
expose
:id
,
:title
expose
:slug
do
|
service
|
service
.
to_param
.
dasherize
end
expose
:created_at
,
:updated_at
,
:active
expose
:commit_events
,
:push_events
,
:issues_events
,
:confidential_issues_events
expose
:merge_requests_events
,
:tag_push_events
,
:note_events
expose
:confidential_note_events
,
:pipeline_events
,
:wiki_page_events
expose
:job_events
,
:comment_on_event_enabled
end
class
ProjectService
<
ProjectServiceBasic
# Expose serialized properties
expose
:properties
do
|
service
,
options
|
# TODO: Simplify as part of https://gitlab.com/gitlab-org/gitlab/issues/29404
if
service
.
data_fields_present?
service
.
data_fields
.
as_json
.
slice
(
*
service
.
api_field_names
)
else
service
.
properties
.
slice
(
*
service
.
api_field_names
)
end
end
end
class
ProjectWithAccess
<
Project
expose
:permissions
do
expose
:project_access
,
using:
Entities
::
ProjectAccess
do
|
project
,
options
|
if
options
[
:project_members
]
options
[
:project_members
].
find
{
|
member
|
member
.
source_id
==
project
.
id
}
else
project
.
project_member
(
options
[
:current_user
])
end
end
expose
:group_access
,
using:
Entities
::
GroupAccess
do
|
project
,
options
|
if
project
.
group
if
options
[
:group_members
]
options
[
:group_members
].
find
{
|
member
|
member
.
source_id
==
project
.
namespace_id
}
else
project
.
group
.
highest_group_member
(
options
[
:current_user
])
end
end
end
end
# rubocop: disable CodeReuse/ActiveRecord
def
self
.
preload_relation
(
projects_relation
,
options
=
{})
relation
=
super
(
projects_relation
,
options
)
project_ids
=
relation
.
select
(
'projects.id'
)
namespace_ids
=
relation
.
select
(
:namespace_id
)
options
[
:project_members
]
=
options
[
:current_user
]
.
project_members
.
where
(
source_id:
project_ids
)
.
preload
(
:source
,
user:
[
notification_settings: :source
])
options
[
:group_members
]
=
options
[
:current_user
]
.
group_members
.
where
(
source_id:
namespace_ids
)
.
preload
(
:source
,
user:
[
notification_settings: :source
])
relation
end
# rubocop: enable CodeReuse/ActiveRecord
end
class
LabelBasic
<
Grape
::
Entity
expose
:id
,
:name
,
:color
,
:description
,
:description_html
,
:text_color
end
...
...
lib/api/entities/global_notification_setting.rb
0 → 100644
View file @
e2b53b5f
# frozen_string_literal: true
module
API
module
Entities
class
GlobalNotificationSetting
<
Entities
::
NotificationSetting
expose
:notification_email
do
|
notification_setting
,
options
|
notification_setting
.
user
.
notification_email
end
end
end
end
lib/api/entities/project_service.rb
0 → 100644
View file @
e2b53b5f
# frozen_string_literal: true
module
API
module
Entities
class
ProjectService
<
Entities
::
ProjectServiceBasic
# Expose serialized properties
expose
:properties
do
|
service
,
options
|
# TODO: Simplify as part of https://gitlab.com/gitlab-org/gitlab/issues/29404
if
service
.
data_fields_present?
service
.
data_fields
.
as_json
.
slice
(
*
service
.
api_field_names
)
else
service
.
properties
.
slice
(
*
service
.
api_field_names
)
end
end
end
end
end
lib/api/entities/project_service_basic.rb
0 → 100644
View file @
e2b53b5f
# frozen_string_literal: true
module
API
module
Entities
class
ProjectServiceBasic
<
Grape
::
Entity
expose
:id
,
:title
expose
:slug
do
|
service
|
service
.
to_param
.
dasherize
end
expose
:created_at
,
:updated_at
,
:active
expose
:commit_events
,
:push_events
,
:issues_events
,
:confidential_issues_events
expose
:merge_requests_events
,
:tag_push_events
,
:note_events
expose
:confidential_note_events
,
:pipeline_events
,
:wiki_page_events
expose
:job_events
,
:comment_on_event_enabled
end
end
end
lib/api/entities/project_with_access.rb
0 → 100644
View file @
e2b53b5f
# frozen_string_literal: true
module
API
module
Entities
class
ProjectWithAccess
<
Project
expose
:permissions
do
expose
:project_access
,
using:
Entities
::
ProjectAccess
do
|
project
,
options
|
if
options
[
:project_members
]
options
[
:project_members
].
find
{
|
member
|
member
.
source_id
==
project
.
id
}
else
project
.
project_member
(
options
[
:current_user
])
end
end
expose
:group_access
,
using:
Entities
::
GroupAccess
do
|
project
,
options
|
if
project
.
group
if
options
[
:group_members
]
options
[
:group_members
].
find
{
|
member
|
member
.
source_id
==
project
.
namespace_id
}
else
project
.
group
.
highest_group_member
(
options
[
:current_user
])
end
end
end
end
# rubocop: disable CodeReuse/ActiveRecord
def
self
.
preload_relation
(
projects_relation
,
options
=
{})
relation
=
super
(
projects_relation
,
options
)
project_ids
=
relation
.
select
(
'projects.id'
)
namespace_ids
=
relation
.
select
(
:namespace_id
)
options
[
:project_members
]
=
options
[
:current_user
]
.
project_members
.
where
(
source_id:
project_ids
)
.
preload
(
:source
,
user:
[
notification_settings: :source
])
options
[
:group_members
]
=
options
[
:current_user
]
.
group_members
.
where
(
source_id:
namespace_ids
)
.
preload
(
:source
,
user:
[
notification_settings: :source
])
relation
end
# rubocop: enable CodeReuse/ActiveRecord
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