diff options
author | Robert Speicher <robert@gitlab.com> | 2016-09-20 16:40:49 +0300 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2016-09-20 16:40:49 +0300 |
commit | 31ff272f763a93b944cd288cc35c54e5c2645ebd (patch) | |
tree | c75989669266a958e13e407a1fce2d34afd894b6 /app | |
parent | 9eed4a8dc2c9a99368ee778946af39578866b066 (diff) | |
parent | f6e5cc3c37f83044ca06d82aacf8ccb2796df724 (diff) |
Merge branch '22218-fix-note-form-footer' into 'master'
Fix note form hint showing slash commands supported for commits
## What are the relevant issue numbers?
Closes #22218
See merge request !6368
Diffstat (limited to 'app')
-rw-r--r-- | app/helpers/notes_helper.rb | 4 | ||||
-rw-r--r-- | app/services/notes/slash_commands_service.rb | 21 | ||||
-rw-r--r-- | app/views/projects/notes/_form.html.haml | 6 |
3 files changed, 20 insertions, 11 deletions
diff --git a/app/helpers/notes_helper.rb b/app/helpers/notes_helper.rb index da230f76bae..b0331f36a2f 100644 --- a/app/helpers/notes_helper.rb +++ b/app/helpers/notes_helper.rb @@ -10,6 +10,10 @@ module NotesHelper Ability.can_edit_note?(current_user, note) end + def note_supports_slash_commands?(note) + Notes::SlashCommandsService.supported?(note, current_user) + end + def noteable_json(noteable) { id: noteable.id, diff --git a/app/services/notes/slash_commands_service.rb b/app/services/notes/slash_commands_service.rb index 4a9a8a64653..2edbd39a9e7 100644 --- a/app/services/notes/slash_commands_service.rb +++ b/app/services/notes/slash_commands_service.rb @@ -5,9 +5,18 @@ module Notes 'MergeRequest' => MergeRequests::UpdateService } - def supported?(note) + def self.noteable_update_service(note) + UPDATE_SERVICES[note.noteable_type] + end + + def self.supported?(note, current_user) noteable_update_service(note) && - can?(current_user, :"update_#{note.noteable_type.underscore}", note.noteable) + current_user && + current_user.can?(:"update_#{note.noteable_type.underscore}", note.noteable) + end + + def supported?(note) + self.class.supported?(note, current_user) end def extract_commands(note) @@ -21,13 +30,7 @@ module Notes return if command_params.empty? return unless supported?(note) - noteable_update_service(note).new(project, current_user, command_params).execute(note.noteable) - end - - private - - def noteable_update_service(note) - UPDATE_SERVICES[note.noteable_type] + self.class.noteable_update_service(note).new(project, current_user, command_params).execute(note.noteable) end end end diff --git a/app/views/projects/notes/_form.html.haml b/app/views/projects/notes/_form.html.haml index 402f5b52f5e..46b402545cd 100644 --- a/app/views/projects/notes/_form.html.haml +++ b/app/views/projects/notes/_form.html.haml @@ -1,3 +1,5 @@ +- supports_slash_commands = note_supports_slash_commands?(@note) + = form_for [@project.namespace.becomes(Namespace), @project, @note], remote: true, html: { :'data-type' => 'json', multipart: true, id: nil, class: "new-note js-new-note-form js-quick-submit common-note-form", "data-noteable-iid" => @note.noteable.try(:iid), }, authenticity_token: true do |f| = hidden_field_tag :view, diff_view = hidden_field_tag :line_type @@ -14,8 +16,8 @@ attr: :note, classes: 'note-textarea js-note-text', placeholder: "Write a comment or drag your files here...", - supports_slash_commands: true - = render 'projects/notes/hints', supports_slash_commands: true + supports_slash_commands: supports_slash_commands + = render 'projects/notes/hints', supports_slash_commands: supports_slash_commands .error-alert .note-form-actions.clearfix |