Files
ai_academy/internal/handler/workspace_operations.go
T
runny 9058149576
Build & Publish (dsh-academy) / End-to-end inside dsh (latest, advisory) (push) Skipped
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Frontend / Docker multi-stage image (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-academy) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-academy) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-academy) / Publish to npm (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Helm / chart (push) Canceled after 0s
refactor: 项目更名 WeKnora → Academy
- 全量替换代码/配置/文档中的项目名(保留上游 GitHub 链接、weixin 文档域名、Docker Hub 镜像名)
- 重命名 32 个含项目名的文件/目录;Go module 路径改为 academy(含 client/cli 子模块)
- docreader proto 描述符采用等长替换,保持序列化字节布局有效
- Dockerfile.app 构建网络修复: browserskill 离线产物通道、PyPI/apt 国内镜像
- 运行验证: go build ✓ docker compose up ✓ 健康检查 ✓
2026-11-13 20:52:51 +08:00

87 lines
3.7 KiB
Go

package handler
import (
"net/http"
"strconv"
"academy/internal/handler/dto"
"academy/internal/types"
"github.com/gin-gonic/gin"
)
// WorkspaceResponse wraps the authenticated workspace profile.
type WorkspaceResponse struct {
Success bool `json:"success"`
Data *dto.TenantResponse `json:"data"`
}
// bindCurrentWorkspace pins the existing handlers to the authenticated caller,
// even for system administrators. No model-supplied workspace ID is accepted.
func bindCurrentWorkspace(c *gin.Context) bool {
id := types.CallerFromContext(c.Request.Context()).TenantID
if id == 0 {
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "workspace context missing"})
return false
}
c.Params = gin.Params{{Key: "id", Value: strconv.FormatUint(id, 10)}}
return true
}
// GetCurrentWorkspace godoc
// @Summary 查询当前空间信息
// @Tags 空间管理
// @Produce json
// @Success 200 {object} WorkspaceResponse
// @Security Bearer
// @x-agent {"id":"workspace.get","risk":"read"}
// @x-agent-hint "Reads the authenticated current workspace only: name, description, status and storage quota/usage in bytes. Does not switch workspaces. Credentials and internal configuration are not returned."
// @Router /tenants/current [get]
func (h *TenantHandler) GetCurrentWorkspace(c *gin.Context) {
if bindCurrentWorkspace(c) {
h.GetTenant(c)
}
}
// UpdateCurrentWorkspace godoc
// @Summary 修改当前空间基本信息
// @Tags 空间管理
// @Accept json
// @Produce json
// @Param request body updateTenantRequest true "需要修改的名称或描述"
// @Success 200 {object} WorkspaceResponse
// @Security Bearer
// @x-agent {"id":"workspace.update","risk":"write","role":"owner","target":"workspace.get","label":"name"}
// @x-agent-hint "Changes only the current workspace name and/or description, visible to all its members. Requires workspace owner. At least one field is required; omitted fields are preserved, empty description clears it. Does not change quota, status, members, permissions or credentials."
// @Router /tenants/current [patch]
func (h *TenantHandler) UpdateCurrentWorkspace(c *gin.Context) {
if bindCurrentWorkspace(c) {
h.UpdateTenant(c)
}
}
// WorkspaceMembersResponse describes the existing paginated member response.
type WorkspaceMembersResponse struct {
Members []types.TenantMemberResponse `json:"members"`
Total int64 `json:"total" extensions:"x-agent"`
Page int `json:"page" extensions:"x-agent"`
PageSize int `json:"page_size" extensions:"x-agent"`
}
// ListCurrentWorkspaceMembers godoc
// @Summary 查询当前空间成员
// @Tags 空间成员
// @Produce json
// @Param q query string false "按邮箱或用户名筛选" extensions(x-agent)
// @Param page query int false "页码,从 1 开始" default(1) minimum(1) extensions(x-agent,x-agent-maximum=10000)
// @Param page_size query int false "每页成员数量" default(20) minimum(1) maximum(100) extensions(x-agent,x-agent-maximum=50)
// @Success 200 {object} DataResponse{data=WorkspaceMembersResponse}
// @Security Bearer
// @x-agent {"id":"workspace.list_members","risk":"read","root":"data.members","max_items":50}
// @x-agent-hint "Lists active members of the current workspace with username, email and workspace role. q filters username/email, not role; to find all owners/admins paginate until meta.total is covered and filter role. Workspace owner/admin roles do not imply system administrator status. Does not include pending invitations or change membership."
// @Router /tenants/current/members [get]
func (h *TenantMemberHandler) ListCurrentWorkspaceMembers(c *gin.Context) {
if bindCurrentWorkspace(c) {
h.ListMembers(c)
}
}