diff options
author | Heinrich Lee Yu <heinrich@gitlab.com> | 2018-11-27 11:47:10 +0300 |
---|---|---|
committer | Heinrich Lee Yu <hleeyu@gmail.com> | 2018-12-19 12:58:53 +0300 |
commit | 6c79e9307e116d6115f6d76ac796176952fb83cd (patch) | |
tree | 85a2981cf3451e9c3918e894b488d3b9fec6337d /app/serializers | |
parent | 1f7c072e08913dda0534bc5534a50f389567433f (diff) |
Refactor issuable sidebar to have extras option
Diffstat (limited to 'app/serializers')
-rw-r--r-- | app/serializers/issuable_sidebar_entity.rb | 15 | ||||
-rw-r--r-- | app/serializers/issue_board_entity.rb | 2 | ||||
-rw-r--r-- | app/serializers/issue_serializer.rb | 6 | ||||
-rw-r--r-- | app/serializers/issue_sidebar_entity.rb | 4 | ||||
-rw-r--r-- | app/serializers/merge_request_basic_entity.rb | 2 | ||||
-rw-r--r-- | app/serializers/merge_request_basic_serializer.rb | 5 | ||||
-rw-r--r-- | app/serializers/merge_request_serializer.rb | 9 | ||||
-rw-r--r-- | app/serializers/merge_request_sidebar_entity.rb | 4 |
8 files changed, 29 insertions, 18 deletions
diff --git a/app/serializers/issuable_sidebar_entity.rb b/app/serializers/issuable_sidebar_entity.rb index 773d78d324c..9af2276b362 100644 --- a/app/serializers/issuable_sidebar_entity.rb +++ b/app/serializers/issuable_sidebar_entity.rb @@ -1,14 +1,17 @@ # frozen_string_literal: true class IssuableSidebarEntity < Grape::Entity - include TimeTrackableEntity include RequestAwareEntity - expose :participants, using: ::API::Entities::UserBasic do |issuable| - issuable.participants(request.current_user) - end + with_options if: { include_extras: true } do + include TimeTrackableEntity + + expose :participants, using: ::API::Entities::UserBasic do |issuable| + issuable.participants(request.current_user) + end - expose :subscribed do |issuable| - issuable.subscribed?(request.current_user, issuable.project) + expose :subscribed do |issuable| + issuable.subscribed?(request.current_user, issuable.project) + end end end diff --git a/app/serializers/issue_board_entity.rb b/app/serializers/issue_board_entity.rb index e3dc43240c6..f7719447b92 100644 --- a/app/serializers/issue_board_entity.rb +++ b/app/serializers/issue_board_entity.rb @@ -37,7 +37,7 @@ class IssueBoardEntity < Grape::Entity end expose :issue_sidebar_endpoint, if: -> (issue) { issue.project } do |issue| - project_issue_path(issue.project, issue, format: :json, serializer: 'sidebar') + project_issue_path(issue.project, issue, format: :json, serializer: 'sidebar_extras') end expose :toggle_subscription_endpoint, if: -> (issue) { issue.project } do |issue| diff --git a/app/serializers/issue_serializer.rb b/app/serializers/issue_serializer.rb index d66f0a5acb7..cdb386b83b9 100644 --- a/app/serializers/issue_serializer.rb +++ b/app/serializers/issue_serializer.rb @@ -2,12 +2,14 @@ class IssueSerializer < BaseSerializer # This overrided method takes care of which entity should be used - # to serialize the `issue` based on `basic` key in `opts` param. + # to serialize the `issue` based on `serializer` key in `opts` param. # Hence, `entity` doesn't need to be declared on the class scope. def represent(issue, opts = {}) entity = case opts[:serializer] - when 'sidebar' + when 'sidebar_extras' + opts[:include_basic] = false + opts[:include_extras] = true IssueSidebarEntity when 'board' IssueBoardEntity diff --git a/app/serializers/issue_sidebar_entity.rb b/app/serializers/issue_sidebar_entity.rb index 349ad9d1fef..1b73ead5cd7 100644 --- a/app/serializers/issue_sidebar_entity.rb +++ b/app/serializers/issue_sidebar_entity.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true class IssueSidebarEntity < IssuableSidebarEntity - expose :assignees, using: API::Entities::UserBasic + with_options if: { include_extras: true } do + expose :assignees, using: API::Entities::UserBasic + end end diff --git a/app/serializers/merge_request_basic_entity.rb b/app/serializers/merge_request_basic_entity.rb index f7eb74cf392..084627f9dbe 100644 --- a/app/serializers/merge_request_basic_entity.rb +++ b/app/serializers/merge_request_basic_entity.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class MergeRequestBasicEntity < IssuableSidebarEntity +class MergeRequestBasicEntity < Grape::Entity expose :assignee_id expose :merge_status expose :merge_error diff --git a/app/serializers/merge_request_basic_serializer.rb b/app/serializers/merge_request_basic_serializer.rb deleted file mode 100644 index a68b48b00db..00000000000 --- a/app/serializers/merge_request_basic_serializer.rb +++ /dev/null @@ -1,5 +0,0 @@ -# frozen_string_literal: true - -class MergeRequestBasicSerializer < BaseSerializer - entity MergeRequestBasicEntity -end diff --git a/app/serializers/merge_request_serializer.rb b/app/serializers/merge_request_serializer.rb index 1f8c830e1aa..e252d9a3501 100644 --- a/app/serializers/merge_request_serializer.rb +++ b/app/serializers/merge_request_serializer.rb @@ -7,9 +7,14 @@ class MergeRequestSerializer < BaseSerializer def represent(merge_request, opts = {}) entity = case opts[:serializer] - when 'basic', 'sidebar' + when 'sidebar_extras' + opts[:include_basic] = false + opts[:include_extras] = true + MergeRequestSidebarEntity + when 'basic' MergeRequestBasicEntity - else # It's 'widget' + else + # fallback to widget for old poll requests without `serializer` set MergeRequestWidgetEntity end diff --git a/app/serializers/merge_request_sidebar_entity.rb b/app/serializers/merge_request_sidebar_entity.rb new file mode 100644 index 00000000000..70607230642 --- /dev/null +++ b/app/serializers/merge_request_sidebar_entity.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +class MergeRequestSidebarEntity < IssuableSidebarEntity +end |