2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
module Users
|
|
|
|
module ParticipableService
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
attr_reader :noteable
|
|
|
|
end
|
|
|
|
|
|
|
|
def noteable_owner
|
|
|
|
return [] unless noteable && noteable.author.present?
|
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
[as_hash(noteable.author)]
|
2018-10-15 14:42:47 +05:30
|
|
|
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-05-30 16:15:17 +05:30
|
|
|
as_hash(user)
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def groups
|
2019-05-30 16:15:17 +05:30
|
|
|
current_user.authorized_groups.sort_by(&:path).map do |group|
|
|
|
|
count = group.users.count
|
|
|
|
{ username: group.full_path, name: group.full_name, count: count, avatar_url: group.avatar_url }
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
def as_hash(user)
|
|
|
|
{ username: user.username, name: user.name, avatar_url: user.avatar_url }
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|