Skip to content

Ignore resource if its root namespace cannot use AI feature

euko requested to merge ek-set-resource-to-nil into master

What does this MR do and why?

Read #421525 for background.

In this MR, the chat service Llm::ChatService is updated to ignore the passed resource and set resource to nil IF the resource's namespace hierarchy cannot use Gitlab Duo Chat.

The GraphQL mutation AiAction still needs to be updated so that it does not immediately reject such resource as unauthorized.

How to test

Prepare a public issue from a project to which the current user does not belong.

user = User.first # user who can use Gitlab Duo Chat
public_issue = Issue.find() # a public issue that the user is not a member of.
Llm::ExecuteMethodService.new(user, public_issue, :chat, { sync: true, content: "How do I reset my password?" }).execute

On the main branch, the the request should be rejected by the service.

=> #<ServiceResponse:0x000000016908e408
 @http_status=nil,
 @message="AI features are not enabled or resource is not permitted to be sent.",
 @payload={},
 @reason=nil,
 @status=:error>

On this MR's branch, the request should proceed and succeed.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by euko

Merge request reports