Changeset 0.21.5 (#91)
This commit is contained in:
@@ -101,6 +101,34 @@ func (h *WorkspaceHandler) Get(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, w)
|
||||
}
|
||||
|
||||
// List returns all workspaces accessible to the current user.
|
||||
// Includes user-owned workspaces and those owned by the user's teams.
|
||||
func (h *WorkspaceHandler) List(c *gin.Context) {
|
||||
userID := getUserID(c)
|
||||
ctx := c.Request.Context()
|
||||
|
||||
// Fetch user-owned workspaces
|
||||
userWs, err := h.stores.Workspaces.ListByOwner(ctx, "user", userID)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
all := make([]models.Workspace, 0, len(userWs))
|
||||
all = append(all, userWs...)
|
||||
|
||||
// Also include team-owned workspaces
|
||||
teamIDs, _ := h.stores.Teams.GetUserTeamIDs(ctx, userID)
|
||||
for _, tid := range teamIDs {
|
||||
teamWs, err := h.stores.Workspaces.ListByOwner(ctx, "team", tid)
|
||||
if err == nil {
|
||||
all = append(all, teamWs...)
|
||||
}
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, all)
|
||||
}
|
||||
|
||||
func (h *WorkspaceHandler) Update(c *gin.Context) {
|
||||
w, ok := h.loadAndAuthorize(c)
|
||||
if !ok {
|
||||
|
||||
Reference in New Issue
Block a user