2018-07-19 14:43:13 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-04 16:45:02 -04:00
|
|
|
class GroupEntity < Grape::Entity
|
2017-05-30 05:24:51 -04:00
|
|
|
include ActionView::Helpers::NumberHelper
|
2017-05-04 16:45:02 -04:00
|
|
|
include RequestAwareEntity
|
2017-05-30 04:09:37 -04:00
|
|
|
include MembersHelper
|
2017-06-06 20:21:53 -04:00
|
|
|
include GroupsHelper
|
2017-05-04 16:45:02 -04:00
|
|
|
|
|
|
|
expose :id, :name, :path, :description, :visibility
|
|
|
|
expose :full_name, :full_path
|
2017-06-16 04:54:20 -04:00
|
|
|
expose :web_url
|
2017-05-04 16:45:02 -04:00
|
|
|
expose :parent_id
|
|
|
|
expose :created_at, :updated_at
|
|
|
|
|
2017-06-16 04:54:20 -04:00
|
|
|
expose :group_path do |group|
|
|
|
|
group_path(group)
|
|
|
|
end
|
|
|
|
|
2017-05-04 16:45:02 -04:00
|
|
|
expose :permissions do
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-06-07 23:40:37 -04:00
|
|
|
expose :human_group_access do |group, options|
|
|
|
|
group.group_members.find_by(user_id: request.current_user)&.human_access
|
2017-05-04 16:45:02 -04:00
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-05-04 16:45:02 -04:00
|
|
|
end
|
2017-05-30 04:09:37 -04:00
|
|
|
|
|
|
|
expose :edit_path do |group|
|
|
|
|
edit_group_path(group)
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :leave_path do |group|
|
|
|
|
leave_group_group_members_path(group)
|
|
|
|
end
|
2017-05-30 04:28:38 -04:00
|
|
|
|
|
|
|
expose :can_edit do |group|
|
|
|
|
can?(request.current_user, :admin_group, group)
|
|
|
|
end
|
2017-05-30 04:53:00 -04:00
|
|
|
|
|
|
|
expose :has_subgroups do |group|
|
2017-06-07 21:22:34 -04:00
|
|
|
GroupsFinder.new(request.current_user, parent: group).execute.any?
|
2017-05-30 04:53:00 -04:00
|
|
|
end
|
2017-05-30 05:24:51 -04:00
|
|
|
|
2017-05-31 16:11:06 -04:00
|
|
|
expose :number_projects_with_delimiter do |group|
|
2017-06-07 21:22:34 -04:00
|
|
|
number_with_delimiter(GroupProjectsFinder.new(group: group, current_user: request.current_user).execute.count)
|
2017-05-30 05:24:51 -04:00
|
|
|
end
|
|
|
|
|
2017-05-31 16:11:06 -04:00
|
|
|
expose :number_users_with_delimiter do |group|
|
2017-05-30 05:24:51 -04:00
|
|
|
number_with_delimiter(group.users.count)
|
|
|
|
end
|
2017-06-06 20:21:53 -04:00
|
|
|
|
|
|
|
expose :avatar_url do |group|
|
2017-10-02 07:35:01 -04:00
|
|
|
group_icon_url(group)
|
2017-06-06 20:21:53 -04:00
|
|
|
end
|
2017-05-04 16:45:02 -04:00
|
|
|
end
|