You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
553 B

  1. # frozen_string_literal: true
  2. class UserPolicy < ApplicationPolicy
  3. def reset_password?
  4. staff? && !record.staff?
  5. end
  6. def disable_2fa?
  7. admin? && !record.staff?
  8. end
  9. def confirm?
  10. staff? && !record.confirmed?
  11. end
  12. def enable?
  13. admin?
  14. end
  15. def disable?
  16. admin? && !record.admin?
  17. end
  18. def promote?
  19. admin? && promoteable?
  20. end
  21. def demote?
  22. admin? && !record.admin? && demoteable?
  23. end
  24. private
  25. def promoteable?
  26. !record.staff? || !record.admin?
  27. end
  28. def demoteable?
  29. record.staff?
  30. end
  31. end