-
Notifications
You must be signed in to change notification settings - Fork 925
feat: add has-ai-task filters to the /workspaces and /templates endpoints #18387
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
Conversation
fb3b8ec
to
d32f3e4
Compare
41eebab
to
31aa2b2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, with a couple nits.
@@ -25,7 +25,7 @@ func userACLMatcher(m sqltypes.VariableMatcher) sqltypes.VariableMatcher { | |||
func TemplateConverter() *sqltypes.VariableConverter { | |||
matcher := sqltypes.NewVariableConverter().RegisterMatcher( | |||
resourceIDMatcher(), | |||
organizationOwnerMatcher(), | |||
sqltypes.StringVarMatcher("t.organization_id :: text", []string{"input", "object", "org_owner"}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the only case where we need to update the organization_id
alias?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bump
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, sorry about that - yes, that's the only place. Only the SQL filter of the GetTemplates
query is affected, and TemplateConverter
is only used for GetTemplates
.
eaae6a8
to
0adf1f2
Compare
0adf1f2
to
32cc427
Compare
return false, xerrors.Errorf("get workspace build parameters: %w", err) | ||
} | ||
for _, param := range parameters { | ||
if param.Name == "AI Prompt" && param.Value != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: this should use the const I'm introducing in the provider: https://github.com/coder/terraform-provider-coder/blob/dk/coder-ai-task-res/provider/ai_task.go#L22
SELECT 1 | ||
FROM workspace_build_parameters | ||
WHERE workspace_build_parameters.workspace_build_id = latest_build.id | ||
AND workspace_build_parameters.name = 'AI Prompt' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm we may want to accept this name as an arg, but could get tricky since this is used in a few places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to enforce that this constant matches the constant in go code, I'd rather define a helper function:
CREATE FUNCTION ai_prompt_param_name() RETURNS TEXT AS $$
BEGIN
RETURN 'AI Prompt';
END;
$$ LANGUAGE plpgsql IMMUTABLE;
Then use that function in the query, and add a test that checks if the result of that function matches the constant in go code.
@@ -25,7 +25,7 @@ func userACLMatcher(m sqltypes.VariableMatcher) sqltypes.VariableMatcher { | |||
func TemplateConverter() *sqltypes.VariableConverter { | |||
matcher := sqltypes.NewVariableConverter().RegisterMatcher( | |||
resourceIDMatcher(), | |||
organizationOwnerMatcher(), | |||
sqltypes.StringVarMatcher("t.organization_id :: text", []string{"input", "object", "org_owner"}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bump
related to #18158 |
This PR allows filtering templates and workspaces with the
has-ai-task
filter as described in the Coder Tasks RFC.