group_entity.rb 1.14 KB
Newer Older
1
class GroupEntity < Grape::Entity
2
  include ActionView::Helpers::NumberHelper
3
  include RequestAwareEntity
4
  include MembersHelper
5
  include GroupsHelper
6 7 8 9 10 11 12 13

  expose :id, :name, :path, :description, :visibility
  expose :web_url
  expose :full_name, :full_path
  expose :parent_id
  expose :created_at, :updated_at

  expose :permissions do
14 15
    expose :human_group_access do |group, options|
      group.group_members.find_by(user_id: request.current_user)&.human_access
16 17
    end
  end
18 19 20 21 22 23 24 25

  expose :edit_path do |group|
    edit_group_path(group)
  end

  expose :leave_path do |group|
    leave_group_group_members_path(group)
  end
26 27 28 29

  expose :can_edit do |group|
    can?(request.current_user, :admin_group, group)
  end
30 31

  expose :has_subgroups do |group|
32
    GroupsFinder.new(request.current_user, parent: group).execute.any?
33
  end
34

35
  expose :number_projects_with_delimiter do |group|
36
    number_with_delimiter(GroupProjectsFinder.new(group: group, current_user: request.current_user).execute.count)
37 38
  end

39
  expose :number_users_with_delimiter do |group|
40 41
    number_with_delimiter(group.users.count)
  end
42 43 44 45

  expose :avatar_url do |group|
    group_icon(group)
  end
46
end