2016-04-29 09:14:38 -04:00
|
|
|
class Projects::EnvironmentsController < Projects::ApplicationController
|
|
|
|
layout 'project'
|
2016-06-10 17:36:54 -04:00
|
|
|
before_action :authorize_read_environment!
|
2016-06-14 08:43:45 -04:00
|
|
|
before_action :authorize_create_environment!, only: [:new, :create]
|
2016-08-01 02:42:09 -04:00
|
|
|
before_action :authorize_update_environment!, only: [:edit, :update, :destroy]
|
2016-07-26 03:35:47 -04:00
|
|
|
before_action :environment, only: [:show, :edit, :update, :destroy]
|
2016-04-29 09:14:38 -04:00
|
|
|
|
|
|
|
def index
|
2016-06-10 17:36:54 -04:00
|
|
|
@environments = project.environments
|
2016-04-29 09:14:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2016-06-15 06:07:06 -04:00
|
|
|
@deployments = environment.deployments.order(id: :desc).page(params[:page])
|
2016-06-10 18:15:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@environment = project.environments.new
|
|
|
|
end
|
|
|
|
|
2016-07-26 03:35:47 -04:00
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
2016-06-10 18:15:53 -04:00
|
|
|
def create
|
2016-07-26 03:35:47 -04:00
|
|
|
@environment = project.environments.create(environment_params)
|
2016-06-14 12:34:48 -04:00
|
|
|
|
|
|
|
if @environment.persisted?
|
|
|
|
redirect_to namespace_project_environment_path(project.namespace, project, @environment)
|
|
|
|
else
|
2016-07-26 03:35:47 -04:00
|
|
|
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-10 18:15:53 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
if @environment.destroy
|
2016-06-14 12:34:48 -04:00
|
|
|
flash[:notice] = 'Environment was successfully removed.'
|
2016-06-10 18:15:53 -04:00
|
|
|
else
|
2016-06-14 12:34:48 -04:00
|
|
|
flash[:alert] = 'Failed to remove environment.'
|
2016-06-10 18:15:53 -04:00
|
|
|
end
|
2016-06-14 12:34:48 -04:00
|
|
|
|
|
|
|
redirect_to namespace_project_environments_path(project.namespace, project)
|
2016-04-29 09:14:38 -04:00
|
|
|
end
|
|
|
|
|
2016-06-10 17:36:54 -04:00
|
|
|
private
|
|
|
|
|
2016-07-26 03:35:47 -04:00
|
|
|
def environment_params
|
|
|
|
params.require(:environment).permit(:name, :external_url)
|
2016-06-10 18:15:53 -04:00
|
|
|
end
|
|
|
|
|
2016-06-10 17:36:54 -04:00
|
|
|
def environment
|
2016-06-15 06:07:06 -04:00
|
|
|
@environment ||= project.environments.find(params[:id])
|
2016-04-29 09:14:38 -04:00
|
|
|
end
|
|
|
|
end
|