Skip to content

[Feature] Enable angular-osf development server as alternative to ember-osf-web development server #11224

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

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 .docker-compose.env
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ MFR_SERVER_URL=http://localhost:7778
#SHARE_URL=http://192.168.168.167:8000/
BROKER_URL=amqp://guest:guest@192.168.168.167:5672/
REDIS_URL=redis://192.168.168.167:6379/1
EMBER_DOMAIN=192.168.168.167
PRIMARY_WEB_APP_DOMAIN=192.168.168.167

#PYTHONUNBUFFERED=0 # This when set to 0 will allow print statements to be visible in the Docker logs
8 changes: 4 additions & 4 deletions addons/osfstorage/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

from osf_tests.factories import ProjectFactory, ApiOAuth2PersonalTokenFactory, PreprintFactory
from website.files.utils import attach_versions
from website.settings import EXTERNAL_EMBER_APPS
from website.settings import EXTERNAL_WEB_APPS
from api_tests.draft_nodes.views.test_draft_node_files_lists import prepare_mock_wb_response


Expand Down Expand Up @@ -1419,7 +1419,7 @@ def test_file_view_updates_history(self):
file = GithubFile.objects.get(_path='/testpath', provider='github')
assert file.history

@mock.patch('website.views.stream_emberapp')
@mock.patch('website.views.stream_web_app')
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)
Expand All @@ -1433,8 +1433,8 @@ def test_file_views(self, mock_ember):
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('/')
assert args[0] == EXTERNAL_WEB_APPS['ember_osf_web']['server']
assert args[1] == EXTERNAL_WEB_APPS['ember_osf_web']['path'].rstrip('/')

def test_download_file(self):
file = create_test_file(target=self.node, user=self.user)
Expand Down
2 changes: 1 addition & 1 deletion addons/wiki/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from website.profile.utils import get_profile_image_url
from website.project.views.node import _view_project
from website.project.model import has_anonymous_link
from website.ember_osf_web.decorators import ember_flag_is_active
from website.external_web_app.decorators import ember_flag_is_active
from website.project.decorators import (
must_be_contributor_or_public,
must_have_addon, must_not_be_registration,
Expand Down
2 changes: 1 addition & 1 deletion framework/auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from osf.models.tag import Tag
from osf.utils.requests import check_select_for_update
from website.util.metrics import CampaignClaimedTags, CampaignSourceTags
from website.ember_osf_web.decorators import ember_flag_is_active
from website.external_web_app.decorators import ember_flag_is_active
from osf import features


Expand Down
8 changes: 4 additions & 4 deletions osf_tests/test_guid.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ def test_resolve_guid_download_file(self):
assert res.status_code == 302
assert f'{WATERBUTLER_URL}/v1/resources/{unpub_pp._id}/providers/{unpub_pp.primary_file.provider}{unpub_pp.primary_file.path}?version=1&action=download&direct' in res.location

@mock.patch('website.settings.USE_EXTERNAL_EMBER', True)
@mock.patch('website.settings.EXTERNAL_EMBER_APPS', {
@mock.patch('website.settings.USE_EXTERNAL_WEB_APP', True)
@mock.patch('website.settings.EXTERNAL_WEB_APPS', {
'preprints': {
'server': 'http://localhost:4200',
'path': '/preprints/'
Expand All @@ -289,8 +289,8 @@ def test_resolve_guid_download_file_from_emberapp_preprints(self):
assert res.status_code == 302
assert f'{WATERBUTLER_URL}/v1/resources/{pp._id}/providers/{pp.primary_file.provider}{pp.primary_file.path}?action=download&direct&version=1' in res.location

@mock.patch('website.settings.USE_EXTERNAL_EMBER', True)
@mock.patch('website.settings.EXTERNAL_EMBER_APPS', {
@mock.patch('website.settings.USE_EXTERNAL_WEB_APP', True)
@mock.patch('website.settings.EXTERNAL_WEB_APPS', {
'preprints': {
'server': 'http://localhost:4200',
'path': '/preprints/'
Expand Down
20 changes: 10 additions & 10 deletions tests/test_addons.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from framework import sentry
from api.base.settings.defaults import API_BASE
from tests.json_api_test_app import JSONAPITestApp
from website.settings import EXTERNAL_EMBER_APPS
from website.settings import EXTERNAL_WEB_APPS
from waffle.testutils import override_flag
from django.conf import settings as django_conf_settings

Expand Down Expand Up @@ -1360,7 +1360,7 @@ def test_action_download_redirects_to_download_with_version(self):
# Note: version is added but us but all other url params are added as well
assert_urls_equal(location.url, file_node.generate_waterbutler_url(action='download', direct=None, revision=1, version=''))

@mock.patch('website.views.stream_emberapp')
@mock.patch('website.views.stream_web_app')
@pytest.mark.enable_bookmark_creation
def test_action_view_calls_view_file(self, mock_ember):
self.user.reload()
Expand All @@ -1374,10 +1374,10 @@ def test_action_view_calls_view_file(self, mock_ember):

args, kwargs = mock_ember.call_args
assert kwargs == {}
assert args[0] == EXTERNAL_EMBER_APPS['ember_osf_web']['server']
assert args[1] == EXTERNAL_EMBER_APPS['ember_osf_web']['path'].rstrip('/')
assert args[0] == EXTERNAL_WEB_APPS['ember_osf_web']['server']
assert args[1] == EXTERNAL_WEB_APPS['ember_osf_web']['path'].rstrip('/')

@mock.patch('website.views.stream_emberapp')
@mock.patch('website.views.stream_web_app')
@pytest.mark.enable_bookmark_creation
def test_no_action_calls_view_file(self, mock_ember):
self.user.reload()
Expand All @@ -1391,8 +1391,8 @@ def test_no_action_calls_view_file(self, mock_ember):

args, kwargs = mock_ember.call_args
assert kwargs == {}
assert args[0] == EXTERNAL_EMBER_APPS['ember_osf_web']['server']
assert args[1] == EXTERNAL_EMBER_APPS['ember_osf_web']['path'].rstrip('/')
assert args[0] == EXTERNAL_WEB_APPS['ember_osf_web']['server']
assert args[1] == EXTERNAL_WEB_APPS['ember_osf_web']['path'].rstrip('/')

def test_download_create_guid(self):
file_node = self.get_test_file()
Expand Down Expand Up @@ -1462,7 +1462,7 @@ def test_nonstorage_addons_raise(self):
)
assert resp.status_code == 400

@mock.patch('website.views.stream_emberapp')
@mock.patch('website.views.stream_web_app')
def test_head_returns_url_and_redriect(self, mock_ember):
file_node = self.get_test_file()
guid = file_node.get_guid(create=True)
Expand All @@ -1473,8 +1473,8 @@ def test_head_returns_url_and_redriect(self, mock_ember):

args, kwargs = mock_ember.call_args
assert kwargs == {}
assert args[0] == EXTERNAL_EMBER_APPS['ember_osf_web']['server']
assert args[1] == EXTERNAL_EMBER_APPS['ember_osf_web']['path'].rstrip('/')
assert args[0] == EXTERNAL_WEB_APPS['ember_osf_web']['server']
assert args[1] == EXTERNAL_WEB_APPS['ember_osf_web']['path'].rstrip('/')


def test_head_returns_url_with_version_and_redirect(self):
Expand Down
32 changes: 17 additions & 15 deletions tests/test_ember_osf_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from flask import request

from tests.base import OsfTestCase
from website.ember_osf_web.decorators import ember_flag_is_active
from website.external_web_app.decorators import ember_flag_is_active
from osf_tests.factories import FlagFactory, UserFactory

from django.contrib.auth.models import Group
Expand All @@ -16,24 +16,26 @@ def setUp(self):
FlagFactory(name='inactive_flag', everyone=False).save()
self.mock_func = lambda: 'test value'

@mock.patch('website.ember_osf_web.decorators.use_ember_app')
def test_use_ember_app(self, mock_use_ember_app):
# TODO: This test case is not Ember App specific.
@mock.patch('website.external_web_app.decorators.use_primary_web_app')
def test_use_primary_web_app(self, mock_use_primary_web_app):
ember_flag_is_active('active_flag')(self.mock_func)()

mock_use_ember_app.assert_called_with()
mock_use_primary_web_app.assert_called_with()

@mock.patch('website.ember_osf_web.decorators.use_ember_app')
def test_dont_use_ember_app(self, mock_use_ember_app):
# TODO: This test case is not Ember App specific.
@mock.patch('website.external_web_app.decorators.use_primary_web_app')
def test_dont_use_primary_web_app(self, mock_use_primary_web_app):
# mock over external module 'waflle.flag_is_active` not ours

ember_flag_is_active('inactive_flag')(self.mock_func)()

assert not mock_use_ember_app.called
assert not mock_use_primary_web_app.called

@mock.patch('api.waffle.utils._get_current_user')
@mock.patch('website.ember_osf_web.decorators.flag_is_active')
@mock.patch('website.ember_osf_web.decorators.use_ember_app')
def test_ember_flag_is_active_authenticated_user(self, mock_use_ember_app, mock_flag_is_active, mock__get_current_user):
@mock.patch('website.external_web_app.decorators.flag_is_active')
@mock.patch('website.external_web_app.decorators.use_primary_web_app')
def test_ember_flag_is_active_authenticated_user(self, mock_use_primary_web_app, mock_flag_is_active, mock__get_current_user):
# mock over external module 'waflle.flag_is_active` not ours

user = UserFactory()
Expand All @@ -42,12 +44,12 @@ def test_ember_flag_is_active_authenticated_user(self, mock_use_ember_app, mock_
ember_flag_is_active('active_flag')(self.mock_func)()

mock_flag_is_active.assert_called_with(request, 'active_flag')
mock_use_ember_app.assert_called_with()
mock_use_primary_web_app.assert_called_with()

@mock.patch('api.waffle.utils._get_current_user', return_value=None)
@mock.patch('website.ember_osf_web.decorators.flag_is_active')
@mock.patch('website.ember_osf_web.decorators.use_ember_app')
def test_ember_flag_is_active_unauthenticated_user(self, mock_use_ember_app, mock_flag_is_active, mock__get_current_user):
@mock.patch('website.external_web_app.decorators.flag_is_active')
@mock.patch('website.external_web_app.decorators.use_primary_web_app')
def test_ember_flag_is_active_unauthenticated_user(self, mock_use_primary_web_app, mock_flag_is_active, mock__get_current_user):
# mock over external module 'waflle.flag_is_active` not ours

ember_flag_is_active('active_flag')(self.mock_func)()
Expand All @@ -56,4 +58,4 @@ def test_ember_flag_is_active_unauthenticated_user(self, mock_use_ember_app, moc
self.flag.groups.add(group)

mock_flag_is_active.assert_called_with(request, 'active_flag')
mock_use_ember_app.assert_called_with()
mock_use_primary_web_app.assert_called_with()
20 changes: 10 additions & 10 deletions tests/test_misc_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,27 +793,27 @@ def test_find_unread_includes_edited_comments(self):
n_unread = Comment.find_n_unread(user=user, node=project, page='node')
assert n_unread == 1

@mock.patch('website.views.PROXY_EMBER_APPS', False)
@mock.patch('website.views.PROXY_WEB_APPS', False)
class TestResolveGuid(OsfTestCase):
def setUp(self):
super().setUp()

@mock.patch('website.views.use_ember_app')
def test_preprint_provider_without_domain(self, mock_use_ember_app):
@mock.patch('website.views.use_primary_web_app')
def test_preprint_provider_without_domain(self, mock_use_primary_web_app):
provider = PreprintProviderFactory(domain='')
preprint = PreprintFactory(provider=provider)
url = web_url_for('resolve_guid', _guid=True, guid=preprint._id)
res = self.app.get(url)
mock_use_ember_app.assert_called_with()
mock_use_primary_web_app.assert_called_with()

@mock.patch('website.views.use_ember_app')
def test_preprint_provider_with_domain_without_redirect(self, mock_use_ember_app):
@mock.patch('website.views.use_primary_web_app')
def test_preprint_provider_with_domain_without_redirect(self, mock_use_primary_web_app):
domain = 'https://test.com/'
provider = PreprintProviderFactory(_id='test', domain=domain, domain_redirect_enabled=False)
preprint = PreprintFactory(provider=provider)
url = web_url_for('resolve_guid', _guid=True, guid=preprint._id)
res = self.app.get(url)
mock_use_ember_app.assert_called_with()
mock_use_primary_web_app.assert_called_with()

def test_preprint_provider_with_domain_with_redirect(self):
domain = 'https://test.com/'
Expand All @@ -827,10 +827,10 @@ def test_preprint_provider_with_domain_with_redirect(self):
assert res.headers['location'] == f'{domain}{preprint._id}/'
assert res.request.path == f'/{preprint._id}/'

@mock.patch('website.views.use_ember_app')
def test_preprint_provider_with_osf_domain(self, mock_use_ember_app):
@mock.patch('website.views.use_primary_web_app')
def test_preprint_provider_with_osf_domain(self, mock_use_primary_web_app):
provider = PreprintProviderFactory(_id='osf', domain='https://osf.io/')
preprint = PreprintFactory(provider=provider)
url = web_url_for('resolve_guid', _guid=True, guid=preprint._id)
res = self.app.get(url)
mock_use_ember_app.assert_called_with()
mock_use_primary_web_app.assert_called_with()
2 changes: 1 addition & 1 deletion website/conferences/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from website import settings
from website.conferences import utils, signals
from website.conferences.message import ConferenceMessage, ConferenceError
from website.ember_osf_web.decorators import ember_flag_is_active
from website.external_web_app.decorators import ember_flag_is_active
from website.mails import CONFERENCE_SUBMITTED, CONFERENCE_INACTIVE, CONFERENCE_FAILED, CONFERENCE_DEPRECATION
from website.mails import send_mail
from website.util import web_url_for
Expand Down
28 changes: 0 additions & 28 deletions website/ember_osf_web/views.py

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from flask import request

from api.waffle.utils import flag_is_active
from website.ember_osf_web.views import use_ember_app
from website.external_web_app.views import use_primary_web_app


def ember_flag_is_active(flag_name):
Expand All @@ -15,7 +15,7 @@ def decorator(func):
@functools.wraps(func)
def wrapped(*args, **kwargs):
if flag_is_active(request, flag_name):
return use_ember_app()
return use_primary_web_app()
else:
return func(*args, **kwargs)
return wrapped
Expand Down
46 changes: 46 additions & 0 deletions website/external_web_app/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import os
import json
from website import settings
from framework.status import pop_status_messages

from website.settings import EXTERNAL_WEB_APPS

def get_primary_app_config():
from website.settings import PRIMARY_WEB_APP
return EXTERNAL_WEB_APPS.get(PRIMARY_WEB_APP, {})

def get_primary_app_dir():
app_config = get_primary_app_config()
if 'path' in app_config:
return os.path.abspath(os.path.join(os.getcwd(), app_config['path']))
return None

routes = [
'/quickfiles/',
'/<uid>/quickfiles/',
'/institutions/',
]

def use_primary_web_app(**kwargs):
from rest_framework import status as http_status
from framework.exceptions import HTTPError
from website.views import stream_web_app

app_config = get_primary_app_config()
if not app_config:
raise HTTPError(
http_status.HTTP_500_INTERNAL_SERVER_ERROR,
data={'message': 'Primary web app not configured'}
)

resp = stream_web_app(app_config['server'], get_primary_app_dir())
messages = pop_status_messages()
if messages:
try:
status = [{'id': stat[5] if stat[5] else stat[0], 'class': stat[2], 'jumbo': stat[1], 'dismiss': stat[3], 'extra': stat[6]} for stat in messages]
resp.set_cookie(settings.COOKIE_NAME + '_status', json.dumps(status))
except IndexError:
# Ignoring the error as it will only occur when statuses were created prior to merging the changes that add
# extra and id, (patch to prevent breaking the app meanwhile)
pass
return resp
6 changes: 3 additions & 3 deletions website/institutions/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from website.ember_osf_web.views import use_ember_app
from website.external_web_app.views import use_primary_web_app

def view_institution(inst_id, **kwargs):
return use_ember_app()
return use_primary_web_app()

def view_institution_dashboard(inst_id, **kwargs):
return use_ember_app()
return use_primary_web_app()
2 changes: 1 addition & 1 deletion website/profile/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from website import mailchimp_utils
from website import settings
from website import language
from website.ember_osf_web.decorators import ember_flag_is_active
from website.external_web_app.decorators import ember_flag_is_active
from website.oauth.utils import get_available_scopes
from website.profile import utils as profile_utils
from website.util import api_v2_url, web_url_for, paths
Expand Down
2 changes: 1 addition & 1 deletion website/project/views/drafts.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
must_have_permission,
)
from website import settings
from website.ember_osf_web.decorators import ember_flag_is_active
from website.external_web_app.decorators import ember_flag_is_active

from website.project import utils
from website.project.metadata.schemas import METASCHEMA_ORDERING
Expand Down
Loading
Loading