2018-11-29 23:03:35 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class IssuableSidebarBasicEntity < Grape::Entity
|
|
|
|
include RequestAwareEntity
|
|
|
|
|
|
|
|
expose :id
|
2019-07-25 22:30:50 -04:00
|
|
|
expose :iid
|
2018-11-29 23:03:35 -05:00
|
|
|
expose :type do |issuable|
|
|
|
|
issuable.to_ability_name
|
|
|
|
end
|
|
|
|
expose :author_id
|
|
|
|
expose :project_id do |issuable|
|
|
|
|
issuable.project.id
|
|
|
|
end
|
|
|
|
expose :discussion_locked
|
|
|
|
expose :reference do |issuable|
|
|
|
|
issuable.to_reference(issuable.project, full: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :milestone, using: ::API::Entities::Milestone
|
|
|
|
expose :labels, using: LabelEntity
|
|
|
|
|
|
|
|
expose :current_user, if: lambda { |_issuable| current_user } do
|
2020-05-12 08:09:47 -04:00
|
|
|
expose :current_user, merge: true, using: ::API::Entities::UserBasic
|
2018-11-29 23:03:35 -05:00
|
|
|
|
|
|
|
expose :todo, using: IssuableSidebarTodoEntity do |issuable|
|
|
|
|
current_user.pending_todo_for(issuable)
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :can_edit do |issuable|
|
|
|
|
can?(current_user, :"admin_#{issuable.to_ability_name}", issuable.project)
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :can_move do |issuable|
|
|
|
|
issuable.can_move?(current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :can_admin_label do |issuable|
|
|
|
|
can?(current_user, :admin_label, issuable.project)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :issuable_json_path do |issuable|
|
|
|
|
if issuable.is_a?(MergeRequest)
|
|
|
|
project_merge_request_path(issuable.project, issuable.iid, :json)
|
|
|
|
else
|
|
|
|
project_issue_path(issuable.project, issuable.iid, :json)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :namespace_path do |issuable|
|
|
|
|
issuable.project.namespace.full_path
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :project_path do |issuable|
|
|
|
|
issuable.project.path
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :project_full_path do |issuable|
|
|
|
|
issuable.project.full_path
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :project_issuables_path do |issuable|
|
|
|
|
project = issuable.project
|
|
|
|
namespace = project.namespace
|
|
|
|
|
|
|
|
if issuable.is_a?(MergeRequest)
|
|
|
|
namespace_project_merge_requests_path(namespace, project)
|
|
|
|
else
|
|
|
|
namespace_project_issues_path(namespace, project)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :create_todo_path do |issuable|
|
|
|
|
project_todos_path(issuable.project)
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :project_milestones_path do |issuable|
|
|
|
|
project_milestones_path(issuable.project, :json)
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :project_labels_path do |issuable|
|
|
|
|
project_labels_path(issuable.project, :json, include_ancestor_groups: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :toggle_subscription_path do |issuable|
|
|
|
|
toggle_subscription_path(issuable)
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :move_issue_path do |issuable|
|
|
|
|
move_namespace_project_issue_path(
|
|
|
|
namespace_id: issuable.project.namespace.to_param,
|
|
|
|
project_id: issuable.project,
|
|
|
|
id: issuable
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :projects_autocomplete_path do |issuable|
|
|
|
|
autocomplete_projects_path(project_id: issuable.project.id)
|
|
|
|
end
|
|
|
|
|
2019-08-17 01:56:48 -04:00
|
|
|
expose :project_emails_disabled do |issuable|
|
|
|
|
issuable.project.emails_disabled?
|
|
|
|
end
|
|
|
|
|
2021-01-04 22:10:19 -05:00
|
|
|
expose :create_note_email do |issuable|
|
|
|
|
issuable.creatable_note_email_address(current_user)
|
|
|
|
end
|
|
|
|
|
2020-08-20 11:10:18 -04:00
|
|
|
expose :supports_time_tracking?, as: :supports_time_tracking
|
2020-08-27 17:10:27 -04:00
|
|
|
expose :supports_milestone?, as: :supports_milestone
|
2020-09-10 14:08:54 -04:00
|
|
|
expose :supports_severity?, as: :supports_severity
|
2020-08-20 11:10:18 -04:00
|
|
|
|
2018-11-29 23:03:35 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def current_user
|
|
|
|
request.current_user
|
|
|
|
end
|
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
IssuableSidebarBasicEntity.prepend_mod_with('IssuableSidebarBasicEntity')
|