Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ishahroz/edx-platform int…
Browse files Browse the repository at this point in the history
…o chore-incrementally-upgrade-npm-packages
  • Loading branch information
ishahroz committed Sep 27, 2022
2 parents b5ec358 + 19c6bae commit ece565d
Show file tree
Hide file tree
Showing 86 changed files with 2,133 additions and 602 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/check-for-tutorial-prs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This workflow detects PRs that make changes to lms/templates/dashboard.html
# and only lms/templates/dashboard.html. This is the file that users are
# guided through changing in the Open edX tutorial:
# https://docs.openedx.org/en/latest/developers/quickstarts/first_openedx_pr.html#exercise-update-the-learner-dashboard

# If this is the only file changed in the PR, we comment on the PR congratulating
# the user and letting others know that this is not a community PR in need of
# review. CODEOWNERS will tag a triaging team to provide reviews & ultimately
# close the PR.

name: Check for Tutorial PR
description: Welcome contributors making their first PR from the tutorial
on:
pull_request:
types: [opened]
paths:
- 'lms/templates/dashboard.html'

jobs:
# Provide helpful bot comment
comment:
runs-on: ubuntu-latest
name: provide helpful bot comment
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Comment PR
uses: thollander/actions-comment-pull-request@v1
with:
message: |
Thank you for your pull request! Congratulations on completing the Open edX tutorial! A team member will be by to take a look shortly.
To those watching community pull requests: No need to worry about this one, a tCRIL team member will be taking care of it.
For this PR's author: If this is a PR that is NOT coming from the Open edX tutorial, please comment and let us know to disregard this message.
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 3 additions & 3 deletions cms/djangoapps/contentstore/signals/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from django.db import transaction
from django.dispatch import receiver
from edx_toggles.toggles import SettingToggle
from edx_event_bus_kafka.publishing.event_producer import send_to_event_bus
from edx_event_bus_kafka import get_producer
from opaque_keys.edx.keys import CourseKey
from openedx_events.content_authoring.data import CourseCatalogData, CourseScheduleData
from openedx_events.content_authoring.signals import COURSE_CATALOG_INFO_CHANGED
Expand Down Expand Up @@ -156,9 +156,9 @@ def listen_for_course_catalog_info_changed(sender, signal, **kwargs):
"""
Publish COURSE_CATALOG_INFO_CHANGED signals onto the event bus.
"""
send_to_event_bus(
get_producer().send(
signal=COURSE_CATALOG_INFO_CHANGED, topic='course-catalog-info-changed',
event_key_field='catalog_info.course_key', event_data={'catalog_info': kwargs['catalog_info']}
event_key_field='catalog_info.course_key', event_data={'catalog_info': kwargs['catalog_info']},
)


Expand Down
6 changes: 4 additions & 2 deletions cms/djangoapps/contentstore/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import datetime
import time
from unittest import mock
from urllib.parse import quote_plus

from ddt import data, ddt, unpack
from django.conf import settings
Expand Down Expand Up @@ -174,10 +175,11 @@ def test_signin_and_signup_buttons_index_page(self, allow_account_creation, asse
with mock.patch.dict(settings.FEATURES, {"ALLOW_PUBLIC_ACCOUNT_CREATION": allow_account_creation}):
response = self.client.get(reverse('homepage'))
assertion_method = getattr(self, assertion_method_name)
login_url = quote_plus(f"http://testserver{settings.LOGIN_URL}")
assertion_method(
response,
'<a class="action action-signup" href="{}/register?next=http%3A%2F%2Ftestserver%2F">Sign Up</a>'.format
(settings.LMS_ROOT_URL)
f'<a class="action action-signup" href="{settings.LMS_ROOT_URL}/register'
f'?next={login_url}">Sign Up</a>'
)
self.assertContains(
response,
Expand Down
9 changes: 9 additions & 0 deletions cms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2686,3 +2686,12 @@
COURSE_LIVE_GLOBAL_CREDENTIALS = {}

PERSONALIZED_RECOMMENDATION_COOKIE_NAME = 'edx-user-personalized-recommendation'

######################## Registration ########################

# Social-core setting that allows inactive users to be able to
# log in. The only case it's used is when user registering a new account through the LMS.
INACTIVE_USER_LOGIN = True

# Redirect URL for inactive user. If not set, user will be redirected to /login after the login itself (loop)
INACTIVE_USER_URL = f'http://{CMS_BASE}'
2 changes: 2 additions & 0 deletions cms/envs/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,3 +648,5 @@ def get_env_setting(setting):
"SECRET": ENV_TOKENS.get('BIG_BLUE_BUTTON_GLOBAL_SECRET', None),
"URL": ENV_TOKENS.get('BIG_BLUE_BUTTON_GLOBAL_URL', None),
}

INACTIVE_USER_URL = f'http{"s" if HTTPS == "on" else ""}://{CMS_BASE}'
1 change: 1 addition & 0 deletions cms/static/sass/views/_dashboard.scss
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
.action-primary {
@extend %btn-primary-blue;
@extend %t-action3;
color: $white;
}

// specific - request button
Expand Down
3 changes: 2 additions & 1 deletion cms/templates/howitworks.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<%!
from django.conf import settings
from django.utils.translation import gettext as _
from urllib.parse import quote_plus
from openedx.core.djangolib.markup import HTML, Text
%>

Expand Down Expand Up @@ -162,7 +163,7 @@ <h2 class="sr">${_("Sign Up for {studio_name} Today!").format(studio_name=settin

<ul class="list-actions">
<li class="action-item">
<a href="${settings.FRONTEND_REGISTER_URL}?next=${current_url}" class="action action-primary">${_("Sign Up & Start Making Your {platform_name} Course").format(platform_name=settings.PLATFORM_NAME)}</a>
<a href="${settings.FRONTEND_REGISTER_URL}?next=${quote_plus(request.build_absolute_uri(settings.LOGIN_URL))}" class="action action-primary">${_("Sign Up & Start Making Your {platform_name} Course").format(platform_name=settings.PLATFORM_NAME)}</a>
</li>
<li class="action-item">
<a href="${settings.LOGIN_URL}?next=${current_url}" class="action action-secondary">${_("Already have a {studio_name} Account? Sign In").format(studio_name=settings.STUDIO_SHORT_NAME)}</a>
Expand Down
3 changes: 2 additions & 1 deletion cms/templates/widgets/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.conf import settings
from django.urls import reverse
from django.utils.translation import gettext as _
from urllib.parse import quote_plus
from cms.djangoapps.contentstore import toggles
from cms.djangoapps.contentstore.utils import get_pages_and_resources_url
from openedx.core.djangoapps.discussions.config.waffle import ENABLE_PAGES_AND_RESOURCES_MICROFRONTEND
Expand Down Expand Up @@ -266,7 +267,7 @@ <h2 class="sr-only">${_("Account Navigation")}</h2>
</li>
% if static.get_value('ALLOW_PUBLIC_ACCOUNT_CREATION', settings.FEATURES.get('ALLOW_PUBLIC_ACCOUNT_CREATION')):
<li class="nav-item nav-not-signedin-signup">
<a class="action action-signup" href="${settings.FRONTEND_REGISTER_URL}?next=${current_url}">${_("Sign Up")}</a>
<a class="action action-signup" href="${settings.FRONTEND_REGISTER_URL}?next=${quote_plus(request.build_absolute_uri(settings.LOGIN_URL))}">${_("Sign Up")}</a>
</li>
% endif
<li class="nav-item nav-not-signedin-signin">
Expand Down
4 changes: 2 additions & 2 deletions common/djangoapps/course_modes/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,11 @@ def post(self, request, course_id):
# been configured. However, alternative enrollment workflows have been introduced into the
# system, such as third-party discovery. These workflows result in learners arriving
# directly at this screen, and they will not necessarily be pre-enrolled in the audit mode.
CourseEnrollment.enroll(request.user, course_key, CourseMode.AUDIT)
CourseEnrollment.enroll(request.user, course_key, CourseMode.AUDIT, request=request)
return self._redirect_to_course_or_dashboard(course, course_key, user)

if requested_mode == 'honor':
CourseEnrollment.enroll(user, course_key, mode=requested_mode)
CourseEnrollment.enroll(user, course_key, mode=requested_mode, request=request)
return self._redirect_to_course_or_dashboard(course, course_key, user)

mode_info = allowed_modes[requested_mode]
Expand Down
93 changes: 92 additions & 1 deletion common/djangoapps/student/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from django.db import IntegrityError, ProgrammingError, transaction
from django.urls import NoReverseMatch, reverse
from django.utils.translation import gettext as _
from pytz import UTC
from pytz import UTC, timezone

from common.djangoapps import third_party_auth
from common.djangoapps.course_modes.models import CourseMode
Expand Down Expand Up @@ -50,10 +50,15 @@
from lms.djangoapps.verify_student.models import VerificationDeadline
from lms.djangoapps.verify_student.services import IDVerificationService
from lms.djangoapps.verify_student.utils import is_verification_expiring_soon, verification_for_datetime
from lms.djangoapps.courseware.courses import get_course_date_blocks, get_course_with_access
from lms.djangoapps.courseware.date_summary import TodaysDate
from lms.djangoapps.courseware.context_processor import user_timezone_locale_prefs
from lms.djangoapps.course_home_api.dates.serializers import DateSummarySerializer
from openedx.core.djangoapps.content.block_structure.exceptions import UsageKeyNotInBlockStructure
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
from openedx.core.djangoapps.theming.helpers import get_themes
from openedx.core.djangoapps.user_authn.utils import is_safe_login_or_logout_redirect
from openedx.core.lib.time_zone_utils import get_time_zone_offset
from xmodule.data import CertificatesDisplayBehaviors # lint-amnesty, pylint: disable=wrong-import-order

# Enumeration of per-course verification statuses
Expand Down Expand Up @@ -814,3 +819,89 @@ def user_has_passing_grade_in_course(enrollment):
except AttributeError:
pass
return False


def get_instructors(course_run, marketing_root_url):
"""
Get course instructors.
"""
instructors = []
staff = course_run.get('staff', [])
for instructor in staff:
instructor = {
'name': f"{instructor.get('given_name')} {instructor.get('family_name')}",
'profile_image_url': instructor.get('profile_image_url'),
'organization_name': (instructor.get('position').get('organization_name')
if instructor.get('position') else ''),
'bio_url': f"{marketing_root_url}/bio/{instructor.get('slug')}"
}
instructors.append(instructor)

return instructors


def _prepare_date_block(block, block_date, user_timezone):
"""
Prepare date block which include assignment related data for this date
"""
timezone_offset = get_time_zone_offset(user_timezone, block_date)
block = {
'title': block.get('title', ''),
'assignment_type': block.get('assignment_type', '') or '',
'assignment_count': 0,
'link': block.get('link', ''),
'date': block_date,
'due_date': block_date.strftime("%a, %b %d, %Y"),
'due_time': (f'{block_date.strftime("%H:%M %p")} GMT{timezone_offset}' if block.get('assignment_type') else '')
}
return block


def get_course_dates_for_email(user, course_id, request):
"""
Getting nearest dates from today one would be before today and one
would be after today.
"""
user_timezone_locale = user_timezone_locale_prefs(request)
user_timezone = timezone(user_timezone_locale['user_timezone'] or str(UTC))

course = get_course_with_access(user, 'load', course_id)
date_blocks = get_course_date_blocks(course, user, request, include_access=True, include_past_dates=True)
date_blocks = [block for block in date_blocks if not isinstance(block, TodaysDate)]
blocks = DateSummarySerializer(date_blocks, many=True).data

today = datetime.now(user_timezone)
course_date = {
'title': '',
'assignment_type': '',
'link': '',
'assignment_count': 0,
'date': '',
'due_date': today.strftime("%a, %b %d, %Y"),
'due_time': ''
}
course_date_list = [{**course_date, }, {**course_date, 'date': today}, {**course_date}]
for block in blocks:
block_date = datetime.strptime(block.get('date')[:19], '%Y-%m-%dT%H:%M:%S')
block_date = block_date.replace(tzinfo=UTC)
block_date = block_date.astimezone(user_timezone)

if block_date < today:
if block_date == course_date_list[0]['date'] and block.get('assignment_type'):
course_date_list[0]['assignment_count'] += 1
else:
course_date_list[0].update(_prepare_date_block(block, block_date, user_timezone))

if block_date == today:
if block.get('assignment_type') and course_date_list[1]['assignment_type'] != '':
course_date_list[1]['assignment_count'] += 1
else:
course_date_list[1].update(_prepare_date_block(block, block_date, user_timezone))

if block_date > today:
if block_date == course_date_list[2]['date'] and block.get('assignment_type'):
course_date_list[2]['assignment_count'] += 1
if course_date_list[2]['date'] == '':
course_date_list[2].update(_prepare_date_block(block, block_date, user_timezone))

return course_date_list
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
)
from common.djangoapps.student.signals import UNENROLL_DONE
from common.djangoapps.student.tests.factories import UserFactory
from openedx.core.djangoapps.catalog.tests.factories import CourseRunFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order

Expand Down Expand Up @@ -54,7 +55,8 @@ def assert_unenroll_signal(self, skip_refund=False, **kwargs): # pylint: disab
assert skip_refund
self.signal_fired = True

def test_transfer_students(self):
@patch('openedx.core.djangoapps.catalog.api.get_course_run_details')
def test_transfer_students(self, mock_get_course_run_details):
"""
Verify the transfer student command works as intended.
"""
Expand All @@ -65,6 +67,12 @@ def test_transfer_students(self):
# Original Course
original_course_location = locator.CourseLocator('Org0', 'Course0', 'Run0')
course = self._create_course(original_course_location)

course_run = CourseRunFactory.create(key=course.id)
course_run['min_effort'] = 1
course_run['enrollment_count'] = 12345

mock_get_course_run_details.return_value = course_run
# Enroll the student in 'verified'
CourseEnrollment.enroll(student, course.id, mode='verified')

Expand Down
Loading

0 comments on commit ece565d

Please sign in to comment.