Commit e4f7b87d authored by Jarka Kadlecova's avatar Jarka Kadlecova
Browse files

Support comments for personal snippets

parent 3556464ea699
......@@ -65,6 +65,15 @@ def destroy
private
def note_html(note)
render_to_string(
"shared/notes/_note",
layout: false,
formats: [:html],
locals: { note: note }
)
end
def note_json(note)
attrs = {
commands_changes: note.commands_changes
......@@ -98,6 +107,41 @@ def note_json(note)
attrs
end
def diff_discussion_html(discussion)
return unless discussion.diff_discussion?
if params[:view] == 'parallel'
template = "discussions/_parallel_diff_discussion"
locals =
if params[:line_type] == 'old'
{ discussions_left: [discussion], discussions_right: nil }
else
{ discussions_left: nil, discussions_right: [discussion] }
end
else
template = "discussions/_diff_discussion"
locals = { discussions: [discussion] }
end
render_to_string(
template,
layout: false,
formats: [:html],
locals: locals
)
end
def discussion_html(discussion)
return if discussion.individual_note?
render_to_string(
"discussions/_discussion",
layout: false,
formats: [:html],
locals: { discussion: discussion }
)
end
def authorize_admin_note!
return access_denied! unless can?(current_user, :admin_note, note)
end
......
......@@ -62,50 +62,6 @@ def note
end
alias_method :awardable, :note
def note_html(note)
render_to_string(
"shared/notes/_note",
layout: false,
formats: [:html],
locals: { note: note }
)
end
def discussion_html(discussion)
return if discussion.individual_note?
render_to_string(
"discussions/_discussion",
layout: false,
formats: [:html],
locals: { discussion: discussion }
)
end
def diff_discussion_html(discussion)
return unless discussion.diff_discussion?
if params[:view] == 'parallel'
template = "discussions/_parallel_diff_discussion"
locals =
if params[:line_type] == 'old'
{ discussions_left: [discussion], discussions_right: nil }
else
{ discussions_left: nil, discussions_right: [discussion] }
end
else
template = "discussions/_diff_discussion"
locals = { discussions: [discussion] }
end
render_to_string(
template,
layout: false,
formats: [:html],
locals: locals
)
end
def finder_params
params.merge(last_fetched_at: last_fetched_at)
end
......
......@@ -13,15 +13,6 @@ def note
end
alias_method :awardable, :note
def note_html(note)
render_to_string(
"shared/notes/_note",
layout: false,
formats: [:html],
locals: { note: note }
)
end
def project
nil
end
......
......@@ -64,6 +64,7 @@ def show
blob = @snippet.blob
override_max_blob_size(blob)
@note = Note.new(noteable: @snippet)
@noteable = @snippet
@discussions = @snippet.discussions
......
......@@ -123,7 +123,11 @@ def project_snippet_url(entity, *args)
end
def preview_markdown_path(project, *args)
preview_markdown_namespace_project_path(project.namespace, project, *args)
if @snippet.is_a?(PersonalSnippet)
preview_markdown_snippet_path(@snippet)
else
preview_markdown_namespace_project_path(project.namespace, project, *args)
end
end
def toggle_subscription_path(entity, *args)
......
......@@ -76,4 +76,47 @@ def discussion_path(discussion)
namespace_project_commit_path(discussion.project.namespace, discussion.project, discussion.noteable, anchor: anchor)
end
end
def notes_url
if @snippet.is_a?(PersonalSnippet)
snippet_notes_path(@snippet)
else
namespace_project_noteable_notes_path(
namespace_id: @project.namespace,
project_id: @project,
target_id: @noteable.id,
target_type: @noteable.class.name.underscore
)
end
end
def note_url(note)
if note.noteable.is_a?(PersonalSnippet)
snippet_note_path(note.noteable, note)
else
namespace_project_note_path(@project.namespace, @project, note)
end
end
def form_resources
if @snippet.is_a?(PersonalSnippet)
[@note]
else
[@project.namespace.becomes(Namespace), @project, @note]
end
end
def new_form_url
return nil unless @snippet.is_a?(PersonalSnippet)
snippet_notes_path(@snippet)
end
def can_create_note?
if @snippet.is_a?(PersonalSnippet)
can?(current_user, :comment_personal_snippet, @snippet)
else
can?(current_user, :create_note, @project)
end
end
end
......@@ -3,8 +3,8 @@ class BuildService < ::BaseService
def execute
in_reply_to_discussion_id = params.delete(:in_reply_to_discussion_id)
if project && in_reply_to_discussion_id.present?
discussion = project.notes.find_discussion(in_reply_to_discussion_id)
if in_reply_to_discussion_id.present?
discussion = find_discussion(in_reply_to_discussion_id)
unless discussion
note = Note.new
......@@ -21,5 +21,19 @@ def execute
note
end
def find_discussion(discussion_id)
if project
project.notes.find_discussion(discussion_id)
else
# only PersonalSnippets can have discussions without project association
discussion = Note.find_discussion(discussion_id)
noteable = discussion.noteable
return nil unless noteable.is_a?(PersonalSnippet) && can?(current_user, :comment_personal_snippet, noteable)
discussion
end
end
end
end
- header_title "Snippets", snippets_path
- content_for :page_specific_javascripts do
- if @snippet&.persisted? && current_user
:javascript
window.uploads_path = "#{upload_path('personal_snippet', @snippet)}";
window.preview_markdown_path = "#{preview_markdown_snippet_path(@snippet)}";
= render template: "layouts/application"
......@@ -13,7 +13,7 @@
.block-connector
= render "projects/diffs/diffs", diffs: @diffs, environment: @environment
= render "projects/notes/notes_with_form"
= render "shared/notes/notes_with_form"
- if can_collaborate_with_project?
- %w(revert cherry-pick).each do |type|
= render "projects/commit/change", type: type, commit: @commit, title: @commit.title
......@@ -4,4 +4,4 @@
= link_to 'Close issue', issue_path(@issue, issue: {state_event: :close}, format: 'json'), data: {no_turbolink: true, original_text: "Close issue", alternative_text: "Comment & close issue"}, class: "btn btn-nr btn-close btn-comment js-note-target-close #{issue_button_visibility(@issue, true)}", title: 'Close issue'
#notes
= render 'projects/notes/notes_with_form'
= render 'shared/notes/notes_with_form'
......@@ -8,4 +8,4 @@
%button.btn.btn-nr.btn-default.append-right-10.js-comment-resolve-button{ "v-if" => "showButton", type: "submit", data: { project_path: "#{project_path(@merge_request.project)}" } }
{{ buttonText }}
#notes= render "projects/notes/notes_with_form"
#notes= render "shared/notes/notes_with_form"
......@@ -11,7 +11,7 @@
.col-sm-10
= render layout: 'projects/md_preview', locals: { url: preview_markdown_path(@project) } do
= render 'projects/zen', f: f, attr: :description, classes: 'note-textarea', placeholder: 'Write milestone description...'
= render 'projects/notes/hints'
= render 'shared/notes/hints'
.clearfix
.error-alert
= render "shared/milestones/form_dates", f: f
......
.original-note-content.hidden{ data: { post_url: namespace_project_note_path(@project.namespace, @project, note), target_id: note.noteable.id, target_type: note.noteable.class.name.underscore } }
#{note.note}
%textarea.hidden.js-task-list-field.original-task-list{ data: {update_url: namespace_project_note_path(@project.namespace, @project, note) } }= note.note
......@@ -13,7 +13,7 @@
= form_for(@release, method: :put, url: namespace_project_tag_release_path(@project.namespace, @project, @tag.name), html: { class: 'form-horizontal common-note-form release-form js-quick-submit' }) do |f|
= render layout: 'projects/md_preview', locals: { url: preview_markdown_path(@project), referenced_users: true } do
= render 'projects/zen', f: f, attr: :description, classes: 'note-textarea', placeholder: "Write your release notes or drag files here..."
= render 'projects/notes/hints'
= render 'shared/notes/hints'
.error-alert
.prepend-top-default
= f.submit 'Save changes', class: 'btn btn-save'
......
......@@ -9,4 +9,4 @@
.row-content-block.top-block.content-component-block
= render 'award_emoji/awards_block', awardable: @snippet, inline: true
#notes= render "projects/notes/notes_with_form"
#notes= render "shared/notes/notes_with_form"
......@@ -30,7 +30,7 @@
.col-sm-10
= render layout: 'projects/md_preview', locals: { url: preview_markdown_path(@project), referenced_users: true } do
= render 'projects/zen', attr: :release_description, classes: 'note-textarea', placeholder: "Write your release notes or drag files here..."
= render 'projects/notes/hints'
= render 'shared/notes/hints'
.help-block Optionally, add release notes to the tag. They will be stored in the GitLab database and displayed on the tags page.
.form-actions
= button_tag 'Create tag', class: 'btn btn-create', tabindex: 3
......
......@@ -14,7 +14,7 @@
.col-sm-10
= render layout: 'projects/md_preview', locals: { url: namespace_project_wiki_preview_markdown_path(@project.namespace, @project, @page.slug) } do
= render 'projects/zen', f: f, attr: :content, classes: 'note-textarea', placeholder: 'Write your content or drag files here...'
= render 'projects/notes/hints'
= render 'shared/notes/hints'
.clearfix
.error-alert
......
......@@ -17,6 +17,6 @@
classes: 'note-textarea',
placeholder: "Write a comment or drag your files here...",
supports_slash_commands: supports_slash_commands
= render 'projects/notes/hints', supports_slash_commands: supports_slash_commands
= render 'shared/notes/hints', supports_slash_commands: supports_slash_commands
.clearfix
.error-alert
.original-note-content.hidden{ data: { post_url: note_url(note), target_id: note.noteable.id, target_type: note.noteable.class.name.underscore } }
#{note.note}
%textarea.hidden.js-task-list-field.original-task-list{ data: {update_url: note_url(note) } }= note.note
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment