Skip to content

Instantly share code, notes, and snippets.

@stp-che
Created October 18, 2019 06:08
Show Gist options
  • Save stp-che/f26a42850c0596ae075deaa38bfa2066 to your computer and use it in GitHub Desktop.
Save stp-che/f26a42850c0596ae075deaa38bfa2066 to your computer and use it in GitHub Desktop.
class ExtraChargeGroundsController < WithSessionController
require_global_permission Access::P_EXTRA_CHARGE_MANAGE
end
class WithSessionController < ApplicationController
class << self
private
def require_global_permission(permission, **opts)
before_action :forbid!, **opts, unless: ->{
CurrentSession.context_by_permission(permission)[Access::Context::GLOBAL]
}
end
end
private
def forbid!
raise ForbiddenError
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment