Merge pull request #6413 from opf/fix/double_user_limit_warning

don't warn twice

[ci skip]
pull/6417/head
Oliver Günther 6 years ago committed by GitHub
commit c35bb4bad8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      app/controllers/concerns/user_limits.rb
  2. 3
      app/controllers/users_controller.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
##

@ -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

Loading…
Cancel
Save