Skip to content

Conversation

@nasthagiri
Copy link
Contributor

@nasthagiri nasthagiri commented Oct 19, 2019

This PR removes an older implementation of the login and registration APIs. They were moved to openedx/core/djangoapps/user_authn/views/deprecated.py as part of a past login/authentication refactor PR.

This PR also removes the ENABLE_COMBINED_LOGIN_REGISTRATION Django setting, as part of our effort to consolidate towards a single implementation.

Further removal and refactor will follow after removal of this earlier version.

@nasthagiri nasthagiri requested review from a team October 19, 2019 17:33
@nasthagiri nasthagiri force-pushed the arch/user-authn-delete-deprecated branch 7 times, most recently from f7cd906 to 67d0d10 Compare October 20, 2019 16:28
obj = json.loads(response.content.decode('utf-8'))
self.assertEqual(
obj['value'],
obj['username'][0]['user_message'],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note to reviewers: These test changes are needed since the old registration API returned the validation error in a value field instead of the new format of field_name (e.g., username) and user_message.

# Check that the correct provider was selected.
self.assertContains(
response,
u'successfully signed in with <strong>%s</strong>' % self.provider.name,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note to reviewers: Since the new implementation presents this string via Javascript in Backbone, we check for the field value in the response instead.

)
third_party_auth_hint = provider_id
initial_mode = "hinted_login"
if 'tpa_hint' in next_args:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note to reviewers: I added this extra if statement here since it is an expected condition for tpa_hint to not be included as a parameter. We receive on the order 100k exceptions a day due to this lack of check.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice.

if data.get("honor_code") and "terms_of_service" not in data:
data["terms_of_service"] = data["honor_code"]

def _get_third_party_auth_redirect_url(self, request):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note to reviewers: I added a redirect_url to the new registration response in order to make old tests pass. I am currently testing removal of this (for now) to see if this addition is actually needed in this cleanup task.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Testing removal of redirect_url in this PR: https://github.com/edx/edx-platform/pull/22090

Copy link
Contributor

Choose a reason for hiding this comment

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

This is the only weird part of this PR, because everything is about removal (or refactor), but this introduces a change to an existing API that is already in use.

It would be cleanest if this code weren't needed in this PR. If it is, I would comment the code (in addition to the comments in the PR) to clarify that this code is not used and is just required temporarily for old tests that will be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update: The third_party_auth...test_full_pipeline_succeeds_registering_new_account test currently requires the redirect_url field in the registration response.

Copy link
Contributor

Choose a reason for hiding this comment

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

I’m missing something. We had two views and you are removing The deprecated one that had this field, but the newer did not.

Does that mean we had a bug in the newer and just never tested it? Or is this testing something that we don’t need? Or other?

Copy link
Contributor

@robrap robrap left a comment

Choose a reason for hiding this comment

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

Nice. Thank you. I especially appreciate you keeping it small even though there is much more to do. It makes it simpler in pieces.

The only potential blocker is double-checking White Label (see comment below).

"This password must contain at least 3 punctuation marks.",
]
for i in range(3):
self.assertEqual(obj['password'][i]['user_message'], error_strings[i])
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: you could add an assertion around length to ensure no additional errors appear that were unexpected.


from lms.djangoapps.commerce.tests import TEST_API_URL
from openedx.core.djangoapps.user_authn.views.deprecated import signin_user, create_account, register_user
from openedx.core.djangoapps.user_api.views import RegistrationView
Copy link
Contributor

Choose a reason for hiding this comment

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

I like that you aren't doing too much in this single PR. I imagine we might move RegistrationView to user_authn in a later pass?

)
third_party_auth_hint = provider_id
initial_mode = "hinted_login"
if 'tpa_hint' in next_args:
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice.

def dispatch(self, request, *args, **kwargs):
return super(RegistrationView, self).dispatch(request, *args, **kwargs)
def _create_response(self, response_dict, status_code):
response_dict['success'] = (status_code == 200)
Copy link
Contributor

Choose a reason for hiding this comment

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

Note: Having errors go from not having a success key, to now having one with a value of 'False' could theoretically throw off a client, but hopefully not. :)

Choose a reason for hiding this comment

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

Sadly this change did cause a spike of registration errors (with accompanying bad reviews) on our edX Android PlayStore app.

if data.get("honor_code") and "terms_of_service" not in data:
data["terms_of_service"] = data["honor_code"]

def _get_third_party_auth_redirect_url(self, request):
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the only weird part of this PR, because everything is about removal (or refactor), but this introduces a change to an existing API that is already in use.

It would be cleanest if this code weren't needed in this PR. If it is, I would comment the code (in addition to the comments in the PR) to clarify that this code is not used and is just required temporarily for old tests that will be removed.

@felipemontoya
Copy link
Member

@nasthagiri we at eduNEXT use those deprecated view extensively. The reason for it, is that theming the new combined login_registration views is a nightmare.

I understand this has been in the works for quite some time, but I'd like to ask if the merging of this can be made after the juniper cut. This way we can have one extra release to move away from our registration theming model. This will be made simpler by the fact that during juniper we will need to implement theming on the MFE and we will gather a lot of experience from that.

@nasthagiri
Copy link
Contributor Author

@felipemontoya I have created a DEPR ticket for this effort. We can continue the discussion there as well: https://openedx.atlassian.net/browse/DEPR-52

At this point, the edX architecture team is resourced to replatform the login and registration pages, which includes simplifying the underlying backend logic and implementation. Unfortunately, this code is unnecessarily complicated because of half-completed past efforts. Because of this gnarly situation, our current approach is to remove old and deprecated code along the way - that is, strip out one spaghetti strand after another.

As for Juniper, we are targeting the upgrade of our massive platform to Python-3 and Django-2. In order to minimize these arduous maintenances costs, we prefer removing any unneeded code prior to upgrades.

For your case, I wonder if there's a path that helps you move forward - where you can use our new Login and Registration micro-frontends - since they will be available for use in Juniper. We will be using them on edx.org by then. Or perhaps you can see how other open edX instances have successfully themed the newer login/registration pages.

@felipemontoya
Copy link
Member

@nasthagiri thanks a lot for the detailed answer. I know how to theme the underscore + backbone based login views. We have done it for several clients. However I find that mechanism cumbersome and very little can be done. I'm all for simplifying the login/registration views. In fact, if by Juniper the MFE are going to be used for login/registration, that is good enough for me, since we can move the bulk of our sites to MFEs directly.

Furthermore, any custom logic that we want to modify in the login/registration process at the backend we should be able to add via plugins then. Does the Arch team have a specific pattern in mind for this? or should we propose something in the form of a PR and have a discussion there?

@nasthagiri nasthagiri force-pushed the arch/user-authn-delete-deprecated branch from 67d0d10 to 5271f88 Compare October 29, 2019 01:35
@nasthagiri nasthagiri force-pushed the arch/user-authn-delete-deprecated branch from 5271f88 to db42c7e Compare October 29, 2019 12:58
@edx-status-bot
Copy link

Your PR has finished running tests. There were no failures.

@nasthagiri
Copy link
Contributor Author

Furthermore, any custom logic that we want to modify in the login/registration process at the backend we should be able to add via plugins then. Does the Arch team have a specific pattern in mind for this? or should we propose something in the form of a PR and have a discussion there?

@felipemontoya Feel free to post in a PR and we can discuss there. My suggestion is to wait for 2-3 weeks, however, while the team continues to simplify the current backend logic. After that, perhaps you can create a Django App Plugin to address your needs.

@nasthagiri nasthagiri merged commit f533134 into master Oct 29, 2019
@edx-pipeline-bot
Copy link
Contributor

EdX Release Notice: This PR has been deployed to the staging environment in preparation for a release to production on Wednesday, October 30, 2019.

@edx-pipeline-bot
Copy link
Contributor

EdX Release Notice: This PR may have caused e2e tests to fail on Stage. If you're a member of the edX org, please visit #e2e-troubleshooting on Slack to help diagnose the cause of these failures. Otherwise, it is the reviewer's responsibility. E2E tests have failed. https://gocd.tools.edx.org/go/tab/pipeline/history/STAGE_edxapp_M-D

@edx-pipeline-bot
Copy link
Contributor

EdX Release Notice: This PR has been deployed to the production environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants