2018-07-16 12:31:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-04-26 15:53:13 -04:00
|
|
|
module Users
|
|
|
|
module ParticipableService
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
attr_reader :noteable
|
|
|
|
end
|
|
|
|
|
|
|
|
def noteable_owner
|
|
|
|
return [] unless noteable && noteable.author.present?
|
|
|
|
|
2019-02-15 09:08:03 -05:00
|
|
|
[user_as_hash(noteable.author)]
|
2018-04-26 15:53:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def participants_in_noteable
|
|
|
|
return [] unless noteable
|
|
|
|
|
|
|
|
users = noteable.participants(current_user)
|
|
|
|
sorted(users)
|
|
|
|
end
|
|
|
|
|
|
|
|
def sorted(users)
|
|
|
|
users.uniq.to_a.compact.sort_by(&:username).map do |user|
|
2019-02-15 09:08:03 -05:00
|
|
|
user_as_hash(user)
|
2018-04-26 15:53:13 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def groups
|
|
|
|
current_user.authorized_groups.sort_by(&:path).map do |group|
|
2019-02-15 09:08:03 -05:00
|
|
|
group_as_hash(group)
|
2018-04-26 15:53:13 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-02-15 09:08:03 -05:00
|
|
|
def user_as_hash(user)
|
|
|
|
{ type: user.class.name, username: user.username, name: user.name, avatar_url: user.avatar_url }
|
|
|
|
end
|
|
|
|
|
|
|
|
def group_as_hash(group)
|
|
|
|
{ type: group.class.name, username: group.full_path, name: group.full_name, avatar_url: group.avatar_url, count: group.users.count }
|
2018-04-26 15:53:13 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|