Class: MetadataPresenter::EngineController

Inherits:
Object
  • Object
show all
Defined in:
app/controllers/metadata_presenter/engine_controller.rb

Instance Method Summary collapse

Instance Method Details

#allow_analytics?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'app/controllers/metadata_presenter/engine_controller.rb', line 92

def allow_analytics?
  cookies[analytics_cookie_name] == 'accepted'
end


87
88
89
# File 'app/controllers/metadata_presenter/engine_controller.rb', line 87

def analytics_cookie_name
  @analytics_cookie_name ||= "analytics-#{service.service_name.parameterize}"
end

#analytics_tags_present?Boolean

Returns:

  • (Boolean)


109
110
111
112
113
# File 'app/controllers/metadata_presenter/engine_controller.rb', line 109

def analytics_tags_present?
  Rails.application.config.supported_analytics.values.flatten.any? do |analytic|
    ENV[analytic].present?
  end
end

#answered?(component_id) ⇒ Boolean

Returns:

  • (Boolean)


82
83
84
# File 'app/controllers/metadata_presenter/engine_controller.rb', line 82

def answered?(component_id)
  @page_answers.send(component_id).present?
end

#authorised_session!Object



141
142
143
144
145
# File 'app/controllers/metadata_presenter/engine_controller.rb', line 141

def authorised_session!
  cookies.signed[:_fb_authorised] = {
    value: 1, same_site: :strict, httponly: true
  }
end


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/controllers/metadata_presenter/engine_controller.rb', line 57

def back_link
  if response.status == 404
    @back_link = File.join(request.script_name, @page.url)
  end

  if use_external_start_page? && first_page?
    return external_start_page_url
  end

  previous_page = PreviousPage.new(
    service:,
    user_data: load_user_data,
    current_page: @page,
    referrer: request.referrer
  ).page

  if previous_page
    @back_link ||= File.join(
      request.script_name,
      previous_page.url
    )
  end
end


147
148
149
150
151
152
153
154
155
156
# File 'app/controllers/metadata_presenter/engine_controller.rb', line 147

def external_or_relative_link(link)
  uri = URI.parse(link)
  return link if uri.scheme.present? && uri.host.present?

  if editor_preview?
    File.join(request.script_name, link)
  else
    link.starts_with?('/') ? link : link.prepend('/')
  end
end

#get_saved_progress(uuid) ⇒ Object



33
34
35
36
37
38
39
# File 'app/controllers/metadata_presenter/engine_controller.rb', line 33

def get_saved_progress(uuid)
  # :nocov:
  if defined? super
    super(uuid)
    # :nocov:
  end
end

#increment_record_counter(uuid) ⇒ Object



41
42
43
44
45
46
47
# File 'app/controllers/metadata_presenter/engine_controller.rb', line 41

def increment_record_counter(uuid)
  # :nocov:
  if defined? super
    super(uuid)
    # :nocov:
  end
end

#invalidate_record(uuid) ⇒ Object



49
50
51
52
53
54
55
# File 'app/controllers/metadata_presenter/engine_controller.rb', line 49

def invalidate_record(uuid)
  # :nocov:
  if defined? super
    super(uuid)
    # :nocov:
  end
end

#load_autocomplete_itemsObject



116
117
118
119
120
121
# File 'app/controllers/metadata_presenter/engine_controller.rb', line 116

def load_autocomplete_items
  if @page.autocomplete_component_present?
    items = autocomplete_items(@page.components)
    @page.assign_autocomplete_items(items)
  end
end

#load_page_contentObject



123
124
125
126
127
128
129
# File 'app/controllers/metadata_presenter/engine_controller.rb', line 123

def load_page_content
  if single_page_preview?
    @page.load_all_content
  else
    @page.load_conditional_content(service, @user_data)
  end
end

#maintenance_mode?Boolean

Returns:

  • (Boolean)


131
132
133
# File 'app/controllers/metadata_presenter/engine_controller.rb', line 131

def maintenance_mode?
  ENV['MAINTENANCE_MODE'].present? && ENV['MAINTENANCE_MODE'] == '1'
end

#reload_user_dataObject



15
16
17
18
19
20
21
22
23
# File 'app/controllers/metadata_presenter/engine_controller.rb', line 15

def reload_user_data
  # :nocov:
  if defined? super
    super
    # :nocov:
  else
    load_user_data
  end
end

#require_basic_authObject



11
12
13
# File 'app/controllers/metadata_presenter/engine_controller.rb', line 11

def require_basic_auth
  redirect_to auth_path unless session_authorised?
end

#save_form_progressObject



25
26
27
28
29
30
31
# File 'app/controllers/metadata_presenter/engine_controller.rb', line 25

def save_form_progress
  # :nocov:
  if defined? super
    super
    # :nocov:
  end
end

#session_authorised?Boolean

Returns:

  • (Boolean)


135
136
137
138
139
# File 'app/controllers/metadata_presenter/engine_controller.rb', line 135

def session_authorised?
  return true if ENV['BASIC_AUTH_USER'].blank? || ENV['BASIC_AUTH_PASS'].blank?

  !!cookies.signed[:_fb_authorised]
end

Returns:

  • (Boolean)


102
103
104
105
106
# File 'app/controllers/metadata_presenter/engine_controller.rb', line 102

def show_cookie_confirmation?
  unless no_analytics_cookie?
    (Rails.application.config.respond_to?(:global_ga4) || analytics_tags_present?) && params[:analytics].present?
  end
end

Returns:

  • (Boolean)


97
98
99
# File 'app/controllers/metadata_presenter/engine_controller.rb', line 97

def show_cookie_request?
  (Rails.application.config.respond_to?(:global_ga4) || analytics_tags_present?) && no_analytics_cookie?
end