diff options
author | Sam Rose <sam@gitlab.com> | 2017-04-06 21:02:25 -0400 |
---|---|---|
committer | Sam Rose <sam@gitlab.com> | 2017-04-06 21:02:25 -0400 |
commit | bb23534b37f0eff6075dbc1a3337009c9f19c327 (patch) | |
tree | c9f465801b7c907ab1160b3d0378e1087bf3507f /lib/api/notes.rb | |
parent | b47d8a333c9aa554f6b820c6da101b67d85015c8 (diff) | |
parent | 3900aa803e574ddbcdb1a899f0e6085a0bb6c457 (diff) | |
download | gitlab-ce-mr-shortcuts-counter.tar.gz |
Update branch with latest stable commitsmr-shortcuts-counter
Diffstat (limited to 'lib/api/notes.rb')
-rw-r--r-- | lib/api/notes.rb | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/api/notes.rb b/lib/api/notes.rb index 3b3e45cbd06..3dee8938179 100644 --- a/lib/api/notes.rb +++ b/lib/api/notes.rb @@ -21,7 +21,7 @@ module API use :pagination end get ":id/#{noteables_str}/:noteable_id/notes" do - noteable = user_project.send(noteables_str.to_sym).find(params[:noteable_id]) + noteable = find_project_noteable(noteables_str, params[:noteable_id]) if can?(current_user, noteable_read_ability_name(noteable), noteable) # We exclude notes that are cross-references and that cannot be viewed @@ -49,7 +49,7 @@ module API requires :noteable_id, type: Integer, desc: 'The ID of the noteable' end get ":id/#{noteables_str}/:noteable_id/notes/:note_id" do - noteable = user_project.send(noteables_str.to_sym).find(params[:noteable_id]) + noteable = find_project_noteable(noteables_str, params[:noteable_id]) note = noteable.notes.find(params[:note_id]) can_read_note = can?(current_user, noteable_read_ability_name(noteable), noteable) && !note.cross_reference_not_visible_for?(current_user) @@ -69,14 +69,14 @@ module API optional :created_at, type: String, desc: 'The creation date of the note' end post ":id/#{noteables_str}/:noteable_id/notes" do + noteable = find_project_noteable(noteables_str, params[:noteable_id]) + opts = { note: params[:body], noteable_type: noteables_str.classify, - noteable_id: params[:noteable_id] + noteable_id: noteable.id } - noteable = user_project.send(noteables_str.to_sym).find(params[:noteable_id]) - if can?(current_user, noteable_read_ability_name(noteable), noteable) if params[:created_at] && (current_user.is_admin? || user_project.owner == current_user) opts[:created_at] = params[:created_at] @@ -137,6 +137,10 @@ module API end helpers do + def find_project_noteable(noteables_str, noteable_id) + public_send("find_project_#{noteables_str.singularize}", noteable_id) + end + def noteable_read_ability_name(noteable) "read_#{noteable.class.to_s.underscore}".to_sym end |