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