Follow-up from "Add name and description fields to member_roles"
The following discussions from !126423 (merged) should be addressed:
-
@kassio started a discussion: (+3 comments) suggestion What do you think to make it more clear where these values come from, and as a side-effect reduce this line.
We could use the existing
Gitlab::Access.options_with_owner
to tie together MemberRole and it's access levels, like:# ee/app/models/members/member_role.rb class MemberRole < ApplicationRecord # ... class << self # ... def levels ::Gitlab::Access .options_with_owner .values end def levels_sentence ::Gitlab::Access .options_with_owner .map { |name, value| "#{value} (#{name})" } .to_sentence end end # ... end
[dev](main)> MemberRole.levels => [10, 20, 30, 40, 50] [dev](main)> MemberRole.levels_sentence => "10 (Guest), 20 (Reporter), 30 (Developer), 40 (Maintainer), and 50 (Owner)"
And, with that, we can use the
levels_sentence
here:description: "Access level. Valid values are #{::MemberRole.levels_sentence}.", values: ::MemberRole.levels
sidenote: I started just trying to reduce this line, but I end up with all that.
😬