diff --git a/controllers/shared_workspace.go b/controllers/shared_workspace.go index 4a074c2..2b938a0 100644 --- a/controllers/shared_workspace.go +++ b/controllers/shared_workspace.go @@ -110,6 +110,115 @@ func (o *SharedWorkspaceController) Get() { o.ServeJSON() } +// @Title Add Workspace +// @Description find shared workspace by id +// @Param id path string true "the id you want to get" +// @Param id2 path string true "the id you want to add" +// @Success 200 {shared workspace} models.shared_workspace +// @router /:id/workspace/:id2 [delete] +func (o *SharedWorkspaceController) RemoveWorkspace() { + var res map[string]interface{} + id := o.Ctx.Input.Param(":id") + id2 := o.Ctx.Input.Param(":id2") + r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id) + shared := r.ToSharedWorkspace() + newWorkspace := []string{} + if slices.Contains(shared.Workspaces, id) { + for _, w := range shared.Workspaces { + if w != id2 { + newWorkspace = append(newWorkspace, w) + } + } + shared.Workspaces = newWorkspace + } + o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), res, id, nil) + o.ServeJSON() +} + +// @Title Remove Workflow +// @Description find shared workspace by id +// @Param id path string true "the id you want to get" +// @Param id2 path string true "the id you want to add" +// @Success 200 {shared workspace} models.shared_workspace +// @router /:id/workflow/:id2 [delete] +func (o *SharedWorkspaceController) RemoveWorkflow() { + var res map[string]interface{} + id := o.Ctx.Input.Param(":id") + id2 := o.Ctx.Input.Param(":id2") + r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id) + shared := r.ToSharedWorkspace() + newWorkflows := []string{} + if slices.Contains(shared.Workflows, id) { + for _, w := range shared.Workflows { + if w != id2 { + newWorkflows = append(newWorkflows, w) + } + } + shared.Workflows = newWorkflows + } + o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), res, id, nil) + o.ServeJSON() +} + +// @Title Remove Peer +// @Description find shared workspace by id +// @Param id path string true "the id you want to get" +// @Param id2 path string true "the id you want to add" +// @Success 200 {shared workspace} models.shared_workspace +// @router /:id/peer/:id2 [delete] +func (o *SharedWorkspaceController) RemovePeer() { + var res map[string]interface{} + id := o.Ctx.Input.Param(":id") + id2 := o.Ctx.Input.Param(":id2") + r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id) + shared := r.ToSharedWorkspace() + newPeers := []string{} + if shared.CreatorID != id2 { + o.Data["json"] = map[string]interface{}{ + "data": nil, + "code": 409, + "error": "You can't remove the creator from the shared workspace", + } + o.ServeJSON() + return + } + if slices.Contains(shared.Peers, id) && shared.CreatorID != id2 { + for _, peer := range shared.Peers { + if peer != id2 { + newPeers = append(newPeers, peer) + } + } + shared.Peers = newPeers + } + o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), res, id, nil) + o.ServeJSON() +} + +// @Title Remove Rule +// @Description find shared workspace by id +// @Param id path string true "the id you want to get" +// @Param id2 path string true "the id you want to add" +// @Success 200 {shared workspace} models.shared_workspace +// @router /:id/rule/:id2 [delete] +func (o *SharedWorkspaceController) RemoveRule() { + var res map[string]interface{} + id := o.Ctx.Input.Param(":id") + id2 := o.Ctx.Input.Param(":id2") + r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id) + shared := r.ToSharedWorkspace() + newRules := []string{} + if slices.Contains(shared.Rules, id) { + for _, rule := range shared.Rules { + if rule != id2 { + newRules = append(newRules, rule) + } + } + shared.Rules = newRules + } + o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), res, id, nil) + o.ServeJSON() +} + // @Title Add Workspace // @Description find shared workspace by id // @Param id path string true "the id you want to get" diff --git a/go.mod b/go.mod index 525fccb..f869286 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( ) require ( - cloud.o-forge.io/core/oc-lib v0.0.0-20240826103423-aff9304b1a71 // indirect + cloud.o-forge.io/core/oc-lib v0.0.0-20240826125854-050e6022cb8d // indirect filippo.io/edwards25519 v1.1.0 // indirect github.com/beego/bee/v2 v2.1.0 // indirect github.com/beorn7/perks v1.0.1 // indirect diff --git a/go.sum b/go.sum index 21ce4fd..f6a0e30 100644 --- a/go.sum +++ b/go.sum @@ -122,6 +122,8 @@ cloud.o-forge.io/core/oc-lib v0.0.0-20240822065024-fb80e05d6a7b h1:A7NBwTXoHTg/o cloud.o-forge.io/core/oc-lib v0.0.0-20240822065024-fb80e05d6a7b/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= cloud.o-forge.io/core/oc-lib v0.0.0-20240826103423-aff9304b1a71 h1:GodGMXVFgSdd5R1FoUjFAloOS+zOd3j66Wa+jcEPa4c= cloud.o-forge.io/core/oc-lib v0.0.0-20240826103423-aff9304b1a71/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240826125854-050e6022cb8d h1:CPwBFl2ecnHMi9sxubA9/peTKn4BVBVpHkCCwRTXUik= +cloud.o-forge.io/core/oc-lib v0.0.0-20240826125854-050e6022cb8d/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= diff --git a/oc-shared b/oc-shared index 5d2e7c4..90ee399 100755 Binary files a/oc-shared and b/oc-shared differ diff --git a/routers/commentsRouter.go b/routers/commentsRouter.go index 7fa67eb..7b4d424 100644 --- a/routers/commentsRouter.go +++ b/routers/commentsRouter.go @@ -115,6 +115,15 @@ func init() { Filters: nil, Params: nil}) + beego.GlobalControllerRouter["oc-shared/controllers:SharedWorkspaceController"] = append(beego.GlobalControllerRouter["oc-shared/controllers:SharedWorkspaceController"], + beego.ControllerComments{ + Method: "RemovePeer", + Router: `/:id/peer/:id2`, + AllowHTTPMethods: []string{"delete"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + beego.GlobalControllerRouter["oc-shared/controllers:SharedWorkspaceController"] = append(beego.GlobalControllerRouter["oc-shared/controllers:SharedWorkspaceController"], beego.ControllerComments{ Method: "AddRule", @@ -124,6 +133,24 @@ func init() { Filters: nil, Params: nil}) + beego.GlobalControllerRouter["oc-shared/controllers:SharedWorkspaceController"] = append(beego.GlobalControllerRouter["oc-shared/controllers:SharedWorkspaceController"], + beego.ControllerComments{ + Method: "RemoveRule", + Router: `/:id/rule/:id2`, + AllowHTTPMethods: []string{"delete"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + + beego.GlobalControllerRouter["oc-shared/controllers:SharedWorkspaceController"] = append(beego.GlobalControllerRouter["oc-shared/controllers:SharedWorkspaceController"], + beego.ControllerComments{ + Method: "RemoveWorkflow", + Router: `/:id/workflow/:id2`, + AllowHTTPMethods: []string{"delete"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + beego.GlobalControllerRouter["oc-shared/controllers:SharedWorkspaceController"] = append(beego.GlobalControllerRouter["oc-shared/controllers:SharedWorkspaceController"], beego.ControllerComments{ Method: "AddWorkflow", @@ -142,6 +169,15 @@ func init() { Filters: nil, Params: nil}) + beego.GlobalControllerRouter["oc-shared/controllers:SharedWorkspaceController"] = append(beego.GlobalControllerRouter["oc-shared/controllers:SharedWorkspaceController"], + beego.ControllerComments{ + Method: "RemoveWorkspace", + Router: `/:id/workspace/:id2`, + AllowHTTPMethods: []string{"delete"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + beego.GlobalControllerRouter["oc-shared/controllers:SharedWorkspaceController"] = append(beego.GlobalControllerRouter["oc-shared/controllers:SharedWorkspaceController"], beego.ControllerComments{ Method: "Search", diff --git a/swagger/swagger.json b/swagger/swagger.json index d86c19a..f6369a5 100644 --- a/swagger/swagger.json +++ b/swagger/swagger.json @@ -311,6 +311,34 @@ "description": "{shared workspace} models.shared_workspace" } } + }, + "delete": { + "tags": [ + "shared/workspace" + ], + "description": "find shared workspace by id\n\u003cbr\u003e", + "operationId": "SharedWorkspaceController.Remove Peer", + "parameters": [ + { + "in": "path", + "name": "id", + "description": "the id you want to get", + "required": true, + "type": "string" + }, + { + "in": "path", + "name": "id2", + "description": "the id you want to add", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "{shared workspace} models.shared_workspace" + } + } } }, "/shared/workspace/{id}/rule/{id2}": { @@ -341,6 +369,34 @@ "description": "{shared workspace} models.shared_workspace" } } + }, + "delete": { + "tags": [ + "shared/workspace" + ], + "description": "find shared workspace by id\n\u003cbr\u003e", + "operationId": "SharedWorkspaceController.Remove Rule", + "parameters": [ + { + "in": "path", + "name": "id", + "description": "the id you want to get", + "required": true, + "type": "string" + }, + { + "in": "path", + "name": "id2", + "description": "the id you want to add", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "{shared workspace} models.shared_workspace" + } + } } }, "/shared/workspace/{id}/workflow/{id2}": { @@ -371,6 +427,34 @@ "description": "{shared workspace} models.shared_workspace" } } + }, + "delete": { + "tags": [ + "shared/workspace" + ], + "description": "find shared workspace by id\n\u003cbr\u003e", + "operationId": "SharedWorkspaceController.Remove Workflow", + "parameters": [ + { + "in": "path", + "name": "id", + "description": "the id you want to get", + "required": true, + "type": "string" + }, + { + "in": "path", + "name": "id2", + "description": "the id you want to add", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "{shared workspace} models.shared_workspace" + } + } } }, "/shared/workspace/{id}/workspace/{id2}": { @@ -401,6 +485,34 @@ "description": "{shared workspace} models.shared_workspace" } } + }, + "delete": { + "tags": [ + "shared/workspace" + ], + "description": "find shared workspace by id\n\u003cbr\u003e", + "operationId": "SharedWorkspaceController.Add Workspace", + "parameters": [ + { + "in": "path", + "name": "id", + "description": "the id you want to get", + "required": true, + "type": "string" + }, + { + "in": "path", + "name": "id2", + "description": "the id you want to add", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "{shared workspace} models.shared_workspace" + } + } } }, "/version/": { diff --git a/swagger/swagger.yml b/swagger/swagger.yml index 9ddcf0c..bacc16e 100644 --- a/swagger/swagger.yml +++ b/swagger/swagger.yml @@ -117,6 +117,27 @@ paths: responses: "200": description: '{shared workspace} models.shared_workspace' + delete: + tags: + - shared/workspace + description: |- + find shared workspace by id +
+ operationId: SharedWorkspaceController.Remove Peer + parameters: + - in: path + name: id + description: the id you want to get + required: true + type: string + - in: path + name: id2 + description: the id you want to add + required: true + type: string + responses: + "200": + description: '{shared workspace} models.shared_workspace' /shared/workspace/{id}/rule/{id2}: post: tags: @@ -139,6 +160,27 @@ paths: responses: "200": description: '{shared workspace} models.shared_workspace' + delete: + tags: + - shared/workspace + description: |- + find shared workspace by id +
+ operationId: SharedWorkspaceController.Remove Rule + parameters: + - in: path + name: id + description: the id you want to get + required: true + type: string + - in: path + name: id2 + description: the id you want to add + required: true + type: string + responses: + "200": + description: '{shared workspace} models.shared_workspace' /shared/workspace/{id}/workflow/{id2}: post: tags: @@ -161,6 +203,27 @@ paths: responses: "200": description: '{shared workspace} models.shared_workspace' + delete: + tags: + - shared/workspace + description: |- + find shared workspace by id +
+ operationId: SharedWorkspaceController.Remove Workflow + parameters: + - in: path + name: id + description: the id you want to get + required: true + type: string + - in: path + name: id2 + description: the id you want to add + required: true + type: string + responses: + "200": + description: '{shared workspace} models.shared_workspace' /shared/workspace/{id}/workspace/{id2}: post: tags: @@ -183,6 +246,27 @@ paths: responses: "200": description: '{shared workspace} models.shared_workspace' + delete: + tags: + - shared/workspace + description: |- + find shared workspace by id +
+ operationId: SharedWorkspaceController.Add Workspace + parameters: + - in: path + name: id + description: the id you want to get + required: true + type: string + - in: path + name: id2 + description: the id you want to add + required: true + type: string + responses: + "200": + description: '{shared workspace} models.shared_workspace' /shared/workspace/rule/: get: tags: