Skip to content

Commit

Permalink
Merge pull request #8 from realstorypro/access-control
Browse files Browse the repository at this point in the history
added access control to the homepage
  • Loading branch information
Leonid Medovyy committed May 1, 2023
2 parents ec92a64 + 37c2853 commit 5fc563c
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
15 changes: 15 additions & 0 deletions app/controllers/concerns/restricted_access.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module RestrictedAccess
extend ActiveSupport::Concern

included do
before_action :authenticate_user!
before_action :check_access
end

private

def check_access
redirect_to unauthorized_index_path unless current_user.has_access?
end

end
4 changes: 2 additions & 2 deletions app/controllers/page_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class PageController < ApplicationController
before_action :authenticate_user!

include RestrictedAccess
def index
end

end
5 changes: 5 additions & 0 deletions app/controllers/unauthorized_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class UnauthorizedController < ApplicationController
def index
redirect_to root_path if current_user.has_access?
end
end
5 changes: 5 additions & 0 deletions app/views/unauthorized/index.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
=r ux.container
=r ux.row
=r ux.column size: 16, class: 'pt-20'
=r ux.h1 text: 'Unauthorized', class: 'center aligned'
=r ux.text text: 'You are not authorized to access this page.', class: 'text-center'
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
apipie

root "page#index"
resources :unauthorized, only: %i[index]

namespace :api, defaults: { format: 'json' } do
namespace :v1 do
Expand Down
1 change: 1 addition & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = {
'./app/frontend/**/*.js',
'./app/views/**/*',
'./app/views/devise/**/*',
'./app/views/unauthorized/**/*',
'./app/components/**/*',
],
theme: {
Expand Down

0 comments on commit 5fc563c

Please sign in to comment.