Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ def auth_folder(apps, schema_editor):

workspace_user_resource_permission_list += get_workspace_user_resource_permission_list(apps,"TOOL",
workspace_user_role_mapping_model_workspace_dict,
knowledge_folder_model)
tool_folder_model)

workspace_user_resource_permission_list += get_workspace_user_resource_permission_list(apps,"KNOWLEDGE",
workspace_user_role_mapping_model_workspace_dict,
tool_folder_model)
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.

Expand Down
Loading