Explicitly pass current_administrateur on publish
This commit is contained in:
parent
0e4b6e1ba2
commit
bb8ba75d22
4 changed files with 29 additions and 25 deletions
|
@ -44,7 +44,7 @@ class Admin::ProceduresController < AdminController
|
|||
|
||||
def edit
|
||||
@path = @procedure.path || @procedure.default_path
|
||||
@availability = @procedure.path_availability(@path)
|
||||
@availability = @procedure.path_availability(current_administrateur, @path)
|
||||
end
|
||||
|
||||
def destroy
|
||||
|
@ -69,7 +69,7 @@ class Admin::ProceduresController < AdminController
|
|||
def create
|
||||
@procedure = Procedure.new(procedure_params.merge(administrateurs: [current_administrateur]))
|
||||
@path = @procedure.path
|
||||
@availability = Procedure.path_availability([current_administrateur], @procedure.path)
|
||||
@availability = Procedure.path_availability(current_administrateur, @procedure.path)
|
||||
|
||||
if !@procedure.save
|
||||
flash.now.alert = @procedure.errors.full_messages
|
||||
|
@ -96,7 +96,7 @@ class Admin::ProceduresController < AdminController
|
|||
flash.now.alert = @procedure.errors.full_messages
|
||||
@path = procedure_params[:path]
|
||||
if @path.present?
|
||||
@availability = @procedure.path_availability(@path)
|
||||
@availability = @procedure.path_availability(current_administrateur, @path)
|
||||
end
|
||||
render 'edit'
|
||||
elsif @procedure.brouillon?
|
||||
|
@ -121,7 +121,7 @@ class Admin::ProceduresController < AdminController
|
|||
procedure.path = nil
|
||||
end
|
||||
|
||||
if procedure.publish_or_reopen!(path)
|
||||
if procedure.publish_or_reopen!(current_administrateur, path)
|
||||
flash.notice = "Démarche publiée"
|
||||
redirect_to admin_procedures_path
|
||||
else
|
||||
|
@ -233,9 +233,9 @@ class Admin::ProceduresController < AdminController
|
|||
|
||||
if procedure_id.present?
|
||||
procedure = current_administrateur.procedures.find(procedure_id)
|
||||
@availability = procedure.path_availability(path)
|
||||
@availability = procedure.path_availability(current_administrateur, path)
|
||||
else
|
||||
@availability = Procedure.path_availability([current_administrateur], path)
|
||||
@availability = Procedure.path_availability(current_administrateur, path)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -102,12 +102,12 @@ class Procedure < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def publish_or_reopen!(path)
|
||||
if archivee? && may_reopen?(path)
|
||||
reopen!(path)
|
||||
elsif may_publish?(path)
|
||||
def publish_or_reopen!(administrateur, path)
|
||||
if archivee? && may_reopen?(administrateur, path)
|
||||
reopen!(administrateur, path)
|
||||
elsif may_publish?(administrateur, path)
|
||||
reset!
|
||||
publish!(path)
|
||||
publish!(administrateur, path)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -340,11 +340,11 @@ class Procedure < ApplicationRecord
|
|||
PATH_NOT_AVAILABLE_BROUILLON = :not_available_brouillon
|
||||
PATH_CAN_PUBLISH = [PATH_AVAILABLE, PATH_AVAILABLE_PUBLIEE]
|
||||
|
||||
def path_availability(path)
|
||||
Procedure.path_availability(administrateurs, path, id)
|
||||
def path_availability(administrateur, path)
|
||||
Procedure.path_availability(administrateur, path, id)
|
||||
end
|
||||
|
||||
def self.path_availability(administrateurs, path, exclude_id = nil)
|
||||
def self.path_availability(administrateur, path, exclude_id = nil)
|
||||
if exclude_id.present?
|
||||
procedure = where.not(id: exclude_id).find_by(path: path)
|
||||
else
|
||||
|
@ -353,7 +353,7 @@ class Procedure < ApplicationRecord
|
|||
|
||||
if procedure.blank?
|
||||
PATH_AVAILABLE
|
||||
elsif administrateurs.any? { |administrateur| administrateur.owns?(procedure) }
|
||||
elsif administrateur.owns?(procedure)
|
||||
if procedure.brouillon?
|
||||
PATH_NOT_AVAILABLE_BROUILLON
|
||||
else
|
||||
|
@ -402,17 +402,21 @@ class Procedure < ApplicationRecord
|
|||
update!(path: path)
|
||||
end
|
||||
|
||||
def can_publish?(path)
|
||||
path_availability(path).in?(PATH_CAN_PUBLISH)
|
||||
def can_publish?(administrateur, path)
|
||||
path_availability(administrateur, path).in?(PATH_CAN_PUBLISH)
|
||||
end
|
||||
|
||||
def after_publish(path)
|
||||
def can_reopen?(administrateur, path)
|
||||
path_availability(administrateur, path).in?(PATH_CAN_PUBLISH)
|
||||
end
|
||||
|
||||
def after_publish(administrateur, path)
|
||||
update!(published_at: Time.zone.now)
|
||||
|
||||
claim_path_ownership!(path)
|
||||
end
|
||||
|
||||
def after_reopen(path)
|
||||
def after_reopen(administrateur, path)
|
||||
update!(published_at: Time.zone.now, archived_at: nil)
|
||||
|
||||
claim_path_ownership!(path)
|
||||
|
|
|
@ -37,7 +37,7 @@ FactoryBot.define do
|
|||
after(:build) do |procedure, _evaluator|
|
||||
procedure.for_individual = true
|
||||
procedure.types_de_champ << create(:type_de_champ, libelle: 'Texte obligatoire', mandatory: true)
|
||||
procedure.publish!(generate(:published_path))
|
||||
procedure.publish!(procedure.administrateurs.first, generate(:published_path))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -135,13 +135,13 @@ FactoryBot.define do
|
|||
|
||||
trait :published do
|
||||
after(:build) do |procedure, _evaluator|
|
||||
procedure.publish!(generate(:published_path))
|
||||
procedure.publish!(procedure.administrateurs.first, generate(:published_path))
|
||||
end
|
||||
end
|
||||
|
||||
trait :archived do
|
||||
after(:build) do |procedure, _evaluator|
|
||||
procedure.publish!(generate(:published_path))
|
||||
procedure.publish!(procedure.administrateurs.first, generate(:published_path))
|
||||
procedure.archive!
|
||||
end
|
||||
end
|
||||
|
@ -150,14 +150,14 @@ FactoryBot.define do
|
|||
# For now the behavior is the same than :archived
|
||||
# (it may be different in the future though)
|
||||
after(:build) do |procedure, _evaluator|
|
||||
procedure.publish!(generate(:published_path))
|
||||
procedure.publish!(procedure.administrateurs.first, generate(:published_path))
|
||||
procedure.archive!
|
||||
end
|
||||
end
|
||||
|
||||
trait :hidden do
|
||||
after(:build) do |procedure, _evaluator|
|
||||
procedure.publish!(generate(:published_path))
|
||||
procedure.publish!(procedure.administrateurs.first, generate(:published_path))
|
||||
procedure.hide!
|
||||
end
|
||||
end
|
||||
|
|
|
@ -493,7 +493,7 @@ describe Procedure do
|
|||
|
||||
before do
|
||||
Timecop.freeze(now)
|
||||
procedure.publish!("example-path")
|
||||
procedure.publish!(procedure.administrateurs.first, "example-path")
|
||||
end
|
||||
after { Timecop.return }
|
||||
|
||||
|
|
Loading…
Reference in a new issue