-
Notifications
You must be signed in to change notification settings - Fork 4.2k
[FC-0049] Handle tags when importing/exporting courses #34356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 23 commits
de3decb
8056ea4
0c74ae2
82dab62
2f931b3
07db758
2ee29e5
f7e3260
abf7b06
97571af
9bba25c
d143b4f
476cf95
1a3fbb6
70d1d64
31eab30
297e212
4534de0
1a8b8b6
5435985
fdf7bc7
8e8a595
bda8da2
a271fde
90d6572
c80f6f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,7 @@ | |
| from common.djangoapps.util.views import ensure_valid_course_key | ||
| from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order | ||
|
|
||
| from openedx.core.djangoapps.content_tagging.auth import has_view_object_tags_access | ||
| from ..storage import course_import_export_storage | ||
| from ..tasks import CourseExportTask, CourseImportTask, export_olx, import_olx | ||
| from ..toggles import use_new_export_page, use_new_import_page | ||
|
|
@@ -343,6 +344,11 @@ def export_handler(request, course_key_string): | |
| requested_format = request.GET.get('_accept', request.META.get('HTTP_ACCEPT', 'text/html')) | ||
|
|
||
| if request.method == 'POST': | ||
| if not has_view_object_tags_access(request.user, str(course_key)): | ||
| raise PermissionDenied( | ||
| "You do not have permission to view object tags for this object_id." | ||
|
||
| ) | ||
|
|
||
| export_olx.delay(request.user.id, course_key_string, request.LANGUAGE_CODE) | ||
| return JsonResponse({'ExportStatus': 1}) | ||
| elif 'text/html' in requested_format: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -170,10 +170,10 @@ def _tags_for_content_object(object_id: UsageKey | LearningContextKey) -> dict: | |
| } | ||
| for obj_tag in all_tags: | ||
| # Add the taxonomy name: | ||
| if obj_tag.name not in result[Fields.tags_taxonomy]: | ||
| result[Fields.tags_taxonomy].append(obj_tag.name) | ||
| # Taxonomy name plus each level of tags, in a list: | ||
| parts = [obj_tag.name] + obj_tag.get_lineage() # e.g. ["Location", "North America", "Canada", "Vancouver"] | ||
| if obj_tag.taxonomy.name not in result[Fields.tags_taxonomy]: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bradenmacdonald On openedx/openedx-learning#172 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's right. Here should be the taxonomy name only. Thanks :) |
||
| result[Fields.tags_taxonomy].append(obj_tag.taxonomy.name) | ||
| # Taxonomy name plus each level of tags, in a list: # e.g. ["Location", "North America", "Canada", "Vancouver"] | ||
| parts = [obj_tag.taxonomy.name] + obj_tag.get_lineage() | ||
| parts = [part.replace(" > ", " _ ") for part in parts] # Escape our separator. | ||
| # Now we build each level (tags.level0, tags.level1, etc.) as applicable. | ||
| # We have a hard-coded limit of 4 levels of tags for now (see Fields.tags above). | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| """ | ||
| Functions to validate the access in content tagging actions | ||
| """ | ||
|
|
||
|
|
||
| from openedx_tagging.core.tagging import rules as oel_tagging_rules | ||
|
|
||
|
|
||
| def has_view_object_tags_access(user, object_id): | ||
| return user.has_perm( | ||
| "oel_tagging.view_objecttag", | ||
| # The obj arg expects a model, but we are passing an object | ||
| oel_tagging_rules.ObjectTagPermissionItem(taxonomy=None, object_id=object_id), # type: ignore[arg-type] | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use snake case:
with_tagsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated here