Module: Decidim::Verifications::ApplicationHelper

Defined in:
app/helpers/decidim/verifications/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#announcement_title(authorization) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/helpers/decidim/verifications/application_helper.rb', line 6

def announcement_title(authorization)
  return t("decidim.verifications.id_documents.authorizations.edit.being_reviewed") unless authorization.rejected?

  body =  :ul do
    items = (:li, t("decidim.verifications.id_documents.authorizations.edit.rejection_correctness"))
    items += (:li, t("decidim.verifications.id_documents.authorizations.edit.rejection_clarity")).html_safe
    items
  end

  {
    title: t("decidim.verifications.id_documents.authorizations.edit.rejection_notice"),
    body:
  }
end

#authorization_display_data(authorization) ⇒ Object



21
22
23
# File 'app/helpers/decidim/verifications/application_helper.rb', line 21

def authorization_display_data(authorization)
  { title: t("#{authorization.name}.name", scope: "decidim.authorization_handlers") }
end

#granted_authorization_button_text(authorization) ⇒ Object



60
61
62
63
64
65
# File 'app/helpers/decidim/verifications/application_helper.rb', line 60

def granted_authorization_button_text(authorization)
  return t("authorizations.index.show_renew_info", scope: "decidim.verifications") if authorization.renewable?
  return unless authorization.expired?

  t("authorizations.index.expired_verification", scope: "decidim.verifications")
end

#granted_authorization_display_data(authorization, redirect_url = nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'app/helpers/decidim/verifications/application_helper.rb', line 25

def granted_authorization_display_data(authorization, redirect_url = nil)
  authorization_display_data(authorization).merge(
    url: granted_authorization_url(authorization, redirect_url),
    remote_url: granted_authorization_remote_url(authorization),
    auth_icon: "checkbox-circle-line",
    is_granted: true,
    explanation: granted_authorization_explanation(authorization),
    button_text: granted_authorization_button_text(authorization)
  )
end

#granted_authorization_explanation(authorization) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'app/helpers/decidim/verifications/application_helper.rb', line 50

def granted_authorization_explanation(authorization)
  expiration_timestamp = authorization.expires_at.presence && l(authorization.expires_at, format: :long_with_particles)
  if authorization.expired?
    t("expired_at", scope: "decidim.authorization_handlers", timestamp: expiration_timestamp)
  else
    "#{t("granted_at", scope: "decidim.authorization_handlers", timestamp: l(authorization.granted_at, format: :long_with_particles))}\
    #{t("expires_at", scope: "decidim.authorization_handlers", timestamp: expiration_timestamp) if expiration_timestamp.present?}"
  end
end

#granted_authorization_remote_url(authorization) ⇒ Object



44
45
46
47
48
# File 'app/helpers/decidim/verifications/application_helper.rb', line 44

def granted_authorization_remote_url(authorization)
  return unless authorization.renewable?

  renew_modal_authorizations_path(handler: authorization.name)
end

#granted_authorization_url(authorization, redirect_url = nil) ⇒ Object



36
37
38
39
40
41
42
# File 'app/helpers/decidim/verifications/application_helper.rb', line 36

def granted_authorization_url(authorization, redirect_url = nil)
  return if authorization.renewable?
  return unless authorization.expired?

  url_params = { redirect_url: }.compact
  authorization_method(authorization).root_path(**url_params)
end

#pending_authorization_display_data(authorization, redirect_url = nil) ⇒ Object



67
68
69
70
71
72
73
74
75
76
# File 'app/helpers/decidim/verifications/application_helper.rb', line 67

def pending_authorization_display_data(authorization, redirect_url = nil)
  url_params = { redirect_url: }.compact

  authorization_display_data(authorization).merge(
    url: authorization_method(authorization).resume_authorization_path(**url_params),
    auth_icon: "time-line",
    explanation: t("started_at", scope: "decidim.authorization_handlers", timestamp: l(authorization.updated_at, format: :long_with_particles)),
    button_text: t("authorizations.index.introduce_code", scope: "decidim.verifications")
  )
end

#unauthorized_method_display_data(method, redirect_url = nil) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
# File 'app/helpers/decidim/verifications/application_helper.rb', line 78

def unauthorized_method_display_data(method, redirect_url = nil)
  url_params = { redirect_url: }.compact

  {
    url: method.root_path(**url_params),
    auth_icon: method.icon,
    title: t("#{method.key}.name", scope: "decidim.authorization_handlers"),
    explanation: t("#{method.key}.explanation", scope: "decidim.authorization_handlers"),
    button_text: t("authorizations.index.subscribe", scope: "decidim.verifications")
  }
end