2019-02-15 15:39:39 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class IssuableSidebarBasicEntity < Grape::Entity
|
|
|
|
include RequestAwareEntity
|
|
|
|
|
|
|
|
expose :id
|
2019-12-04 20:38:33 +05:30
|
|
|
expose :iid
|
2019-02-15 15:39:39 +05:30
|
|
|
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-24 23:13:21 +05:30
|
|
|
expose :current_user, merge: true, using: ::API::Entities::UserBasic
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
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-10-12 21:52:04 +05:30
|
|
|
expose :project_emails_disabled do |issuable|
|
|
|
|
issuable.project.emails_disabled?
|
|
|
|
end
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
expose :create_note_email do |issuable|
|
|
|
|
issuable.creatable_note_email_address(current_user)
|
|
|
|
end
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
expose :supports_time_tracking?, as: :supports_time_tracking
|
|
|
|
expose :supports_milestone?, as: :supports_milestone
|
|
|
|
expose :supports_severity?, as: :supports_severity
|
2022-04-04 11:22:00 +05:30
|
|
|
expose :supports_escalation?, as: :supports_escalation
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def current_user
|
|
|
|
request.current_user
|
|
|
|
end
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
IssuableSidebarBasicEntity.prepend_mod_with('IssuableSidebarBasicEntity')
|