Skip to content

Commit

Permalink
Merge branch 'develop' into even-more-py3-back-compat-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Johnetordoff authored Sep 12, 2019
2 parents a541a6c + dfe3259 commit 3396128
Show file tree
Hide file tree
Showing 60 changed files with 847 additions and 674 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

We follow the CalVer (https://calver.org/) versioning scheme: YY.MINOR.MICRO.

19.26.0 (2019-09-11)
===================
- Create a custom through table for linking files and versions
for storing version names. Supports different versions of the same
file having different names.
- Update README for populating institutions.


19.25.0 (2019-09-05)
===================
- Automate account deactivation if users have no content
- Clean up EZID workflow
- Check redirect URL's for spam

19.24.0 (2019-08-27)
===================
- APIv2: Allow creating a node with a license attached on creation
Expand Down
2 changes: 1 addition & 1 deletion README-docker-compose.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
- `docker-compose run --rm web python manage.py migrate`
- Populate institutions:
- After resetting your database or with a new install you will need to populate the table of institutions. **You must have run migrations first.**
- `docker-compose run --rm web python -m scripts.populate_institutions test`
- `docker-compose run --rm web python -m scripts.populate_institutions -e test -a`
- Populate preprint, registration, and collection providers:
- After resetting your database or with a new install, the required providers and subjects will be created automatically **when you run migrations.** To create more:
- `docker-compose run --rm web python manage.py populate_fake_providers`
Expand Down
7 changes: 6 additions & 1 deletion addons/base/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from addons.base import signals as file_signals
from addons.base.utils import format_last_known_metadata, get_mfr_url
from osf import features
from osf.models import (BaseFileNode, TrashedFileNode,
from osf.models import (BaseFileNode, TrashedFileNode, BaseFileVersionsThrough,
OSFUser, AbstractNode, Preprint,
NodeLog, DraftRegistration, RegistrationSchema,
Guid, FileVersionUserMetadata, FileVersion)
Expand Down Expand Up @@ -875,6 +875,10 @@ def addon_view_file(auth, node, file_node, version):
args={'url': download_url.url}
)

version_names = BaseFileVersionsThrough.objects.filter(
basefilenode_id=file_node.id
).order_by('-fileversion_id').values_list('version_name', flat=True)

ret.update({
'urls': {
'render': render_url.url,
Expand Down Expand Up @@ -902,6 +906,7 @@ def addon_view_file(auth, node, file_node, version):
'allow_comments': file_node.provider in settings.ADDONS_COMMENTABLE,
'checkout_user': file_node.checkout._id if file_node.checkout else None,
'pre_reg_checkout': is_pre_reg_checkout(node, file_node),
'version_names': list(version_names)
})

ret.update(rubeus.collect_addon_assets(node))
Expand Down
13 changes: 13 additions & 0 deletions addons/forward/models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# -*- coding: utf-8 -*-
from osf.utils.requests import get_request_and_user_id, get_headers_from_request

from addons.base.models import BaseNodeSettings
from dirtyfields import DirtyFieldsMixin
from django.db import models
from osf.exceptions import ValidationValueError
from osf.models.validators import validate_no_html
from osf.models import OSFUser


class NodeSettings(DirtyFieldsMixin, BaseNodeSettings):
Expand Down Expand Up @@ -33,6 +35,17 @@ def after_register(self, node, registration, user, save=True):

return clone, None

def save(self, request=None, *args, **kwargs):
super(NodeSettings, self).save(*args, **kwargs)
if request:
if not hasattr(request, 'user'): # TODO: remove when Flask is removed
_, user_id = get_request_and_user_id()
user = OSFUser.load(user_id)
else:
user = request.user

self.owner.check_spam(user, {'addons_forward_node_settings__url'}, get_headers_from_request(request))

def clean(self):
if self.url and self.owner._id in self.url:
raise ValidationValueError('Circular URL')
22 changes: 20 additions & 2 deletions addons/forward/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import mock
import pytest

from nose.tools import assert_equal

from addons.forward.tests.utils import ForwardAddonTestCase
from tests.base import OsfTestCase
from website import settings

pytestmark = pytest.mark.django_db

class TestForwardLogs(ForwardAddonTestCase, OsfTestCase):
class TestForward(ForwardAddonTestCase, OsfTestCase):

def setUp(self):
super(TestForwardLogs, self).setUp()
super(TestForward, self).setUp()
self.app.authenticate(*self.user.auth)

def test_change_url_log_added(self):
Expand Down Expand Up @@ -40,3 +42,19 @@ def test_change_timeout_log_not_added(self):
self.project.logs.count(),
log_count
)

@mock.patch.object(settings, 'SPAM_CHECK_ENABLED', True)
@mock.patch('osf.models.node.Node.do_check_spam')
def test_change_url_check_spam(self, mock_check_spam):
self.project.is_public = True
self.project.save()
self.app.put_json(self.project.api_url_for('forward_config_put'), {'url': 'http://possiblyspam.com'})

assert mock_check_spam.called
data, _ = mock_check_spam.call_args
author, author_email, content, request_headers = data

assert author == self.user.fullname
assert author_email == self.user.username
assert content == 'http://possiblyspam.com'

2 changes: 1 addition & 1 deletion addons/forward/views/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def forward_config_put(auth, node_addon, **kwargs):
# Save settings and get changed fields; crash if validation fails
try:
dirty_fields = node_addon.get_dirty_fields()
node_addon.save()
node_addon.save(request=request)
except ValidationValueError:
raise HTTPError(http_status.HTTP_400_BAD_REQUEST)

Expand Down
3 changes: 2 additions & 1 deletion addons/osfstorage/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ def create_version(self, creator, location, metadata=None):
version._find_matching_archive(save=False)

version.save()
self.versions.add(version)
# Adds version to the list of file versions - using custom through table
self.add_version(version)
self.save()

return version
Expand Down
43 changes: 41 additions & 2 deletions addons/osfstorage/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,24 @@ def test_materialized_path_nested(self):
def test_copy(self):
to_copy = self.node_settings.get_root().append_file('Carp')
copy_to = self.node_settings.get_root().append_folder('Cloud')
version = to_copy.create_version(
self.user,
{
'service': 'cloud',
settings.WATERBUTLER_RESOURCE: 'osf',
'object': '06d80e',
}, {
'sha256': 'existing',
'vault': 'the cloud',
'archive': 'erchiv'
})
assert_equal(to_copy.versions.first().get_basefilenode_version(to_copy).version_name, 'Carp')

copied = to_copy.copy_under(copy_to)

assert_not_equal(copied, to_copy)
assert_equal(copied.parent, copy_to)
assert_equal(copied.versions.first().get_basefilenode_version(copied).version_name, 'Carp')
assert_equal(to_copy.parent, self.node_settings.get_root())

def test_copy_node_file_to_preprint(self):
Expand Down Expand Up @@ -347,7 +360,7 @@ def test_move_nested_between_regions(self):

for _ in range(2):
version = factories.FileVersionFactory(region=self.node_settings.region)
child.versions.add(version)
child.add_version(version)
child.save()

moved = to_move.move_under(move_to)
Expand All @@ -361,8 +374,21 @@ def test_move_nested_between_regions(self):
def test_copy_rename(self):
to_copy = self.node_settings.get_root().append_file('Carp')
copy_to = self.node_settings.get_root().append_folder('Cloud')
version = to_copy.create_version(
self.user,
{
'service': 'cloud',
settings.WATERBUTLER_RESOURCE: 'osf',
'object': '06d80e',
}, {
'sha256': 'existing',
'vault': 'the cloud',
'archive': 'erchiv'
})
assert_equal(to_copy.versions.first().get_basefilenode_version(to_copy).version_name, 'Carp')

copied = to_copy.copy_under(copy_to, name='But')
assert_equal(copied.versions.first().get_basefilenode_version(copied).version_name, 'But')

assert_equal(copied.name, 'But')
assert_not_equal(copied, to_copy)
Expand All @@ -381,12 +407,25 @@ def test_move(self):

def test_move_and_rename(self):
to_move = self.node_settings.get_root().append_file('Carp')
version = to_move.create_version(
self.user,
{
'service': 'cloud',
settings.WATERBUTLER_RESOURCE: 'osf',
'object': '06d80e',
}, {
'sha256': 'existing',
'vault': 'the cloud',
'archive': 'erchiv'
})
move_to = self.node_settings.get_root().append_folder('Cloud')
assert_equal(to_move.versions.first().get_basefilenode_version(to_move).version_name, 'Carp')

moved = to_move.move_under(move_to, name='Tuna')

assert_equal(to_move, moved)
assert_equal(to_move.name, 'Tuna')
assert_equal(moved.versions.first().get_basefilenode_version(moved).version_name, 'Tuna')
assert_equal(moved.parent, move_to)

def test_move_preprint_primary_file_to_node(self):
Expand Down Expand Up @@ -649,7 +688,7 @@ def test_after_fork_copies_versions(self):

for _ in range(num_versions):
version = factories.FileVersionFactory()
record.versions.add(version)
record.add_version(version)

fork = self.project.fork_node(self.auth_obj)
fork_node_settings = fork.get_addon('osfstorage')
Expand Down
3 changes: 2 additions & 1 deletion addons/osfstorage/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from addons.osfstorage import utils

from addons.osfstorage.tests.utils import StorageTestCase
from website.files.utils import attach_versions


@pytest.mark.django_db
Expand All @@ -25,7 +26,7 @@ def setUp(self):
factories.FileVersionFactory(creator=self.user)
for __ in range(3)
]
self.record.versions = self.versions
attach_versions(self.record, self.versions)
self.record.save()

def test_serialize_revision(self):
Expand Down
Loading

0 comments on commit 3396128

Please sign in to comment.