mirror of
https://github.com/coder/coder.git
synced 2025-07-13 21:36:50 +00:00
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:
@ -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{
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user