68 lines
1.0 KiB
Ruby
68 lines
1.0 KiB
Ruby
# typed: strict
|
|
class State::IpAddressRolePolicy < ApplicationPolicy
|
|
extend T::Sig
|
|
|
|
sig { returns(T::Boolean) }
|
|
def index?
|
|
is_role_admin?
|
|
end
|
|
|
|
sig { returns(T::Boolean) }
|
|
def create?
|
|
is_role_admin?
|
|
end
|
|
|
|
sig { returns(T::Boolean) }
|
|
def new?
|
|
create?
|
|
end
|
|
|
|
sig { returns(T::Boolean) }
|
|
def update?
|
|
is_role_admin?
|
|
end
|
|
|
|
sig { returns(T::Boolean) }
|
|
def edit?
|
|
update?
|
|
end
|
|
|
|
sig { returns(T::Boolean) }
|
|
def destroy?
|
|
is_role_admin?
|
|
end
|
|
|
|
sig { returns(T::Boolean) }
|
|
def toggle?
|
|
update?
|
|
end
|
|
|
|
private
|
|
|
|
class Scope
|
|
extend T::Sig
|
|
|
|
sig do
|
|
params(
|
|
user: T.nilable(User),
|
|
scope: T.untyped,
|
|
controller: ApplicationController,
|
|
).void
|
|
end
|
|
def initialize(user, scope, controller)
|
|
@user = user
|
|
@scope = scope
|
|
@controller = controller
|
|
end
|
|
|
|
sig { returns(T.untyped) }
|
|
def resolve
|
|
if @user&.admin?
|
|
@scope
|
|
else
|
|
@scope.where(id: nil) # Returns empty relation
|
|
end
|
|
end
|
|
end
|
|
end
|