Skip to content

Commit

Permalink
fix: rebasing
Browse files Browse the repository at this point in the history
  • Loading branch information
rpenido committed Feb 15, 2024
1 parent f637076 commit 3cf462f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
4 changes: 2 additions & 2 deletions openedx/core/djangoapps/content_tagging/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import openedx_tagging.core.tagging.api as oel_tagging
from django.db.models import Exists, OuterRef, Q, QuerySet
from opaque_keys.edx.keys import CourseKey, UsageKey
from opaque_keys.edx.keys import CourseKey
from opaque_keys.edx.locator import LibraryLocatorV2
from openedx_tagging.core.tagging.models import ObjectTag, Taxonomy
from organizations.models import Organization
Expand Down Expand Up @@ -149,7 +149,7 @@ def get_all_object_tags(

# There is no API method in oel_tagging.api that does this yet,
# so for now we have to build the ORM query directly.
all_object_tags = list(ContentObjectTag.objects.filter(
all_object_tags = list(ObjectTag.objects.filter(
Q(object_id__startswith=block_id_prefix) | Q(object_id=content_key),
Q(tag__isnull=False, tag__taxonomy__isnull=False),
).select_related("tag__taxonomy"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import openedx.core.djangoapps.content_libraries.api as library_api
from openedx.core.djangoapps.content_libraries.api import LibraryXBlockMetadata
from xmodule.modulestore.django import ModuleStore, modulestore
from xmodule.modulestore.django import modulestore

from ...types import ObjectTagByObjectIdDict, ObjectTagByTaxonomyIdDict

Expand Down
12 changes: 6 additions & 6 deletions openedx/core/djangoapps/content_tagging/rest_api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from typing import Iterator

from django.http import StreamingHttpResponse
from opaque_keys import InvalidKeyError
from opaque_keys.edx.keys import CourseKey
from opaque_keys.edx.keys import CourseKey, UsageKey
from opaque_keys.edx.locator import LibraryLocatorV2
from openedx_tagging.core.tagging import rules as oel_tagging_rules
from openedx_tagging.core.tagging.rest_api.v1.views import ObjectTagView, TaxonomyView
from rest_framework import status
Expand All @@ -28,6 +28,7 @@
set_taxonomy_orgs
)
from ...rules import get_admin_orgs
from ...utils import get_content_key_from_string
from .filters import ObjectTagTaxonomyOrgFilterBackend, UserOrgFilterBackend
from .objecttag_export_helpers import build_object_tree_with_objecttags, iterate_with_level
from .serializers import TaxonomyOrgListQueryParamsSerializer, TaxonomyOrgSerializer, TaxonomyUpdateOrgBodySerializer
Expand Down Expand Up @@ -198,10 +199,9 @@ def _generate_csv_rows() -> Iterator[str]:

object_id: str = kwargs.get('context_id', None)

try:
content_key = CourseKey.from_string(object_id)
except InvalidKeyError as e:
raise ValidationError("context_id is not a valid course key.") from e
content_key = get_content_key_from_string(object_id)
if isinstance(content_key, UsageKey):
raise ValidationError("The object_id must be a CourseKey or a LibraryLocatorV2.")

# Check if the user has permission to view object tags for this object_id
try:
Expand Down
32 changes: 22 additions & 10 deletions openedx/core/djangoapps/content_tagging/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,38 +346,50 @@ def setUp(self):
# Library tags and library contents need a unique block_id that is persisted along test runs
self.block_sufix = str(round(time.time() * 1000))

self.library_tags = api.tag_content_object(
object_key=LibraryLocatorV2.from_string(f"lib:orgA:lib_{self.block_sufix}"),
api.tag_object(
object_id=f"lib:orgA:lib_{self.block_sufix}",
taxonomy=self.taxonomy_2,
tags=['Tag 2.1'],
)
self.library_tags = api.get_object_tags(f"lib:orgA:lib_{self.block_sufix}")

self.problem1_tags = api.tag_content_object(
object_key=UsageKey.from_string(f"lb:orgA:lib_{self.block_sufix}:problem:problem1_{self.block_sufix}"),
api.tag_object(
object_id=f"lb:orgA:lib_{self.block_sufix}:problem:problem1_{self.block_sufix}",
taxonomy=self.taxonomy_1,
tags=['Tag 1.1'],
)
self.problem1_tags = api.get_object_tags(
f"lb:orgA:lib_{self.block_sufix}:problem:problem1_{self.block_sufix}"
)

self.library_html_tags1 = api.tag_content_object(
object_key=UsageKey.from_string(f"lb:orgA:lib_{self.block_sufix}:html:html_{self.block_sufix}"),
api.tag_object(
object_id=f"lb:orgA:lib_{self.block_sufix}:html:html_{self.block_sufix}",
taxonomy=self.taxonomy_1,
tags=['Tag 1.2'],
)
self.library_html_tags1 = api.get_object_tags(
object_id=f"lb:orgA:lib_{self.block_sufix}:html:html_{self.block_sufix}",
taxonomy_id=self.taxonomy_1.id,
)

self.library_html_tags2 = api.tag_content_object(
object_key=UsageKey.from_string(f"lb:orgA:lib_{self.block_sufix}:html:html_{self.block_sufix}"),
api.tag_object(
object_id=f"lb:orgA:lib_{self.block_sufix}:html:html_{self.block_sufix}",
taxonomy=self.taxonomy_2,
tags=['Tag 2.2'],
)
self.library_html_tags2 = api.get_object_tags(
object_id=f"lb:orgA:lib_{self.block_sufix}:html:html_{self.block_sufix}",
taxonomy_id=self.taxonomy_2.id,
)

# Create "deleted" object tags, which will be omitted from the results.
for object_id in (
f"lib:orgA:lib_{self.block_sufix}",
f"lb:orgA:lib_{self.block_sufix}:problem:problem1_{self.block_sufix}",
f"lb:orgA:lib_{self.block_sufix}:html:html_{self.block_sufix}",
):
ContentObjectTag.objects.create(
object_id=str(object_id),
ObjectTag.objects.create(
object_id=object_id,
taxonomy=None,
tag=None,
_value="deleted tag",
Expand Down

0 comments on commit 3cf462f

Please sign in to comment.