mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
chore: reorder prebuilt workspace authorization logic (#18506)
## Description Follow-up from PR https://github.com/coder/coder/pull/18333 Related with: https://github.com/coder/coder/pull/18333#discussion_r2159300881 This changes the authorization logic to first try the normal workspace authorization check, and only if the resource is a prebuilt workspace, fall back to the prebuilt workspace authorization check. Since prebuilt workspaces are a subset of workspaces, the normal workspace check is more likely to succeed. This is a small optimization to reduce unnecessary prebuilt authorization calls.
This commit is contained in:
@ -1049,14 +1049,12 @@ func (b *Builder) authorize(authFunc func(action policy.Action, object rbac.Obje
|
||||
return BuildError{http.StatusBadRequest, msg, xerrors.New(msg)}
|
||||
}
|
||||
|
||||
// Try default workspace authorization first
|
||||
authorized := authFunc(action, b.workspace)
|
||||
|
||||
// Special handling for prebuilt workspace deletion
|
||||
authorized := false
|
||||
if action == policy.ActionDelete && b.workspace.IsPrebuild() && authFunc(action, b.workspace.AsPrebuild()) {
|
||||
authorized = true
|
||||
}
|
||||
// Fallback to default authorization
|
||||
if !authorized && authFunc(action, b.workspace) {
|
||||
authorized = true
|
||||
if !authorized && action == policy.ActionDelete && b.workspace.IsPrebuild() {
|
||||
authorized = authFunc(action, b.workspace.AsPrebuild())
|
||||
}
|
||||
|
||||
if !authorized {
|
||||
|
Reference in New Issue
Block a user