2018-11-29 19:02:04 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ApplicationPolicy
|
2019-09-11 18:28:45 -04:00
|
|
|
attr_reader :context, :record
|
2018-11-29 19:02:04 -05:00
|
|
|
|
2019-09-11 19:02:10 -04:00
|
|
|
delegate :account, :params, to: :context, allow_nil: true
|
|
|
|
|
2019-09-11 18:28:45 -04:00
|
|
|
def initialize(context, record)
|
|
|
|
@context = context
|
2018-11-29 19:02:04 -05:00
|
|
|
@record = record
|
|
|
|
end
|
|
|
|
|
2018-12-01 06:17:55 -05:00
|
|
|
# :nocov:
|
|
|
|
|
2018-11-29 19:02:04 -05:00
|
|
|
def index?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def show?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def create?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def new?
|
|
|
|
create?
|
|
|
|
end
|
|
|
|
|
|
|
|
def update?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit?
|
|
|
|
update?
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2018-12-01 06:17:55 -05:00
|
|
|
# :nocov:
|
|
|
|
|
2018-11-30 03:47:54 -05:00
|
|
|
def policy(record)
|
2018-12-12 22:09:49 -05:00
|
|
|
Pundit.policy account, record
|
2018-11-30 03:47:54 -05:00
|
|
|
end
|
|
|
|
|
2019-09-11 18:25:58 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def restricted?
|
|
|
|
Rails.application.restricted?
|
|
|
|
end
|
|
|
|
|
2018-11-29 19:02:04 -05:00
|
|
|
class Scope
|
2019-09-11 18:28:45 -04:00
|
|
|
attr_reader :context, :scope
|
2018-11-29 19:02:04 -05:00
|
|
|
|
2019-09-11 19:02:10 -04:00
|
|
|
delegate :account, :params, to: :context, allow_nil: true
|
|
|
|
|
2019-09-11 18:28:45 -04:00
|
|
|
def initialize(context, scope)
|
|
|
|
@context = context
|
2018-11-29 19:02:04 -05:00
|
|
|
@scope = scope
|
|
|
|
end
|
|
|
|
|
2018-12-01 06:17:55 -05:00
|
|
|
# :nocov:
|
|
|
|
|
2018-11-29 19:02:04 -05:00
|
|
|
def resolve
|
2018-11-29 19:17:26 -05:00
|
|
|
scope.none
|
2018-11-29 19:02:04 -05:00
|
|
|
end
|
2018-12-01 06:17:55 -05:00
|
|
|
|
2019-09-09 18:22:17 -04:00
|
|
|
# :nocov:
|
2019-09-09 18:02:46 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def restricted?
|
|
|
|
Rails.application.restricted?
|
|
|
|
end
|
|
|
|
end
|
2019-09-11 18:28:45 -04:00
|
|
|
|
|
|
|
class Context
|
2019-09-11 19:01:19 -04:00
|
|
|
attr_reader :account, :params
|
2019-09-11 18:28:45 -04:00
|
|
|
|
2019-09-11 19:01:19 -04:00
|
|
|
def initialize(account:, params:)
|
2019-09-11 18:28:45 -04:00
|
|
|
@account = account
|
2019-09-11 19:01:19 -04:00
|
|
|
@params = params
|
2019-09-11 18:28:45 -04:00
|
|
|
end
|
|
|
|
end
|
2018-11-29 19:02:04 -05:00
|
|
|
end
|