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

spike experiment for pundit injection #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
/test/dummy/tmp/development_secret.txt

.byebug_history

.DS_Store
40 changes: 39 additions & 1 deletion app/controllers/rake_ui/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,51 @@
module RakeUi
class ApplicationController < ActionController::Base
before_action :black_hole_production
before_action :auth_validate
before_action :policy_validate

# include Pundit::Authorization

# before_action :authorize_pundit
# before_action :authorize!

STAGING_OK = (Rails.env.staging? && RakeUi.configuration.allow_staging)
PROD_OK = RakeUi.configuration.allow_production

private

def authorize_pundit
r = 3
@current_user = authenticate_admin_user!
authorize(@current_user)
# binding.pry
# authorize :rake_tasks, :show?
end

def black_hole_production
return if Rails.env.test? || Rails.env.development? || RakeUi.configuration.allow_production
return if Rails.env.test? || Rails.env.development? || STAGING_OK || PROD_OK

raise ActionController::RoutingError, "Not Found"
end

def auth_validate
return true unless RakeUi.configuration.auth_engine

if defined?(RakeUi.configuration.auth_engine)
cb = RakeUi.configuration.auth_callback
return false unless cb && (cb.class == Proc)
RakeUi.configuration.auth_callback.call(self)
end
end

def policy_validate
return true unless RakeUi.configuration.policy_engine

if defined?(RakeUi.configuration.policy_engine)
cb = RakeUi.configuration.policy_callback
return false unless cb && (cb.class == Proc)
RakeUi.configuration.policy_callback.call(self)
end
end
end
end
11 changes: 11 additions & 0 deletions lib/rake-ui.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,18 @@

module RakeUi
mattr_accessor :allow_production
mattr_accessor :allow_staging
mattr_accessor :policy_engine
mattr_accessor :policy_callback
mattr_accessor :auth_engine
mattr_accessor :auth_callback

self.allow_production = false
self.allow_staging = true
self.policy_engine = nil
self.policy_callback = nil
self.auth_engine = nil
self.auth_callback = nil

def self.configuration
yield(self) if block_given?
Expand Down