-
Notifications
You must be signed in to change notification settings - Fork 558
UN-2880[FEAT] Add organization-level sharing for Prompt Studio projects #1592
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
UN-2880[FEAT] Add organization-level sharing for Prompt Studio projects #1592
Conversation
Implemented organization-wide sharing functionality for CustomTool (Prompt Studio projects), bringing them to parity with workflows and adapters. Changes: - Added shared_to_org BooleanField to CustomTool model - Updated CustomToolModelManager.for_user() to include org-level filtering - Added shared_to_org field to SharedUserListSerializer - Updated permissions to use IsOwnerOrSharedUserOrSharedToOrg - Added email notifications for sharing events in partial_update() - Updated frontend ListOfTools component to support org-wide sharing - Created database migration for shared_to_org field Users can now share Prompt Studio projects with all members of their organization using the "Share with everyone in current org" checkbox. Email notifications are sent to users when projects are shared with them individually. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Summary by CodeRabbit
WalkthroughAdds organization-wide sharing for CustomTool: new Boolean field shared_to_org; model manager query updated; serializer exposes the field; view permissions expanded to include org-shared access; partial update now sends notifications to newly added shared users; frontend share flow sends shared_to_org and updates UI. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor U as User
participant FE as Frontend (ListOfTools)
participant API as Backend API (View)
participant M as Model/DB
participant N as SharingNotificationService
U->>FE: Open share dialog / submit (users, shareWithEveryone)
FE->>API: PATCH /custom-tools/{id} { shared_users, shared_to_org }
API->>API: get_permissions() uses IsOwnerOrSharedUserOrSharedToOrg
API->>M: Update CustomTool shared_users/shared_to_org
M-->>API: Updated object
alt shared_users changed
API->>N: notify(newly_added_users, resource, actor)
note right of N: Failures logged, do not affect response
N-->>API: ack/exception (ignored)
end
API-->>FE: 200 OK (updated tool)
FE-->>U: Show success alert
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (3)
backend/prompt_studio/prompt_studio_core_v2/models.py (1)
152-156: Consider indexing for frequent org‑wide lookupsIf org‑wide sharing is commonly queried, add a composite index on
(organization, shared_to_org)to help thefor_userOR condition. Standalone boolean indexes are less helpful; the composite with org is more practical.frontend/src/components/custom-tools/list-of-tools/ListOfTools.jsx (1)
316-327: PATCH payload correctly includes org‑sharing flag — minor nits
- Optional: add
"Content-Type": "application/json"for consistency with other calls; Axios defaults to JSON though.Confirm
userIdsis an array of IDs and backend expectsshared_usersas IDs (ModelSerializer with PK field).Also applies to: 331-334
backend/prompt_studio/prompt_studio_core_v2/views.py (1)
156-195: Safer diff on user IDs and fix logging.exception usage; verify org‑share notifications
- Use ID sets instead of model instances for set‑diff to avoid equality/hash pitfalls across Django model instances.
- Prefer parameterized
logger.exceptionwithout interpolatingstr(e); it already logs the exception and traceback.- Notifications currently only for explicit shared_users updates; if you also want to notify on org‑wide toggle, add a branch for
shared_to_orgchanges.Apply:
@@ - custom_tool = self.get_object() - current_shared_users = set(custom_tool.shared_users.all()) + custom_tool = self.get_object() + current_shared_user_ids = set( + custom_tool.shared_users.values_list("id", flat=True) + ) @@ - if response.status_code == 200 and "shared_users" in request.data: + if response.status_code == 200 and "shared_users" in request.data: @@ - custom_tool.refresh_from_db() - updated_shared_users = set(custom_tool.shared_users.all()) + custom_tool.refresh_from_db() + updated_shared_user_ids = set( + custom_tool.shared_users.values_list("id", flat=True) + ) @@ - newly_shared_users = updated_shared_users - current_shared_users + newly_shared_user_ids = updated_shared_user_ids - current_shared_user_ids @@ - if newly_shared_users: + if newly_shared_user_ids: + from account_v2.models import User + newly_shared_users = list( + User.objects.filter(id__in=newly_shared_user_ids) + ) notification_service = SharingNotificationService() try: notification_service.send_sharing_notification( resource_type=ResourceType.TEXT_EXTRACTOR.value, resource_name=custom_tool.tool_name, resource_id=str(custom_tool.tool_id), shared_by=request.user, - shared_to=list(newly_shared_users), + shared_to=newly_shared_users, resource_instance=custom_tool, ) except Exception as e: - # Log error but don't fail the request - logger.exception( - f"Failed to send sharing notification for " - f"custom tool {custom_tool.tool_id}: {str(e)}" - ) + # Log error but don't fail the request + logger.exception( + "Failed to send sharing notification for custom tool %s", + custom_tool.tool_id, + )Also verify the correct ResourceType enum for Prompt Studio projects (TEXT_EXTRACTOR vs a dedicated type).
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to Reviews > Disable Cache setting
Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting
📒 Files selected for processing (5)
backend/prompt_studio/prompt_studio_core_v2/migrations/0004_add_shared_to_org_to_custom_tool.py(1 hunks)backend/prompt_studio/prompt_studio_core_v2/models.py(2 hunks)backend/prompt_studio/prompt_studio_core_v2/serializers.py(1 hunks)backend/prompt_studio/prompt_studio_core_v2/views.py(3 hunks)frontend/src/components/custom-tools/list-of-tools/ListOfTools.jsx(2 hunks)
🧰 Additional context used
🪛 Ruff (0.14.0)
backend/prompt_studio/prompt_studio_core_v2/migrations/0004_add_shared_to_org_to_custom_tool.py
7-9: Mutable class attributes should be annotated with typing.ClassVar
(RUF012)
11-20: Mutable class attributes should be annotated with typing.ClassVar
(RUF012)
backend/prompt_studio/prompt_studio_core_v2/views.py
192-192: Use explicit conversion flag
Replace with conversion flag
(RUF010)
192-192: Redundant exception object included in logging.exception call
(TRY401)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
🔇 Additional comments (6)
backend/prompt_studio/prompt_studio_core_v2/serializers.py (1)
188-189: Expose org-sharing flag in listings — LGTMIncluding shared_to_org here matches the new model field and view usage.
backend/prompt_studio/prompt_studio_core_v2/migrations/0004_add_shared_to_org_to_custom_tool.py (1)
12-20: Migration looks goodField name, default, and comment align with model; dependency is correct.
frontend/src/components/custom-tools/list-of-tools/ListOfTools.jsx (1)
394-395: Confirm SharePermission’s onApply signature includes org flagEnsure SharePermission calls onApply(userIds, adapter, shareWithEveryone) so the third arg reaches onShare; otherwise
shared_to_orgwill be stuck at false.backend/prompt_studio/prompt_studio_core_v2/views.py (2)
13-13: Permission import updated — LGTMSwapping to IsOwnerOrSharedUserOrSharedToOrg is consistent with org‑sharing.
97-98: Use new permission for non‑delete actions — LGTMKeeps destroy as owner‑only; others allow owner/shared/org‑shared.
backend/prompt_studio/prompt_studio_core_v2/models.py (1)
34-38: CustomTool.for_user is correctly scoped to the current organization
The manager inherits DefaultOrganizationManagerMixin, soget_queryset()already filters by the user’s org before applyingQ(shared_to_org=True).
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.
Looks fine to me.
…mpt-studio-project
…mpt-studio-project
Test ResultsSummary
Runner Tests - Full Report
SDK1 Tests - Full Report
|
|
…ts (#1592) Add organization-level sharing for Prompt Studio projects Implemented organization-wide sharing functionality for CustomTool (Prompt Studio projects), bringing them to parity with workflows and adapters. Changes: - Added shared_to_org BooleanField to CustomTool model - Updated CustomToolModelManager.for_user() to include org-level filtering - Added shared_to_org field to SharedUserListSerializer - Updated permissions to use IsOwnerOrSharedUserOrSharedToOrg - Added email notifications for sharing events in partial_update() - Updated frontend ListOfTools component to support org-wide sharing - Created database migration for shared_to_org field Users can now share Prompt Studio projects with all members of their organization using the "Share with everyone in current org" checkbox. Email notifications are sent to users when projects are shared with them individually. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Gayathri <142381512+gaya3-zipstack@users.noreply.github.com> Co-authored-by: Athul <89829560+athul-rs@users.noreply.github.com>
…ts (#1592) Add organization-level sharing for Prompt Studio projects Implemented organization-wide sharing functionality for CustomTool (Prompt Studio projects), bringing them to parity with workflows and adapters. Changes: - Added shared_to_org BooleanField to CustomTool model - Updated CustomToolModelManager.for_user() to include org-level filtering - Added shared_to_org field to SharedUserListSerializer - Updated permissions to use IsOwnerOrSharedUserOrSharedToOrg - Added email notifications for sharing events in partial_update() - Updated frontend ListOfTools component to support org-wide sharing - Created database migration for shared_to_org field Users can now share Prompt Studio projects with all members of their organization using the "Share with everyone in current org" checkbox. Email notifications are sent to users when projects are shared with them individually. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Gayathri <142381512+gaya3-zipstack@users.noreply.github.com> Co-authored-by: Athul <89829560+athul-rs@users.noreply.github.com>



Summary
Implemented organization-level sharing functionality for CustomTool (Prompt Studio projects)
Changes
Backend
shared_to_orgBooleanField to CustomTool modelCustomToolModelManager.for_user()to include org-level filtering withQ(shared_to_org=True)shared_to_orgfield toSharedUserListSerializerfor API responsesIsOwnerOrSharedUsertoIsOwnerOrSharedUserOrSharedToOrgpartial_update()for newly shared users0004_add_shared_to_org_to_custom_tool.pyFrontend
onShare()function to sendshared_to_orgflag to backendisSharableToOrg={true}propScreenshots
Features
Testing
Notes
🤖 Generated with Claude Code