2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
class IssueEntity < IssuableEntity
|
2018-03-17 18:26:18 +05:30
|
|
|
include TimeTrackableEntity
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
format_with(:upcase) do |item|
|
|
|
|
item.try(:upcase)
|
|
|
|
end
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
format_with(:iso8601) do |item|
|
|
|
|
item.try(:iso8601)
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expose :state
|
|
|
|
expose :milestone_id
|
|
|
|
expose :updated_by_id
|
2023-03-04 22:38:38 +05:30
|
|
|
expose :created_at, format_with: :iso8601
|
|
|
|
expose :updated_at, format_with: :iso8601
|
2018-03-17 18:26:18 +05:30
|
|
|
expose :milestone, using: API::Entities::Milestone
|
|
|
|
expose :labels, using: LabelEntity
|
|
|
|
expose :lock_version
|
|
|
|
expose :author_id
|
2017-08-17 22:00:37 +05:30
|
|
|
expose :confidential
|
2018-03-17 18:26:18 +05:30
|
|
|
expose :discussion_locked
|
2017-08-17 22:00:37 +05:30
|
|
|
expose :assignees, using: API::Entities::UserBasic
|
|
|
|
expose :due_date
|
|
|
|
expose :project_id
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
expose :moved_to_id do |issue|
|
2019-12-04 20:38:33 +05:30
|
|
|
if issue.moved? && can?(request.current_user, :read_issue, issue.moved_to)
|
2019-07-31 22:56:46 +05:30
|
|
|
issue.moved_to_id
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
expose :duplicated_to_id do |issue|
|
|
|
|
if issue.duplicated? && can?(request.current_user, :read_issue, issue.duplicated_to)
|
|
|
|
issue.duplicated_to_id
|
|
|
|
end
|
2019-07-31 22:56:46 +05:30
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expose :web_url do |issue|
|
2022-07-16 23:28:13 +05:30
|
|
|
Gitlab::UrlBuilder.build(issue, only_path: true)
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
expose :current_user do
|
|
|
|
expose :can_create_note do |issue|
|
|
|
|
can?(request.current_user, :create_note, issue)
|
|
|
|
end
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
expose :can_create_confidential_note do |issue|
|
2023-03-17 16:20:25 +05:30
|
|
|
can?(request.current_user, :mark_note_as_internal, issue)
|
2022-11-25 23:54:43 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expose :can_update do |issue|
|
|
|
|
can?(request.current_user, :update_issue, issue)
|
|
|
|
end
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
expose :can_set_issue_metadata do |issue|
|
|
|
|
can?(request.current_user, :set_issue_metadata, issue)
|
|
|
|
end
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
expose :can_award_emoji do |issue|
|
|
|
|
can?(request.current_user, :award_emoji, issue)
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
expose :create_note_path do |issue|
|
|
|
|
project_notes_path(issue.project, target_type: 'issue', target_id: issue.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :preview_note_path do |issue|
|
2019-07-07 11:18:12 +05:30
|
|
|
preview_markdown_path(issue.project, target_type: 'Issue', target_id: issue.iid)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2019-09-04 21:01:54 +05:30
|
|
|
|
|
|
|
expose :confidential_issues_docs_path, if: -> (issue) { issue.confidential? } do |issue|
|
|
|
|
help_page_path('user/project/issues/confidential_issues.md')
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :locked_discussion_docs_path, if: -> (issue) { issue.discussion_locked? } do |issue|
|
2022-06-21 17:19:12 +05:30
|
|
|
help_page_path('user/discussions/index.md', anchor: 'prevent-comments-by-locking-an-issue')
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
expose :is_project_archived do |issue|
|
|
|
|
issue.project.archived?
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :archived_project_docs_path, if: -> (issue) { issue.project.archived? } do |issue|
|
2022-08-13 15:12:31 +05:30
|
|
|
help_page_path('user/project/settings/index.md', anchor: 'archive-a-project')
|
2020-01-01 13:55:28 +05:30
|
|
|
end
|
2021-03-08 18:12:59 +05:30
|
|
|
|
|
|
|
expose :issue_email_participants do |issue|
|
2023-04-23 21:23:45 +05:30
|
|
|
presented_issue = issue.present(current_user: request.current_user)
|
2023-03-04 22:38:38 +05:30
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
presented_issue.issue_email_participants.map do |participant|
|
|
|
|
{
|
|
|
|
email: participant.email
|
|
|
|
}
|
|
|
|
end
|
2021-03-08 18:12:59 +05:30
|
|
|
end
|
2022-07-23 23:45:48 +05:30
|
|
|
|
|
|
|
expose :issue_type,
|
|
|
|
as: :type,
|
|
|
|
format_with: :upcase,
|
|
|
|
documentation: { type: "String", desc: "One of #{::WorkItems::Type.base_types.keys.map(&:upcase)}" }
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
IssueEntity.prepend_mod_with('IssueEntity')
|