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

make it easier to run SHARE with OSF locally #10386

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
7b4379a
osf.metadata vocab updates
aaxelb Feb 28, 2023
f8f9824
support datacite schema version 4.4
aaxelb Apr 14, 2023
5f99c93
tidy gather.Basket
aaxelb Apr 25, 2023
530ba09
gather more preprint metadata
aaxelb Apr 25, 2023
f57357e
chore: serialized-metadata tests
aaxelb May 9, 2023
fd91aaf
wip
aaxelb Jul 5, 2023
2c0ccc6
osfmap updates
aaxelb Jul 31, 2023
dd1fd5d
osfmap metadata updates
aaxelb Aug 1, 2023
686e16e
use rdf:type for foaf:Person and foaf:Organization
aaxelb Aug 2, 2023
e668468
osfmap metadata updates
aaxelb Aug 2, 2023
a7f0739
make it easier to run SHARE with OSF locally
aaxelb Apr 21, 2023
b963eb8
feature: recatalog_metadata --all-types
aaxelb Jul 20, 2023
8e3eb2a
feature: update_share with rdf metadata
aaxelb Jun 22, 2023
19ebb9d
wip
aaxelb Jul 27, 2023
0be5f41
[ENG-3919] Redirect rr to registration workflow (#10051)
Johnetordoff Jul 25, 2023
60393b6
Get latest by identifier
mfraezz Jul 25, 2023
7af3c80
Bump version and update CHANGELOG
Jul 26, 2023
be790e2
Allow files with '&' to be attached to drafts
mfraezz Jul 27, 2023
2fa4adc
fix: upgrade pyyaml to 6.0.1 to avoid build error
aaxelb Jul 28, 2023
030a71c
use share api/v3/ (instead of trove/ synonym)
aaxelb Jul 28, 2023
4cdbd47
disable ia if no pigeon
aaxelb Jul 28, 2023
8cac5d0
enable EMBER_SEARCH_PAGE for everyone
aaxelb Aug 1, 2023
cf35cf0
update_share from update_search
aaxelb Aug 2, 2023
fad8d4a
update_share: support files
aaxelb Aug 4, 2023
0245d42
fix: high means high (not low)
aaxelb Aug 4, 2023
d2d0cb6
fix bad import
aaxelb Aug 4, 2023
519798d
constant schema url for test
aaxelb Aug 4, 2023
ed6aa99
fix: AnalysisPlan means AnalysisPlan, not StudyDesign
aaxelb Aug 7, 2023
9d5e694
remove unused import
aaxelb Aug 9, 2023
2fdb503
remove sharev2-serialization tests
aaxelb Aug 9, 2023
7972ac8
remove "old_subjects"
aaxelb Aug 9, 2023
1e41e28
api_tests.share overhaul
aaxelb Aug 9, 2023
ca772af
tidy send-metadata-to-share tests
aaxelb Aug 10, 2023
cc4ca0f
further tidy send-metadata-to-share tests
aaxelb Aug 10, 2023
1b831a8
remove cross-mixin call
aaxelb Aug 10, 2023
90d9bba
update reindex-to-share admin test
aaxelb Aug 11, 2023
db1f528
add to metadata included for related items
aaxelb Aug 11, 2023
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repos:
hooks:
- id: double-quote-string-fixer
- id: trailing-whitespace
exclude: website/static/vendor/*
exclude: "^(website/static/vendor/|osf/metadata/definitions/.*\\.xsd)"
- id: flake8
additional_dependencies: ["flake8==3.6.0", "flake8-mutable==1.2.0"]
- repo: https://github.com/pre-commit/mirrors-jshint
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

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

23.09.0 (2023-7-26)
===================
- Allow Institutions to specify a default storage region for institutional
users
- Serialize branding info for preprint providers
- Remove out-of-date registered reports landing page

23.08.0 (2023-5-25)
===================
- Provide users with institution support email when SSO fails for expected
Expand Down
16 changes: 8 additions & 8 deletions addons/osfstorage/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,22 +232,22 @@ class OsfStorageFile(OsfStorageFileNode, File):

@property
def _hashes(self):
last_version = self.versions.last()
if not last_version:
latest_version = self.versions.latest('identifier')
if not latest_version:
return None
return {
'sha1': last_version.metadata.get('sha1', ''),
'sha256': last_version.metadata.get('sha256', ''),
'md5': last_version.metadata.get('md5', ''),
'sha1': latest_version.metadata.get('sha1', ''),
'sha256': latest_version.metadata.get('sha256', ''),
'md5': latest_version.metadata.get('md5', ''),
}

@property
def last_known_metadata(self):
last_version = self.versions.last()
if not last_version:
latest_version = self.versions.latest('identifier')
if not latest_version:
size = None
else:
size = last_version.size
size = latest_version.size
return {
'path': self.materialized_path,
'hashes': self._hashes,
Expand Down
4 changes: 1 addition & 3 deletions admin/nodes/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,7 @@ class NodeReindexShare(NodeMixin, View):

def post(self, request, *args, **kwargs):
node = self.get_object()
if settings.SHARE_ENABLED:
update_share(node)

update_share(node)
update_admin_log(
user_id=self.request.user.id,
object_id=node._id,
Expand Down
2 changes: 1 addition & 1 deletion admin/preprint_providers/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def get(self, request, *args, **kwargs):
except ValidationError as e:
messages.error(request, e.message)

return redirect(reverse_lazy('preprint_providers:share_source', kwargs={'preprint_provider_id': provider.id}))
return redirect(reverse_lazy('preprint_providers:detail', kwargs={'preprint_provider_id': provider.id}))

class SubjectDynamicUpdateView(PermissionRequiredMixin, View):
permission_required = 'osf.change_preprintprovider'
Expand Down
5 changes: 2 additions & 3 deletions admin/preprints/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
UNFLAG_SPAM,
)

from website import search, settings
from website import search


class PreprintMixin(PermissionRequiredMixin):
Expand Down Expand Up @@ -141,8 +141,7 @@ class PreprintReindexShare(PreprintMixin, View):

def post(self, request, *args, **kwargs):
preprint = self.get_object()
if settings.SHARE_ENABLED:
update_share(preprint)
update_share(preprint)
update_admin_log(
user_id=self.request.user.id,
object_id=preprint._id,
Expand Down
32 changes: 9 additions & 23 deletions admin_tests/nodes/test_views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import datetime as dt
import pytest
import json
import mock
import pytz
import datetime
import responses

from osf.models import AdminLogEntry, NodeLog, AbstractNode
from admin.nodes.views import (
Expand All @@ -22,6 +20,7 @@
RemoveStuckRegistrationsView
)
from admin_tests.utilities import setup_log_view, setup_view
from api_tests.share._utils import mock_update_share
from website import settings
from nose import tools as nt
from django.utils import timezone
Expand Down Expand Up @@ -265,32 +264,19 @@ def test_reindex_node_share(self):
count = AdminLogEntry.objects.count()
view = NodeReindexShare()
view = setup_log_view(view, self.request, guid=self.node._id)
with mock.patch('api.share.utils.settings.SHARE_ENABLED', True):
with mock.patch('api.share.utils.settings.SHARE_API_TOKEN', 'mock-api-token'):
with responses.RequestsMock(assert_all_requests_are_fired=True) as rsps:
rsps.add(responses.POST, 'https://share.osf.io/api/v2/normalizeddata/')
view.post(self.request)
data = json.loads(rsps.calls[-1].request.body.decode())

share_graph = data['data']['attributes']['data']['@graph']
identifier_node = next(n for n in share_graph if n['@type'] == 'workidentifier')
assert identifier_node['creative_work']['@type'] == 'project'
nt.assert_equal(AdminLogEntry.objects.count(), count + 1)
with mock_update_share() as _shmock:
view.post(self.request)
assert _shmock.called_once_with(self.node._id)
nt.assert_equal(AdminLogEntry.objects.count(), count + 1)

def test_reindex_registration_share(self):
count = AdminLogEntry.objects.count()
view = NodeReindexShare()
view = setup_log_view(view, self.request, guid=self.registration._id)
with mock.patch('api.share.utils.settings.SHARE_ENABLED', True):
with mock.patch('api.share.utils.settings.SHARE_API_TOKEN', 'mock-api-token'):
with responses.RequestsMock(assert_all_requests_are_fired=True) as rsps:
rsps.add(responses.POST, 'https://share.osf.io/api/v2/normalizeddata/')
view.post(self.request)
data = json.loads(rsps.calls[-1].request.body.decode())

assert any(graph for graph in data['data']['attributes']['data']['@graph']
if graph['@type'] == self.registration.provider.share_publish_type.lower())
nt.assert_equal(AdminLogEntry.objects.count(), count + 1)
with mock_update_share() as _shmock:
view.post(self.request)
assert _shmock.called_once_with(self.registration._id)
nt.assert_equal(AdminLogEntry.objects.count(), count + 1)

@mock.patch('website.search.search.update_node')
def test_reindex_node_elastic(self, mock_update_node):
Expand Down
16 changes: 5 additions & 11 deletions admin_tests/preprints/test_views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import pytest
import mock
import json
import responses

from django.test import RequestFactory
from django.urls import reverse
Expand All @@ -24,6 +22,7 @@
from osf.models.spam import SpamStatus
from osf.utils.workflows import DefaultStates, RequestTypes

from api_tests.share._utils import expect_ingest_request
from admin_tests.utilities import setup_view, setup_log_view

from admin.preprints import views
Expand Down Expand Up @@ -334,22 +333,17 @@ def test_change_preprint_provider_subjects_change_permissions(self, plain_view,
@pytest.mark.enable_implicit_clean
class TestPreprintReindex:

def test_reindex_preprint_share(self, preprint, req):
def test_reindex_preprint_share(self, preprint, req, mock_share_requests):
preprint.provider.access_token = 'totally real access token I bought from a guy wearing a trenchcoat in the summer'
preprint.provider.save()

count = AdminLogEntry.objects.count()
view = views.PreprintReindexShare()
view = setup_log_view(view, req, guid=preprint._id)

with mock.patch('api.share.utils.settings.SHARE_ENABLED', True):
with mock.patch('api.share.utils.settings.SHARE_API_TOKEN', 'mock-api-token'):
with responses.RequestsMock(assert_all_requests_are_fired=True) as rsps:
rsps.add(responses.POST, 'https://share.osf.io/api/v2/normalizeddata/')
view.post(req)
data = json.loads(rsps.calls[0].request.body.decode())
assert data['data']['type'] == 'NormalizedData'
assert AdminLogEntry.objects.count() == count + 1
with expect_ingest_request(mock_share_requests, preprint._id, token=preprint.provider.access_token):
view.post(req)
assert AdminLogEntry.objects.count() == count + 1

@mock.patch('website.search.search.update_preprint')
def test_reindex_preprint_elastic(self, mock_update_search, preprint, req):
Expand Down
12 changes: 6 additions & 6 deletions admin_tests/registration_providers/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ def view(self, req, provider):
view = views.ShareSourceRegistrationProvider()
return setup_view(view, req, registration_provider_id=provider.id)

def test_share_source(self, mock_share, view, provider, req):
mock_share.reset()
mock_share.add(
def test_share_source(self, mock_share_responses, view, provider, req):
mock_share_responses.reset()
mock_share_responses.add(
responses.POST,
f'{settings.SHARE_URL}api/v2/sources/',
json.dumps(
Expand All @@ -172,9 +172,9 @@ def test_share_source(self, mock_share, view, provider, req):
assert provider.access_token == 'test access token'

@mock.patch.object(settings, 'SHARE_PROVIDER_PREPEND', 'testenv')
def test_share_source_prefix(self, mock_share, view, provider, req):
mock_share.reset()
mock_share.add(
def test_share_source_prefix(self, mock_share_responses, view, provider, req):
mock_share_responses.reset()
mock_share_responses.add(
responses.POST,
f'{settings.SHARE_URL}api/v2/sources/',
json.dumps(
Expand Down
4 changes: 2 additions & 2 deletions api/base/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from storages.backends.gcloud import GoogleCloudStorage
from future.moves.urllib.parse import urljoin

from website.settings import DOMAIN
from website.settings import INTERNAL_DOMAIN


class DevFileSystemStorage(FileSystemStorage):
Expand All @@ -14,7 +14,7 @@ def url(self, name):
url = filepath_to_uri(name)
if url is not None:
url = url.lstrip('/')
url = urljoin(DOMAIN, url)
url = urljoin(INTERNAL_DOMAIN, url)
return urljoin(self.base_url, url)

class RequestlessURLGoogleCloudStorage(GoogleCloudStorage):
Expand Down
Loading
Loading