diff options
author | Winnie Hellmann <winnie@gitlab.com> | 2018-10-22 22:06:05 +0200 |
---|---|---|
committer | Winnie Hellmann <winnie@gitlab.com> | 2018-10-22 22:06:05 +0200 |
commit | 53be95daf41fc4e59deab149485210835e7e54cd (patch) | |
tree | 3f377dcc6289049581e2473b7e12f260e774784f /app/serializers | |
parent | 3fb7a1f97a812b7b2b5e80a8a0575cb7bfd2d3c4 (diff) | |
parent | d6be7ed79557ce31a5d0062ceea00c877157a6c7 (diff) | |
download | gitlab-ce-53be95daf41fc4e59deab149485210835e7e54cd.tar.gz |
Merge branch 'master' into scheduled-manual-jobs-environment-play-buttons
Conflicts:
spec/javascripts/environments/environment_actions_spec.js
Diffstat (limited to 'app/serializers')
-rw-r--r-- | app/serializers/build_details_entity.rb | 3 | ||||
-rw-r--r-- | app/serializers/environment_status_entity.rb | 62 | ||||
-rw-r--r-- | app/serializers/environment_status_serializer.rb | 5 | ||||
-rw-r--r-- | app/serializers/issue_entity.rb | 2 | ||||
-rw-r--r-- | app/serializers/merge_request_widget_entity.rb | 2 |
5 files changed, 71 insertions, 3 deletions
diff --git a/app/serializers/build_details_entity.rb b/app/serializers/build_details_entity.rb index 3d508a9a407..066a5b1885c 100644 --- a/app/serializers/build_details_entity.rb +++ b/app/serializers/build_details_entity.rb @@ -4,11 +4,12 @@ class BuildDetailsEntity < JobEntity expose :coverage, :erased_at, :duration expose :tag_list, as: :tags expose :has_trace?, as: :has_trace + expose :stage expose :user, using: UserEntity expose :runner, using: RunnerEntity expose :pipeline, using: PipelineEntity - expose :deployment_status, if: -> (*) { build.has_environment? } do + expose :deployment_status, if: -> (*) { build.starts_environment? } do expose :deployment_status, as: :status expose :persisted_environment, as: :environment, with: EnvironmentEntity diff --git a/app/serializers/environment_status_entity.rb b/app/serializers/environment_status_entity.rb new file mode 100644 index 00000000000..3dfa4f204c9 --- /dev/null +++ b/app/serializers/environment_status_entity.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true + +class EnvironmentStatusEntity < Grape::Entity + include RequestAwareEntity + + expose :id + expose :name + + expose :url do |es| + project_environment_path(es.project, es.environment) + end + + expose :metrics_url, if: ->(*) { can_read_environment? && environment.has_metrics? } do |es| + metrics_project_environment_deployment_path(es.project, es.environment, es.deployment) + end + + expose :metrics_monitoring_url, if: ->(*) { can_read_environment? } do |es| + environment_metrics_path(es.environment) + end + + expose :stop_url, if: ->(*) { can_stop_environment? } do |es| + stop_project_environment_path(es.project, es.environment) + end + + expose :external_url do |es| + es.environment.external_url + end + + expose :external_url_formatted do |es| + es.environment.formatted_external_url + end + + expose :deployed_at + + expose :deployed_at_formatted do |es| + es.deployment.try(:formatted_deployment_time) + end + + expose :changes, if: ->(*) { Feature.enabled?(:ci_environments_status_changes, project) } + + private + + def environment + object.environment + end + + def project + object.environment.project + end + + def current_user + request.current_user + end + + def can_read_environment? + can?(current_user, :read_environment, environment) + end + + def can_stop_environment? + can?(current_user, :stop_environment, environment) + end +end diff --git a/app/serializers/environment_status_serializer.rb b/app/serializers/environment_status_serializer.rb new file mode 100644 index 00000000000..f8d37934763 --- /dev/null +++ b/app/serializers/environment_status_serializer.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class EnvironmentStatusSerializer < BaseSerializer + entity EnvironmentStatusEntity +end diff --git a/app/serializers/issue_entity.rb b/app/serializers/issue_entity.rb index 16a477c92fa..c3f7d4651fb 100644 --- a/app/serializers/issue_entity.rb +++ b/app/serializers/issue_entity.rb @@ -42,6 +42,6 @@ class IssueEntity < IssuableEntity end expose :preview_note_path do |issue| - preview_markdown_path(issue.project, quick_actions_target_type: 'Issue', quick_actions_target_id: issue.id) + preview_markdown_path(issue.project, quick_actions_target_type: 'Issue', quick_actions_target_id: issue.iid) end end diff --git a/app/serializers/merge_request_widget_entity.rb b/app/serializers/merge_request_widget_entity.rb index 380e8804f51..9ec24f799ef 100644 --- a/app/serializers/merge_request_widget_entity.rb +++ b/app/serializers/merge_request_widget_entity.rb @@ -222,7 +222,7 @@ class MergeRequestWidgetEntity < IssuableEntity end expose :preview_note_path do |merge_request| - preview_markdown_path(merge_request.project, quick_actions_target_type: 'MergeRequest', quick_actions_target_id: merge_request.id) + preview_markdown_path(merge_request.project, quick_actions_target_type: 'MergeRequest', quick_actions_target_id: merge_request.iid) end expose :merge_commit_path do |merge_request| |