prevent update if template is in use

This commit is contained in:
Bilal
2020-07-13 20:01:06 +02:00
parent cefa30b331
commit f44eca5328
7 changed files with 39 additions and 6 deletions

View File

@@ -5,8 +5,9 @@ class ContractTemplatesController < ApplicationController
layout 'project'
before_action :set_project, except: [:destroy, :edit]
before_action :set_contract_template, only: [:destroy, :edit]
before_action :set_project, except: [:destroy, :edit, :update]
before_action :set_contract_template, only: [:destroy, :edit, :update]
before_action :set_project_from_contract_template, only: [:edit, :update]
before_action :show_splash_screen, only: :index
def index
@@ -33,7 +34,21 @@ class ContractTemplatesController < ApplicationController
end
def edit
@project = @contract_template.project
@release_type = @contract_template.release_type
end
def update
unless @contract_template.editable?
redirect_to([@project, :contract_templates], alert: t('.error')) and return
end
@contract_template.attributes = contract_template_params
if @contract_template.save
redirect_to [@project, :contract_templates], notice: t('.notice')
else
render :edit
end
end
def destroy
@@ -43,6 +58,10 @@ class ContractTemplatesController < ApplicationController
private
def set_project_from_contract_template
@project = @contract_template.project
end
def show_splash_screen
render :splash if contract_templates.non_archived.count.zero?
end