summaryrefslogtreecommitdiff
path: root/lib/api/notes.rb
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2017-01-23 21:55:34 +0000
committerRobert Speicher <robert@gitlab.com>2017-01-23 21:55:34 +0000
commitd2db3649993b5ad3708d737c88998dc3e4d7ad80 (patch)
treee5ee1f52bd9e537feedd1ff4431ccca34239d5fe /lib/api/notes.rb
parent2d3fcf904869ae38edab5ddd49fcb5881b3f47ab (diff)
parent76deb55f5602ffb137d6e1daf17212e36efb52bf (diff)
downloadgitlab-ce-d2db3649993b5ad3708d737c88998dc3e4d7ad80.tar.gz
Merge branch 'rs-pick-security-fixes' into 'master'
Pick security fixes from 8.16.1 et al into master Closes #26813, #26249, #26259, #26243, #26242 See merge request !8724
Diffstat (limited to 'lib/api/notes.rb')
-rw-r--r--lib/api/notes.rb26
1 files changed, 16 insertions, 10 deletions
diff --git a/lib/api/notes.rb b/lib/api/notes.rb
index 284e4cf549a..4d2a8f48267 100644
--- a/lib/api/notes.rb
+++ b/lib/api/notes.rb
@@ -70,21 +70,27 @@ module API
end
post ":id/#{noteables_str}/:noteable_id/notes" do
opts = {
- note: params[:body],
- noteable_type: noteables_str.classify,
- noteable_id: params[:noteable_id]
+ note: params[:body],
+ noteable_type: noteables_str.classify,
+ noteable_id: params[:noteable_id]
}
- if params[:created_at] && (current_user.is_admin? || user_project.owner == current_user)
- opts[:created_at] = params[:created_at]
- end
+ 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]
+ end
- note = ::Notes::CreateService.new(user_project, current_user, opts).execute
+ note = ::Notes::CreateService.new(user_project, current_user, opts).execute
- if note.valid?
- present note, with: Entities::const_get(note.class.name)
+ if note.valid?
+ present note, with: Entities::const_get(note.class.name)
+ else
+ not_found!("Note #{note.errors.messages}")
+ end
else
- not_found!("Note #{note.errors.messages}")
+ not_found!("Note")
end
end