Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore updated_at and updated_by field values when updating plots via the API. #2963

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion opentreemap/api/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,14 @@ def update_or_create_plot(request, instance, plot_id=None):
for key, val in request_dict[model].iteritems():
data["%s.%s" % (model, key)] = val

# We explicitly disallow setting a plot's tree id
# We explicitly disallow setting a plot's tree id.
# We ignore plot's updated at and by because
# auditing sets them automatically.
keys = ["tree.plot",
"tree.udfs",
"tree.instance",
"plot.updated_at",
"plot.updated_by",
"plot.instance",
"plot.udfs"]

Expand Down
13 changes: 9 additions & 4 deletions opentreemap/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,11 +596,13 @@ def test_update_plot(self):

reputation_count = self.user.get_reputation(self.instance)

# Include `updated_by` because the app does send it,
# and the endpoint must ignore it.
updated_values = {'plot':
{'geom':
{'y': 0.001, 'x': 0.001, 'srid': 4326},
{'geom': {'y': 0.001, 'x': 0.001, 'srid': 4326},
'width': 11,
'length': 22}}
'length': 22,
'updated_by': self.user.pk}}

response = put_json("%s/instance/%s/plots/%d" %
(API_PFX, self.instance.url_name, test_plot.pk),
Expand Down Expand Up @@ -725,7 +727,10 @@ def test_update_tree(self):
test_tree.diameter = 2.3
test_tree.save_with_user(self.user)

updated_values = {'tree': {'diameter': 3.9}}
# Include `updated_by` because the app does send it,
# and the endpoint must ignore it.
updated_values = {'tree': {'diameter': 3.9},
'plot': {'updated_by': self.user.pk}}
response = put_json("%s/instance/%s/plots/%d" %
(API_PFX, self.instance.url_name, test_plot.id),
updated_values, self.client, self.user)
Expand Down