Remove shared
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user