Commit 25076520 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Introduce serializer for ClusterEntity

parent 65b4627d
...@@ -46,10 +46,9 @@ class Projects::ClustersController < Projects::ApplicationController ...@@ -46,10 +46,9 @@ class Projects::ClustersController < Projects::ApplicationController
format.json do format.json do
Gitlab::PollingInterval.set_header(response, interval: 10_000) Gitlab::PollingInterval.set_header(response, interval: 10_000)
render json: { render json: ClusterSerializer
status: cluster.status, # The current status of the operation. .new(project: @project, current_user: @current_user)
status_reason: cluster.status_reason # If an error has occurred, a textual description of the error. .represent_status(@cluster)
}
end end
end end
end end
...@@ -62,7 +61,15 @@ class Projects::ClustersController < Projects::ApplicationController ...@@ -62,7 +61,15 @@ class Projects::ClustersController < Projects::ApplicationController
.new(project, current_user, cluster_params) .new(project, current_user, cluster_params)
.execute(cluster) .execute(cluster)
render :show respond_to do |format|
format.html do
render :show
end
format.json do
head :no_data
end
end
end end
def destroy def destroy
...@@ -80,9 +87,13 @@ class Projects::ClustersController < Projects::ApplicationController ...@@ -80,9 +87,13 @@ class Projects::ClustersController < Projects::ApplicationController
end end
def cluster_params def cluster_params
params.require(:cluster) params.require(:cluster).permit(:gcp_project_id,
.permit(:gcp_project_id, :gcp_cluster_zone, :gcp_cluster_name, :gcp_cluster_size, :gcp_cluster_zone,
:gcp_machine_type, :project_namespace, :enabled) :gcp_cluster_name,
:gcp_cluster_size,
:gcp_machine_type,
:project_namespace,
:enabled)
end end
def authorize_google_api def authorize_google_api
...@@ -103,10 +114,10 @@ class Projects::ClustersController < Projects::ApplicationController ...@@ -103,10 +114,10 @@ class Projects::ClustersController < Projects::ApplicationController
end end
def authorize_update_cluster! def authorize_update_cluster!
return access_denied! unless can?(current_user, :update_cluster, cluster) access_denied! unless can?(current_user, :update_cluster, cluster)
end end
def authorize_admin_cluster! def authorize_admin_cluster!
return access_denied! unless can?(current_user, :admin_cluster, cluster) access_denied! unless can?(current_user, :admin_cluster, cluster)
end end
end end
class ClusterEntity < Grape::Entity
include RequestAwareEntity
expose :status
expose :status_reason
end
class ClusterSerializer < BaseSerializer
entity ClusterEntity
def represent_status(resource)
represent(resource, { only: [:status, :status_reason] })
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment