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.

61 lines
841 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. staff? && !record.staff?
  8. end
  9. def disable_2fa?
  10. admin? && !record.staff?
  11. end
  12. def disable_sign_in_token_auth?
  13. staff?
  14. end
  15. def enable_sign_in_token_auth?
  16. staff?
  17. end
  18. def confirm?
  19. staff? && !record.confirmed?
  20. end
  21. def enable?
  22. staff?
  23. end
  24. def approve?
  25. staff? && !record.approved?
  26. end
  27. def reject?
  28. staff? && !record.approved?
  29. end
  30. def disable?
  31. staff? && !record.admin?
  32. end
  33. def promote?
  34. admin? && promoteable?
  35. end
  36. def demote?
  37. admin? && !record.admin? && demoteable?
  38. end
  39. private
  40. def promoteable?
  41. record.approved? && (!record.staff? || !record.admin?)
  42. end
  43. def demoteable?
  44. record.staff?
  45. end
  46. end