Skip to content

fix: Workflow debugging for authorized applications will result in an error message indicating unauthorized access to the model #2819

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 1 commit into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from all 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: 1 addition & 1 deletion apps/application/views/chat_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class OpenWorkFlowTemp(APIView):
tags=[_("Application/Chat")])
def post(self, request: Request):
return result.success(ChatSerializers.OpenWorkFlowChat(
data={**request.data, 'user_id': request.user.id}).open())
data={'user_id': request.user.id, **request.data}).open())

class OpenTemp(APIView):
authentication_classes = [TokenAuth]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The provided code has a few issues:

  1. In OpenWorkFlowTemp.post(), the serializer is instantiated with extra arguments (data), which might be unnecessary if they are not used in the serialization process.

  2. The method is using kwargs, but there's no use of unpacking them into the serializer. This can be simplified without affecting the functionality.

Here’s an updated version that addresses these points:

class OpenWorkFlowTemp(APIView):
    @action(detail=False, methods=['post'], url_name='chat-list', name=_('Application/Chat'), authentication_classes=[],
            permission_classes=[], tags=[_("Application/Chat")])
    def post(self, request: Request):
        chat_data = {'user_id': request.user.id}
        # Merge other data from the request.POST (if needed)
        chat_data.update(request.data)
        
        # Create the serialized object and open it
        return result.success(ChatSerializer.OpenWorkFlowChat(data=chat_data).open())

class OpenTemp(APIView):
    authentication_classes = [TokenAuth]

Changes made:

  1. Simplified the instantiation of the serializer to pass just 'user_id'.
  2. Removed the unnecessary dictionary spread operator before request.data.

These changes should resolve the potential issue and make the code cleaner. If you have additional requirements or need further modifications, let me know!

Expand Down
4 changes: 3 additions & 1 deletion ui/src/components/ai-chat/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,10 @@ const openChatId: () => Promise<string> = () => {
})
} else {
if (isWorkFlow(obj.type)) {
console.log(obj)
const submitObj = {
work_flow: obj.work_flow
work_flow: obj.work_flow,
user_id: obj.user
}
return applicationApi.postWorkflowChatOpen(submitObj).then((res) => {
chartOpenId.value = res.data
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is one issue in the given code that could cause problems if obj doesn't have a property named work_flow. The error would occur because of accessing .work_flow on submitObj, assuming it exists.

To prevent this from causing errors, you should add conditions to ensure both properties (work_flow and user) exist before constructing the submitObj.

Here’s an optimized version with these changes:

const openChatId: () => Promise<string> = () => {
  if (isWorkFlow(obj.type)) {
    // Check if work_flow and user exist
    if (typeof obj.work_flow === 'string' && typeof obj.user !== 'undefined') {
      const submitObj = {
        work_flow: obj.work_flow,
        user_id: obj.user
      };
      return applicationApi.postWorkflowChatOpen(submitObj).then((res) => {
        chartOpenId.value = res.data;
      });
    } else {
      throw new Error('Missing required fields: work_flow or user');
    }
  } else {
    // ...
  }
}

With this modification, we first check if obj.work_flow exists as a string using typeof ("string"), and verify that obj.user does not equal undefined. If either condition fails, an error is thrown with a descriptive message. This prevents potential runtime errors and makes your function safer and more robust.

Expand Down