From e0dc73527a478188cfa28b456b64798639aa73c9 Mon Sep 17 00:00:00 2001 From: Jarka Kadlecova Date: Fri, 24 Mar 2017 11:11:36 +0100 Subject: Project deploy keys json end point --- app/serializers/deploy_key_entity.rb | 12 ++++++++++++ app/serializers/deploy_key_serializer.rb | 3 +++ app/serializers/project_entity.rb | 12 ++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 app/serializers/deploy_key_entity.rb create mode 100644 app/serializers/deploy_key_serializer.rb create mode 100644 app/serializers/project_entity.rb (limited to 'app/serializers') diff --git a/app/serializers/deploy_key_entity.rb b/app/serializers/deploy_key_entity.rb new file mode 100644 index 00000000000..cdedc2c7bd0 --- /dev/null +++ b/app/serializers/deploy_key_entity.rb @@ -0,0 +1,12 @@ +class DeployKeyEntity < Grape::Entity + expose :id + expose :user_id + expose :title + expose :fingerprint + expose :can_push + expose :created_at + expose :updated_at + expose :projects, using: ProjectEntity do |deploy_key| + deploy_key.projects.select { |project| options[:user].can?(:read_project, project) } + end +end diff --git a/app/serializers/deploy_key_serializer.rb b/app/serializers/deploy_key_serializer.rb new file mode 100644 index 00000000000..8f849eb88b7 --- /dev/null +++ b/app/serializers/deploy_key_serializer.rb @@ -0,0 +1,3 @@ +class DeployKeySerializer < BaseSerializer + entity DeployKeyEntity +end diff --git a/app/serializers/project_entity.rb b/app/serializers/project_entity.rb new file mode 100644 index 00000000000..6f8061f7530 --- /dev/null +++ b/app/serializers/project_entity.rb @@ -0,0 +1,12 @@ +class ProjectEntity < Grape::Entity + expose :id + expose :name + + expose :full_path do |project| + project.full_path + end + + expose :full_name do |project| + project.full_name + end +end -- cgit v1.2.1 From 3dbef510c187606ef12eb9f2aaf51f30ddc3e30d Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 6 Apr 2017 12:58:13 +0200 Subject: Expose manual action abilities from a build entity --- app/serializers/build_entity.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'app/serializers') diff --git a/app/serializers/build_entity.rb b/app/serializers/build_entity.rb index b804d6d0e8a..401a277dadc 100644 --- a/app/serializers/build_entity.rb +++ b/app/serializers/build_entity.rb @@ -12,7 +12,7 @@ class BuildEntity < Grape::Entity path_to(:retry_namespace_project_build, build) end - expose :play_path, if: ->(build, _) { build.playable? } do |build| + expose :play_path, if: proc { playable? } do |build| path_to(:play_namespace_project_build, build) end @@ -25,11 +25,15 @@ class BuildEntity < Grape::Entity alias_method :build, :object - def path_to(route, build) - send("#{route}_path", build.project.namespace, build.project, build) + def playable? + build.playable? && build.can_play?(request.user) end def detailed_status build.detailed_status(request.user) end + + def path_to(route, build) + send("#{route}_path", build.project.namespace, build.project, build) + end end -- cgit v1.2.1 From 7bcca2284b09e18438e6163c6ead72e10fdd2f57 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 6 Apr 2017 17:16:19 +0200 Subject: Check branch permission in manual action entity --- app/serializers/build_action_entity.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'app/serializers') diff --git a/app/serializers/build_action_entity.rb b/app/serializers/build_action_entity.rb index 184b4b7a681..3d12c64b88a 100644 --- a/app/serializers/build_action_entity.rb +++ b/app/serializers/build_action_entity.rb @@ -13,4 +13,12 @@ class BuildActionEntity < Grape::Entity end expose :playable?, as: :playable + + private + + alias_method :build, :object + + def playable? + build.playable? && build.can_play?(request.user) + end end -- cgit v1.2.1 From 703df2881bb137a79284baafe2cc12ff32ab9ff5 Mon Sep 17 00:00:00 2001 From: Jarka Kadlecova Date: Fri, 7 Apr 2017 13:34:39 +0200 Subject: expose additional values in deploy key entity --- app/serializers/deploy_key_entity.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'app/serializers') diff --git a/app/serializers/deploy_key_entity.rb b/app/serializers/deploy_key_entity.rb index cdedc2c7bd0..d75a83d0fa5 100644 --- a/app/serializers/deploy_key_entity.rb +++ b/app/serializers/deploy_key_entity.rb @@ -4,6 +4,8 @@ class DeployKeyEntity < Grape::Entity expose :title expose :fingerprint expose :can_push + expose :destroyed_when_orphaned?, as: :destroyed_when_orphaned + expose :almost_orphaned?, as: :almost_orphaned expose :created_at expose :updated_at expose :projects, using: ProjectEntity do |deploy_key| -- cgit v1.2.1 From 2aa211fa69ffd02ba11757e06e19d34f6ca51865 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 12 Apr 2017 13:48:43 +0200 Subject: Use build policy to determine if user can play build --- app/serializers/build_action_entity.rb | 2 +- app/serializers/build_entity.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'app/serializers') diff --git a/app/serializers/build_action_entity.rb b/app/serializers/build_action_entity.rb index 3d12c64b88a..0bb7e561073 100644 --- a/app/serializers/build_action_entity.rb +++ b/app/serializers/build_action_entity.rb @@ -19,6 +19,6 @@ class BuildActionEntity < Grape::Entity alias_method :build, :object def playable? - build.playable? && build.can_play?(request.user) + can?(request.user, :play_build, build) && build.playable? end end diff --git a/app/serializers/build_entity.rb b/app/serializers/build_entity.rb index 401a277dadc..f301900c43c 100644 --- a/app/serializers/build_entity.rb +++ b/app/serializers/build_entity.rb @@ -26,7 +26,7 @@ class BuildEntity < Grape::Entity alias_method :build, :object def playable? - build.playable? && build.can_play?(request.user) + can?(request.user, :play_build, build) && build.playable? end def detailed_status -- cgit v1.2.1 From e11a702afceee7f5edeb8c93a4192fa05209b091 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Fri, 28 Apr 2017 17:06:19 +0100 Subject: Re-wrote to match our docs - still not 100% sure but closer than it was --- app/serializers/project_entity.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'app/serializers') diff --git a/app/serializers/project_entity.rb b/app/serializers/project_entity.rb index 6f8061f7530..a471a7e6a88 100644 --- a/app/serializers/project_entity.rb +++ b/app/serializers/project_entity.rb @@ -1,9 +1,11 @@ class ProjectEntity < Grape::Entity + include RequestAwareEntity + expose :id expose :name expose :full_path do |project| - project.full_path + namespace_project_path(project.namespace, project) end expose :full_name do |project| -- cgit v1.2.1 From 72307940bb04d29dc751adb5e76330d2ce45e9ce Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 3 May 2017 12:32:39 +0200 Subject: Improve code style related to protected actions --- app/serializers/build_action_entity.rb | 2 +- app/serializers/build_entity.rb | 4 ++-- app/serializers/pipeline_entity.rb | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'app/serializers') diff --git a/app/serializers/build_action_entity.rb b/app/serializers/build_action_entity.rb index 0bb7e561073..3eff724ae91 100644 --- a/app/serializers/build_action_entity.rb +++ b/app/serializers/build_action_entity.rb @@ -19,6 +19,6 @@ class BuildActionEntity < Grape::Entity alias_method :build, :object def playable? - can?(request.user, :play_build, build) && build.playable? + build.playable? && can?(request.user, :play_build, build) end end diff --git a/app/serializers/build_entity.rb b/app/serializers/build_entity.rb index f301900c43c..10ba7c90c10 100644 --- a/app/serializers/build_entity.rb +++ b/app/serializers/build_entity.rb @@ -12,7 +12,7 @@ class BuildEntity < Grape::Entity path_to(:retry_namespace_project_build, build) end - expose :play_path, if: proc { playable? } do |build| + expose :play_path, if: -> (*) { playable? } do |build| path_to(:play_namespace_project_build, build) end @@ -26,7 +26,7 @@ class BuildEntity < Grape::Entity alias_method :build, :object def playable? - can?(request.user, :play_build, build) && build.playable? + build.playable? && can?(request.user, :play_build, build) end def detailed_status diff --git a/app/serializers/pipeline_entity.rb b/app/serializers/pipeline_entity.rb index ad8b4d43e8f..7eb7aac72eb 100644 --- a/app/serializers/pipeline_entity.rb +++ b/app/serializers/pipeline_entity.rb @@ -48,15 +48,15 @@ class PipelineEntity < Grape::Entity end expose :commit, using: CommitEntity - expose :yaml_errors, if: ->(pipeline, _) { pipeline.has_yaml_errors? } + expose :yaml_errors, if: -> (pipeline, _) { pipeline.has_yaml_errors? } - expose :retry_path, if: proc { can_retry? } do |pipeline| + expose :retry_path, if: -> (*) { can_retry? } do |pipeline| retry_namespace_project_pipeline_path(pipeline.project.namespace, pipeline.project, pipeline.id) end - expose :cancel_path, if: proc { can_cancel? } do |pipeline| + expose :cancel_path, if: -> (*) { can_cancel? } do |pipeline| cancel_namespace_project_pipeline_path(pipeline.project.namespace, pipeline.project, pipeline.id) -- cgit v1.2.1 From dbd1bdaeed596f14af89d662e73030bb02571cfd Mon Sep 17 00:00:00 2001 From: Ruben Davila Date: Wed, 3 May 2017 21:05:38 -0500 Subject: More updates for translations plus some refactoring. --- app/serializers/analytics_stage_entity.rb | 1 + app/serializers/analytics_summary_entity.rb | 5 +---- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'app/serializers') diff --git a/app/serializers/analytics_stage_entity.rb b/app/serializers/analytics_stage_entity.rb index 69bf693de8d..564612202b5 100644 --- a/app/serializers/analytics_stage_entity.rb +++ b/app/serializers/analytics_stage_entity.rb @@ -2,6 +2,7 @@ class AnalyticsStageEntity < Grape::Entity include EntityDateHelper expose :title + expose :name expose :legend expose :description diff --git a/app/serializers/analytics_summary_entity.rb b/app/serializers/analytics_summary_entity.rb index 91803ec07f5..9c37afd53e1 100644 --- a/app/serializers/analytics_summary_entity.rb +++ b/app/serializers/analytics_summary_entity.rb @@ -1,7 +1,4 @@ class AnalyticsSummaryEntity < Grape::Entity expose :value, safe: true - - expose :title do |object| - object.title.pluralize(object.value) - end + expose :title end -- cgit v1.2.1 From 387c4b2c21a44360386a9b8ce6849e7f1b8a3de9 Mon Sep 17 00:00:00 2001 From: Valery Sizov Date: Thu, 4 May 2017 15:11:15 +0300 Subject: Backport of multiple_assignees_feature [ci skip] --- app/serializers/issuable_entity.rb | 1 - app/serializers/issue_entity.rb | 1 + app/serializers/merge_request_entity.rb | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) (limited to 'app/serializers') diff --git a/app/serializers/issuable_entity.rb b/app/serializers/issuable_entity.rb index 29aecb50849..65b204d4dd2 100644 --- a/app/serializers/issuable_entity.rb +++ b/app/serializers/issuable_entity.rb @@ -1,7 +1,6 @@ class IssuableEntity < Grape::Entity expose :id expose :iid - expose :assignee_id expose :author_id expose :description expose :lock_version diff --git a/app/serializers/issue_entity.rb b/app/serializers/issue_entity.rb index 6429159ebe1..bc4f68710b2 100644 --- a/app/serializers/issue_entity.rb +++ b/app/serializers/issue_entity.rb @@ -1,6 +1,7 @@ class IssueEntity < IssuableEntity expose :branch_name expose :confidential + expose :assignees, using: API::Entities::UserBasic expose :due_date expose :moved_to_id expose :project_id diff --git a/app/serializers/merge_request_entity.rb b/app/serializers/merge_request_entity.rb index 5f80ab397a9..453ba52b892 100644 --- a/app/serializers/merge_request_entity.rb +++ b/app/serializers/merge_request_entity.rb @@ -1,4 +1,5 @@ class MergeRequestEntity < IssuableEntity + expose :assignee_id expose :in_progress_merge_commit_sha expose :locked_at expose :merge_commit_sha -- cgit v1.2.1 From 936367538043854c7b093b71ca315b8e469c55a4 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 5 May 2017 12:25:24 +0200 Subject: Use update build policy instead of new play policy --- app/serializers/build_action_entity.rb | 2 +- app/serializers/build_entity.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'app/serializers') diff --git a/app/serializers/build_action_entity.rb b/app/serializers/build_action_entity.rb index 3eff724ae91..75dda1af709 100644 --- a/app/serializers/build_action_entity.rb +++ b/app/serializers/build_action_entity.rb @@ -19,6 +19,6 @@ class BuildActionEntity < Grape::Entity alias_method :build, :object def playable? - build.playable? && can?(request.user, :play_build, build) + build.playable? && can?(request.user, :update_build, build) end end diff --git a/app/serializers/build_entity.rb b/app/serializers/build_entity.rb index 10ba7c90c10..1380b347d8e 100644 --- a/app/serializers/build_entity.rb +++ b/app/serializers/build_entity.rb @@ -26,7 +26,7 @@ class BuildEntity < Grape::Entity alias_method :build, :object def playable? - build.playable? && can?(request.user, :play_build, build) + build.playable? && can?(request.user, :update_build, build) end def detailed_status -- cgit v1.2.1 From b51f2a60800829ee7585f10451a41bc4db0359a9 Mon Sep 17 00:00:00 2001 From: Winnie Hellmann Date: Fri, 5 May 2017 22:47:32 +0000 Subject: Colorize labels in issue search field --- app/serializers/label_entity.rb | 1 + app/serializers/label_serializer.rb | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 app/serializers/label_serializer.rb (limited to 'app/serializers') diff --git a/app/serializers/label_entity.rb b/app/serializers/label_entity.rb index 304fd9de08f..ad565654342 100644 --- a/app/serializers/label_entity.rb +++ b/app/serializers/label_entity.rb @@ -6,6 +6,7 @@ class LabelEntity < Grape::Entity expose :group_id expose :project_id expose :template + expose :text_color expose :created_at expose :updated_at end diff --git a/app/serializers/label_serializer.rb b/app/serializers/label_serializer.rb new file mode 100644 index 00000000000..ad6ba8c46c9 --- /dev/null +++ b/app/serializers/label_serializer.rb @@ -0,0 +1,7 @@ +class LabelSerializer < BaseSerializer + entity LabelEntity + + def represent_appearance(resource) + represent(resource, { only: [:id, :title, :color, :text_color] }) + end +end -- cgit v1.2.1 From c17e6a6c68b0412b3433632802b852db474a7b30 Mon Sep 17 00:00:00 2001 From: Zeger-Jan van de Weg Date: Sat, 6 May 2017 16:45:46 +0000 Subject: Real time pipeline show action --- app/serializers/job_group_entity.rb | 16 ++++++++++++++++ app/serializers/stage_entity.rb | 8 +++++--- app/serializers/status_entity.rb | 7 +++++++ 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 app/serializers/job_group_entity.rb (limited to 'app/serializers') diff --git a/app/serializers/job_group_entity.rb b/app/serializers/job_group_entity.rb new file mode 100644 index 00000000000..a4d3737429c --- /dev/null +++ b/app/serializers/job_group_entity.rb @@ -0,0 +1,16 @@ +class JobGroupEntity < Grape::Entity + include RequestAwareEntity + + expose :name + expose :size + expose :detailed_status, as: :status, with: StatusEntity + expose :jobs, with: BuildEntity + + private + + alias_method :group, :object + + def detailed_status + group.detailed_status(request.user) + end +end diff --git a/app/serializers/stage_entity.rb b/app/serializers/stage_entity.rb index 7a047bdc712..97ced8730ed 100644 --- a/app/serializers/stage_entity.rb +++ b/app/serializers/stage_entity.rb @@ -7,9 +7,11 @@ class StageEntity < Grape::Entity "#{stage.name}: #{detailed_status.label}" end - expose :detailed_status, - as: :status, - with: StatusEntity + expose :groups, + if: -> (_, opts) { opts[:grouped] }, + with: JobGroupEntity + + expose :detailed_status, as: :status, with: StatusEntity expose :path do |stage| namespace_project_pipeline_path( diff --git a/app/serializers/status_entity.rb b/app/serializers/status_entity.rb index 188c3747f18..3e40ecf1c1c 100644 --- a/app/serializers/status_entity.rb +++ b/app/serializers/status_entity.rb @@ -12,4 +12,11 @@ class StatusEntity < Grape::Entity ActionController::Base.helpers.image_path(File.join(dir, "#{status.favicon}.ico")) end + + expose :action, if: -> (status, _) { status.has_action? } do + expose :action_icon, as: :icon + expose :action_title, as: :title + expose :action_path, as: :path + expose :action_method, as: :method + end end -- cgit v1.2.1 From 0151325dacebb99d54b6effb1d5842c0c712168c Mon Sep 17 00:00:00 2001 From: Fatih Acet Date: Tue, 9 May 2017 04:15:34 +0000 Subject: Merge request widget redesign --- app/serializers/base_serializer.rb | 6 +- app/serializers/build_action_entity.rb | 2 +- app/serializers/build_entity.rb | 4 +- app/serializers/environment_entity.rb | 2 +- app/serializers/event_entity.rb | 4 + app/serializers/job_group_entity.rb | 2 +- app/serializers/merge_request_basic_entity.rb | 10 ++ app/serializers/merge_request_basic_serializer.rb | 3 + app/serializers/merge_request_entity.rb | 172 ++++++++++++++++++++++ app/serializers/merge_request_serializer.rb | 8 +- app/serializers/pipeline_entity.rb | 8 +- app/serializers/pipeline_serializer.rb | 7 + app/serializers/stage_entity.rb | 2 +- 13 files changed, 218 insertions(+), 12 deletions(-) create mode 100644 app/serializers/event_entity.rb create mode 100644 app/serializers/merge_request_basic_entity.rb create mode 100644 app/serializers/merge_request_basic_serializer.rb (limited to 'app/serializers') diff --git a/app/serializers/base_serializer.rb b/app/serializers/base_serializer.rb index 311ee9c96be..4e6c15f673b 100644 --- a/app/serializers/base_serializer.rb +++ b/app/serializers/base_serializer.rb @@ -3,8 +3,10 @@ class BaseSerializer @request = EntityRequest.new(parameters) end - def represent(resource, opts = {}) - self.class.entity_class + def represent(resource, opts = {}, entity_class = nil) + entity_class = entity_class || self.class.entity_class + + entity_class .represent(resource, opts.merge(request: @request)) .as_json end diff --git a/app/serializers/build_action_entity.rb b/app/serializers/build_action_entity.rb index 75dda1af709..5e99204c658 100644 --- a/app/serializers/build_action_entity.rb +++ b/app/serializers/build_action_entity.rb @@ -19,6 +19,6 @@ class BuildActionEntity < Grape::Entity alias_method :build, :object def playable? - build.playable? && can?(request.user, :update_build, build) + build.playable? && can?(request.current_user, :update_build, build) end end diff --git a/app/serializers/build_entity.rb b/app/serializers/build_entity.rb index 1380b347d8e..e2276808b90 100644 --- a/app/serializers/build_entity.rb +++ b/app/serializers/build_entity.rb @@ -26,11 +26,11 @@ class BuildEntity < Grape::Entity alias_method :build, :object def playable? - build.playable? && can?(request.user, :update_build, build) + build.playable? && can?(request.current_user, :update_build, build) end def detailed_status - build.detailed_status(request.user) + build.detailed_status(request.current_user) end def path_to(route, build) diff --git a/app/serializers/environment_entity.rb b/app/serializers/environment_entity.rb index 4ff15a78115..4e8a3c67b21 100644 --- a/app/serializers/environment_entity.rb +++ b/app/serializers/environment_entity.rb @@ -31,7 +31,7 @@ class EnvironmentEntity < Grape::Entity end expose :terminal_path, if: ->(environment, _) { environment.has_terminals? } do |environment| - can?(request.user, :admin_environment, environment.project) && + can?(request.current_user, :admin_environment, environment.project) && terminal_namespace_project_environment_path( environment.project.namespace, environment.project, diff --git a/app/serializers/event_entity.rb b/app/serializers/event_entity.rb new file mode 100644 index 00000000000..935d67a4f37 --- /dev/null +++ b/app/serializers/event_entity.rb @@ -0,0 +1,4 @@ +class EventEntity < Grape::Entity + expose :author, using: UserEntity + expose :updated_at +end diff --git a/app/serializers/job_group_entity.rb b/app/serializers/job_group_entity.rb index a4d3737429c..04487e59009 100644 --- a/app/serializers/job_group_entity.rb +++ b/app/serializers/job_group_entity.rb @@ -11,6 +11,6 @@ class JobGroupEntity < Grape::Entity alias_method :group, :object def detailed_status - group.detailed_status(request.user) + group.detailed_status(request.current_user) end end diff --git a/app/serializers/merge_request_basic_entity.rb b/app/serializers/merge_request_basic_entity.rb new file mode 100644 index 00000000000..8771345c135 --- /dev/null +++ b/app/serializers/merge_request_basic_entity.rb @@ -0,0 +1,10 @@ +class MergeRequestBasicEntity < Grape::Entity + expose :merge_status + expose :merge_error + expose :state + expose :source_branch_exists?, as: :source_branch_exists + expose :time_estimate + expose :total_time_spent + expose :human_time_estimate + expose :human_total_time_spent +end diff --git a/app/serializers/merge_request_basic_serializer.rb b/app/serializers/merge_request_basic_serializer.rb new file mode 100644 index 00000000000..cc5c664c8fa --- /dev/null +++ b/app/serializers/merge_request_basic_serializer.rb @@ -0,0 +1,3 @@ +class MergeRequestBasicSerializer < BaseSerializer + entity MergeRequestBasicEntity +end diff --git a/app/serializers/merge_request_entity.rb b/app/serializers/merge_request_entity.rb index 453ba52b892..a2542c54f7a 100644 --- a/app/serializers/merge_request_entity.rb +++ b/app/serializers/merge_request_entity.rb @@ -1,4 +1,6 @@ class MergeRequestEntity < IssuableEntity + include RequestAwareEntity + expose :assignee_id expose :in_progress_merge_commit_sha expose :locked_at @@ -12,4 +14,174 @@ class MergeRequestEntity < IssuableEntity expose :source_project_id expose :target_branch expose :target_project_id + + # Events + expose :merge_event, using: EventEntity + expose :closed_event, using: EventEntity + + # User entities + expose :author, using: UserEntity + expose :merge_user, using: UserEntity + + # Diff sha's + expose :diff_head_sha do |merge_request| + merge_request.diff_head_sha if merge_request.diff_head_commit + end + + expose :merge_commit_sha + expose :merge_commit_message + expose :head_pipeline, with: PipelineEntity, as: :pipeline + + # Booleans + expose :work_in_progress?, as: :work_in_progress + expose :source_branch_exists?, as: :source_branch_exists + expose :mergeable_discussions_state?, as: :mergeable_discussions_state + expose :branch_missing?, as: :branch_missing + expose :commits_count + expose :cannot_be_merged?, as: :has_conflicts + expose :can_be_merged?, as: :can_be_merged + + expose :project_archived do |merge_request| + merge_request.project.archived? + end + + expose :only_allow_merge_if_pipeline_succeeds do |merge_request| + merge_request.project.only_allow_merge_if_pipeline_succeeds? + end + + # CI related + expose :has_ci?, as: :has_ci + expose :ci_status do |merge_request| + presenter(merge_request).ci_status + end + + expose :issues_links do + expose :assign_to_closing do |merge_request| + presenter(merge_request).assign_to_closing_issues_link + end + + expose :closing do |merge_request| + presenter(merge_request).closing_issues_links + end + + expose :mentioned_but_not_closing do |merge_request| + presenter(merge_request).mentioned_issues_links + end + end + + expose :source_branch_with_namespace_link do |merge_request| + presenter(merge_request).source_branch_with_namespace_link + end + + expose :source_branch_path do |merge_request| + presenter(merge_request).source_branch_path + end + + expose :current_user do + expose :can_remove_source_branch do |merge_request| + merge_request.source_branch_exists? && merge_request.can_remove_source_branch?(current_user) + end + + expose :can_revert_on_current_merge_request do |merge_request| + presenter(merge_request).can_revert_on_current_merge_request? + end + + expose :can_cherry_pick_on_current_merge_request do |merge_request| + presenter(merge_request).can_cherry_pick_on_current_merge_request? + end + end + + # Paths + # + expose :target_branch_commits_path do |merge_request| + presenter(merge_request).target_branch_commits_path + end + + expose :conflict_resolution_path do |merge_request| + presenter(merge_request).conflict_resolution_path + end + + expose :remove_wip_path do |merge_request| + presenter(merge_request).remove_wip_path + end + + expose :cancel_merge_when_pipeline_succeeds_path do |merge_request| + presenter(merge_request).cancel_merge_when_pipeline_succeeds_path + end + + expose :create_issue_to_resolve_discussions_path do |merge_request| + presenter(merge_request).create_issue_to_resolve_discussions_path + end + + expose :merge_path do |merge_request| + presenter(merge_request).merge_path + end + + expose :cherry_pick_in_fork_path do |merge_request| + presenter(merge_request).cherry_pick_in_fork_path + end + + expose :revert_in_fork_path do |merge_request| + presenter(merge_request).revert_in_fork_path + end + + expose :email_patches_path do |merge_request| + namespace_project_merge_request_path(merge_request.project.namespace, + merge_request.project, + merge_request, + format: :patch) + end + + expose :plain_diff_path do |merge_request| + namespace_project_merge_request_path(merge_request.project.namespace, + merge_request.project, + merge_request, + format: :diff) + end + + expose :status_path do |merge_request| + namespace_project_merge_request_path(merge_request.target_project.namespace, + merge_request.target_project, + merge_request, + format: :json) + end + + expose :merge_check_path do |merge_request| + merge_check_namespace_project_merge_request_path(merge_request.project.namespace, + merge_request.project, + merge_request) + end + + expose :ci_environments_status_path do |merge_request| + ci_environments_status_namespace_project_merge_request_path(merge_request.project.namespace, + merge_request.project, + merge_request) + end + + expose :merge_commit_message_with_description do |merge_request| + merge_request.merge_commit_message(include_description: true) + end + + expose :diverged_commits_count do |merge_request| + if merge_request.open? && merge_request.diverged_from_target_branch? + merge_request.diverged_commits_count + else + 0 + end + end + + expose :commit_change_content_path do |merge_request| + commit_change_content_namespace_project_merge_request_path(merge_request.project.namespace, + merge_request.project, + merge_request) + end + + private + + delegate :current_user, to: :request + + def presenter(merge_request) + @presenters ||= {} + @presenters[merge_request] ||= MergeRequestPresenter.new(merge_request, current_user: current_user) + end end diff --git a/app/serializers/merge_request_serializer.rb b/app/serializers/merge_request_serializer.rb index aa6e00dfcb4..f67034ce47a 100644 --- a/app/serializers/merge_request_serializer.rb +++ b/app/serializers/merge_request_serializer.rb @@ -1,3 +1,9 @@ class MergeRequestSerializer < BaseSerializer - entity MergeRequestEntity + # This overrided method takes care of which entity should be used + # to serialize the `merge_request` based on `basic` key in `opts` param. + # Hence, `entity` doesn't need to be declared on the class scope. + def represent(merge_request, opts = {}) + entity = opts[:basic] ? MergeRequestBasicEntity : MergeRequestEntity + super(merge_request, opts, entity) + end end diff --git a/app/serializers/pipeline_entity.rb b/app/serializers/pipeline_entity.rb index 7eb7aac72eb..51ad0a3f8ba 100644 --- a/app/serializers/pipeline_entity.rb +++ b/app/serializers/pipeline_entity.rb @@ -3,6 +3,8 @@ class PipelineEntity < Grape::Entity expose :id expose :user, using: UserEntity + expose :active?, as: :active + expose :coverage expose :path do |pipeline| namespace_project_pipeline_path( @@ -69,16 +71,16 @@ class PipelineEntity < Grape::Entity alias_method :pipeline, :object def can_retry? - can?(request.user, :update_pipeline, pipeline) && + can?(request.current_user, :update_pipeline, pipeline) && pipeline.retryable? end def can_cancel? - can?(request.user, :update_pipeline, pipeline) && + can?(request.current_user, :update_pipeline, pipeline) && pipeline.cancelable? end def detailed_status - pipeline.detailed_status(request.user) + pipeline.detailed_status(request.current_user) end end diff --git a/app/serializers/pipeline_serializer.rb b/app/serializers/pipeline_serializer.rb index e7a9df8ac4e..e37af63774c 100644 --- a/app/serializers/pipeline_serializer.rb +++ b/app/serializers/pipeline_serializer.rb @@ -37,4 +37,11 @@ class PipelineSerializer < BaseSerializer data = represent(resource, { only: [{ details: [:status] }] }) data.dig(:details, :status) || {} end + + def represent_stages(resource) + return {} unless resource.present? + + data = represent(resource, { only: [{ details: [:stages] }] }) + data.dig(:details, :stages) || [] + end end diff --git a/app/serializers/stage_entity.rb b/app/serializers/stage_entity.rb index 97ced8730ed..cee0089056f 100644 --- a/app/serializers/stage_entity.rb +++ b/app/serializers/stage_entity.rb @@ -35,6 +35,6 @@ class StageEntity < Grape::Entity alias_method :stage, :object def detailed_status - stage.detailed_status(request.user) + stage.detailed_status(request.current_user) end end -- cgit v1.2.1 From ff82acf34319fbcd3598dba7c025715874ba903c Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Thu, 11 May 2017 10:47:44 -0500 Subject: Consistently use monospace font for commit SHAs and branch and tag names --- app/serializers/pipeline_entity.rb | 5 +---- app/serializers/request_aware_entity.rb | 1 + 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'app/serializers') diff --git a/app/serializers/pipeline_entity.rb b/app/serializers/pipeline_entity.rb index 51ad0a3f8ba..ea57cc97a7e 100644 --- a/app/serializers/pipeline_entity.rb +++ b/app/serializers/pipeline_entity.rb @@ -38,10 +38,7 @@ class PipelineEntity < Grape::Entity expose :path do |pipeline| if pipeline.ref - namespace_project_tree_path( - pipeline.project.namespace, - pipeline.project, - id: pipeline.ref) + project_ref_path(pipeline.project, pipeline.ref) end end diff --git a/app/serializers/request_aware_entity.rb b/app/serializers/request_aware_entity.rb index 3039014aaaa..d53fcfb8c1b 100644 --- a/app/serializers/request_aware_entity.rb +++ b/app/serializers/request_aware_entity.rb @@ -3,6 +3,7 @@ module RequestAwareEntity included do include Gitlab::Routing + include GitlabRoutingHelper include Gitlab::Allowable end -- cgit v1.2.1 From ca3d868c3731018e18c4b5931d5a37466a16fa6a Mon Sep 17 00:00:00 2001 From: Fatih Acet Date: Wed, 10 May 2017 23:05:25 +0300 Subject: MRWidget: Implement new design for nothing to commit state. --- app/serializers/merge_request_entity.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'app/serializers') diff --git a/app/serializers/merge_request_entity.rb b/app/serializers/merge_request_entity.rb index a2542c54f7a..d31057c030c 100644 --- a/app/serializers/merge_request_entity.rb +++ b/app/serializers/merge_request_entity.rb @@ -97,6 +97,12 @@ class MergeRequestEntity < IssuableEntity presenter(merge_request).target_branch_commits_path end + expose :new_blob_path do |merge_request| + namespace_project_new_blob_path(merge_request.project.namespace, + merge_request.project, + merge_request.source_branch) + end + expose :conflict_resolution_path do |merge_request| presenter(merge_request).conflict_resolution_path end -- cgit v1.2.1 From 3f6121f2f57fab49326a2082a14dae249a91ac9d Mon Sep 17 00:00:00 2001 From: Oswaldo Ferreira Date: Wed, 10 May 2017 20:29:00 -0300 Subject: Returns new_blob_path only when user can push_code to project --- app/serializers/merge_request_entity.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'app/serializers') diff --git a/app/serializers/merge_request_entity.rb b/app/serializers/merge_request_entity.rb index d31057c030c..a49f4d834cd 100644 --- a/app/serializers/merge_request_entity.rb +++ b/app/serializers/merge_request_entity.rb @@ -98,9 +98,11 @@ class MergeRequestEntity < IssuableEntity end expose :new_blob_path do |merge_request| - namespace_project_new_blob_path(merge_request.project.namespace, - merge_request.project, - merge_request.source_branch) + if can?(current_user, :push_code, merge_request.project) + namespace_project_new_blob_path(merge_request.project.namespace, + merge_request.project, + merge_request.source_branch) + end end expose :conflict_resolution_path do |merge_request| -- cgit v1.2.1 From 907dd68e0a18e995dc5772c9bc8117aa150edc25 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Wed, 17 May 2017 13:01:24 +0100 Subject: Added move to project in issue inline edit form [ci skip] --- app/serializers/issue_entity.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'app/serializers') diff --git a/app/serializers/issue_entity.rb b/app/serializers/issue_entity.rb index bc4f68710b2..6bc8d0f70c3 100644 --- a/app/serializers/issue_entity.rb +++ b/app/serializers/issue_entity.rb @@ -1,4 +1,6 @@ class IssueEntity < IssuableEntity + include RequestAwareEntity + expose :branch_name expose :confidential expose :assignees, using: API::Entities::UserBasic @@ -7,4 +9,8 @@ class IssueEntity < IssuableEntity expose :project_id expose :milestone, using: API::Entities::Milestone expose :labels, using: LabelEntity + + expose :path do |issue| + namespace_project_issue_path(issue.project.namespace, issue.project, issue) + end end -- cgit v1.2.1 From 71777a4a184945d6b58170af55d9fd9fef821ac9 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Tue, 16 May 2017 19:41:15 +0800 Subject: Rename BuildsController to JobsController Rename other URL generators admin_builds_path -> admin_jobs_path Fix tests and more renaming Fix more tests Also change build_id to job_id in the controller --- app/serializers/analytics_build_entity.rb | 2 +- app/serializers/build_action_entity.rb | 2 +- app/serializers/build_artifact_entity.rb | 2 +- app/serializers/build_entity.rb | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) (limited to 'app/serializers') diff --git a/app/serializers/analytics_build_entity.rb b/app/serializers/analytics_build_entity.rb index a0db5b8f0f4..ad7ad020b03 100644 --- a/app/serializers/analytics_build_entity.rb +++ b/app/serializers/analytics_build_entity.rb @@ -25,7 +25,7 @@ class AnalyticsBuildEntity < Grape::Entity end expose :url do |build| - url_to(:namespace_project_build, build) + url_to(:namespace_project_job, build) end expose :commit_url do |build| diff --git a/app/serializers/build_action_entity.rb b/app/serializers/build_action_entity.rb index 5e99204c658..301b718d060 100644 --- a/app/serializers/build_action_entity.rb +++ b/app/serializers/build_action_entity.rb @@ -6,7 +6,7 @@ class BuildActionEntity < Grape::Entity end expose :path do |build| - play_namespace_project_build_path( + play_namespace_project_job_path( build.project.namespace, build.project, build) diff --git a/app/serializers/build_artifact_entity.rb b/app/serializers/build_artifact_entity.rb index 8b643d8e783..dde17aa68b8 100644 --- a/app/serializers/build_artifact_entity.rb +++ b/app/serializers/build_artifact_entity.rb @@ -6,7 +6,7 @@ class BuildArtifactEntity < Grape::Entity end expose :path do |build| - download_namespace_project_build_artifacts_path( + download_namespace_project_job_artifacts_path( build.project.namespace, build.project, build) diff --git a/app/serializers/build_entity.rb b/app/serializers/build_entity.rb index e2276808b90..05dd8270e92 100644 --- a/app/serializers/build_entity.rb +++ b/app/serializers/build_entity.rb @@ -5,15 +5,15 @@ class BuildEntity < Grape::Entity expose :name expose :build_path do |build| - path_to(:namespace_project_build, build) + path_to(:namespace_project_job, build) end expose :retry_path do |build| - path_to(:retry_namespace_project_build, build) + path_to(:retry_namespace_project_job, build) end expose :play_path, if: -> (*) { playable? } do |build| - path_to(:play_namespace_project_build, build) + path_to(:play_namespace_project_job, build) end expose :playable?, as: :playable -- cgit v1.2.1 From a355bcac4ba2fda77032f1cb7d88579f77a0ebe6 Mon Sep 17 00:00:00 2001 From: Oswaldo Ferreira Date: Thu, 18 May 2017 20:05:47 -0300 Subject: Stop loading MergeRequestEntity data on sidebar request --- app/serializers/merge_request_basic_entity.rb | 1 + app/serializers/merge_request_entity.rb | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) (limited to 'app/serializers') diff --git a/app/serializers/merge_request_basic_entity.rb b/app/serializers/merge_request_basic_entity.rb index 8771345c135..8461f158bb5 100644 --- a/app/serializers/merge_request_basic_entity.rb +++ b/app/serializers/merge_request_basic_entity.rb @@ -1,4 +1,5 @@ class MergeRequestBasicEntity < Grape::Entity + expose :assignee_id expose :merge_status expose :merge_error expose :state diff --git a/app/serializers/merge_request_entity.rb b/app/serializers/merge_request_entity.rb index a49f4d834cd..eb9d3861ee7 100644 --- a/app/serializers/merge_request_entity.rb +++ b/app/serializers/merge_request_entity.rb @@ -1,7 +1,6 @@ class MergeRequestEntity < IssuableEntity include RequestAwareEntity - expose :assignee_id expose :in_progress_merge_commit_sha expose :locked_at expose :merge_commit_sha -- cgit v1.2.1 From 3e08713c7975dc738b32e8b0e17651fbe3802ec2 Mon Sep 17 00:00:00 2001 From: Oswaldo Ferreira Date: Thu, 18 May 2017 22:30:51 -0300 Subject: Remove route --- app/serializers/merge_request_entity.rb | 6 ------ 1 file changed, 6 deletions(-) (limited to 'app/serializers') diff --git a/app/serializers/merge_request_entity.rb b/app/serializers/merge_request_entity.rb index eb9d3861ee7..b3247ae36dd 100644 --- a/app/serializers/merge_request_entity.rb +++ b/app/serializers/merge_request_entity.rb @@ -153,12 +153,6 @@ class MergeRequestEntity < IssuableEntity format: :json) end - expose :merge_check_path do |merge_request| - merge_check_namespace_project_merge_request_path(merge_request.project.namespace, - merge_request.project, - merge_request) - end - expose :ci_environments_status_path do |merge_request| ci_environments_status_namespace_project_merge_request_path(merge_request.project.namespace, merge_request.project, -- cgit v1.2.1 From 33923a49f85cb814f87a495d63c09503f53466e4 Mon Sep 17 00:00:00 2001 From: Oswaldo Ferreira Date: Wed, 24 May 2017 21:54:57 -0300 Subject: Expose remove_source_branch boolean/null --- app/serializers/merge_request_entity.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'app/serializers') diff --git a/app/serializers/merge_request_entity.rb b/app/serializers/merge_request_entity.rb index b3247ae36dd..f7eb75395b5 100644 --- a/app/serializers/merge_request_entity.rb +++ b/app/serializers/merge_request_entity.rb @@ -39,6 +39,7 @@ class MergeRequestEntity < IssuableEntity expose :commits_count expose :cannot_be_merged?, as: :has_conflicts expose :can_be_merged?, as: :can_be_merged + expose :remove_source_branch?, as: :remove_source_branch expose :project_archived do |merge_request| merge_request.project.archived? -- cgit v1.2.1 From 625d3442061d102f7020ef322c2c2febafc891aa Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Thu, 25 May 2017 11:20:52 +0100 Subject: renamed path to web_url in endpoint --- app/serializers/issue_entity.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/serializers') diff --git a/app/serializers/issue_entity.rb b/app/serializers/issue_entity.rb index 6bc8d0f70c3..35df95549b7 100644 --- a/app/serializers/issue_entity.rb +++ b/app/serializers/issue_entity.rb @@ -10,7 +10,7 @@ class IssueEntity < IssuableEntity expose :milestone, using: API::Entities::Milestone expose :labels, using: LabelEntity - expose :path do |issue| + expose :web_url do |issue| namespace_project_issue_path(issue.project.namespace, issue.project, issue) end end -- cgit v1.2.1 From 161af17c1b69e7e00aefcd4f540a55755259ceda Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Wed, 24 May 2017 15:13:51 +0200 Subject: Introduce source to pipeline entity --- app/serializers/pipeline_entity.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/serializers') diff --git a/app/serializers/pipeline_entity.rb b/app/serializers/pipeline_entity.rb index ea57cc97a7e..486f8c36fbd 100644 --- a/app/serializers/pipeline_entity.rb +++ b/app/serializers/pipeline_entity.rb @@ -5,6 +5,7 @@ class PipelineEntity < Grape::Entity expose :user, using: UserEntity expose :active?, as: :active expose :coverage + expose :source expose :path do |pipeline| namespace_project_pipeline_path( @@ -24,7 +25,6 @@ class PipelineEntity < Grape::Entity expose :flags do expose :latest?, as: :latest - expose :triggered?, as: :triggered expose :stuck?, as: :stuck expose :has_yaml_errors?, as: :yaml_errors expose :can_retry?, as: :retryable -- cgit v1.2.1