Skip to content

Commit c05ed88

Browse files
authored
Merge pull request #191 from ncbo/fix/notes-controller-creator-assignment
Fix/notes controller creator assignment
2 parents d0deffb + 2f7c5d7 commit c05ed88

5 files changed

Lines changed: 87 additions & 30 deletions

File tree

Gemfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ gem 'haml', '~> 5.2.2' # pin see https://github.com/ncbo/ontologies_api/pull/107
4343
gem 'redcarpet'
4444

4545
# NCBO gems (can be from a local dev path or from rubygems/git)
46-
gem 'goo', github: 'ncbo/goo', branch: 'master'
47-
gem 'ncbo_annotator', github: 'ncbo/ncbo_annotator', branch: 'master'
48-
gem 'ncbo_cron', github: 'ncbo/ncbo_cron', branch: 'master'
49-
gem 'ncbo_ontology_recommender', github: 'ncbo/ncbo_ontology_recommender', branch: 'master'
50-
gem 'ontologies_linked_data', github: 'ncbo/ontologies_linked_data', branch: 'master'
46+
gem 'goo', github: 'ncbo/goo', branch: 'develop'
47+
gem 'ncbo_annotator', github: 'ncbo/ncbo_annotator', branch: 'develop'
48+
gem 'ncbo_cron', github: 'ncbo/ncbo_cron', branch: 'develop'
49+
gem 'ncbo_ontology_recommender', github: 'ncbo/ncbo_ontology_recommender', branch: 'develop'
50+
gem 'ontologies_linked_data', github: 'ncbo/ontologies_linked_data', branch: 'develop'
5151
gem 'sparql-client', github: 'ncbo/sparql-client', tag: 'v6.3.0'
5252

5353
group :development do

Gemfile.lock

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
GIT
22
remote: https://github.com/ncbo/goo.git
3-
revision: 26c0a69e67ac59778a46caf51202ebd38ccac767
4-
branch: master
3+
revision: 87a21a76bc61392d0629a19c8a18593f606b52e5
4+
branch: develop
55
specs:
66
goo (0.0.2)
77
addressable (~> 2.8)
@@ -16,8 +16,8 @@ GIT
1616

1717
GIT
1818
remote: https://github.com/ncbo/ncbo_annotator.git
19-
revision: 4fb9114b80b99f0a654c7f70aaa96839c74fc615
20-
branch: master
19+
revision: 2abcd54c148d0983570d681506002d9d3782d2eb
20+
branch: develop
2121
specs:
2222
ncbo_annotator (0.0.1)
2323
goo
@@ -27,8 +27,8 @@ GIT
2727

2828
GIT
2929
remote: https://github.com/ncbo/ncbo_cron.git
30-
revision: 6118e8275ea771e9e4de4132eccca293e8c8b739
31-
branch: master
30+
revision: 48770b7861110cabc20607939d18f336ae7ce41c
31+
branch: develop
3232
specs:
3333
ncbo_cron (0.0.1)
3434
dante
@@ -45,8 +45,8 @@ GIT
4545

4646
GIT
4747
remote: https://github.com/ncbo/ncbo_ontology_recommender.git
48-
revision: c6a18eb7700b23a1a4f1e32ebc94003bf75efe93
49-
branch: master
48+
revision: f92a42f660635522eb8709e618ff2e641aef0d17
49+
branch: develop
5050
specs:
5151
ncbo_ontology_recommender (0.0.1)
5252
goo
@@ -56,8 +56,8 @@ GIT
5656

5757
GIT
5858
remote: https://github.com/ncbo/ontologies_linked_data.git
59-
revision: 098c1e1b00a04a5b0f3c9eb335f95e12bc7e7829
60-
branch: master
59+
revision: d55bddd1a06eeec7353525b7d7ceba095cc756a1
60+
branch: develop
6161
specs:
6262
ontologies_linked_data (0.0.1)
6363
activesupport
@@ -119,6 +119,7 @@ GEM
119119
bcrypt (3.1.20)
120120
bcrypt_pbkdf (1.1.1)
121121
bcrypt_pbkdf (1.1.1-arm64-darwin)
122+
bcrypt_pbkdf (1.1.1-x86_64-darwin)
122123
bigdecimal (3.2.2)
123124
builder (3.3.0)
124125
byebug (12.0.0)
@@ -144,7 +145,7 @@ GEM
144145
date (3.4.1)
145146
docile (1.4.1)
146147
domain_name (0.6.20240107)
147-
ed25519 (1.3.0)
148+
ed25519 (1.4.0)
148149
faraday (2.13.2)
149150
faraday-net_http (>= 2.0, < 3.5)
150151
json
@@ -155,9 +156,17 @@ GEM
155156
net-http (>= 0.5.0)
156157
faraday-retry (2.3.2)
157158
faraday (~> 2.0)
159+
ffi (1.17.2)
158160
ffi (1.17.2-aarch64-linux-gnu)
161+
ffi (1.17.2-aarch64-linux-musl)
162+
ffi (1.17.2-arm-linux-gnu)
163+
ffi (1.17.2-arm-linux-musl)
159164
ffi (1.17.2-arm64-darwin)
165+
ffi (1.17.2-x86-linux-gnu)
166+
ffi (1.17.2-x86-linux-musl)
167+
ffi (1.17.2-x86_64-darwin)
160168
ffi (1.17.2-x86_64-linux-gnu)
169+
ffi (1.17.2-x86_64-linux-musl)
161170
gapic-common (1.0.0)
162171
faraday (>= 1.9, < 3.a)
163172
faraday-retry (>= 1.0, < 3.a)
@@ -184,8 +193,11 @@ GEM
184193
faraday (>= 1.0, < 3.a)
185194
google-cloud-errors (1.5.0)
186195
google-logging-utils (0.2.0)
196+
google-protobuf (3.25.8)
187197
google-protobuf (3.25.8-aarch64-linux)
188198
google-protobuf (3.25.8-arm64-darwin)
199+
google-protobuf (3.25.8-x86-linux)
200+
google-protobuf (3.25.8-x86_64-darwin)
189201
google-protobuf (3.25.8-x86_64-linux)
190202
googleapis-common-protos (1.8.0)
191203
google-protobuf (>= 3.18, < 5.a)
@@ -201,19 +213,28 @@ GEM
201213
multi_json (~> 1.11)
202214
os (>= 0.9, < 2.0)
203215
signet (>= 0.16, < 2.a)
216+
grpc (1.73.0)
217+
google-protobuf (>= 3.25, < 5.0)
218+
googleapis-common-protos-types (~> 1.0)
204219
grpc (1.73.0-aarch64-linux)
205220
google-protobuf (>= 3.25, < 5.0)
206221
googleapis-common-protos-types (~> 1.0)
207222
grpc (1.73.0-arm64-darwin)
208223
google-protobuf (>= 3.25, < 5.0)
209224
googleapis-common-protos-types (~> 1.0)
225+
grpc (1.73.0-x86-linux)
226+
google-protobuf (>= 3.25, < 5.0)
227+
googleapis-common-protos-types (~> 1.0)
228+
grpc (1.73.0-x86_64-darwin)
229+
google-protobuf (>= 3.25, < 5.0)
230+
googleapis-common-protos-types (~> 1.0)
210231
grpc (1.73.0-x86_64-linux)
211232
google-protobuf (>= 3.25, < 5.0)
212233
googleapis-common-protos-types (~> 1.0)
213234
haml (5.2.2)
214235
temple (>= 0.8.0)
215236
tilt
216-
hashdiff (1.1.2)
237+
hashdiff (1.2.0)
217238
http-accept (1.7.0)
218239
http-cookie (1.0.8)
219240
domain_name (~> 0.5)
@@ -226,7 +247,7 @@ GEM
226247
jwt (2.10.2)
227248
base64
228249
kgio (2.11.4)
229-
language_server-protocol (3.17.0.4)
250+
language_server-protocol (3.17.0.5)
230251
libxml-ruby (5.0.4)
231252
lint_roller (1.1.0)
232253
logger (1.7.0)
@@ -271,7 +292,7 @@ GEM
271292
net-protocol
272293
net-ssh (7.3.0)
273294
netrc (0.11.0)
274-
newrelic_rpm (9.18.0)
295+
newrelic_rpm (9.19.0)
275296
oj (3.16.11)
276297
bigdecimal (>= 3.0)
277298
ostruct (>= 0.2)
@@ -301,7 +322,7 @@ GEM
301322
rack (>= 0.4)
302323
rack-cors (1.0.6)
303324
rack (>= 1.6.0)
304-
rack-mini-profiler (3.3.1)
325+
rack-mini-profiler (4.0.0)
305326
rack (>= 1.2.0)
306327
rack-protection (1.5.5)
307328
rack
@@ -335,18 +356,18 @@ GEM
335356
rsolr (2.6.0)
336357
builder (>= 2.1.2)
337358
faraday (>= 0.9, < 3, != 2.0.0)
338-
rubocop (1.75.4)
359+
rubocop (1.78.0)
339360
json (~> 2.3)
340361
language_server-protocol (~> 3.17.0.2)
341362
lint_roller (~> 1.1.0)
342363
parallel (~> 1.10)
343364
parser (>= 3.3.0.2)
344365
rainbow (>= 2.2.2, < 4.0)
345366
regexp_parser (>= 2.9.3, < 3.0)
346-
rubocop-ast (>= 1.44.0, < 2.0)
367+
rubocop-ast (>= 1.45.1, < 2.0)
347368
ruby-progressbar (~> 1.7)
348369
unicode-display_width (>= 2.4.0, < 4.0)
349-
rubocop-ast (1.44.1)
370+
rubocop-ast (1.45.1)
350371
parser (>= 3.3.7.2)
351372
prism (~> 1.4)
352373
ruby-progressbar (1.13.0)
@@ -363,7 +384,7 @@ GEM
363384
docile (~> 1.1)
364385
simplecov-html (~> 0.11)
365386
simplecov_json_formatter (~> 0.1)
366-
simplecov-cobertura (2.1.0)
387+
simplecov-cobertura (3.0.0)
367388
rexml
368389
simplecov (~> 0.19)
369390
simplecov-html (0.13.1)
@@ -391,7 +412,7 @@ GEM
391412
systemu (2.6.5)
392413
temple (0.10.3)
393414
thread_safe (0.3.6)
394-
tilt (2.6.0)
415+
tilt (2.6.1)
395416
time (0.4.1)
396417
date
397418
timeout (0.4.3)
@@ -417,10 +438,19 @@ GEM
417438

418439
PLATFORMS
419440
aarch64-linux
420-
arm64-darwin-22
421-
arm64-darwin-23
422-
arm64-darwin-24
441+
aarch64-linux-gnu
442+
aarch64-linux-musl
443+
arm-linux-gnu
444+
arm-linux-musl
445+
arm64-darwin
446+
ruby
447+
x86-linux
448+
x86-linux-gnu
449+
x86-linux-musl
450+
x86_64-darwin
423451
x86_64-linux
452+
x86_64-linux-gnu
453+
x86_64-linux-musl
424454

425455
DEPENDENCIES
426456
activesupport (~> 5)

controllers/notes_controller.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,10 @@ class NotesController < ApplicationController
9494

9595
def note_from_params
9696
note_params = params.dup
97+
note_params.delete("creator")
9798
proposal_params = clean_notes_hash(note_params.delete("proposal"))
9899
note = instance_from_params(LinkedData::Models::Note, clean_notes_hash(note_params))
100+
note.creator = current_user
99101

100102
if proposal_params
101103
proposal = instance_from_params(LinkedData::Models::Notes::Proposal, proposal_params)
@@ -121,4 +123,4 @@ def clean_notes_hash(hash)
121123
hash
122124
end
123125
end
124-
end
126+
end

helpers/application_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module ApplicationHelper
1212
def h(text)
1313
Rack::Utils.escape_html(text)
1414
end
15-
15+
1616
##
1717
# Populate +obj+ using values from +params+
1818
# Will also try to find related objects using a Goo lookup.

test/controllers/test_notes_controller.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def test_single_note
5555
end
5656

5757
def test_note_lifecycle
58+
env("REMOTE_USER", @@user)
5859
note = {
5960
creator: @@user.id.to_s,
6061
body: "Testing body",
@@ -81,6 +82,7 @@ def test_note_lifecycle
8182
end
8283

8384
def test_proposal_lifecycle
85+
env("REMOTE_USER", @@user)
8486
note = {
8587
:subject=>"New Term Proposal: Sleep Study Facility",
8688
:creator=>@@user.id.to_s,
@@ -136,4 +138,27 @@ def test_notes_for_class
136138
assert_equal 1, test_note.length
137139
assert_operator 5, :<=, notes.length
138140
end
141+
142+
def test_note_creator_ignores_user_input
143+
# Set current user for this test
144+
env("REMOTE_USER", @@user)
145+
post "/notes", MultiJson.dump({
146+
body: "Testing body",
147+
subject: "Testing subject",
148+
relatedOntology: [@@ontology.id.to_s],
149+
creator: "wrong_user_id"
150+
}), { "CONTENT_TYPE" => "application/json" }
151+
152+
assert_equal 201, last_response.status
153+
154+
new_note = MultiJson.load(last_response.body)
155+
get new_note["@id"]
156+
assert last_response.ok?
157+
158+
# Verify the creator is the current user, not the wrong user
159+
retrieved_note = MultiJson.load(last_response.body)
160+
assert_equal @@user.id.to_s, retrieved_note["creator"]
161+
refute_equal "wrong_user_id", retrieved_note["creator"]
162+
end
163+
139164
end

0 commit comments

Comments
 (0)