debian-mirror-gitlab/app/serializers/merge_request_noteable_entity.rb

83 lines
2.7 KiB
Ruby
Raw Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
class MergeRequestNoteableEntity < IssuableEntity
include RequestAwareEntity
# Currently this attr is exposed to be used in app/assets/javascripts/notes/stores/getters.js
# in order to determine whether a noteable is an issue or an MR
expose :merge_params
expose :state
expose :source_branch
expose :target_branch
2022-10-11 01:57:18 +05:30
expose :source_branch_path, if: -> (merge_request) { merge_request.source_project } do |merge_request|
project_tree_path(merge_request.source_project, merge_request.source_branch)
end
expose :target_branch_path, if: -> (merge_request) { merge_request.source_project } do |merge_request|
project_tree_path(merge_request.source_project, merge_request.target_branch)
end
2019-12-04 20:38:33 +05:30
expose :diff_head_sha
expose :create_note_path do |merge_request|
project_notes_path(merge_request.project, target_type: 'merge_request', target_id: merge_request.id)
end
expose :preview_note_path do |merge_request|
preview_markdown_path(merge_request.project, target_type: 'MergeRequest', target_id: merge_request.iid)
end
expose :supports_suggestion?, as: :can_receive_suggestion
expose :create_issue_to_resolve_discussions_path do |merge_request|
presenter(merge_request).create_issue_to_resolve_discussions_path
end
expose :new_blob_path do |merge_request|
if presenter(merge_request).can_push_to_source_branch?
project_new_blob_path(merge_request.source_project, merge_request.source_branch)
end
end
expose :current_user do
expose :can_create_note do |merge_request|
can?(current_user, :create_note, merge_request)
end
expose :can_update do |merge_request|
can?(current_user, :update_merge_request, merge_request)
end
2022-10-11 01:57:18 +05:30
expose :can_approve do |merge_request|
2022-11-25 23:54:43 +05:30
merge_request.eligible_for_approval_by?(current_user)
2022-10-11 01:57:18 +05:30
end
2019-12-04 20:38:33 +05:30
end
2020-01-01 13:55:28 +05:30
expose :locked_discussion_docs_path, if: -> (merge_request) { merge_request.discussion_locked? } do |merge_request|
2022-06-21 17:19:12 +05:30
help_page_path('user/discussions/index.md', anchor: 'prevent-comments-by-locking-an-issue')
2020-01-01 13:55:28 +05:30
end
expose :is_project_archived do |merge_request|
merge_request.project.archived?
end
2020-06-23 00:09:42 +05:30
expose :project_id
2020-01-01 13:55:28 +05:30
expose :archived_project_docs_path, if: -> (merge_request) { merge_request.project.archived? } do |merge_request|
2023-01-13 00:05:48 +05:30
help_page_path('user/project/settings/index.md', anchor: 'archive-a-project')
2020-01-01 13:55:28 +05:30
end
2019-12-04 20:38:33 +05:30
private
delegate :current_user, to: :request
def presenter(merge_request)
@presenters ||= {}
@presenters[merge_request] ||= MergeRequestPresenter.new(merge_request, current_user: current_user) # rubocop: disable CodeReuse/Presenter
end
end
2022-10-11 01:57:18 +05:30
MergeRequestNoteableEntity.prepend_mod_with('MergeRequestNoteableEntity')