Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add some comments
  • Loading branch information
Emyrk committed May 3, 2022
commit b76f373ae1dc276110b71f3b701ccfaf102e970d
4 changes: 2 additions & 2 deletions coderd/httpmw/authorize.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func Authorize(logger slog.Logger, auth *rbac.RegoAuthorizer, action rbac.Action
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
roles := UserRoles(r)
object := authObject(r)
object := rbacObject(r)

if object.Type == "" {
panic("developer error: auth object has no type")
Expand Down Expand Up @@ -72,7 +72,7 @@ func Authorize(logger slog.Logger, auth *rbac.RegoAuthorizer, action rbac.Action
type authObjectKey struct{}

// APIKey returns the API key from the ExtractAPIKey handler.
func authObject(r *http.Request) rbac.Object {
func rbacObject(r *http.Request) rbac.Object {
obj, ok := r.Context().Value(authObjectKey{}).(rbac.Object)
if !ok {
panic("developer error: auth object middleware not provided")
Expand Down
10 changes: 7 additions & 3 deletions coderd/rbac/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,11 @@ func IsOrgRole(roleName string) (string, bool) {
}

// OrganizationRoles lists all roles that can be applied to an organization user
// in the given organization.
// in the given organization. This is the list of available roles,
// and specific to an organization.
//
// This should be a list in a database, but until then we build
// the list from the builtins.
// the list from the builtins.
func OrganizationRoles(organizationID uuid.UUID) []string {
var roles []string
for _, roleF := range builtInRoles {
Expand All @@ -166,8 +168,10 @@ func OrganizationRoles(organizationID uuid.UUID) []string {
}

// SiteRoles lists all roles that can be applied to a user.
// This is the list of available roles, and not specific to a user
//
// This should be a list in a database, but until then we build
// the list from the builtins.
// the list from the builtins.
func SiteRoles() []string {
var roles []string
for role := range builtInRoles {
Expand Down