Skip to content

Commit 3e17ba4

Browse files
authored
Revert "Sync opencraft-release/palm.1 with Upstream 20230728-1690565702 (#562)" (#565)
This reverts commit dcf72e1.
1 parent dcf72e1 commit 3e17ba4

File tree

8 files changed

+22
-147
lines changed

8 files changed

+22
-147
lines changed

cms/djangoapps/contentstore/views/course.py

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@
5353
CourseInstructorRole,
5454
CourseStaffRole,
5555
GlobalStaff,
56-
UserBasedRole,
57-
OrgStaffRole
56+
UserBasedRole
5857
)
5958
from common.djangoapps.util.course import get_link_for_about_page
6059
from common.djangoapps.util.date_utils import get_default_time_display
@@ -600,7 +599,6 @@ def format_in_process_course_view(uca):
600599
'optimization_enabled': optimization_enabled,
601600
'active_tab': 'courses',
602601
'allowed_organizations': get_allowed_organizations(user),
603-
'allowed_organizations_for_libraries': get_allowed_organizations_for_libraries(user),
604602
'can_create_organizations': user_can_create_organizations(user),
605603
})
606604

@@ -628,7 +626,6 @@ def library_listing(request):
628626
'split_studio_home': split_library_view_on_dashboard(),
629627
'active_tab': 'libraries',
630628
'allowed_organizations': get_allowed_organizations(request.user),
631-
'allowed_organizations_for_libraries': get_allowed_organizations_for_libraries(request.user),
632629
'can_create_organizations': user_can_create_organizations(request.user),
633630
}
634631
return render_to_response('index.html', data)
@@ -1963,37 +1960,13 @@ def get_allowed_organizations(user):
19631960
return []
19641961

19651962

1966-
def get_allowed_organizations_for_libraries(user):
1967-
"""
1968-
Helper method for returning the list of organizations for which the user is allowed to create libraries.
1969-
"""
1970-
if settings.FEATURES.get('ENABLE_ORGANIZATION_STAFF_ACCESS_FOR_CONTENT_LIBRARIES', False):
1971-
return get_organizations_for_non_course_creators(user)
1972-
elif settings.FEATURES.get('ENABLE_CREATOR_GROUP', False):
1973-
return get_organizations(user)
1974-
else:
1975-
return []
1976-
1977-
19781963
def user_can_create_organizations(user):
19791964
"""
19801965
Returns True if the user can create organizations.
19811966
"""
19821967
return user.is_staff or not settings.FEATURES.get('ENABLE_CREATOR_GROUP', False)
19831968

19841969

1985-
def get_organizations_for_non_course_creators(user):
1986-
"""
1987-
Returns the list of organizations which the user is a staff member of, as a list of strings.
1988-
"""
1989-
orgs_map = set()
1990-
orgs = OrgStaffRole().get_orgs_for_user(user)
1991-
# deduplicate
1992-
for org in orgs:
1993-
orgs_map.add(org)
1994-
return list(orgs_map)
1995-
1996-
19971970
def get_organizations(user):
19981971
"""
19991972
Returns the list of organizations for which the user is allowed to create courses.

cms/djangoapps/contentstore/views/library.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,14 @@
3535
from common.djangoapps.student.roles import (
3636
CourseInstructorRole,
3737
CourseStaffRole,
38-
LibraryUserRole,
39-
OrgStaffRole,
40-
UserBasedRole,
38+
LibraryUserRole
4139
)
4240
from common.djangoapps.util.json_request import JsonResponse, JsonResponseBadRequest, expect_json
4341

4442
from ..config.waffle import REDIRECT_TO_LIBRARY_AUTHORING_MICROFRONTEND
4543
from ..utils import add_instructor, reverse_library_url
4644
from .component import CONTAINER_TEMPLATES, get_component_templates
45+
from .helpers import is_content_creator
4746
from .block import create_xblock_info
4847
from .user import user_with_role
4948

@@ -80,11 +79,10 @@ def user_can_create_library(user, org=None):
8079
elif user.is_staff:
8180
return True
8281
elif settings.FEATURES.get('ENABLE_CREATOR_GROUP', False):
83-
is_course_creator = get_course_creator_status(user) == 'granted'
84-
has_org_staff_role = OrgStaffRole().get_orgs_for_user(user).exists()
85-
has_course_staff_role = UserBasedRole(user=user, role=CourseStaffRole.ROLE).courses_with_role().exists()
86-
87-
return is_course_creator or has_org_staff_role or has_course_staff_role
82+
has_course_creator_role = True
83+
if org:
84+
has_course_creator_role = is_content_creator(user, org)
85+
return get_course_creator_status(user) == 'granted' and has_course_creator_role
8886
else:
8987
# EDUCATOR-1924: DISABLE_LIBRARY_CREATION overrides DISABLE_COURSE_CREATION, if present.
9088
disable_library_creation = settings.FEATURES.get('DISABLE_LIBRARY_CREATION', None)

cms/djangoapps/contentstore/views/tests/test_course_index.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -423,13 +423,13 @@ def check_index_page(self, separate_archived_courses, org):
423423

424424
@ddt.data(
425425
# Staff user has course staff access
426-
(True, 'staff', None, 0, 21),
427-
(False, 'staff', None, 0, 21),
426+
(True, 'staff', None, 0, 20),
427+
(False, 'staff', None, 0, 20),
428428
# Base user has global staff access
429-
(True, 'user', ORG, 2, 21),
430-
(False, 'user', ORG, 2, 21),
431-
(True, 'user', None, 2, 21),
432-
(False, 'user', None, 2, 21),
429+
(True, 'user', ORG, 2, 20),
430+
(False, 'user', ORG, 2, 20),
431+
(True, 'user', None, 2, 20),
432+
(False, 'user', None, 2, 20),
433433
)
434434
@ddt.unpack
435435
def test_separate_archived_courses(self, separate_archived_courses, username, org, mongo_queries, sql_queries):

cms/djangoapps/contentstore/views/tests/test_library.py

Lines changed: 6 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,11 @@
1919
from cms.djangoapps.contentstore.tests.utils import AjaxEnabledTestClient, CourseTestCase, parse_json
2020
from cms.djangoapps.contentstore.utils import reverse_course_url, reverse_library_url
2121
from cms.djangoapps.course_creators.views import add_user_with_status_granted as grant_course_creator_status
22-
from common.djangoapps.student.roles import LibraryUserRole, CourseStaffRole
22+
from common.djangoapps.student.roles import LibraryUserRole
2323
from xmodule.modulestore.tests.factories import LibraryFactory # lint-amnesty, pylint: disable=wrong-import-order
24-
from cms.djangoapps.course_creators.models import CourseCreator
25-
26-
from common.djangoapps.student import auth
2724

2825
from ..component import get_component_templates
2926
from ..library import user_can_create_library
30-
from ..course import get_allowed_organizations_for_libraries
3127

3228
LIBRARY_REST_URL = '/library/' # URL for GET/POST requests involving libraries
3329

@@ -55,51 +51,26 @@ def setUp(self):
5551
######################################################
5652
# Tests for /library/ - list and create libraries:
5753

58-
# When libraries are disabled, nobody can create libraries
5954
@mock.patch("cms.djangoapps.contentstore.views.library.LIBRARIES_ENABLED", False)
6055
def test_library_creator_status_libraries_not_enabled(self):
6156
_, nostaff_user = self.create_non_staff_authed_user_client()
6257
self.assertEqual(user_can_create_library(nostaff_user), False)
6358

64-
# When creator group is disabled, non-staff users can create libraries
65-
@mock.patch("cms.djangoapps.contentstore.views.library.LIBRARIES_ENABLED", True)
66-
def test_library_creator_status_with_no_course_creator_role(self):
67-
_, nostaff_user = self.create_non_staff_authed_user_client()
68-
self.assertEqual(user_can_create_library(nostaff_user), True)
69-
70-
# When creator group is enabled, Non staff users cannot create libraries
71-
@mock.patch("cms.djangoapps.contentstore.views.library.LIBRARIES_ENABLED", True)
72-
def test_library_creator_status_for_enabled_creator_group_setting_for_non_staff_users(self):
73-
_, nostaff_user = self.create_non_staff_authed_user_client()
74-
with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}):
75-
self.assertEqual(user_can_create_library(nostaff_user), False)
76-
77-
# Global staff can create libraries
7859
@mock.patch("cms.djangoapps.contentstore.views.library.LIBRARIES_ENABLED", True)
7960
def test_library_creator_status_with_is_staff_user(self):
8061
self.assertEqual(user_can_create_library(self.user), True)
8162

82-
# When creator groups are enabled, global staff can create libraries
83-
@mock.patch("cms.djangoapps.contentstore.views.library.LIBRARIES_ENABLED", True)
84-
def test_library_creator_status_for_enabled_creator_group_setting_with_is_staff_user(self):
85-
with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}):
86-
self.assertEqual(user_can_create_library(self.user), True)
87-
88-
# When creator groups are enabled, course creators can create libraries
8963
@mock.patch("cms.djangoapps.contentstore.views.library.LIBRARIES_ENABLED", True)
90-
def test_library_creator_status_with_course_creator_role_for_enabled_creator_group_setting(self):
64+
def test_library_creator_status_with_course_creator_role(self):
9165
_, nostaff_user = self.create_non_staff_authed_user_client()
9266
with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}):
9367
grant_course_creator_status(self.user, nostaff_user)
9468
self.assertEqual(user_can_create_library(nostaff_user), True)
9569

96-
# When creator groups are enabled, course staff members can create libraries
9770
@mock.patch("cms.djangoapps.contentstore.views.library.LIBRARIES_ENABLED", True)
98-
def test_library_creator_status_with_course_staff_role_for_enabled_creator_group_setting(self):
71+
def test_library_creator_status_with_no_course_creator_role(self):
9972
_, nostaff_user = self.create_non_staff_authed_user_client()
100-
with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}):
101-
auth.add_users(self.user, CourseStaffRole(self.course.id), nostaff_user)
102-
self.assertEqual(user_can_create_library(nostaff_user), True)
73+
self.assertEqual(user_can_create_library(nostaff_user), True)
10374

10475
@ddt.data(
10576
(False, False, True),
@@ -217,9 +188,9 @@ def test_lib_create_permission_no_course_creator_role_and_no_course_creator_grou
217188
self.assertEqual(response.status_code, 200)
218189

219190
@patch.dict('django.conf.settings.FEATURES', {'ENABLE_CREATOR_GROUP': True})
220-
def test_lib_create_permission_no_course_creator_role_and_no_course_creator_group_and_no_course_staff_role(self):
191+
def test_lib_create_permission_no_course_creator_role_and_course_creator_group(self):
221192
"""
222-
Users who are not given course creator roles or course staff role should not be able to create libraries
193+
Users who are not given course creator roles should not be able to create libraries
223194
if ENABLE_CREATOR_GROUP is enabled.
224195
"""
225196
self.client.logout()
@@ -230,23 +201,6 @@ def test_lib_create_permission_no_course_creator_role_and_no_course_creator_grou
230201
})
231202
self.assertEqual(response.status_code, 403)
232203

233-
@patch.dict('django.conf.settings.FEATURES', {'ENABLE_CREATOR_GROUP': True})
234-
def test_lib_create_permission_course_staff_role(self):
235-
"""
236-
Users who are staff on any existing course should able to create libraries
237-
if ENABLE_CREATOR_GROUP is enabled.
238-
"""
239-
self.client.logout()
240-
ns_user, password = self.create_non_staff_user()
241-
self.client.login(username=ns_user.username, password=password)
242-
243-
auth.add_users(self.user, CourseStaffRole(self.course.id), ns_user)
244-
self.assertTrue(auth.user_has_role(ns_user, CourseStaffRole(self.course.id)))
245-
response = self.client.ajax_post(LIBRARY_REST_URL, {
246-
'org': 'org', 'library': 'lib', 'display_name': "New Library",
247-
})
248-
self.assertEqual(response.status_code, 200)
249-
250204
@ddt.data(
251205
{},
252206
{'org': 'org'},
@@ -451,41 +405,3 @@ def test_component_limits(self):
451405
response = self.client.ajax_post(reverse('xblock_handler'), data)
452406
self.assertEqual(response.status_code, 400)
453407
self.assertIn('cannot have more than 1 component', parse_json(response)['error'])
454-
455-
def test_allowed_organizations_for_library(self):
456-
"""
457-
Test the different organizations that a user can select for creating a library, depending
458-
on Feature Flags and on user role.
459-
With organization staff access enabled, a user should be able to select organizations they
460-
are a staff member of. Else, with creator groups enabled, the user should be able to select
461-
organizations they are course creator for.
462-
"""
463-
course_creator = CourseCreator.objects.create(user=self.user, all_organizations=True)
464-
with patch('cms.djangoapps.course_creators.models.CourseCreator.objects.filter') as mock_filter:
465-
mock_filter.return_value.first.return_value = course_creator
466-
with patch('organizations.models.Organization.objects.all') as mock_all:
467-
mock_all.return_value.values_list.return_value = ['org1', 'org2']
468-
with patch('common.djangoapps.student.roles.OrgStaffRole.get_orgs_for_user') as get_user_orgs:
469-
get_user_orgs.return_value = ['org3']
470-
# Call the method under test
471-
with mock.patch.dict(
472-
'django.conf.settings.FEATURES',
473-
{"ENABLE_ORGANIZATION_STAFF_ACCESS_FOR_CONTENT_LIBRARIES": False}
474-
):
475-
with mock.patch.dict(
476-
'django.conf.settings.FEATURES',
477-
{"ENABLE_CREATOR_GROUP": False}
478-
):
479-
organizations = get_allowed_organizations_for_libraries(self.user)
480-
# Assert that the method returned the expected value
481-
self.assertEqual(organizations, [])
482-
with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}):
483-
organizations = get_allowed_organizations_for_libraries(self.user)
484-
# Assert that the method returned the expected value
485-
self.assertEqual(organizations, ['org1', 'org2'])
486-
with mock.patch.dict(
487-
'django.conf.settings.FEATURES',
488-
{"ENABLE_ORGANIZATION_STAFF_ACCESS_FOR_CONTENT_LIBRARIES": True}
489-
):
490-
organizations = get_allowed_organizations_for_libraries(self.user)
491-
self.assertEqual(organizations, ['org3'])

cms/envs/common.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,6 @@
220220
# an Open edX admin has added them to the course creator group.
221221
'ENABLE_CREATOR_GROUP': True,
222222

223-
# If set to True, organization staff members can create libraries for their specific
224-
# organization and no other organizations. They do not need to be course creators,
225-
# even when ENABLE_CREATOR_GROUP is True.
226-
'ENABLE_ORGANIZATION_STAFF_ACCESS_FOR_CONTENT_LIBRARIES': True,
227-
228223
# Turn off account locking if failed login attempts exceeds a limit
229224
'ENABLE_MAX_FAILED_LOGIN_ATTEMPTS': False,
230225

cms/envs/devstack.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,7 @@ def should_show_debug_toolbar(request): # lint-amnesty, pylint: disable=missing
156156
FEATURES['CERTIFICATES_HTML_VIEW'] = True
157157

158158
########################## AUTHOR PERMISSION #######################
159-
FEATURES['ENABLE_CREATOR_GROUP'] = True
160-
161-
########################## Library creation organizations restriction #######################
162-
FEATURES['ENABLE_ORGANIZATION_STAFF_ACCESS_FOR_CONTENT_LIBRARIES'] = True
159+
FEATURES['ENABLE_CREATOR_GROUP'] = False
163160

164161
################### FRONTEND APPLICATION PUBLISHER URL ###################
165162
FEATURES['FRONTEND_APP_PUBLISHER_URL'] = 'http://localhost:18400'

cms/templates/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ <h3 class="title">${_("Create a New Library")}</h3>
167167
<input class="new-library-org" id="new-library-org" type="text" name="new-library-org" required placeholder="${_('e.g. UniversityX or OrganizationX')}" aria-describedby="tip-new-library-org tip-error-new-library-org" />
168168
% else:
169169
<select class="new-library-org" id="new-library-org" name="new-library-org" required aria-describedby="tip-new-library-org tip-error-new-library-org">
170-
% for org in allowed_organizations_for_libraries:
170+
% for org in allowed_organizations:
171171
<option value="${org}">${org}</option>
172172
% endfor
173173
</select>

lms/templates/wiki/base.html

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,11 @@
7676
{% block wiki_breadcrumbs %}{% endblock %}
7777

7878
{% if messages %}
79-
{% comment %}
80-
The message is not actually safe, but StatusAlertRenderer uses react which adds escaping,
81-
so marking as safe keeps the message from being double-escaped.
82-
{% endcomment %}
8379
{% for message in messages %}
8480
<div id="alert_stat_bar"></div>
8581
<script type="text/javascript">
8682
new StatusAlertRenderer(
87-
"{{ message|safe }}",
83+
"{{ message }}",
8884
"#alert_stat_bar",
8985
".nav nav-tabs"
9086
);

0 commit comments

Comments
 (0)