2016-06-16 23:09:34 +05:30
|
|
|
class Projects::EnvironmentsController < Projects::ApplicationController
|
|
|
|
layout 'project'
|
|
|
|
before_action :authorize_read_environment!
|
|
|
|
before_action :authorize_create_environment!, only: [:new, :create]
|
2016-11-03 12:29:30 +05:30
|
|
|
before_action :authorize_create_deployment!, only: [:stop]
|
|
|
|
before_action :authorize_update_environment!, only: [:edit, :update]
|
|
|
|
before_action :environment, only: [:show, :edit, :update, :stop]
|
2016-06-16 23:09:34 +05:30
|
|
|
|
|
|
|
def index
|
2016-11-03 12:29:30 +05:30
|
|
|
@scope = params[:scope]
|
|
|
|
@all_environments = project.environments
|
|
|
|
@environments =
|
|
|
|
if @scope == 'stopped'
|
|
|
|
@all_environments.stopped
|
|
|
|
else
|
|
|
|
@all_environments.available
|
|
|
|
end
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
@deployments = environment.deployments.order(id: :desc).page(params[:page])
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@environment = project.environments.new
|
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
def create
|
2016-09-13 17:45:13 +05:30
|
|
|
@environment = project.environments.create(environment_params)
|
2016-06-16 23:09:34 +05:30
|
|
|
|
|
|
|
if @environment.persisted?
|
|
|
|
redirect_to namespace_project_environment_path(project.namespace, project, @environment)
|
|
|
|
else
|
2016-09-13 17:45:13 +05:30
|
|
|
render :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
if @environment.update(environment_params)
|
|
|
|
redirect_to namespace_project_environment_path(project.namespace, project, @environment)
|
|
|
|
else
|
|
|
|
render :edit
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
def stop
|
|
|
|
return render_404 unless @environment.stoppable?
|
2016-06-16 23:09:34 +05:30
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
new_action = @environment.stop!(current_user)
|
|
|
|
redirect_to polymorphic_path([project.namespace.becomes(Namespace), project, new_action])
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
def environment_params
|
|
|
|
params.require(:environment).permit(:name, :external_url)
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def environment
|
|
|
|
@environment ||= project.environments.find(params[:id])
|
|
|
|
end
|
|
|
|
end
|