| Conditions | 2 |
| Total Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | # frozen_string_literal: true |
||
| 24 | def disabled_roles(user) |
||
| 25 | current_user_role = current_user.highest_priority_role |
||
| 26 | |||
| 27 | # Admins are able to remove the admin role from other admins |
||
| 28 | # For all other roles they can only add/remove roles with a higher priority |
||
| 29 | disallowed_roles = if current_user_role.name == "admin" |
||
| 30 | Role.editable_roles(@user_domain).where("priority < #{current_user_role.priority}") |
||
| 31 | .pluck(:id) |
||
| 32 | else |
||
| 33 | Role.editable_roles(@user_domain).where("priority <= #{current_user_role.priority}") |
||
| 34 | .pluck(:id) |
||
| 35 | end |
||
| 36 | |||
| 37 | user.roles.by_priority.pluck(:id) | disallowed_roles |
||
| 38 | end |
||
| 39 | end |
||
| 40 |