fix removing workspace from users
This commit is contained in:
@@ -35,6 +35,7 @@ func (aH *AccessHandler) AddWorkspace(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uid, err := uuid.NewUUID()
|
uid, err := uuid.NewUUID()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
aH.logger.Error("AddWorkspace", err)
|
aH.logger.Error("AddWorkspace", err)
|
||||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||||
@@ -53,7 +54,7 @@ func (aH *AccessHandler) AddWorkspace(c *gin.Context) {
|
|||||||
aH.dbHandler.AddNewColum(&models.Workspace{
|
aH.dbHandler.AddNewColum(&models.Workspace{
|
||||||
Name: workspace.Name,
|
Name: workspace.Name,
|
||||||
Description: workspace.Description,
|
Description: workspace.Description,
|
||||||
Uuid: uid,
|
Uuid: &uid,
|
||||||
})
|
})
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
@@ -155,15 +156,22 @@ func (aH *AccessHandler) DeleteWorkspace(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, u := range users {
|
for _, u := range users {
|
||||||
if u.Workspaces == nil {
|
if u.Settings.Workspace == nil {
|
||||||
continue
|
continue
|
||||||
} else if u.Settings.Workspace.Name == workspace.Name {
|
} else if u.Settings.Workspace.Uuid.String() == workspace.Uuid.String() {
|
||||||
u.Settings.Workspace = nil
|
u.Settings.Workspace = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
u.Workspaces = slices.DeleteFunc(u.Workspaces, func(w *models.Workspace) bool {
|
u.Workspaces = slices.DeleteFunc(u.Workspaces, func(w *models.Workspace) bool {
|
||||||
return w != nil && w.Name == workspace.Name
|
return w != nil && w.Name == workspace.Name
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if err := aH.dbHandler.UpdateValuesById(&u, u.Id); err != nil {
|
||||||
|
aH.logger.Error("DeleteWorkspace", err)
|
||||||
|
c.JSON(http.StatusInternalServerError, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove folder
|
// remove folder
|
||||||
@@ -192,13 +200,15 @@ func (aH *AccessHandler) ReadWorkspaceData(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if workspace.Uuid == uuid.Nil {
|
if workspace.Uuid == nil {
|
||||||
aH.logger.Error("ReadWorkspaceData", "uuid nil")
|
aH.logger.Error("ReadWorkspaceData", "uuid nil")
|
||||||
c.JSON(http.StatusBadRequest, nil)
|
c.JSON(http.StatusBadRequest, nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
fmt.Println(123, workspace)
|
||||||
files, err := os.ReadDir(workspace.Uuid.String())
|
files, err := os.ReadDir(workspace.Uuid.String())
|
||||||
|
fmt.Println(124, err)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
aH.logger.Error("ReadWorkspaceData", err)
|
aH.logger.Error("ReadWorkspaceData", err)
|
||||||
c.JSON(http.StatusBadRequest, nil)
|
c.JSON(http.StatusBadRequest, nil)
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ package models
|
|||||||
import "github.com/google/uuid"
|
import "github.com/google/uuid"
|
||||||
|
|
||||||
type Workspace struct {
|
type Workspace struct {
|
||||||
Id uint `gorm:"primaryKey" json:"id"`
|
Id uint `gorm:"primaryKey" json:"id"`
|
||||||
Name string `gorm:"column:name" json:"name"`
|
Name string `gorm:"column:name" json:"name"`
|
||||||
Description string `gorm:"type:json" json:"description"`
|
Description string `gorm:"type:json" json:"description"`
|
||||||
Uuid uuid.UUID `gorm:"type:text" json:"uuid"`
|
Uuid *uuid.UUID `gorm:"type:text" json:"uuid,omitempty"`
|
||||||
Users []*User `gorm:"many2many:users_workspaces;" `
|
Users []*User `gorm:"many2many:users_workspaces;" `
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user