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

[PLAT-1181] Waffle all Prereg Challenge specific parts of the codebase #8833

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3f32b5b
add to tests for new prereg landing page
Johnetordoff Dec 3, 2018
b2d26f4
add and rename prereg landing page images
Johnetordoff Dec 3, 2018
d6afc55
waffle language and images for new osf prereg landing page
Johnetordoff Dec 3, 2018
d854276
waffle reminder emails for osf prereg challenge
Johnetordoff Dec 3, 2018
c0514ba
waffle prereg challenge views to prevent new entries from being made.
Johnetordoff Dec 3, 2018
30594d9
change tooltip language
Johnetordoff Dec 4, 2018
4a29ea8
add test for Prereg challenge depreciation and change error message
Johnetordoff Dec 4, 2018
bc920db
remove prereg_reminder email and task
Johnetordoff Dec 4, 2018
4486c60
remove custom message from email templates
Johnetordoff Dec 5, 2018
60aa3d0
fix waffling for form registering buttons
Johnetordoff Dec 6, 2018
795f2d0
fix email templates for prereg tests
Johnetordoff Dec 6, 2018
9bfe36a
remove colon typo
Johnetordoff Dec 6, 2018
1895ad5
Merge branch 'develop' of https://github.com/CenterForOpenScience/osf…
Johnetordoff Dec 6, 2018
d97ced0
remove extraneous cache cleaning
Johnetordoff Dec 6, 2018
b021d50
clean up error response for prereg wind down
Johnetordoff Dec 6, 2018
039c0b2
Remove mention of remind_draft_preregistrations script.
caseyrollins Dec 11, 2018
551d857
Merge pull request #6 from caseyrollins/winddown-waffle-the-rest
Johnetordoff Dec 11, 2018
965c95e
OSF Prereg copy edits
caseyrollins Dec 15, 2018
7c89dc3
Merge pull request #7 from caseyrollins/feature/prereg-copy-edits
Johnetordoff Dec 17, 2018
876c235
Add ensure_schemas migration.
caseyrollins Dec 18, 2018
816c61b
Merge pull request #8 from caseyrollins/prereg-add-migration
Johnetordoff Dec 18, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
81 changes: 77 additions & 4 deletions osf_tests/test_prereg.py
@@ -1,6 +1,11 @@
from nose.tools import * # noqa: F403

from waffle.testutils import override_switch
from waffle.models import Switch
from django.core.cache import cache

from osf.models import RegistrationSchema
from osf.features import OSF_PREREGISTRATION
from website.prereg import prereg_landing_page as landing_page
from website.prereg.utils import get_prereg_schema
from website.registries.utils import drafts_for_user
Expand All @@ -21,23 +26,55 @@ def test_not_logged_in(self):
'has_projects': False,
'has_draft_registrations': False,
'campaign_long': 'Prereg Challenge',
'campaign_short': 'prereg',
'campaign_short': 'prereg_challenge',
'is_logged_in': False,
}
)

cache.delete(Switch._cache_key(OSF_PREREGISTRATION))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? If you're using override_switch to set the value of a switch, you shouldn't have to worry about the cache.


with override_switch(name=OSF_PREREGISTRATION, active=True):
assert_equal(
landing_page(),
{
'has_projects': False,
'has_draft_registrations': False,
'campaign_long': 'OSF Preregistration',
'campaign_short': 'prereg',
'is_logged_in': False,
}
)

cache.delete(Switch._cache_key(OSF_PREREGISTRATION))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are unnecessary, too, right?


def test_no_projects(self):
assert_equal(
landing_page(user=self.user),
{
'has_projects': False,
'has_draft_registrations': False,
'campaign_long': 'Prereg Challenge',
'campaign_short': 'prereg',
'campaign_short': 'prereg_challenge',
'is_logged_in': True,
}
)

cache.delete(Switch._cache_key(OSF_PREREGISTRATION))

with override_switch(name=OSF_PREREGISTRATION, active=True):
assert_equal(
landing_page(user=self.user),
{
'has_projects': False,
'has_draft_registrations': False,
'campaign_long': 'OSF Preregistration',
'campaign_short': 'prereg',
'is_logged_in': True,
}
)

cache.delete(Switch._cache_key(OSF_PREREGISTRATION))

def test_has_project(self):
factories.ProjectFactory(creator=self.user)

Expand All @@ -47,10 +84,25 @@ def test_has_project(self):
'has_projects': True,
'has_draft_registrations': False,
'campaign_long': 'Prereg Challenge',
'campaign_short': 'prereg',
'campaign_short': 'prereg_challenge',
'is_logged_in': True,
}
)
cache.delete(Switch._cache_key(OSF_PREREGISTRATION))

with override_switch(name=OSF_PREREGISTRATION, active=True):
assert_equal(
landing_page(user=self.user),
{
'has_projects': True,
'has_draft_registrations': False,
'campaign_long': 'OSF Preregistration',
'campaign_short': 'prereg',
'is_logged_in': True,
}
)

cache.delete(Switch._cache_key(OSF_PREREGISTRATION))

def test_has_project_and_draft_registration(self):
prereg_schema = RegistrationSchema.objects.get(name='Prereg Challenge')
Expand All @@ -65,11 +117,32 @@ def test_has_project_and_draft_registration(self):
'has_projects': True,
'has_draft_registrations': True,
'campaign_long': 'Prereg Challenge',
'campaign_short': 'prereg',
'campaign_short': 'prereg_challenge',
'is_logged_in': True,
}
)

cache.delete(Switch._cache_key(OSF_PREREGISTRATION))

with override_switch(name=OSF_PREREGISTRATION, active=True):
prereg_schema = RegistrationSchema.objects.get(name='OSF Preregistration')
factories.DraftRegistrationFactory(
initiator=self.user,
registration_schema=prereg_schema
)
assert_equal(
landing_page(user=self.user),
{
'has_projects': True,
'has_draft_registrations': True,
'campaign_long': 'OSF Preregistration',
'campaign_short': 'prereg',
'is_logged_in': True,
}
)

cache.delete(Switch._cache_key(OSF_PREREGISTRATION))

def test_drafts_for_user_omits_registered(self):
prereg_schema = RegistrationSchema.objects.get(name='Prereg Challenge', schema_version=2)

Expand Down
12 changes: 8 additions & 4 deletions scripts/remind_draft_preregistrations.py
Expand Up @@ -9,9 +9,12 @@
from osf.models import DraftRegistration, QueuedMail
from osf.models.queued_mail import PREREG_REMINDER, PREREG_REMINDER_TYPE, queue_mail

import waffle
from website.app import init_app
from website import settings

from osf import features

from scripts.utils import add_file_logger

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -69,8 +72,9 @@ def find_neglected_prereg_within_reminder_limit():

@celery_app.task(name='scripts.remind_draft_preregistrations')
def run_main(dry_run=True):
init_app(routes=False)
if not dry_run:
add_file_logger(logger, __file__)
main(dry_run=dry_run)
if not waffle.switch_is_active(features.OSF_PREREGISTRATION):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might seem better to waffle this in the Celery config in defaults.py then here inside the running task, but that causes a circular import in waffle

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed with David M. in person and we can completely remove this reminder email now (no sense reminding people to finish their prereg draft when there's two weeks remaining...). Go ahead and remove the script, task, and email template.

init_app(routes=False)
if not dry_run:
add_file_logger(logger, __file__)
main(dry_run=dry_run)

2 changes: 1 addition & 1 deletion website/prereg/utils.py
@@ -1,5 +1,5 @@
from website.registries.utils import get_campaign_schema


def get_prereg_schema(campaign='prereg'):
def get_prereg_schema(campaign='prereg_challenge'):
return get_campaign_schema(campaign)
9 changes: 7 additions & 2 deletions website/prereg/views.py
Expand Up @@ -9,8 +9,13 @@
* website/static/css/prereg.css
"""

import waffle

from website.registries import views
from osf import features

def prereg_landing_page(**kwargs):
"""Landing page for the prereg challenge"""
return views._view_registries_landing_page('prereg', **kwargs)
"""Landing page for osf prereg"""
if waffle.switch_is_active(features.OSF_PREREGISTRATION):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the changes to this function necessary? The same mako template is returned regardless of the switch and it doesn't look like _view_registraties_landing_page was changed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, campaign is used to determine which draft registrations to load on the landing page. Got it.

return views._view_registries_landing_page('prereg', **kwargs)
return views._view_registries_landing_page('prereg_challenge', **kwargs)
5 changes: 5 additions & 0 deletions website/project/views/drafts.py
Expand Up @@ -21,6 +21,8 @@
from osf.utils.functional import rapply
from osf.models import NodeLog, RegistrationSchema, DraftRegistration, Sanction

import waffle

from website.exceptions import NodeStateError
from website.project.decorators import (
must_be_valid_project,
Expand Down Expand Up @@ -121,6 +123,9 @@ def submit_draft_for_review(auth, node, draft, *args, **kwargs):
:rtype: dict
:raises: HTTPError if embargo end date is invalid
"""
if waffle.switch_is_active(features.OSF_PREREGISTRATION):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test to ensure that this function doesn't execute when the switch is active?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

raise DeprecationWarning('The Prereg Challenge is over this endpoint is deprecated.')

data = request.get_json()
meta = {}
registration_choice = data.get('registrationChoice', 'immediate')
Expand Down
3 changes: 2 additions & 1 deletion website/registries/utils.py
@@ -1,5 +1,6 @@
REG_CAMPAIGNS = {
'prereg': 'Prereg Challenge',
'prereg_challenge': 'Prereg Challenge',
'prereg': 'OSF Preregistration',
'registered_report': 'Registered Report Protocol Preregistration',
}

Expand Down
Binary file added website/static/img/registries/osf-prereg-red.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 21 additions & 9 deletions website/templates/prereg_landing_page.mako
@@ -1,8 +1,12 @@
<%inherit file="base.mako"/>


<%def name="title()">OSF Prereg Challenge</%def>

<%def name="title()">
%if waffle.switch_is_active(features.OSF_PREREGISTRATION):
OSF Preregistration
%else:
OSF Prereg Challenge
%endif
</%def>
<%def name="stylesheets()">
${ parent.stylesheets() }
<link rel="stylesheet" href="/static/css/registration_landing.css">
Expand Down Expand Up @@ -41,11 +45,19 @@
<%def name="content()">
<div class="prereg-container">
<h1 class="m-t-xl m-b-lg text-center">
<img class="reg-landing-page-logo" src="/static/img/registries/osf-prereg-black.png" alt="preregistration_challenge_logo">
%if waffle.switch_is_active(features.OSF_PREREGISTRATION):
<img class="reg-landing-page-logo" src="/static/img/registries/osf-prereg-red.png" alt="preregistration_logo">
%else:
<img class="reg-landing-page-logo" src="/static/img/registries/osf-prereg-challenge-black.png" alt="preregistration_logo">
%endif
</h1>
<p><strong> Articles must be published by an <a target='_blank' href='http://cos.io/our-services/prereg-more-information/'>approved</a> journal by December 31, 2018, to be eligible for a prize. Please use this this helpful workflow to preregister, even if you are not seeking a prize. </strong></p>
<p> Improve your research with preregistration. The process of creating a <a href='http://www.cos.io/prereg'> preregistration</a> is beneficial to both the scientific field and to you, the scientist. By writing out detailed data collection methods, analysis plans, and rules for excluding or missing data, you can make important decisions that affect your workflow earlier, without the biases that occur once the data are in front of you.</p>

%if waffle.switch_is_active(features.OSF_PREREGISTRATION):
<p>Improve your research with <a target='_blank' href='http://www.cos.io/prereg/'>preregistration</a>. By writing out specific details such as data collection methods, analysis plans, and rules for data exclusion, you can make important decisions early on and have a clear record of these choices. This can help reduce biases that occur once the data are in front of you.</p>
<p>Use <a target='_blank' href='https://osf.io/registries/'>OSF Registries</a> to discover previously registered work.</p>
%else:
<p><strong> Articles must be published by an <a target='_blank' href='http://cos.io/our-services/prereg-more-information/'>approved</a> journal by December 31, 2018, to be eligible for a prize. Please use this this helpful workflow to preregister, even if you are not seeking a prize. </strong></p>
<p> Improve your research with preregistration. The process of creating a <a href='http://www.cos.io/prereg'> preregistration</a> is beneficial to both the scientific field and to you, the scientist. By writing out detailed data collection methods, analysis plans, and rules for excluding or missing data, you can make important decisions that affect your workflow earlier, without the biases that occur once the data are in front of you.</p>
%endif
<div class="col-md-12 visible-xs">
%if is_logged_in:
<div class="row">
Expand All @@ -69,7 +81,7 @@
%endif
%if has_projects:
<div class="row">
<div class="reg-landing-page-button-xs reg-landing-page-button reg-button-qtoggle m-b-md p-md osf-box-lt p-md box-round" data-qtoggle-group="prereg" data-qtoggle-target="#existingProjectXS">Preregister a project you already have on the OSF
<div class="reg-landing-page-button-xs reg-landing-page-button reg-button-qtoggle m-b-md p-md osf-box-lt p-md box-round" data-qtoggle-group="prereg" data-qtoggle-target="#existingProjectXS">Preregister a project you already have on OSF
</div>
<div class="reg-button-content-xs">
${existingProject('XS')}
Expand Down Expand Up @@ -111,7 +123,7 @@
%endif
%if has_projects:
<td class="col-sm-${ num_cols } reg-landing-page-button-col">
<div class="reg-landing-page-button reg-button-qtoggle m-b-md p-md osf-box-lt p-md box-round" data-qtoggle-group="prereg" data-qtoggle-target="#existingProject">Preregister a project you already have on the OSF</div>
<div class="reg-landing-page-button reg-button-qtoggle m-b-md p-md osf-box-lt p-md box-round" data-qtoggle-group="prereg" data-qtoggle-target="#existingProject">Preregister a project you already have on OSF</div>
</td>
%endif
</tr>
Expand Down
11 changes: 10 additions & 1 deletion website/templates/project/register_draft.mako
Expand Up @@ -25,14 +25,23 @@
<div class="row-md-12 scripted">
<span data-bind="ifnot: draft.isPendingApproval">
<a type="button" class="btn btn-default pull-left" href="${draft['urls']['edit']}">Continue editing</a>

%if waffle.switch_is_active(features.OSF_PREREGISTRATION):
<button type="button" class="btn btn-success pull-right"
data-toggle="tooltip" data-placement="top" title="The Prereg Challenge has expired"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about "The Prereg Challenge has ended."? Ended sounds a bit more accurate than expired imo.

style="margin-left: 5px;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird use of style tags here because the disabled class unjustly disables tooltips, so it's hacked to look and act disabled.

box-shadow: none;
opacity: .65;">
Submit for review
</button>
%else:
<button id="register-submit" type="button" class="btn btn-success pull-right"
style="margin-left: 5px;"
data-bind="visible: draft.requiresApproval,
click: draft.submitForReview.bind(draft),
enable: editor.canSubmit">
Submit for review
</button>
%endif
</span>
<span data-bind="if: draft.isPendingApproval">
<a type="button" class="btn btn-default pull-left" href="${web_url_for('node_registrations', pid=node['id'], tab='drafts', _guid=True)}"> Back </a>
Expand Down