diff --git a/cypress/e2e/8.Login/login.cy.js b/cypress/e2e/8.Login/login.cy.js index 047dbe1591..fdeef63854 100644 --- a/cypress/e2e/8.Login/login.cy.js +++ b/cypress/e2e/8.Login/login.cy.js @@ -18,13 +18,13 @@ describe('Log In Feature: Test Instructor Login', () => { cy.get('.choose-course').should('contain', 'Sample Course'); cy.get('.choose-course').click(); cy.title().should('contain', 'Sample Course'); - cy.visit('/accounts/logout/?next=/'); + cy.get('.sign-out').click(); cy.title().should('contain', 'Splash'); }); }); describe('Log In Feature: Test Invalid login', () => { - it('should not log in', () => { + it('should not log in with invalid credentials', () => { cy.visit('/accounts/login/'); cy.title().should('contain', 'Login'); cy.get('#cu-privacy-notice-button').click(); @@ -36,7 +36,7 @@ describe('Log In Feature: Test Invalid login', () => { }); describe('Log In Feature: Test Student Login', () => { - it('should test student login', () => { + it('should log in as student_one', () => { cy.visit('/accounts/login/'); cy.title().should('contain', 'Login'); cy.get('#cu-privacy-notice-button').click(); @@ -45,13 +45,13 @@ describe('Log In Feature: Test Student Login', () => { cy.login('student_one', 'test'); cy.visit('/'); cy.title().should('contain', 'Sample Course'); - cy.visit('/accounts/logout/?next=/'); + cy.get('.sign-out').click(); cy.title().should('contain', 'Splash'); }); }); describe('Log In Feature: Test Switch Course feature', () => { - it('should test student login', () => { + it('should log in as student_one and see courses', () => { cy.visit('/accounts/login/'); cy.title().should('contain', 'Login'); cy.get('#cu-privacy-notice-button').click(); diff --git a/mediathread/main/middleware.py b/mediathread/main/middleware.py index 03ace3feac..8ec98cb900 100644 --- a/mediathread/main/middleware.py +++ b/mediathread/main/middleware.py @@ -8,7 +8,7 @@ class MethCourseManagerMiddleware(CourseManagerMiddleware): def set_course(self, course, request): - request.session[SESSION_KEY] = course + request.session[SESSION_KEY] = course.pk request.course = course self.decorate_request(request, course) diff --git a/mediathread/main/views.py b/mediathread/main/views.py index a1f9545623..49f77e6588 100644 --- a/mediathread/main/views.py +++ b/mediathread/main/views.py @@ -129,7 +129,7 @@ def dispatch(self, request, *args, **kwargs): # Set the course in the session cookie. This is legacy # functionality, but still used by the Mediathread collection # browser extension. - request.session[SESSION_KEY] = course + request.session[SESSION_KEY] = course.pk return super(CourseDetailView, self).dispatch(request, *args, **kwargs) @@ -393,7 +393,16 @@ def get_initial(self): initial['issue_date'] = timezone.now() if SESSION_KEY in self.request.session: - initial['course'] = self.request.session[SESSION_KEY].title + course_pk = self.request.session[SESSION_KEY] + course = None + + try: + course = Course.objects.get(pk=course_pk) + except Course.DoesNotExist: + pass + + if course: + initial['course'] = course.title return initial @@ -467,7 +476,16 @@ def get(self, request, *args, **kwargs): course_name = '' if SESSION_KEY in request.session: - course_name = request.session[SESSION_KEY].title + course_pk = self.request.session[SESSION_KEY] + course = None + + try: + course = Course.objects.get(pk=course_pk) + except Course.DoesNotExist: + pass + + if course: + course_name = course.title d = { 'logged_in': logged_in, diff --git a/mediathread/settings_shared.py b/mediathread/settings_shared.py index 2ff333552b..87daf2b6c7 100644 --- a/mediathread/settings_shared.py +++ b/mediathread/settings_shared.py @@ -180,8 +180,6 @@ DEFAULT_COLLABORATION_POLICY = 'InstructorManaged' -SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer' - ACCOUNT_ACTIVATION_DAYS = 7 CORS_ALLOW_ALL_ORIGINS = True diff --git a/mediathread/templates/navbar.html b/mediathread/templates/navbar.html index b1d3a148c2..a897b465a7 100644 --- a/mediathread/templates/navbar.html +++ b/mediathread/templates/navbar.html @@ -111,10 +111,13 @@