Skip to content

Juniper upgrade Studio standalone login/logout - #842

Closed
johnbaldwin wants to merge 7 commits into
mainfrom
john/studio-signin
Closed

Juniper upgrade Studio standalone login/logout#842
johnbaldwin wants to merge 7 commits into
mainfrom
john/studio-signin

Conversation

@johnbaldwin

@johnbaldwin johnbaldwin commented Mar 12, 2021

Copy link
Copy Markdown

Studio local login should work now and the signin form should look like Hawthorn.

There may need to be some improvements, but I think it is good enough to get this pushed to Juniper staging

https://appsembler.atlassian.net/browse/RED-1571

Comment thread cms/djangoapps/appsembler/views.py Outdated

@OmarIthawi OmarIthawi left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks @johnbaldwin! I've checked it quickly knowing that it's WIP.

I like that you're working on a simple implementation for this feature set.

I see some external authentication code, which is probably just leftovers from LMS views. I think we should not plan for external auth on this PR.

Please let me know whenever this is ready for review!

@OmarIthawi
OmarIthawi self-requested a review March 14, 2021 12:29
Comment thread cms/djangoapps/appsembler/views.py Outdated

@OmarIthawi OmarIthawi left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@johnbaldwin I've answered your comment and went for a quick review.

Nothing big, but mostly to reply to inline comments and suggest follow up refactoring once the form works.

Comment thread cms/djangoapps/appsembler/views.py Outdated
Comment thread cms/djangoapps/appsembler/views.py Outdated
Comment thread cms/djangoapps/appsembler/views.py Outdated
Comment thread cms/djangoapps/appsembler/views.py Outdated
Comment thread cms/djangoapps/appsembler/views.py Outdated
Comment thread cms/urls.py Outdated
Comment on lines 90 to 91

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I agree! feature flags should help to preserve upstream behaviour in standalone mode.

@johnbaldwin
johnbaldwin marked this pull request as ready for review March 15, 2021 21:23
@johnbaldwin

johnbaldwin commented Mar 15, 2021

Copy link
Copy Markdown
Author

@OmarIthawi Ready for review now. I did a bunch of refactoring. Code much smaller now. Also fixed the login error message so it looks as it was before

@johnbaldwin
johnbaldwin force-pushed the john/studio-signin branch 3 times, most recently from ede8a55 to 11c4d39 Compare March 15, 2021 22:35
Comment thread cms/djangoapps/appsembler/views.py Outdated

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Class based views are the thing to do. Much better than function based views with conditional request.method == 'GET_ME_OUT_OF_HERE' checks

Comment thread cms/djangoapps/appsembler/views.py Outdated

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

At some point, we probably want to get this implemented with Django Forms. Did this as a quick hack to save time

@johnbaldwin johnbaldwin changed the title WIP Juniper upgrade Studio standalone login/logout Juniper upgrade Studio standalone login/logout Mar 15, 2021
Comment thread cms/djangoapps/appsembler/views.py Outdated

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@OmarIthawi This is where all the MTE magic happens. We might want to pull this code out of './openedx/core/djangoapps/user_authn/views/login.py' and make it a Python API instead of pinky-swear private functions.

Comment thread cms/djangoapps/appsembler/views.py Outdated

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@OmarIthawi I think we need to add a check here for authorization to be a studio author/admin

The basic workflow works. Should work well enough for staging.
Absolutely needs a bunch more work for production
Refactored, simplified and cleaned up studio login code
This should be ready for staging work. Should only need the following:

The login 'Sign in here' button needs to be disabled until form
fields are valid (having email in the email field, some text in the
password field

@OmarIthawi OmarIthawi left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I did one more review round for this PR aiming to reduce conflicts in large settings files. It with the Koa upgrade:

  • We do IdP before Koa: It makes this PR easy to revert.
  • We do IdP after Koa: We can do an easier merge.

Please add few basic test cases to ensure that login/logout actually works as expected for correct/incorrect passwords.

from django.utils.decorators import method_decorator

from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
from openedx.core.djangoapps.user_authn.views.login import _get_user_by_email

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I like your suggestion. I think we should do that now, the function wasn't used outside login until now. A good step is to make a function that's more usable and discoverable by other modules:

I think for now we can do the following until we can refactor it better:

# user_authn/api.py
def get_user_from_login_request(request):
    """
    Gets the email from a login POST request. 

    Performs needed checks and handle Multi-Tenant Emails logic.
    """
    return _get_user_by_email(request)

Comment thread cms/urls.py
Comment on lines +44 to 45
# Can we remove this one or maybe use settings to conditionally include
url(r'', include('openedx.core.djangoapps.user_authn.urls_common')),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I read the module comments and I'm thinking that we probably should keep these lines as-is.

"""
Common URLs for User Authentication
Note: The split between urls.py and urls_common.py is hopefully temporary.
For now, this is needed because of difference in CMS and LMS that have
not yet been cleaned up.
This is also home to urls for endpoints that have been consolidated from other djangoapps,
which leads to inconsistent prefixing.
"""

Suggested change
# Can we remove this one or maybe use settings to conditionally include
url(r'', include('openedx.core.djangoapps.user_authn.urls_common')),
url(r'', include('openedx.core.djangoapps.user_authn.urls_common')),

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Ok, I'll remove the comment then

Comment thread cms/urls.py
Comment on lines +89 to 92
# Keeping the original Juniper LMD redirect login code
# TBD if we want to conditionally include via settings so that it is
# disabled on prod
url(r'^signin_redirect_to_lms$', contentstore.views.login_redirect_to_lms, name='login_redirect_to_lms'),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yup, I think we should use settings to disable the redirect view. A basic start would be:

Suggested change
# Keeping the original Juniper LMD redirect login code
# TBD if we want to conditionally include via settings so that it is
# disabled on prod
url(r'^signin_redirect_to_lms$', contentstore.views.login_redirect_to_lms, name='login_redirect_to_lms'),
( # Tahoe: Enable the Hawthorn-like Studio login form
url(r'', include('cms.djangoapps.appsembler.urls'))
if settings.FEATURES['TAHOE_STUDIO_LOGIN'] else
url(r'^signin_redirect_to_lms$', contentstore.views.login_redirect_to_lms, name='login_redirect_to_lms')
),

Comment thread cms/envs/common.py
ENTERPRISE_API_URL = LMS_INTERNAL_ROOT_URL + '/enterprise/api/v1/'
ENTERPRISE_CONSENT_API_URL = LMS_INTERNAL_ROOT_URL + '/consent/api/v1/'
ENTERPRISE_MARKETING_FOOTER_QUERY_PARAMS = {}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

settings files are very large which creates a challenge during merge

Suggested change
# Public domain name of Studio (should be resolvable from the end-user's browser)
CMS_BASE = 'localhost:18010'

Comment thread cms/envs/common.py
Comment on lines +574 to +577
# Public domain name of Studio (should be resolvable from the end-user's browser)
CMS_BASE = 'localhost:18010'
CMS_ROOT_URL = '//localhost:18010'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

To reduce conflicts: please see the lines below.

Suggested change
# Public domain name of Studio (should be resolvable from the end-user's browser)
CMS_BASE = 'localhost:18010'
CMS_ROOT_URL = '//localhost:18010'

Comment thread cms/envs/common.py
Comment on lines +584 to +589
# Original 'LOGIN_URL' renamed to 'LMS_REDIRECT_LOGIN_URL'
# This is a candidate for conditional setings to switch between Studio local
# login and LMS redirection login
LMS_REDIRECT_LOGIN_URL = reverse_lazy('login_redirect_to_lms')
LOGIN_URL = reverse_lazy('login')
FRONTEND_LOGIN_URL = lambda settings: settings.CMS_ROOT_URL + '/login'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reduce the change with clearer # Tahoe: comments so it's more obvious during release merge:

Suggested change
# Original 'LOGIN_URL' renamed to 'LMS_REDIRECT_LOGIN_URL'
# This is a candidate for conditional setings to switch between Studio local
# login and LMS redirection login
LMS_REDIRECT_LOGIN_URL = reverse_lazy('login_redirect_to_lms')
LOGIN_URL = reverse_lazy('login')
FRONTEND_LOGIN_URL = lambda settings: settings.CMS_ROOT_URL + '/login'
LOGOUT_REDIRECT_URL = reverse_lazy('home') # Tahoe: To make `TAHOE_STUDIO_LOGIN` feature work
LOGIN_URL = reverse_lazy('login') # Tahoe: To make `TAHOE_STUDIO_LOGIN` feature work
FRONTEND_LOGIN_URL = lambda settings: settings.LMS_ROOT_URL + '/login'

Comment thread cms/envs/common.py
Comment on lines +591 to 592
FRONTEND_LOGOUT_URL = lambda settings: settings.CMS_ROOT_URL + '/logout/'
derived('FRONTEND_LOGOUT_URL')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Simplify the change with clearer comments for the release merge

Suggested change
FRONTEND_LOGOUT_URL = lambda settings: settings.CMS_ROOT_URL + '/logout/'
derived('FRONTEND_LOGOUT_URL')
# Tahoe: in Juniper.master was `FRONTEND_LOGOUT_URL = lambda settings: settings.LMS_ROOT_URL + '/logout'`
# Tahoe: in Juniper.master was `derived('FRONTEND_LOGOUT_URL')`
FRONTEND_LOGOUT_URL = reverse_lazy('logout') # Tahoe: To make `TAHOE_STUDIO_LOGIN` feature work

Comment thread cms/envs/common.py
Comment on lines +596 to +597
LOGOUT_REDIRECT_URL = reverse_lazy('home')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Added above with # Tahoe: comments

Suggested change
LOGOUT_REDIRECT_URL = reverse_lazy('home')

@@ -0,0 +1,50 @@
<%namespace name='static' file='/static_content.html'/>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This could resolve the test failures.

Suggested change
<%namespace name='static' file='/static_content.html'/>
## mako
<%namespace name='static' file='/static_content.html'/>

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I don't think ## mako has anything to do with test failures.
It appears to be just a Mako comment line. Perhaps it's a hint to the developers?
I see it unevenly used in edx-platform Mako templates
I don't see it mentioned anywhere as some kind of compiler hint or directive in the Mako documentation or on the web. Do you?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I don't see it mentioned anywhere as some kind of compiler hint or directive in the Mako documentation or on the web. Do you?

Yes, it's a compiler hint that is useful in Class Based Views. Not to say that it's required.

Comment thread cms/djangoapps/appsembler/urls.py
This is just to get the tests passing. We'll follow on with adding
confugration so the default state (login direct to LMS) will be back for
the nominal tests
@johnbaldwin
johnbaldwin requested a review from OmarIthawi March 16, 2021 17:22
@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.004%) to 40.155% when pulling 58b1f91 on john/studio-signin into 09601e1 on main.

@johnbaldwin

Copy link
Copy Markdown
Author

Closing. This PR has been superseded by #847

@johnbaldwin
johnbaldwin deleted the john/studio-signin branch March 17, 2021 16:38
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.

3 participants