20136b7ac8
* add base controller for public api * add dossiers controller with basic checks * create the dossier * ensure content-type is json * prefill dossier with given values * mark a dossier as prefilled When a dossier is prefilled, it's allowed not to have a user. Plus, we add a secure token to the dossier, which we will need later to set a user after sign in / sign up. * set user as owner of an orphan prefilled dossier When a visitor comes from the dossier_url answered by the public api, the dossier is orphan: - when the user is already authenticated: they become the owner - when the user is not authenticated: they can sign in / sign up / france_connect and then they become the owner So here is the procedure: - allow to sign in / sign up / france connect when user is unauthenticated - set dossier ownership when the dossier is orphan - check dossier ownership when the dossier is not - redirect to brouillon path when user is signed in and owner * mark the dossier as prefilled when it's prefilled (even with a GET request, because it will be useful later on, for exmample in order to cleanup the unused prefilled dossiers) * system spec: prefilling dossier with post request
85 lines
2.5 KiB
Ruby
85 lines
2.5 KiB
Ruby
module ProcedureHelper
|
||
def procedure_lien(procedure, prefill_token: nil)
|
||
if procedure.brouillon?
|
||
commencer_test_url(path: procedure.path, prefill_token: prefill_token)
|
||
else
|
||
commencer_url(path: procedure.path, prefill_token: prefill_token)
|
||
end
|
||
end
|
||
|
||
def procedure_libelle(procedure)
|
||
parts = procedure.brouillon? ? [procedure_badge(procedure)] : []
|
||
parts << procedure.libelle
|
||
safe_join(parts, ' ')
|
||
end
|
||
|
||
def procedure_badge(procedure)
|
||
return nil unless procedure.brouillon?
|
||
|
||
tag.span(t('helpers.procedure.testing_procedure'), class: 'fr-badge')
|
||
end
|
||
|
||
def procedure_publish_label(procedure, key)
|
||
# i18n-tasks-use t('modal.publish.body.publish')
|
||
# i18n-tasks-use t('modal.publish.body.reopen')
|
||
# i18n-tasks-use t('modal.publish.submit.publish')
|
||
# i18n-tasks-use t('modal.publish.submit.reopen')
|
||
# i18n-tasks-use t('modal.publish.title.publish')
|
||
# i18n-tasks-use t('modal.publish.title.reopen')
|
||
action = procedure.close? ? :reopen : :publish
|
||
t(action, scope: [:modal, :publish, key])
|
||
end
|
||
|
||
def procedure_auto_archive_date(procedure)
|
||
I18n.l(procedure.auto_archive_on - 1.day, format: '%-d %B %Y')
|
||
end
|
||
|
||
def procedure_auto_archive_time(procedure)
|
||
"à 23 h 59 (heure de " + Rails.application.config.time_zone + ")"
|
||
end
|
||
|
||
def procedure_auto_archive_datetime(procedure)
|
||
procedure_auto_archive_date(procedure) + ' ' + procedure_auto_archive_time(procedure)
|
||
end
|
||
|
||
def can_manage_groupe_instructeurs?(procedure)
|
||
procedure.routing_enabled? && current_administrateur&.owns?(procedure)
|
||
end
|
||
|
||
def can_send_groupe_message?(procedure)
|
||
procedure.dossiers
|
||
.state_brouillon
|
||
.includes(:groupe_instructeur)
|
||
.exists?(groupe_instructeur: current_instructeur.groupe_instructeurs)
|
||
end
|
||
|
||
def url_or_email_to_lien_dpo(procedure)
|
||
URI::MailTo.build([procedure.lien_dpo, "subject="]).to_s
|
||
rescue URI::InvalidComponentError
|
||
uri = URI.parse(procedure.lien_dpo)
|
||
return "//#{uri}" if uri.scheme.nil?
|
||
uri.to_s
|
||
end
|
||
|
||
def estimated_fill_duration_minutes(procedure)
|
||
seconds = procedure.active_revision.estimated_fill_duration
|
||
minutes = (seconds / 60.0).round
|
||
[1, minutes].max
|
||
end
|
||
|
||
def admin_procedures_back_path(procedure)
|
||
statut = if procedure.discarded?
|
||
'supprimees'
|
||
else
|
||
case procedure.aasm_state
|
||
when 'brouillon'
|
||
'brouillons'
|
||
when 'close', 'depubliee'
|
||
'archivees'
|
||
else
|
||
'publiees'
|
||
end
|
||
end
|
||
admin_procedures_path(statut:)
|
||
end
|
||
end
|