MCPcopy Create free account
hub / github.com/pydio/cells / DeleteWorkspace

Method DeleteWorkspace

idm/workspace/rest/handler.go:159–196  ·  view source on GitHub ↗
(req *restful.Request, rsp *restful.Response)

Source from the content-addressed store, hash-verified

157}
158
159func (h *WorkspaceHandler) DeleteWorkspace(req *restful.Request, rsp *restful.Response) error {
160
161 slug := req.PathParameter("Slug")
162 log.Logger(req.Request.Context()).Debug("Received Workspace.Delete API request", zap.String("Slug", slug))
163 singleQ := &idm.WorkspaceSingleQuery{}
164 singleQ.Slug = slug
165
166 query, _ := anypb.New(singleQ)
167 serviceQuery := &service.Query{SubQueries: []*anypb.Any{query}}
168
169 ctx := req.Request.Context()
170 cli := idmc.WorkspaceServiceClient(ctx)
171
172 stream, e := cli.SearchWorkspace(ctx, &idm.SearchWorkspaceRequest{Query: serviceQuery})
173 if resp, found, er := commons.MustStreamOne[*idm.SearchWorkspaceResponse](stream, e); er != nil {
174 return er
175 } else if !found {
176 return errors.WithAPICode(errors.WorkspaceNotFound, errors.ApiWorkspaceNotFound)
177 } else if !h.MatchPolicies(ctx, resp.Workspace.UUID, resp.Workspace.Policies, service.ResourcePolicyAction_WRITE) {
178 log.Auditer(ctx).Error(
179 fmt.Sprintf("Forbidden action could not delete workspace [%s]", slug),
180 log.GetAuditId(common.AuditWsDelete),
181 )
182 return errors.WithAPICode(errors.StatusForbidden, errors.ApiWorkspaceNotEditable, "You are not allowed to edit this workspace!")
183 }
184
185 n, er := cli.DeleteWorkspace(req.Request.Context(), &idm.DeleteWorkspaceRequest{Query: serviceQuery})
186 if er != nil {
187 return er
188 }
189
190 log.Auditer(ctx).Info(
191 fmt.Sprintf("Removed workspace [%s]", slug),
192 log.GetAuditId(common.AuditWsDelete),
193 )
194 return rsp.WriteEntity(&rest.DeleteResponse{Success: true, NumRows: n.RowsDeleted})
195
196}
197
198func (h *WorkspaceHandler) SearchWorkspaces(req *restful.Request, rsp *restful.Response) error {
199

Callers

nothing calls this directly

Calls 15

LoggerFunction · 0.92
WorkspaceServiceClientFunction · 0.92
MustStreamOneFunction · 0.92
WithAPICodeFunction · 0.92
AuditerFunction · 0.92
GetAuditIdFunction · 0.92
DebugMethod · 0.65
ContextMethod · 0.65
StringMethod · 0.65
NewMethod · 0.65
SearchWorkspaceMethod · 0.65
MatchPoliciesMethod · 0.65

Tested by

no test coverage detected