Skip to content

Commit

Permalink
Prune old code for Journals/Faculty sign-ups (#3599)
Browse files Browse the repository at this point in the history
* Prune old code for Journals/Faculty sign-ups

* Remove now-extraneous import
  • Loading branch information
cmsetzer authored Sep 6, 2024
1 parent 469d69e commit ea2e497
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 349 deletions.
2 changes: 0 additions & 2 deletions perma_web/perma/settings/deployments/settings_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,6 @@
'dev_docs',
'sign_up',
'sign_up_courts',
'sign_up_faculty',
'sign_up_journals',
'sign_up_firm',
'libraries'
]
Expand Down
49 changes: 0 additions & 49 deletions perma_web/perma/templates/registration/sign-up-faculty.html

This file was deleted.

49 changes: 0 additions & 49 deletions perma_web/perma/templates/registration/sign-up-journals.html

This file was deleted.

196 changes: 0 additions & 196 deletions perma_web/perma/tests/test_views_user_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -2442,202 +2442,6 @@ def test_new_firm_failure(self):
)
self.assertEqual(len(mail.outbox), 0)

### Journals ###

def new_journal(self):
rand = random()
return { 'requested_account_note': 'Journal {}'.format(rand)}

def new_journal_user(self):
rand = random()
email = self.randomize_capitalization('user{}@university.org'.format(rand))
return { 'raw_email': email,
'normalized_email': email.lower(),
'first': 'Joe',
'last': 'Yacobówski' }

@override_settings(REQUIRE_JS_FORM_SUBMISSIONS=False)
def test_new_journal_success(self):
'''
Does the journal signup form submit as expected? Success cases.
'''
new_journal = self.new_journal()
new_user = self.new_journal_user()
existing_user = {'email': '[email protected]'}
expected_emails_sent = 0

# NOT LOGGED IN

# New user email address + journal info
self.submit_form('sign_up_journals',
data = { 'e-address': new_user['raw_email'],
'requested_account_note': new_journal['requested_account_note']},
success_url = reverse('register_email_instructions'))
expected_emails_sent += 1
self.assertEqual(len(mail.outbox), expected_emails_sent)
self.check_new_activation_email(mail.outbox[expected_emails_sent - 1], new_user['raw_email'])

# LOGGED IN

# New user email address + journal info
# (This succeeds and creates a new account; see issue 1749)
new_user = self.new_journal_user()
self.submit_form('sign_up_journals',
data = { 'e-address': new_user['raw_email'],
'requested_account_note': new_journal['requested_account_note']},
user = existing_user['email'],
success_url = reverse('register_email_instructions'))
expected_emails_sent += 1
self.assertEqual(len(mail.outbox), expected_emails_sent)
self.check_new_activation_email(mail.outbox[expected_emails_sent - 1], new_user['raw_email'])

@override_settings(REQUIRE_JS_FORM_SUBMISSIONS=False)
def test_new_journal_form_honeypot(self):
new_journal = self.new_journal()
new_user = self.new_journal_user()
self.submit_form('sign_up_journals',
data = { 'e-address': new_user['raw_email'],
'requested_account_note': new_journal['requested_account_note'],
'telephone': "I'm a bot." },
success_url = reverse('register_email_instructions'))
self.assertEqual(len(mail.outbox), 0)
self.assertFalse(LinkUser.objects.filter(email__iexact=new_user['raw_email']).exists())

@override_settings(REQUIRE_JS_FORM_SUBMISSIONS=False)
def test_new_journal_failure(self):
'''
Does the journal signup form submit as expected? Failure cases.
'''

# NOT LOGGED IN

# Blank submission reports correct fields required
self.submit_form('sign_up_journals',
data = {},
error_keys = ['email', 'requested_account_note'])
self.assertEqual(len(mail.outbox), 0)

# If email address already belongs to an account, validation fails
self.submit_form('sign_up_journals',
data = { 'e-address': self.randomize_capitalization('[email protected]'),
'requested_account_note': 'Here'},
error_keys = ['email'])
self.assertEqual(len(mail.outbox), 0)

# LOGGED IN
# (This is odd; see issue 1749)

# Blank submission reports correct fields required
self.submit_form('sign_up_journals',
data = {},
user = '[email protected]',
error_keys = ['email', 'requested_account_note'])
self.assertEqual(len(mail.outbox), 0)

# If email address already belongs to an account, validation fails
self.submit_form('sign_up_journals',
data = { 'e-address': self.randomize_capitalization('[email protected]'),
'requested_account_note': 'Here'},
user = '[email protected]',
error_keys = ['email'])
self.assertEqual(len(mail.outbox), 0)


### Faculty ###

def new_faculty_user(self):
rand = random()
email = self.randomize_capitalization('user{}@university.org'.format(rand))
return { 'raw_email': email,
'normalized_email': email.lower(),
'first': 'Joe',
'last': 'Yacobówski',
'requested_account_note': 'Journal {}'.format(rand) }

@override_settings(REQUIRE_JS_FORM_SUBMISSIONS=False)
def test_new_faculty_success(self):
'''
Does the faculty signup form submit as expected? Success cases.
'''
new_user = self.new_faculty_user()
existing_user = {'email': '[email protected]'}
expected_emails_sent = 0

# NOT LOGGED IN

# New user email address + journal info
self.submit_form('sign_up_faculty',
data = { 'e-address': new_user['raw_email'],
'requested_account_note': new_user['requested_account_note']},
success_url = reverse('register_email_instructions'))
expected_emails_sent += 1
self.assertEqual(len(mail.outbox), expected_emails_sent)
self.check_new_activation_email(mail.outbox[expected_emails_sent - 1], new_user['raw_email'])

# LOGGED IN

# New user email address + journal info
# (This succeeds and creates a new account; see issue 1749)
new_user = self.new_faculty_user()
self.submit_form('sign_up_faculty',
data = { 'e-address': new_user['raw_email'],
'requested_account_note': new_user['requested_account_note']},
user = existing_user['email'],
success_url = reverse('register_email_instructions'))
expected_emails_sent += 1
self.assertEqual(len(mail.outbox), expected_emails_sent)
self.check_new_activation_email(mail.outbox[expected_emails_sent - 1], new_user['raw_email'])

@override_settings(REQUIRE_JS_FORM_SUBMISSIONS=False)
def test_new_faculty_form_honeypot(self):
new_user = self.new_faculty_user()
self.submit_form('sign_up_faculty',
data = { 'e-address': new_user['raw_email'],
'requested_account_note': new_user['requested_account_note'],
'telephone': "I'm a bot." },
success_url = reverse('register_email_instructions'))
self.assertEqual(len(mail.outbox), 0)
self.assertFalse(LinkUser.objects.filter(email__iexact=new_user['raw_email']).exists())

@override_settings(REQUIRE_JS_FORM_SUBMISSIONS=False)
def test_new_faculty_failure(self):
'''
Does the faculty signup form submit as expected? Failure cases.
'''

# NOT LOGGED IN

# Blank submission reports correct fields required
self.submit_form('sign_up_faculty',
data = {},
error_keys = ['email', 'requested_account_note'])
self.assertEqual(len(mail.outbox), 0)

# If email address already belongs to an account, validation fails
self.submit_form('sign_up_faculty',
data = { 'e-address': self.randomize_capitalization('[email protected]'),
'requested_account_note': 'Here'},
error_keys = ['email'])
self.assertEqual(len(mail.outbox), 0)

# LOGGED IN
# (This is odd; see issue 1749)

# Blank submission reports correct fields required
self.submit_form('sign_up_faculty',
data = {},
user = '[email protected]',
error_keys = ['email', 'requested_account_note'])
self.assertEqual(len(mail.outbox), 0)

# If email address already belongs to an account, validation fails
self.submit_form('sign_up_faculty',
data = { 'e-address': self.randomize_capitalization('[email protected]'),
'requested_account_note': 'Here'},
user = '[email protected]',
error_keys = ['email'])
self.assertEqual(len(mail.outbox), 0)

### Individual Users ###

def check_new_activation_email(self, message, user_email):
Expand Down
2 changes: 0 additions & 2 deletions perma_web/perma/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@

re_path(r'^sign-up/?$', user_management.sign_up, name='sign_up'),
re_path(r'^sign-up/courts/?$', user_management.sign_up_courts, name='sign_up_courts'),
re_path(r'^sign-up/faculty/?$', user_management.sign_up_faculty, name='sign_up_faculty'),
re_path(r'^sign-up/journals/?$', user_management.sign_up_journals, name='sign_up_journals'),
re_path(r'^sign-up/firms/?$', user_management.sign_up_firm, name='sign_up_firm'),
re_path(r'^libraries/?$', user_management.libraries, name='libraries'),

Expand Down
51 changes: 0 additions & 51 deletions perma_web/perma/views/user_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
UserFormWithOrganization,
CreateUserFormWithCourt,
CreateUserFormWithFirm,
CreateUserFormWithUniversity,
UserAddRegistrarForm,
UserAddSponsoringRegistrarForm,
UserAddOrganizationForm,
Expand Down Expand Up @@ -1871,31 +1870,6 @@ def sign_up_courts(request):
return render(request, "registration/sign-up-courts.html", {'form': form})


@ratelimit(rate=settings.REGISTER_MINUTE_LIMIT, block=True, key=ratelimit_ip_key)
def sign_up_faculty(request):
"""
Register a new user
"""
if request.method == 'POST':

if something_took_the_bait := check_honeypot(request, 'register_email_instructions', check_js=True):
return something_took_the_bait

form = CreateUserFormWithUniversity(request.POST)
if form.is_valid():
new_user = form.save(commit=False)
new_user.requested_account_type = 'faculty'
new_user.save()

email_new_user(request, new_user)

messages.add_message(request, messages.INFO, "Remember to ask your library about access to special Perma.cc privileges.")
return HttpResponseRedirect(reverse('register_email_instructions'))
else:
form = CreateUserFormWithUniversity()

return render(request, "registration/sign-up-faculty.html", {'form': form})

@ratelimit(rate=settings.REGISTER_MINUTE_LIMIT, block=True, key=ratelimit_ip_key)
def sign_up_firm(request):
"""
Expand Down Expand Up @@ -1964,31 +1938,6 @@ def sign_up_firm(request):
)


@ratelimit(rate=settings.REGISTER_MINUTE_LIMIT, block=True, key=ratelimit_ip_key)
def sign_up_journals(request):
"""
Register a new user
"""
if request.method == 'POST':

if something_took_the_bait := check_honeypot(request, 'register_email_instructions', check_js=True):
return something_took_the_bait

form = CreateUserFormWithUniversity(request.POST)
if form.is_valid():
new_user = form.save(commit=False)
new_user.requested_account_type = 'journal'
new_user.save()

email_new_user(request, new_user)

messages.add_message(request, messages.INFO, "Remember to ask your library about access to special Perma.cc privileges.")
return HttpResponseRedirect(reverse('register_email_instructions'))
else:
form = CreateUserFormWithUniversity()

return render(request, "registration/sign-up-journals.html", {'form': form})

def register_email_instructions(request):
"""
After the user has registered, give the instructions for confirming
Expand Down

0 comments on commit ea2e497

Please sign in to comment.