Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into remove-quickfiles-code

# Conflicts:
#	api_tests/files/views/test_file_detail.py
#	osf/models/quickfiles.py
#	scripts/remove_after_use/verify_groups_guardian_migration.py
#	tests/test_addons.py
#	tests/test_views.py
#	website/search/elastic_search.py
#	website/static/js/components/quickFiles.js
#	website/templates/include/profile/names.mako
  • Loading branch information
John Tordoff committed Apr 26, 2022
2 parents 1eb3e64 + 313e31f commit f86d345
Show file tree
Hide file tree
Showing 231 changed files with 6,004 additions and 14,584 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@

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

22.04.0 (2022-03-31)
====================
- Update JS and Python dependencies
- Remove unused "PreReg Challenge" code paths
- Remove SLOAN study code paths now that the "experiment" is always on
- Improve A11y on the legacy FE
- Update post-archival workflow for registrations to parse schema structure from SchemaBlocks

22.03.0 (2022-03-31)
====================
- Add waffle flags for registration files
- Enable writeable tags on registration files
- Allow embedding of target on files
- Fix serialization of files

22.02.0 (2022-3-10)
====================
- Stop creating Quickfiles for new users
Expand Down
57 changes: 29 additions & 28 deletions addons/base/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from future.moves.urllib.parse import quote
from django.utils import timezone

from distutils.util import strtobool
from flask import make_response
from flask import redirect
from flask import request
Expand All @@ -18,7 +17,6 @@
from django.contrib.contenttypes.models import ContentType
from elasticsearch import exceptions as es_exceptions

from api.base.settings.defaults import SLOAN_ID_COOKIE_NAME
from api.caching.tasks import update_storage_usage_with_size

from addons.base.models import BaseStorageAddon
Expand All @@ -39,31 +37,31 @@
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, BaseFileVersionsThrough,
OSFUser, AbstractNode, DraftNode, Preprint,
NodeLog, DraftRegistration,
Guid, FileVersionUserMetadata, FileVersion)
from osf.models import (
BaseFileNode,
TrashedFileNode,
BaseFileVersionsThrough,
OSFUser,
AbstractNode,
DraftNode,
Preprint,
Node,
NodeLog,
Registration,
DraftRegistration,
Guid,
FileVersionUserMetadata,
FileVersion
)
from osf.metrics import PreprintView, PreprintDownload
from osf.utils import permissions
from website.ember_osf_web.views import use_ember_app
from website.profile.utils import get_profile_image_url
from website.project import decorators
from website.project.decorators import must_be_contributor_or_public, must_be_valid_project, check_contributor_auth
from website.ember_osf_web.decorators import ember_flag_is_active
from website.project.utils import serialize_node
from website.util import rubeus

from osf.features import (
SLOAN_COI_DISPLAY,
SLOAN_DATA_DISPLAY,
SLOAN_PREREG_DISPLAY
)

SLOAN_FLAGS = (
SLOAN_COI_DISPLAY,
SLOAN_DATA_DISPLAY,
SLOAN_PREREG_DISPLAY
)

# import so that associated listener is instantiated and gets emails
from website.notifications.events.files import FileEvent # noqa

Expand Down Expand Up @@ -339,19 +337,12 @@ def get_auth(auth, **kwargs):
if isinstance(node, Preprint):
metric_class = get_metric_class_for_action(action, from_mfr=from_mfr)
if metric_class:
sloan_flags = {'sloan_id': request.cookies.get(SLOAN_ID_COOKIE_NAME)}
for flag_name in SLOAN_FLAGS:
value = request.cookies.get(f'dwf_{flag_name}_custom_domain') or request.cookies.get(f'dwf_{flag_name}')
if value:
sloan_flags[flag_name.replace('_display', '')] = strtobool(value)

try:
metric_class.record_for_preprint(
preprint=node,
user=auth.user,
version=fileversion.identifier if fileversion else None,
path=path,
**sloan_flags
)
except es_exceptions.ConnectionError:
log_exception()
Expand Down Expand Up @@ -697,7 +688,6 @@ def addon_deleted_file(auth, target, error_type='BLAME_PROVIDER', **kwargs):


@must_be_contributor_or_public
@ember_flag_is_active(features.EMBER_FILE_DETAIL)
def addon_view_or_download_file(auth, path, provider, **kwargs):
extras = request.args.to_dict()
extras.pop('_', None) # Clean up our url params a bit
Expand Down Expand Up @@ -737,6 +727,17 @@ def addon_view_or_download_file(auth, path, provider, **kwargs):

savepoint_id = transaction.savepoint()
file_node = BaseFileNode.resolve_class(provider, BaseFileNode.FILE).get_or_create(target, path)
if isinstance(target, Node) and waffle.flag_is_active(request, features.EMBER_FILE_PROJECT_DETAIL):
return use_ember_app()

if action != 'download' and isinstance(target, Registration) and waffle.flag_is_active(request, features.EMBER_FILE_REGISTRATION_DETAIL):
if file_node.get_guid():
guid = file_node.get_guid()
else:
guid = file_node.get_guid(create=True)
guid.save()
file_node.save()
return redirect(f'{settings.DOMAIN}{guid._id}/')

# Note: Cookie is provided for authentication to waterbutler
# it is overriden to force authentication as the current user
Expand Down Expand Up @@ -795,7 +796,7 @@ def addon_view_or_download_file(auth, path, provider, **kwargs):
if action == 'get_guid':
draft_id = extras.get('draft')
draft = DraftRegistration.load(draft_id)
if draft is None or draft.is_approved:
if draft is None:
raise HTTPError(http_status.HTTP_400_BAD_REQUEST, data={
'message_short': 'Bad Request',
'message_long': 'File not associated with required object.'
Expand Down
2 changes: 1 addition & 1 deletion addons/bitbucket/templates/bitbucket_node_settings.mako
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<div>
<h4 class="addon-title">
<img class="addon-icon" src="${addon_icon_url}">
<img class="addon-icon" src="${addon_icon_url}" aria-label="Bitbucket icon" alt="Bitbucket icon">
Bitbucket
<small class="authorized-by">
% if node_has_auth:
Expand Down
2 changes: 1 addition & 1 deletion addons/dataverse/static/dataverseFangornConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ function _fangornDataverseTitle(item, col) {
}
} else {
contents.push(
m('span.text.text-muted', '[Draft]')
m('span.text.high-contrast-link', '[Draft]')
);
}
return m('span', contents);
Expand Down
3 changes: 1 addition & 2 deletions addons/dataverse/templates/dataverse_credentials_modal.mako
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@

<!-- Select Dataverse installation -->
<div class="form-group">
<label for="hostSelect">Dataverse Repository</label>
<label>Dataverse Repository</label>
<select class="form-control"
id="hostSelect"
data-bind="options: visibleHosts,
optionsCaption: 'Select a Dataverse repository',
value: selectedHost,
Expand Down
2 changes: 1 addition & 1 deletion addons/dataverse/templates/dataverse_node_settings.mako
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<%include file="dataverse_credentials_modal.mako"/>

<h4 class="addon-title">
<img class="addon-icon" src=${addon_icon_url}>
<img class="addon-icon" src=${addon_icon_url} aria-label="Dataverse icon" alt="Dataverse icon">
${addon_full_name}

<small class="authorized-by">
Expand Down
4 changes: 2 additions & 2 deletions addons/dataverse/templates/dataverse_user_settings.mako
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<%include file="dataverse_credentials_modal.mako"/>

<h4 class="addon-title">
<img class="addon-icon" src=${addon_icon_url}>
<img class="addon-icon" src=${addon_icon_url} aria-label="Dataverse icon" alt="Dataverse icon">
<span data-bind="text: properName"></span> <!-- TODO: Can we use mako addon_full_name as some other addons do? -->
<small>
<a href="#dataverseInputCredentials" data-toggle="modal" class="pull-right text-primary">Connect or Reauthorize Account</a>
Expand All @@ -20,7 +20,7 @@
<table class="table table-hover">
<thead>
<tr class="user-settings-addon-auth">
<th class="text-muted default-authorized-by">Authorized on <a data-bind="attr: {href: dataverseUrl}"><em data-bind="text: dataverseHost"></em></a></th><th></th>
<th class="default-authorized-by">Authorized on <a data-bind="attr: {href: dataverseUrl}"><em data-bind="text: dataverseHost"></em></a></th><th></th>
</tr>
</thead>
<!-- ko if: connectedNodes().length > 0 -->
Expand Down
2 changes: 1 addition & 1 deletion addons/github/templates/github_node_settings.mako
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<div>
<h4 class="addon-title">
<img class="addon-icon" src="${addon_icon_url}">
<img class="addon-icon" src="${addon_icon_url}" aria-label="Github icon" alt="Github icon">
GitHub
<small class="authorized-by">
% if node_has_auth:
Expand Down
2 changes: 1 addition & 1 deletion addons/gitlab/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def before_page_load(self, node, user):
else:
message += (
' The files in this GitLab repo can be viewed on GitLab '
'<u><a href="{url}">here</a></u>.'
'<u><a href="{url}" aria-label="github link" >here</a></u>.'
).format(url=repo.http_url_to_repo)
messages.append(message)
return messages
Expand Down
4 changes: 2 additions & 2 deletions addons/gitlab/templates/gitlab_credentials_modal.mako
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<div class="col-sm-6">
<!-- Select GitLab installation -->
<div class="form-group">
<label for="hostSelect">GitLab Repository</label>
<select class="form-control" id="hostSelect"
<label>GitLab Repository</label>
<select class="form-control"
data-bind="options: visibleHosts,
optionsCaption: 'Select a GitLab repository',
value: selectedHost,
Expand Down
2 changes: 1 addition & 1 deletion addons/gitlab/templates/gitlab_node_settings.mako
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<form role="form" id="addonSettingsGitLab" data-addon="${addon_short_name}">
<div>
<h4 class="addon-title">
<img class="addon-icon" src="${addon_icon_url}">
<img class="addon-icon" src="${addon_icon_url}" aria-label="${addon_full_name} icon" alt="${addon_full_name} icon">
GitLab
<small class="authorized-by">
% if node_has_auth:
Expand Down
4 changes: 2 additions & 2 deletions addons/gitlab/templates/gitlab_user_settings.mako
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<%include file="gitlab_credentials_modal.mako"/>

<h4 class="addon-title">
<img class="addon-icon" src=${addon_icon_url}>
<img class="addon-icon" src=${addon_icon_url} aria-label="${addon_full_name} icon" alt="${addon_full_name} icon">
<span data-bind="text: properName"></span>
<small>
<a href="#gitlabInputCredentials" data-toggle="modal" class="pull-right text-primary">Connect or Reauthorize Account</a>
Expand All @@ -20,7 +20,7 @@
<table class="table table-hover">
<thead>
<tr class="user-settings-addon-auth">
<th class="text-muted default-authorized-by">Authorized on <a data-bind="attr: {href: gitlabUrl}"><em data-bind="text: gitlabHost"></em></a></th>
<th class="default-authorized-by">Authorized on <a data-bind="attr: {href: gitlabUrl}"><em data-bind="text: gitlabHost"></em></a></th>
</tr>
</thead>
<!-- ko if: connectedNodes().length > 0 -->
Expand Down
24 changes: 16 additions & 8 deletions addons/osfstorage/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from addons.base.models import BaseNodeSettings, BaseStorageAddon, BaseUserSettings
from osf.utils.fields import EncryptedJSONField
from osf.utils.datetime_aware_jsonfield import DateTimeAwareJSONField
from osf.exceptions import InvalidTagError, NodeStateError, TagNotFoundError
from osf.exceptions import InvalidTagError, TagNotFoundError
from framework.auth.core import Auth
from osf.models.mixins import Loggable
from osf.models import AbstractNode
Expand Down Expand Up @@ -239,9 +239,9 @@ def _hashes(self):
if not last_version:
return None
return {
'sha1': last_version.metadata['sha1'],
'sha256': last_version.metadata['sha256'],
'md5': last_version.metadata['md5']
'sha1': last_version.metadata.get('sha1', ''),
'sha256': last_version.metadata.get('sha256', ''),
'md5': last_version.metadata.get('md5', ''),
}

@property
Expand Down Expand Up @@ -352,7 +352,7 @@ def add_tag_log(self, action, tag, auth):
def add_tag(self, tag, auth, save=True, log=True):
from osf.models import Tag, NodeLog # Prevent import error

if not self.tags.filter(system=False, name=tag).exists() and not getattr(self.target, 'is_registration', False):
if not self.tags.filter(system=False, name=tag).exists():
new_tag = Tag.load(tag)
if not new_tag:
new_tag = Tag(name=tag)
Expand All @@ -367,9 +367,6 @@ def add_tag(self, tag, auth, save=True, log=True):

def remove_tag(self, tag, auth, save=True, log=True):
from osf.models import Tag, NodeLog # Prevent import error
if getattr(self.target, 'is_registration', False):
# Can't perform edits on a registration
raise NodeStateError
tag_instance = Tag.objects.filter(system=False, name=tag).first()
if not tag_instance:
raise InvalidTagError
Expand All @@ -383,6 +380,17 @@ def remove_tag(self, tag, auth, save=True, log=True):
self.save()
return True

def add_tags(self, tags, auth=None, save=True, log=True, system=False):
for tag in tags:
self.add_tag(tag, auth, save, log=log)

def remove_tags(self, tags, auth, save=True):
if not tags:
raise InvalidTagError

for tag in tags:
self.remove_tag(tag, auth, save)

def delete(self, user=None, **kwargs):
from website.search import search

Expand Down
30 changes: 13 additions & 17 deletions addons/osfstorage/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

from osf_tests.factories import ProjectFactory, ApiOAuth2PersonalTokenFactory, PreprintFactory
from website.files.utils import attach_versions
from website.settings import EXTERNAL_EMBER_APPS

def create_record_with_version(path, node_settings, **kwargs):
version = factories.FileVersionFactory(**kwargs)
Expand Down Expand Up @@ -1409,24 +1410,19 @@ def test_file_remove_tag_fail_doesnt_create_log(self, mock_log):
@pytest.mark.django_db
@pytest.mark.enable_bookmark_creation
class TestFileViews(StorageTestCase):
def test_file_views(self):
file = create_test_file(target=self.node, user=self.user)
url = self.node.web_url_for('addon_view_or_download_file', path=file._id, provider=file.provider)
# Test valid url file 200 on redirect
redirect = self.app.get(url, auth=self.user.auth)
assert redirect.status_code == 302
res = redirect.follow(auth=self.user.auth)
assert res.status_code == 200

# Test invalid node but valid deep_url redirects (moved log urls)
project_two = ProjectFactory(creator=self.user)
url = project_two.web_url_for('addon_view_or_download_file', path=file._id, provider=file.provider)
redirect = self.app.get(url, auth=self.user.auth)
assert redirect.status_code == 302
redirect_two = redirect.follow(auth=self.user.auth)
assert redirect_two.status_code == 302
res = redirect_two.follow(auth=self.user.auth)
assert res.status_code == 200
@mock.patch('website.views.stream_emberapp')
def test_file_views(self, mock_ember):
with override_flag(features.EMBER_FILE_PROJECT_DETAIL, active=True):
file = create_test_file(target=self.node, user=self.user)
url = self.node.web_url_for('addon_view_or_download_file', path=file._id, provider=file.provider)
res = self.app.get(url, auth=self.user.auth)
assert res.status_code == 200
assert mock_ember.called
args, kwargs = mock_ember.call_args

assert args[0] == EXTERNAL_EMBER_APPS['ember_osf_web']['server']
assert args[1] == EXTERNAL_EMBER_APPS['ember_osf_web']['path'].rstrip('/')

def test_download_file(self):
file = create_test_file(target=self.node, user=self.user)
Expand Down
3 changes: 1 addition & 2 deletions addons/owncloud/templates/owncloud_credentials_modal.mako
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
<div class="col-sm-6">
<div data-bind="if: hasDefaultHosts">
<div class="form-group">
<label for="hostSelect">ownCloud Instance</label>
<label>ownCloud Instance</label>
<select class="form-control"
id="hostSelect"
data-bind="options: visibleHosts,
optionsCaption: 'Select an ownCloud Instance',
value: selectedHost,
Expand Down
2 changes: 1 addition & 1 deletion addons/owncloud/templates/owncloud_node_settings.mako
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<%include file="owncloud_credentials_modal.mako"/>

<h4 class="addon-title">
<img class="addon-icon" src=${addon_icon_url}>
<img class="addon-icon" src=${addon_icon_url} aria-label="${addon_full_name} icon" alt="${addon_full_name} icon">
${addon_full_name}

<small class="authorized-by">
Expand Down
4 changes: 2 additions & 2 deletions addons/owncloud/templates/owncloud_user_settings.mako
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<%include file="owncloud_credentials_modal.mako"/>

<h4 class="addon-title">
<img class="addon-icon" src=${addon_icon_url}>
<img class="addon-icon" src=${addon_icon_url} aria-label="Owncloud icon" alt="Owncloud icon">
<span data-bind="text: properName"></span>
<small>
<a href="#ownCloudCredentialsModal" data-toggle="modal" class="pull-right text-primary">Connect or Reauthorize Account</a>
Expand All @@ -20,7 +20,7 @@
<table class="table table-hover">
<thead>
<tr class="user-settings-addon-auth">
<th class="text-muted default-authorized-by">Authorized by <em><span data-bind="text: name"></span></em> on <a data-bind="attr: {href: profileUrl}"><em data-bind="text: profileUrl"></em></a></th><th></th>
<th class="default-authorized-by">Authorized by <em><span data-bind="text: name"></span></em> on <a data-bind="attr: {href: profileUrl}"><em data-bind="text: profileUrl"></em></a></th><th></th>
</tr>
</thead>
<!-- ko if: connectedNodes().length > 0 -->
Expand Down
Loading

0 comments on commit f86d345

Please sign in to comment.