Skip to content

Commit

Permalink
Check for logging on other node and wiki actions that have associated…
Browse files Browse the repository at this point in the history
… logs

Update tests to check for node logs
  • Loading branch information
erinspace committed Jul 18, 2018
1 parent 264a750 commit c56c7d9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 10 additions & 1 deletion api/nodes/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1428,7 +1428,7 @@ def update_wiki_fields(self, obj, validated_data, auth):
if not obj.is_public and anyone_can_edit_wiki:
raise exceptions.ValidationError('To allow all OSF users to edit the wiki, the project must be public.')
if wiki_addon:
wiki_addon.is_publicly_editable = True if anyone_can_edit_wiki else False
wiki_addon.set_editing(permissions=anyone_can_edit_wiki, auth=auth, log=True)
wiki_addon.save()
else:
raise exceptions.ValidationError('You must have the wiki enabled before changing wiki settings.')
Expand All @@ -1450,6 +1450,15 @@ def update_forward_fields(self, obj, validated_data, auth):
if not forward_addon:
raise exceptions.ValidationError('You must first set redirect_link_enabled to True before specifying a redirect link URL.')
forward_addon.url = redirect_link_url
obj.add_log(
action='forward_url_changed',
params=dict(
node=obj._id,
project=obj.parent_id,
forward_url=redirect_link_url,
),
auth=auth
)
save_forward = True

if redirect_link_label is not None:
Expand Down
4 changes: 4 additions & 0 deletions api_tests/nodes/views/test_node_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,15 @@ def test_patch_anyone_can_edit_wiki(self, app, project, payload, admin_contrib,
assert res.status_code == 200
wiki_addon.reload()
assert wiki_addon.is_publicly_editable is True
assert project.logs.latest().action == NodeLog.MADE_WIKI_PUBLIC

payload['data']['attributes']['anyone_can_edit_wiki'] = False
# Logged in admin
res = app.patch_json_api(url, payload, auth=admin_contrib.auth)
assert res.status_code == 200
wiki_addon.reload()
assert wiki_addon.is_publicly_editable is False
assert project.logs.latest().action == NodeLog.MADE_WIKI_PRIVATE

# Test wiki disabled in same request so cannot change wiki_settings
payload['data']['attributes']['wiki_enabled'] = False
Expand All @@ -286,6 +288,7 @@ def test_patch_anyone_can_edit_wiki(self, app, project, payload, admin_contrib,
res = app.patch_json_api(url, payload, auth=admin_contrib.auth, expect_errors=True)
assert res.status_code == 200
assert project.get_addon('wiki').is_publicly_editable is True
assert project.logs.latest().action == NodeLog.MADE_WIKI_PUBLIC

# If project is private, cannot change settings to allow anyone to edit wiki
project.is_public = False
Expand Down Expand Up @@ -341,6 +344,7 @@ def test_redirect_link_enabled(self, app, project, payload, admin_contrib, write
assert forward_addon is not None
assert forward_addon.url == 'https://cos.io'
assert forward_addon.label == 'My Link'
assert project.logs.latest().action == 'forward_url_changed'

# Attempting to set redirect_link_url when redirect_link not enabled
payload['data']['attributes']['redirect_link_enabled'] = False
Expand Down

0 comments on commit c56c7d9

Please sign in to comment.