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.

54 lines
755 B

  1. # frozen_string_literal: true
  2. class UserPolicy < ApplicationPolicy
  3. def reset_password?
  4. staff? && !record.staff?
  5. end
  6. def change_email?
  7. return false
  8. staff? && !record.staff?
  9. end
  10. def disable_2fa?
  11. admin? && !record.staff?
  12. end
  13. def confirm?
  14. staff? && !record.confirmed?
  15. end
  16. def enable?
  17. staff?
  18. end
  19. def approve?
  20. staff? && !record.approved?
  21. end
  22. def reject?
  23. staff? && !record.approved?
  24. end
  25. def disable?
  26. staff? && !record.admin?
  27. end
  28. def promote?
  29. admin? && promoteable?
  30. end
  31. def demote?
  32. admin? && !record.admin? && demoteable?
  33. end
  34. private
  35. def promoteable?
  36. record.approved? && (!record.staff? || !record.admin?)
  37. end
  38. def demoteable?
  39. record.staff?
  40. end
  41. end