mirror of
https://github.com/coder/coder.git
synced 2025-07-06 15:41:45 +00:00
chore: push rbac actions to policy package (#13274)
Just moved `rbac.Action` -> `policy.Action`. This is for the stacked PR to not have circular dependencies when doing autogen. Without this, the autogen can produce broken golang code, which prevents the autogen from compiling. So just avoiding circular dependencies. Doing this in it's own PR to reduce LoC diffs in the primary PR, since this has 0 functional changes.
This commit is contained in:
@ -16,6 +16,7 @@ import (
|
||||
"github.com/coder/coder/v2/coderd/httpapi"
|
||||
"github.com/coder/coder/v2/coderd/httpmw"
|
||||
"github.com/coder/coder/v2/coderd/rbac"
|
||||
"github.com/coder/coder/v2/coderd/rbac/policy"
|
||||
"github.com/coder/coder/v2/codersdk"
|
||||
)
|
||||
|
||||
@ -35,7 +36,7 @@ func (api *API) templateAvailablePermissions(rw http.ResponseWriter, r *http.Req
|
||||
|
||||
// Requires update permission on the template to list all avail users/groups
|
||||
// for assignment.
|
||||
if !api.Authorize(r, rbac.ActionUpdate, template) {
|
||||
if !api.Authorize(r, policy.ActionUpdate, template) {
|
||||
httpapi.ResourceNotFound(rw)
|
||||
return
|
||||
}
|
||||
@ -305,9 +306,9 @@ func validateTemplateRole(role codersdk.TemplateRole) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func convertToTemplateRole(actions []rbac.Action) codersdk.TemplateRole {
|
||||
func convertToTemplateRole(actions []policy.Action) codersdk.TemplateRole {
|
||||
switch {
|
||||
case len(actions) == 1 && actions[0] == rbac.ActionRead:
|
||||
case len(actions) == 1 && actions[0] == policy.ActionRead:
|
||||
return codersdk.TemplateRoleUse
|
||||
case len(actions) == 1 && actions[0] == rbac.WildcardSymbol:
|
||||
return codersdk.TemplateRoleAdmin
|
||||
@ -316,12 +317,12 @@ func convertToTemplateRole(actions []rbac.Action) codersdk.TemplateRole {
|
||||
return ""
|
||||
}
|
||||
|
||||
func convertSDKTemplateRole(role codersdk.TemplateRole) []rbac.Action {
|
||||
func convertSDKTemplateRole(role codersdk.TemplateRole) []policy.Action {
|
||||
switch role {
|
||||
case codersdk.TemplateRoleAdmin:
|
||||
return []rbac.Action{rbac.WildcardSymbol}
|
||||
return []policy.Action{rbac.WildcardSymbol}
|
||||
case codersdk.TemplateRoleUse:
|
||||
return []rbac.Action{rbac.ActionRead}
|
||||
return []policy.Action{policy.ActionRead}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user