For the sake of future visitors of this topic, here’s the final solution that I came up with.
It’s not perfect, nor optimised but working! And that’s the first and most important step ![]()
after_initialize {
require_dependency 'basic_user_serializer'
class ::BasicUserSerializer
attributes :name
def name
if user_is_current_user
return _old_name_method
else
# TODO: make this list editable
clubGroups = Array['...']
if scope.user
ownGroups = GroupUser.where(user_id: scope.user.id)
.map { |gu| gu.group_id }
.map { |group_id| Group.find_by(id: group_id) }
.filter { |group| clubGroups.include? group.name }
if ownGroups.length > 0
ownGroupsIds = ownGroups.map { |g| g.id }
if GroupUser.exists?(user_id: user.id, group_id: ownGroupsIds)
return _old_name_method
end
end
end
end
return ''
end
private def _old_name_method
return Hash === user ? user[:name] : user.try(:name)
end
end
}