MCPcopy Index your code
hub / github.com/53AI/53AIHub / UpdateSpace

Function UpdateSpace

api/controller/space.go:269–357  ·  view source on GitHub ↗

UpdateSpace godoc @Summary 更新空间信息 @Description 更新空间的基本信息 @Tags 空间管理 @Accept json @Produce json @Security BearerAuth @Param space_id path int true "空间ID" @Param request body SpaceRequest true "空间信息" @Success 200 {object} model.CommonResponse{data=model.Space} @Router /api/spaces/{space_id} [put]

(c *gin.Context)

Source from the content-addressed store, hash-verified

267// @Success 200 {object} model.CommonResponse{data=model.Space}
268// @Router /api/spaces/{space_id} [put]
269func UpdateSpace(c *gin.Context) {
270 eid := config.GetEID(c)
271 userID := config.GetUserId(c)
272
273 id := c.Param("space_id")
274 if id == "" {
275 c.JSON(http.StatusBadRequest, model.ParamError.ToResponse(errors.New("空间ID不能为空")))
276 return
277 }
278
279 spaceID, err := strconv.ParseInt(id, 10, 64)
280 if err != nil {
281 c.JSON(http.StatusBadRequest, model.ParamError.ToResponse(errors.New("无效的空间ID")))
282 return
283 }
284
285 // 检查功能是否可用
286 params := map[string]interface{}{
287 "from": "space",
288 }
289 _, featureErr := service.IsFeatureAvailable(c, "space", params)
290 if featureErr != nil {
291 c.JSON(http.StatusForbidden, model.FeatureNotAvailableError.ToResponse(featureErr))
292 return
293 }
294
295 sps := service.NewSpacePermissionService(eid)
296 canEditSpc, err := sps.CheckSpacePermission(userID, spaceID, model.PERMISSION_MANAGE)
297
298 if (!canEditSpc || err != nil) && !common.IsAdmin(c) {
299 c.JSON(http.StatusForbidden, model.AuthFailed.ToResponse(errors.New("无权限修改此空间")))
300 return
301 }
302
303 var req SpaceRequest
304 if err := c.ShouldBindJSON(&req); err != nil {
305 c.JSON(http.StatusBadRequest, model.ParamError.ToResponse(err))
306 return
307 }
308
309 space, err := model.GetSpaceByID(eid, spaceID)
310 if err != nil {
311 c.JSON(http.StatusNotFound, model.NotFound.ToResponse(err))
312 return
313 }
314
315 // 保存原始数据用于日志记录
316 oldSpace := *space
317
318 space.Name = req.Name
319 space.Description = req.Description
320 space.Icon = req.Icon
321
322 // 处理可见性更新
323 visibility := req.Visibility
324
325 space.Visibility = visibility
326

Callers

nothing calls this directly

Calls 9

CheckSpacePermissionMethod · 0.95
GetEIDMethod · 0.80
ToResponseMethod · 0.80
LoadOwnerInfoMethod · 0.80
LoadLibraryCountMethod · 0.80
UpdateMethod · 0.65
NewMethod · 0.45

Tested by

no test coverage detected