Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sql-exception causes session-delete (back-button) #8

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 25 additions & 20 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@
# require 'inshape'

class ApplicationController < ActionController::Base
include Concerns::ActionMethods
include Concerns::MadekCookieSession
include Concerns::ResponsibleEntityPath
include Concerns::WebappPathHelpers
include Errors
include Pundit::Authorization

self.responder = ApplicationResponder
self.respond_to :html

protect_from_forgery

# https://github.com/Madek/Madek/issues/423
before_action do
begin
Expand All @@ -11,34 +23,20 @@ class ApplicationController < ActionController::Base
end
end

include Concerns::MadekCookieSession
before_action :authorize_admin, except: :status
before_action :set_context_for_app_layout
before_action :notify_if_session_expiring_soon

include Concerns::ResponsibleEntityPath
include Pundit::Authorization
include Errors

include Concerns::WebappPathHelpers

self.responder = ApplicationResponder
respond_to :html
before_action :forget_vocabulary_url_params_if_requested

rescue_from ActiveRecord::ActiveRecordError,
with: :render_error
rescue_from Pundit::NotAuthorizedError,
with: :error_according_to_login_state

before_action :authorize_admin, except: :status

include Concerns::ActionMethods
before_action :forget_vocabulary_url_params_if_requested

protect_from_forgery

helper_method :capitalize_all
helper_method :current_user
helper_method :filter_value
helper_method :feature_toggle_sql_reports
helper_method :capitalize_all
helper_method :filter_value

def status
render plain: 'OK, but we need to provide memory usage info ' \
Expand All @@ -47,8 +45,15 @@ def status

private

def set_context_for_app_layout
# Using this so that error template (incl. base layout)
# can be rendered even if exception occured on the DB-level and
# the transaction has been closed for further DB-queries.
@beta_tester_notifications = current_user.try(:beta_tester_notifications?)
end

def current_user
validate_services_session_cookie_and_get_user
@current_user ||= validate_services_session_cookie_and_get_user
end

def render_error(error, only_text = false)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/notification_cases_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class NotificationCasesController < ApplicationController
include ApplicationHelper

before_action do
unless current_user.beta_tester_notifications?
unless @beta_tester_notifications
raise("Not allowed to use this feature.")
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/smtp_settings_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class SmtpSettingsController < ApplicationController

before_action do
unless current_user.beta_tester_notifications?
unless @beta_tester_notifications
raise("Not allowed to use this feature.")
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/_base.haml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

= navbar_item 'Dashboard', root_path
= navbar_item 'Settings', app_settings_path
- if current_user.try(:beta_tester_notifications?)
- if @beta_tester_notifications
= navbar_item 'SMTP', smtp_settings_path
= navbar_item 'Notifications', notification_cases_path
%li.dropdown
Expand Down
4 changes: 3 additions & 1 deletion spec/features/meta_keys_spec.rb
SeduroDotCom marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,6 @@ def meta_datum_types

scenario 'meta key cannot be deleted' do
visit meta_key_path(meta_key)
binding.pry

AuditedChange.delete_all
audited_changes_before = AuditedChange.count
Expand All @@ -567,6 +566,9 @@ def meta_datum_types
expect(current_path).to eq(meta_key_path(meta_key))
expect(meta_key.meta_data.reload).to eq(meta_data)

visit '/admin/meta_keys'
expect(page).not_to have_content('Unauthenticated code: 401')

expect(AuditedChange.count).to eq audited_changes_before
expect(AuditedRequest.count).to eq (audited_requests_before + 1)
expect(AuditedResponse.count).to eq (audited_responses_before + 1)
Expand Down