feat: Implement list roles & enforce authorize examples (#1273)

This commit is contained in:
Steven Masley
2022-05-03 16:10:19 -05:00
committed by GitHub
parent 0f9e30e54f
commit d0293e4d33
13 changed files with 627 additions and 5 deletions

27
coderd/roles.go Normal file
View File

@ -0,0 +1,27 @@
package coderd
import (
"net/http"
"github.com/coder/coder/coderd/httpmw"
"github.com/coder/coder/coderd/httpapi"
"github.com/coder/coder/coderd/rbac"
)
// assignableSiteRoles returns all site wide roles that can be assigned.
func (*api) assignableSiteRoles(rw http.ResponseWriter, _ *http.Request) {
// TODO: @emyrk in the future, allow granular subsets of roles to be returned based on the
// role of the user.
roles := rbac.SiteRoles()
httpapi.Write(rw, http.StatusOK, roles)
}
// assignableSiteRoles returns all site wide roles that can be assigned.
func (*api) assignableOrgRoles(rw http.ResponseWriter, r *http.Request) {
// TODO: @emyrk in the future, allow granular subsets of roles to be returned based on the
// role of the user.
organization := httpmw.OrganizationParam(r)
roles := rbac.OrganizationRoles(organization.ID)
httpapi.Write(rw, http.StatusOK, roles)
}