peimelo/controlled_health_api

View on GitHub
app/policies/unit_policy.rb

Summary

Maintainability
A
0 mins
Test Coverage
C
75%
# frozen_string_literal: true

class UnitPolicy < ApplicationPolicy
  class Scope < Scope
    def resolve
      if user&.admin?
        scope.all
      else
        raise Pundit::NotAuthorizedError
      end
    end
  end

  def create?
    user&.admin?
  end

  def update?
    user&.admin?
  end

  def destroy?
    user&.admin?
  end
end