diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-11-03 12:54:10 +0100 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-11-03 13:27:00 +0100 |
commit | 573921cb9d0b139dec324fb1368feb1347b51624 (patch) | |
tree | 048c3f8a4c05127a0fc1be1de6ad60b6165bcb32 /app/serializers | |
parent | f1e9c97d64b96bdd398616743ad048f8d147e26b (diff) | |
download | gitlab-ce-573921cb9d0b139dec324fb1368feb1347b51624.tar.gz |
Implement entities needed for environments folders
Diffstat (limited to 'app/serializers')
-rw-r--r-- | app/serializers/base_serializer.rb | 12 | ||||
-rw-r--r-- | app/serializers/build_entity.rb | 20 | ||||
-rw-r--r-- | app/serializers/commit_entity.rb | 10 | ||||
-rw-r--r-- | app/serializers/deployment_entity.rb | 27 | ||||
-rw-r--r-- | app/serializers/environment_entity.rb | 22 | ||||
-rw-r--r-- | app/serializers/request_aware_entity.rb | 10 |
6 files changed, 79 insertions, 22 deletions
diff --git a/app/serializers/base_serializer.rb b/app/serializers/base_serializer.rb index f9f7135551b..aeb01dc2ad5 100644 --- a/app/serializers/base_serializer.rb +++ b/app/serializers/base_serializer.rb @@ -1,17 +1,17 @@ class BaseSerializer - def initialize(request = {}) - @request = EntityRequest.new(request) + def initialize(parameters = {}) + @entity = self.class.entity_class + @request = EntityRequest.new(parameters) @opts = { request: @request } end - def set(opts) - @request.merge!(opts) + def set(parameters) + @request.merge!(parameters) self end def represent(resource, opts = {}) - self.class.entity_class - .represent(resource, @opts.reverse_merge(opts)) + @entity.represent(resource, @opts.reverse_merge(opts)) end def self.entity(entity_class) diff --git a/app/serializers/build_entity.rb b/app/serializers/build_entity.rb new file mode 100644 index 00000000000..38169ab9864 --- /dev/null +++ b/app/serializers/build_entity.rb @@ -0,0 +1,20 @@ +class BuildEntity < Grape::Entity + include RequestAwareEntity + + expose :id + expose :name + + expose :build_url do |build| + @urls.namespace_project_build_url( + build.project.namespace, + build.project, + build) + end + + expose :retry_url do |build| + @urls.retry_namespace_project_build_url( + build.project.namespace, + build.project, + build) + end +end diff --git a/app/serializers/commit_entity.rb b/app/serializers/commit_entity.rb new file mode 100644 index 00000000000..ae53de0c750 --- /dev/null +++ b/app/serializers/commit_entity.rb @@ -0,0 +1,10 @@ +class CommitEntity < API::Entities::RepoCommit + include RequestAwareEntity + + expose :commit_url do |commit| + @urls.namespace_project_tree_url( + @request.project.namespace, + @request.project, + id: commit.id) + end +end diff --git a/app/serializers/deployment_entity.rb b/app/serializers/deployment_entity.rb new file mode 100644 index 00000000000..3462b188337 --- /dev/null +++ b/app/serializers/deployment_entity.rb @@ -0,0 +1,27 @@ +class DeploymentEntity < Grape::Entity + include RequestAwareEntity + + expose :id + expose :iid + expose :sha + + expose :ref do + expose :name do |deployment| + deployment.ref + end + + expose :ref_url do |deployment| + @urls.namespace_project_tree_url( + deployment.project.namespace, + deployment.project, + id: deployment.ref) + end + end + + expose :tag + expose :last? + expose :user, using: API::Entities::UserBasic + expose :commit, using: CommitEntity + expose :deployable, using: BuildEntity + expose :manual_actions +end diff --git a/app/serializers/environment_entity.rb b/app/serializers/environment_entity.rb index 006b2841e8f..6b037e65e55 100644 --- a/app/serializers/environment_entity.rb +++ b/app/serializers/environment_entity.rb @@ -1,25 +1,21 @@ class EnvironmentEntity < Grape::Entity include RequestAwareEntity - include Gitlab::Routing.url_helpers expose :id expose :name + expose :state + expose :external_url + expose :environment_type expose :project, with: ProjectEntity - expose :last_deployment, - as: :deployment, - using: API::Entities::Deployment + expose :last_deployment, using: DeploymentEntity + expose :stoppable? - expose :gitlab_path do |environment| - namespace_project_environment_path( + expose :environmenturl do |environment| + @urls.namespace_project_environment_url( environment.project.namespace, environment.project, - environment - ) + environment) end - expose :can_read? - - def can_read? - Ability.allowed?(request.user, :read_environment, @object) - end + expose :created_at, :updated_at end diff --git a/app/serializers/request_aware_entity.rb b/app/serializers/request_aware_entity.rb index fc7d1698b1a..1586507492d 100644 --- a/app/serializers/request_aware_entity.rb +++ b/app/serializers/request_aware_entity.rb @@ -1,6 +1,10 @@ module RequestAwareEntity - def request - options[:request] || - raise(StandardError, 'Request not set!!') + attr_reader :request + + def initialize(object, options = {}) + super(object, options) + + @request = options.fetch(:request) + @urls = Gitlab::Routing.url_helpers end end |