Skip to content
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

[do not merge] restricted runs modeling spike (again) #953

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions enterprise_catalog/apps/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
from django.urls import include, path

from enterprise_catalog.apps.api.v1 import urls as v1_urls
from enterprise_catalog.apps.api.v2 import urls as v2_urls


app_name = 'api'
urlpatterns = [
path('v1/', include(v1_urls)),
path('v2/', include(v2_urls)),
]
Empty file.
37 changes: 37 additions & 0 deletions enterprise_catalog/apps/api/v2/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""
URL definitions for enterprise catalog API version 2.
"""
from django.urls import path, re_path
from rest_framework.routers import DefaultRouter

from enterprise_catalog.apps.api.v2.views.enterprise_catalog_contains_content_items import (
EnterpriseCatalogContainsContentItemsV2,
)
from enterprise_catalog.apps.api.v2.views.enterprise_catalog_get_content_metadata import (
EnterpriseCatalogGetContentMetadataV2,
)
from enterprise_catalog.apps.api.v2.views.enterprise_customer import (
EnterpriseCustomerViewSetV2,
)


app_name = 'v2'

router = DefaultRouter()
router.register(r'enterprise-catalogs', EnterpriseCatalogContainsContentItemsV2, basename='enterprise-catalog-content-v2')
router.register(r'enterprise-customer', EnterpriseCustomerViewSetV2, basename='enterprise-customer-v2')

urlpatterns = [
re_path(
r'^enterprise-catalogs/(?P<uuid>[\S]+)/get_content_metadata',
EnterpriseCatalogGetContentMetadataV2.as_view({'get': 'get'}),
name='get-content-metadata-v2'
),
path(
'enterprise-customer/<enterprise_uuid>/content-metadata/<content_identifier>/',
EnterpriseCustomerViewSetV2.as_view({'get': 'content_metadata'}),
name='customer-content-metadata-retrieve-v2'
),
]

urlpatterns += router.urls
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from enterprise_catalog.apps.api.v1.views.enterprise_catalog_contains_content_items import EnterpriseCatalogContainsContentItems


class EnterpriseCatalogContainsContentItemsV2(EnterpriseCatalogContainsContentItems):
"""
View to determine if an enterprise catalog contains certain content
"""
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from enterprise_catalog.apps.api.v1.views.enterprise_catalog_get_content_metadata import EnterpriseCatalogGetContentMetadata


class EnterpriseCatalogGetContentMetadataV2(EnterpriseCatalogGetContentMetadata):
"""
View for retrieving all the content metadata associated with a catalog.
"""
def get_queryset(self, **kwargs):
"""
Returns all of the json of content metadata associated with the catalog.
"""
# Avoids ordering the content metadata by any field on that model to avoid using a temporary table / filesort
queryset = self.enterprise_catalog.content_metadata_with_restricted
content_filter = kwargs.get('content_keys_filter')
if content_filter:
queryset = self.enterprise_catalog.get_matching_content(content_keys=content_filter, include_restricted=True)

return queryset.order_by('catalog_queries')
10 changes: 10 additions & 0 deletions enterprise_catalog/apps/api/v2/views/enterprise_customer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from enterprise_catalog.apps.api.v1.views.enterprise_customer import EnterpriseCustomerViewSet


class EnterpriseCustomerViewSetV2(EnterpriseCustomerViewSet):
"""
Viewset for operations on enterprise customers.

Although we don't have a specific EnterpriseCustomer model, this viewset handles operations that use an enterprise
identifier to perform operations on their associated catalogs, etc.
"""
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Generated by Django 4.2.16 on 2024-10-01 19:40

import collections
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import jsonfield.encoder
import jsonfield.fields
import model_utils.fields


class Migration(migrations.Migration):

dependencies = [
('catalog', '0039_alter_catalogquery_unique_together_and_more'),
]

operations = [
migrations.CreateModel(
name='RestrictedCourseMetadata',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')),
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')),
('content_uuid', models.UUIDField(blank=True, help_text='The UUID that represents a piece of content. This value is usually a secondary identifier to content_key in the enterprise environment.', null=True, verbose_name='Content UUID')),
('content_type', models.CharField(choices=[('course', 'Course'), ('courserun', 'Course Run'), ('program', 'Program'), ('learnerpathway', 'Learner Pathway')], max_length=255)),
('parent_content_key', models.CharField(blank=True, db_index=True, help_text="The key represents this content's parent. For example for course_runs content their parent course key.", max_length=255, null=True)),
('_json_metadata', jsonfield.fields.JSONField(blank=True, default={}, dump_kwargs={'cls': jsonfield.encoder.JSONEncoder, 'indent': 4, 'separators': (',', ':')}, help_text="The metadata about a particular piece content as retrieved from the discovery service's search/all endpoint results, specified as a JSON object.", load_kwargs={'object_pairs_hook': collections.OrderedDict}, null=True)),
('content_key', models.CharField(help_text='The key that represents a piece of content, such as a course, course run, or program.', max_length=255)),
],
options={
'verbose_name': 'Restricted Content Metadata',
'verbose_name_plural': 'Restricted Content Metadata',
},
),
migrations.RenameField(
model_name='contentmetadata',
old_name='json_metadata',
new_name='_json_metadata',
),
Comment on lines +36 to +40
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what makes it so that the name of the field in the database doesn't actually change, but the reference to it in django is renamed.

migrations.AlterField(
model_name='catalogquery',
name='content_filter',
field=jsonfield.fields.JSONField(default=dict, dump_kwargs={'cls': jsonfield.encoder.JSONEncoder, 'ensure_ascii': False, 'indent': 4, 'separators': (',', ':')}, help_text="Query parameters which will be used to filter the discovery service's search/all endpoint results, specified as a JSON object.", load_kwargs={'object_pairs_hook': collections.OrderedDict}),
),
migrations.DeleteModel(
name='HistoricalContentMetadata',
),
migrations.AddField(
model_name='restrictedcoursemetadata',
name='catalog_query',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='restricted_content_metadata', to='catalog.catalogquery'),
),
migrations.AlterUniqueTogether(
name='restrictedcoursemetadata',
unique_together={('content_key', 'catalog_query')},
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.16 on 2024-10-01 20:01

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('catalog', '0040_restrictedcoursemetadata_and_more'),
]

operations = [
migrations.AddField(
model_name='contentmetadata',
name='is_restricted_run',
field=models.BooleanField(default=False, help_text='If true, cause this run to be included in various v2 endpoints.'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.2.16 on 2024-10-01 20:34

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('catalog', '0041_contentmetadata_is_restricted_run'),
]

operations = [
migrations.AddField(
model_name='restrictedcoursemetadata',
name='unrestricted_parent',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='restricted_courses', to='catalog.contentmetadata'),
),
]
Loading
Loading