mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
chore: fetch workspaces by username with organization permissions (#17707)
Closes https://github.com/coder/coder/issues/17691 `ExtractOrganizationMembersParam` will allow fetching a user with only organization permissions. If the user belongs to 0 orgs, then the user "does not exist" from an org perspective. But if you are a site-wide admin, then the user does exist.
This commit is contained in:
@ -1189,15 +1189,25 @@ func New(options *Options) *API {
|
||||
})
|
||||
r.Route("/{user}", func(r chi.Router) {
|
||||
r.Group(func(r chi.Router) {
|
||||
r.Use(httpmw.ExtractUserParamOptional(options.Database))
|
||||
r.Use(httpmw.ExtractOrganizationMembersParam(options.Database, api.HTTPAuth.Authorize))
|
||||
// Creating workspaces does not require permissions on the user, only the
|
||||
// organization member. This endpoint should match the authz story of
|
||||
// postWorkspacesByOrganization
|
||||
r.Post("/workspaces", api.postUserWorkspaces)
|
||||
r.Route("/workspace/{workspacename}", func(r chi.Router) {
|
||||
r.Get("/", api.workspaceByOwnerAndName)
|
||||
r.Get("/builds/{buildnumber}", api.workspaceBuildByBuildNumber)
|
||||
})
|
||||
})
|
||||
|
||||
r.Group(func(r chi.Router) {
|
||||
r.Use(httpmw.ExtractUserParam(options.Database))
|
||||
|
||||
// Similarly to creating a workspace, evaluating parameters for a
|
||||
// new workspace should also match the authz story of
|
||||
// postWorkspacesByOrganization
|
||||
// TODO: Do not require site wide read user permission. Make this work
|
||||
// with org member permissions.
|
||||
r.Route("/templateversions/{templateversion}", func(r chi.Router) {
|
||||
r.Use(
|
||||
httpmw.ExtractTemplateVersionParam(options.Database),
|
||||
@ -1205,10 +1215,6 @@ func New(options *Options) *API {
|
||||
)
|
||||
r.Get("/parameters", api.templateVersionDynamicParameters)
|
||||
})
|
||||
})
|
||||
|
||||
r.Group(func(r chi.Router) {
|
||||
r.Use(httpmw.ExtractUserParam(options.Database))
|
||||
|
||||
r.Post("/convert-login", api.postConvertLoginType)
|
||||
r.Delete("/", api.deleteUser)
|
||||
@ -1250,10 +1256,7 @@ func New(options *Options) *API {
|
||||
r.Get("/", api.organizationsByUser)
|
||||
r.Get("/{organizationname}", api.organizationByUserAndName)
|
||||
})
|
||||
r.Route("/workspace/{workspacename}", func(r chi.Router) {
|
||||
r.Get("/", api.workspaceByOwnerAndName)
|
||||
r.Get("/builds/{buildnumber}", api.workspaceBuildByBuildNumber)
|
||||
})
|
||||
|
||||
r.Get("/gitsshkey", api.gitSSHKey)
|
||||
r.Put("/gitsshkey", api.regenerateGitSSHKey)
|
||||
r.Route("/notifications", func(r chi.Router) {
|
||||
|
Reference in New Issue
Block a user