feat: Move workspaces under organizations (#1109)

This removes split ownership for workspaces. They are now
a resource of organizations and have a designated owner,
which is a user.

This enables simple administration for commands like:
- `coder stop ben/dev`
- `coder build logs colin/arch`

or if we decide to allow administrators to access workspaces,
they could even SSH using this syntax: `coder ssh colin/dev`.
This commit is contained in:
Kyle Carberry
2022-04-25 16:11:03 -05:00
committed by GitHub
parent 759fa5f626
commit 88669fd578
51 changed files with 885 additions and 671 deletions

View File

@ -20,12 +20,6 @@ func parseUUID(rw http.ResponseWriter, r *http.Request, param string) (uuid.UUID
return uuid.UUID{}, false
}
// Automatically set uuid.Nil to the acting users id.
if param == UserKey && rawID == "me" {
key := APIKey(r)
return key.UserID, true
}
parsed, err := uuid.Parse(rawID)
if err != nil {
httpapi.Write(rw, http.StatusBadRequest, httpapi.Response{

View File

@ -5,12 +5,13 @@ import (
"fmt"
"net/http"
"github.com/go-chi/chi/v5"
"github.com/google/uuid"
"github.com/coder/coder/coderd/database"
"github.com/coder/coder/coderd/httpapi"
)
const UserKey = "user"
type userParamContextKey struct{}
// UserParam returns the user from the ExtractUserParam handler.
@ -26,9 +27,15 @@ func UserParam(r *http.Request) database.User {
func ExtractUserParam(db database.Store) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
userID, ok := parseUUID(rw, r, UserKey)
if !ok {
return
var userID uuid.UUID
if chi.URLParam(r, "user") == "me" {
userID = APIKey(r).UserID
} else {
var ok bool
userID, ok = parseUUID(rw, r, "user")
if !ok {
return
}
}
apiKey := APIKey(r)