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

Function GetSpace

api/controller/space.go:193–256  ·  view source on GitHub ↗

GetSpace godoc @Summary 获取空间详情 @Description 获取指定空间的详细信息 @Tags 空间管理 @Accept json @Produce json @Security BearerAuth @Param space_id path int true "空间ID" @Success 200 {object} model.CommonResponse{data=model.Space} @Router /api/spaces/{space_id} [get]

(c *gin.Context)

Source from the content-addressed store, hash-verified

191// @Success 200 {object} model.CommonResponse{data=model.Space}
192// @Router /api/spaces/{space_id} [get]
193func GetSpace(c *gin.Context) {
194 eid := config.GetEID(c)
195 userID := config.GetUserId(c)
196
197 id := c.Param("space_id")
198 if id == "" {
199 c.JSON(http.StatusBadRequest, model.ParamError.ToResponse(errors.New("空间ID不能为空")))
200 return
201 }
202
203 spaceID, err := strconv.ParseInt(id, 10, 64)
204 if err != nil {
205 c.JSON(http.StatusBadRequest, model.ParamError.ToResponse(errors.New("无效的空间ID")))
206 return
207 }
208
209 // 检查功能是否可用
210 params := map[string]interface{}{
211 "from": "space",
212 }
213 _, featureErr := service.IsFeatureAvailable(c, "space", params)
214 if featureErr != nil {
215 c.JSON(http.StatusForbidden, model.FeatureNotAvailableError.ToResponse(featureErr))
216 return
217 }
218
219 // 检查用户是否是空间成员
220 sps := service.NewSpacePermissionService(eid)
221 canViewSpc, err := sps.CheckSpacePermission(userID, spaceID, model.PERMISSION_PUBLIC_ONLY)
222
223 if (!canViewSpc || err != nil) && !common.IsAdmin(c) {
224 logger.SysLogf("User %d has no permission to access space %d", userID, spaceID)
225 c.JSON(http.StatusForbidden, model.AuthFailed.ToResponse(errors.New("无权限访问此空间")))
226 return
227 }
228
229 space, err := model.GetSpaceByID(eid, spaceID)
230 if err != nil {
231 c.JSON(http.StatusNotFound, model.NotFound.ToResponse(err))
232 return
233 }
234
235 // 获取用户对该空间的实际权限值(管理员跳过权限获取,直接设为管理权限)
236 if common.IsAdmin(c) {
237 space.Permission = model.PERMISSION_MANAGE
238 } else {
239 permission, err := sps.GetUserSpacePermission(userID, spaceID)
240 if err != nil {
241 c.JSON(http.StatusInternalServerError, model.SystemError.ToResponse(err))
242 return
243 }
244 space.Permission = permission
245 }
246
247 domain := config.GetProtocol(c) + "://" + config.GetDomain(c)
248 if icon := space.Icon; len(icon) > 0 && icon[0] == '/' {
249 space.Icon = domain + icon
250 }

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected