Skip to content

Conversation

@shaohuzhang1
Copy link
Contributor

fix: Migrate file

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Oct 30, 2025

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Oct 30, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

knowledge_folder_model)
delete_auth(apps,application_folder_model)
delete_auth(apps,knowledge_folder_model)
delete_auth(apps,tool_folder_model)
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 appears to be an inconsistency between how workspace_user_resource_permission_list is being generated using resource_model (which could refer to either "TOOL" or "KNOWLEDGE") and the subsequent call where it's deleted later (folder_model). This should ideally correspond to the same resource type.

Here’s a revised version of your function to address this issue:

def auth_folder(apps, schema_editor):

    # Initialize an empty list for workspace user permissions
    workspace_user_resource_permission_list = []

    # Get permission lists using different types of resources (TOOL or KNOWLEDGE)
    for resource_type in ["TOOL", "KNOWLEDGE"]:
        resource_model_name = f"{resource_type}FolderModel"
        folder_model = apps.get_model("yourappname", resource_model_name)

        if not folder_model:
            continue

        workspace_user_role_mapping_model_workspace_dict = {
            'WORKSPACE': {'id': 1},
            'USER': {'id': 2}
        }

        workspace_user_resource_permission_list += get_workspace_user_resource_permission_list(
            apps, resource_type,
            workspace_user_role_mapping_model_workspace_dict,
            folder_model
        )

    # Delete all permissions associated with each type of resource
    for resource_type in ["TOOL", "KNOWLEDGE"]:
        resource_model_name = f"{resource_type}FolderModel"
        folder_model = apps.get_model("yourappname", resource_model_name)

        if not folder_model:
            continue

        delete_auth(apps, folder_model)

Key Points:

  1. Consistent Resource Model: Ensure that the model names match correctly when generating permission lists.
  2. Deletion Consistency: Verify that you are deleting models from the correct database table.
  3. Error Handling: Optional: Add error handling to manage cases where required models might not exist. For example, checking if not folder_model: before proceeding can prevent errors related to non-existent tables.

This will ensure that authorization logic across your application maintains consistency regarding what types of resources are being operated on.

@zhanweizhang7 zhanweizhang7 merged commit aba41c4 into v2 Oct 30, 2025
4 of 6 checks passed
@zhanweizhang7 zhanweizhang7 deleted the pr@v2@fix_migrate_file branch October 30, 2025 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants