Skip to content
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
8 changes: 4 additions & 4 deletions internal/handlers/llm_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func shareDefinitionFunc(ctx context.Context, input *models.ShareDefinitionReque
return nil, huma.Error500InternalServerError(fmt.Sprintf("unable to retrieve definition: %v", err))
}
if definition.Owner != ctx.Value(auth.AuthUserKey).(string) {
return nil, huma.Error401Unauthorized(fmt.Sprintf("Not authorized to share definition %s/%s", input.UserHandle, input.DefinitionHandle))
return nil, huma.Error403Forbidden(fmt.Sprintf("not authorized to share definition %s/%s", input.UserHandle, input.DefinitionHandle))
}

// Check if target user exists
Expand Down Expand Up @@ -353,7 +353,7 @@ func unshareDefinitionFunc(ctx context.Context, input *models.UnshareDefinitionR
return nil, huma.Error500InternalServerError(fmt.Sprintf("unable to retrieve definition: %v", err))
}
if definition.Owner != ctx.Value(auth.AuthUserKey).(string) {
return nil, huma.Error401Unauthorized(fmt.Sprintf("Not authorized to share definition %s/%s", input.UserHandle, input.DefinitionHandle))
return nil, huma.Error403Forbidden(fmt.Sprintf("not authorized to share definition %s/%s", input.UserHandle, input.DefinitionHandle))
}
fmt.Printf("Definition retrieved: %s/%s (id %d)\n", definition.Owner, definition.DefinitionHandle, definition.DefinitionID)
fmt.Printf("Attempting to unshare with %s\n", input.UnshareWithHandle)
Expand Down Expand Up @@ -574,7 +574,7 @@ func postInstanceFromDefinitionFunc(ctx context.Context, input *models.PostInsta
hasAccess = true
}
if !hasAccess {
return huma.Error401Unauthorized(fmt.Sprintf("user does not have access to definition %s/%s", input.Body.DefinitionOwner, input.Body.DefinitionHandle))
return huma.Error403Forbidden(fmt.Sprintf("user does not have access to definition %s/%s", input.Body.DefinitionOwner, input.Body.DefinitionHandle))
}
}

Expand Down Expand Up @@ -849,7 +849,7 @@ func shareInstanceFunc(ctx context.Context, input *models.ShareInstanceRequest)
}
// Check if instance belongs to current user (only owner can share)
if instance.Owner != ctx.Value(auth.AuthUserKey).(string) {
return nil, huma.Error401Unauthorized(fmt.Sprintf("Not authorized to share instance %s/%s", input.UserHandle, input.InstanceHandle))
return nil, huma.Error403Forbidden(fmt.Sprintf("not authorized to share instance %s/%s", input.UserHandle, input.InstanceHandle))
}
// Check if target user exists
_, err = getUserFunc(ctx, &models.GetUserRequest{UserHandle: input.Body.ShareWithHandle})
Expand Down
4 changes: 2 additions & 2 deletions internal/handlers/llm_services_sharing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ func TestDefinitionSharingFunc(t *testing.T) {
requestPath: "/v1/llm-instances/bob/from-definition",
bodyJSON: `{"user_handle": "bob", "instance_handle": "bob-instance1", "definition_owner": "alice", "definition_handle": "openai-large", "endpoint": "https://api.openai.com/v1/embeddings", "description": "Bob's instance based on Alice's definition"}`,
VDBKey: bobAPIKey,
expectBody: "{\n \"$schema\": \"http://localhost:8080/schemas/ErrorModel.json\",\n \"title\": \"Unauthorized\",\n \"status\": 401,\n \"detail\": \"user does not have access to definition alice/openai-large\"\n}\n",
expectStatus: http.StatusUnauthorized,
expectBody: "{\n \"$schema\": \"http://localhost:8080/schemas/ErrorModel.json\",\n \"title\": \"Forbidden\",\n \"status\": 403,\n \"detail\": \"user does not have access to definition alice/openai-large\"\n}\n",
expectStatus: http.StatusForbidden,
},
{
name: "Create an instance based on a nonexistent definition - should fail",
Expand Down
2 changes: 1 addition & 1 deletion internal/handlers/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ func shareProjectFunc(ctx context.Context, input *models.ShareProjectRequest) (*
}
// Check if project belongs to current user (only owner can share)
if project.Owner != ctx.Value(auth.AuthUserKey).(string) {
return nil, huma.Error401Unauthorized(fmt.Sprintf("not authorized to share project %s/%s", input.UserHandle, input.ProjectHandle))
return nil, huma.Error403Forbidden(fmt.Sprintf("not authorized to share project %s/%s", input.UserHandle, input.ProjectHandle))
}
// Check if target user exists
_, err = getUserFunc(ctx, &models.GetUserRequest{UserHandle: input.Body.ShareWithHandle})
Expand Down