plugins/identity/app/controllers/identity/projects/role_assignments_controller.rb
# This method groups role assignments by user and group.
# Further it extends role and member descriptions using data from cache.
# Returns an array of maps.
This method groups role assignments by user and group.
Further it extends role and member descriptions using data from cache.
Returns an array of maps.
This method groups role assignments by user and group . Further it extends role and member descriptions using data from cache . Returns an array of maps .
def group_and_extend_role_assignments(role_assignments)
        member_ids = role_assignments.collect do |ra|
          (ra.user || ra.group || {})['id']
        end.uniq
        member_descriptions = ObjectCache.where(id: member_ids).pluck(:id, :payload)
                                         .each_with_object({}) do |data, map|
          map[data[0]] = data[1]['description']
        end
        role_assignments.each_with_object({}) do |ra, map|
          member_type = ''
          member_type = 'user' if ra.user.present?
          member_type = 'group' if ra.group.present?
          member = (ra.user || ra.group || {})
          role_name = ra.role['name']
          ra.role['description'] = I18n.t(
            "roles.#{role_name}", default: role_name.try(:titleize)
          ) + " (#{role_name})"
          member['description'] = member_descriptions[member['id']]
          map[member['id']] ||= {}
          map[member['id']][member_type] = member
          map[member['id']]['roles'] ||= []
          map[member['id']]['roles'] << ra.role
        end.values
      end
def group_and_extend_role_assignments ( role_assignments ) member_ids = role_assignments . collect do | ra | ( ra . user || ra . group || { } ) [ 'id' ] end . uniq member_descriptions = ObjectCache . where ( id : member_ids ) . pluck ( :id , :payload ) . each_with_object ( { } ) do | data , map | map [ data [ 0 ] ] = data [ 1 ] [ 'description' ] end role_assignments . each_with_object ( { } ) do | ra , map | member_type = '' member_type = 'user' if ra . user . present? member_type = 'group' if ra . group . present? member = ( ra . user || ra . group || { } ) role_name = ra . role [ 'name' ] ra . role [ 'description' ] = I18n . t ( "roles.#{role_name}" , default : role_name . try ( :titleize ) ) + " (#{role_name})" member [ 'description' ] = member_descriptions [ member [ 'id' ] ] map [ member [ 'id' ] ] ||= { } map [ member [ 'id' ] ] [ member_type ] = member map [ member [ 'id' ] ] [ 'roles' ] ||= [ ] map [ member [ 'id' ] ] [ 'roles' ] << ra . role end . values end
This method groups role assignments by user and group.
This method groups role assignments by user and group .
# get user or group descriptions from cache # map: id => description # extend role description using translations # build the map: member id => {member, roles}
role_assignments
<not_specific>