-
Notifications
You must be signed in to change notification settings - Fork 10
Edit prompt template from studio #183
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
Merged
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4cce2c5
feat: adding backend API to list all profiles within the current scope
felipemontoya 2d54a9b
feat: adding a UI to show the list of profiles
felipemontoya 9909628
feat: adding scopes to each profile in the list
felipemontoya 984abb8
feat: showing scopes in the UI
felipemontoya 67f81df
feat: showing prompt templates in studio and allowing updates
felipemontoya e202981
feat: moving permission checks to its own file and adding granularity…
felipemontoya 17c3d62
feat: addressing feedback to not use authz, but courseacessrole instead
felipemontoya e44009b
feat: sending the course context from the UI
felipemontoya bc8c216
fix: addressing comments made by qa process
felipemontoya 2ab2e0a
feat: moving all user facing strings to i18n messages
felipemontoya 25e9738
feat: making the number of profiles affected by a template change ava…
felipemontoya 6e1ae6e
fix: all the qa addressed
felipemontoya c754525
fix: addressing comments by @henrrypg
felipemontoya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,3 +8,4 @@ omit = | |
| *admin.py | ||
| */static/* | ||
| */templates/* | ||
| */edxapp_wrapper/backends/* | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
backend/openedx_ai_extensions/api/v1/workflows/permissions.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| """ | ||
| DRF permission classes and shared request utilities for AI Workflows API. | ||
| """ | ||
|
|
||
| import json | ||
| import logging | ||
|
|
||
| from django.core.exceptions import ValidationError | ||
| from opaque_keys import InvalidKeyError | ||
| from opaque_keys.edx.keys import CourseKey, UsageKey | ||
| from rest_framework.permissions import BasePermission | ||
|
|
||
| from openedx_ai_extensions.edxapp_wrapper.student_module import permission_is_course_staff | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def get_context_from_request(request): | ||
| """ | ||
| Extract and validate context from request query parameters. | ||
|
|
||
| Validates course_id and location_id formats using Open edX opaque_keys. | ||
| Returns a dict with snake_case keys. | ||
|
|
||
| Args: | ||
| request: Django request object with query parameters | ||
|
|
||
| Returns: | ||
| dict: Context with validated course_id and location_id in snake_case | ||
|
|
||
| Raises: | ||
| ValidationError: If course_id or location_id are invalid | ||
| """ | ||
| if hasattr(request, "GET"): | ||
| context_str = request.GET.get("context", "{}") | ||
| else: | ||
| context_str = request.query_params.get("context", "{}") | ||
|
|
||
| try: | ||
| context = json.loads(context_str) | ||
| except json.JSONDecodeError as e: | ||
| raise ValidationError("Invalid JSON format in 'context' parameter.") from e | ||
| validated_context = {} | ||
|
|
||
| # Validate and convert courseId to course_id | ||
| course_id_raw = context.get("courseId") or context.get("course_id") | ||
| if course_id_raw: | ||
| try: | ||
| CourseKey.from_string(course_id_raw) | ||
| validated_context["course_id"] = course_id_raw | ||
| except InvalidKeyError as e: | ||
| raise ValidationError(f"Invalid course_id format: {course_id_raw}") from e | ||
|
|
||
| # Validate and convert locationId to location_id | ||
|
felipemontoya marked this conversation as resolved.
Outdated
|
||
| location_id_raw = context.get("locationId") or context.get("location_id") | ||
| if location_id_raw: | ||
| try: | ||
| UsageKey.from_string(location_id_raw) | ||
| validated_context["location_id"] = location_id_raw | ||
| except InvalidKeyError as e: | ||
| raise ValidationError(f"Invalid location_id format: {location_id_raw}") from e | ||
|
|
||
| # Pass ui_slot_selector_id as-is (plain string, no special validation needed) | ||
|
felipemontoya marked this conversation as resolved.
Outdated
|
||
| ui_slot_selector_id_raw = context.get("uiSlotSelectorId") or context.get("ui_slot_selector_id") | ||
| if ui_slot_selector_id_raw: | ||
| validated_context["ui_slot_selector_id"] = str(ui_slot_selector_id_raw) | ||
|
|
||
| return validated_context | ||
|
|
||
|
|
||
| class CourseStaffPermission(BasePermission): | ||
| """ | ||
| Restricts access to users who are authorised to manage advanced settings | ||
| for a course. | ||
|
|
||
| * Staff and superusers are always allowed. | ||
| * Otherwise, requires a valid ``course_id`` in the ``context`` query param | ||
| and delegates to the configured ``STUDENT_MODULE_BACKEND`` to check | ||
| whether the user holds a course-level staff or instructor role. | ||
| """ | ||
|
|
||
| def has_permission(self, request, view): | ||
| user = request.user | ||
|
|
||
| if not user or not user.is_authenticated: | ||
| return False | ||
|
|
||
| if user.is_staff or user.is_superuser: | ||
| return True | ||
|
|
||
| try: | ||
| context = get_context_from_request(request) | ||
| except ValidationError as e: | ||
| logger.debug("CourseStaffPermission denied — invalid context: %s", e) | ||
| return False | ||
|
|
||
| course_id = context.get("course_id") | ||
| if not course_id: | ||
| return False | ||
|
|
||
| return permission_is_course_staff(user, course_id) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.