From c9e832f6878ceeea7be013b97d7a00ad08c17858 Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Thu, 5 Jul 2018 10:35:57 +0100 Subject: [PATCH] don't warn twice --- app/controllers/concerns/user_limits.rb | 22 +++++++++++++++------- app/controllers/users_controller.rb | 3 ++- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/app/controllers/concerns/user_limits.rb b/app/controllers/concerns/user_limits.rb index a1ce9af26a..98f0c98185 100644 --- a/app/controllers/concerns/user_limits.rb +++ b/app/controllers/concerns/user_limits.rb @@ -29,19 +29,23 @@ ## # Intended to be used by the UsersController to enforce the user limit. module Concerns::UserLimits - def enforce_user_limit(redirect_to: users_path, hard: OpenProject::Enterprise.fail_fast?) + def enforce_user_limit( + redirect_to: users_path, + hard: OpenProject::Enterprise.fail_fast?, + flash_now: false + ) if user_limit_reached? if hard show_user_limit_error! redirect_back fallback_location: redirect_to else - show_user_limit_warning! + show_user_limit_warning! flash_now: flash_now end true elsif imminent_user_limit? - show_imminent_user_limit_warning! + show_imminent_user_limit_warning! flash_now: flash_now true else @@ -78,8 +82,10 @@ module Concerns::UserLimits flash[:error] = I18n.t(:error_enterprise_activation_user_limit) end - def show_user_limit_warning! - flash[:warning] = user_limit_warning + def show_user_limit_warning!(flash_now: false) + f = flash_now ? flash.now : flash + + f[:warning] = user_limit_warning end def show_user_limit_error! @@ -95,8 +101,10 @@ module Concerns::UserLimits warning.html_safe end - def show_imminent_user_limit_warning! - flash[:warning] = imminent_user_limit_warning + def show_imminent_user_limit_warning!(flash_now: false) + f = flash_now ? flash.now : flash + + f[:warning] = imminent_user_limit_warning end ## diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 9bd96f3844..f9dcce0277 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -51,7 +51,8 @@ class UsersController < ApplicationController before_action :check_password_confirmation, only: [:destroy] include Concerns::UserLimits - before_action :enforce_user_limit, only: [:new, :create] + before_action :enforce_user_limit, only: [:create] + before_action -> { enforce_user_limit flash_now: true }, only: [:new] accept_key_auth :index, :show, :create, :update, :destroy