Skip to content

Commit

Permalink
Create a permission_error page for permission related messages
Browse files Browse the repository at this point in the history
Related to issue itccsro#22, instead of logging of the users anytime
there is a permission issue, now the user will be redirected
to a permission_error page that does not log him off.

If the user was not logged in in the first place, the behavior
is not changed, the user will be redirected to the login page
with a relevant message instead.
  • Loading branch information
Catalin committed Jul 27, 2017
1 parent 8c7fc43 commit 0a24965
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/controllers/concerns/login_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ def layout_for_current_user
module ClassMethods
def authorization_required(required_level = USER_LEVEL_FELLOW, opts={})
before_action opts do
redirect_to login_path, notice: 'Higher level authorization is required to access requested resource' if !is_user_logged_in? or !is_user_level_authorized?(required_level)
redirect_to login_path, notice: 'You must be logged in to access requested resource.' if !is_user_logged_in?
redirect_to permission_error_path if !is_user_level_authorized?(required_level)
end
end
end
Expand Down
12 changes: 12 additions & 0 deletions app/views/static/permission_error.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div class="container">
<div class="row">
<div class="col-lg-6 col-lg-offset-3">
<%= render partial: 'shared/notice' %>
<div class="login-form panel panel-default text-center">
Higher level permissions are required to access the requested resource.
<br /><br />
<%= link_to "Click here to go back.", :back %>
</div>
</div>
</div>
</div>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
get 'me', to: 'redirect#me'
get '/login', to: 'static#login'
post '/login', to: 'static#login_post'
get '/permission_error', to: 'static#permission_error'
post '/123contacts_signup', to: 'static#contacts_signup'
get 'httpsify', to: 'static#httpsify'

Expand Down

0 comments on commit 0a24965

Please sign in to comment.