Skip to content

Commit

Permalink
Merge branch 'release/19.26.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
pattisdr committed Sep 11, 2019
2 parents 96b96a3 + cefe84c commit 219491d
Show file tree
Hide file tree
Showing 24 changed files with 450 additions and 53 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

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
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
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 219491d

Please sign in to comment.