Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f4b00ba297 | ||
|
|
5b1488e347 | ||
|
|
6e3df3ffa0 | ||
|
|
9dc6c217fa | ||
|
|
c4bd121388 |
@@ -122,11 +122,12 @@ func (aH *AccessHandler) Login(c *gin.Context) {
|
||||
aH.logger.Info("Login", "user "+user.Name+" logged in successfully")
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "login successful",
|
||||
"id": user.Id,
|
||||
"user": user.Name,
|
||||
"role": user.Role.Role,
|
||||
"settings": user.Settings,
|
||||
"message": "login successful",
|
||||
"id": user.Id,
|
||||
"user": user.Name,
|
||||
"role": user.Role.Role,
|
||||
"settings": user.Settings,
|
||||
"workspace": user.WorkspaceID,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -223,9 +224,10 @@ func (aH *AccessHandler) Me(c *gin.Context) {
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"id": claims["id"],
|
||||
"user": claims["username"],
|
||||
"role": claims["role"],
|
||||
"id": claims["id"],
|
||||
"user": claims["username"],
|
||||
"role": claims["role"],
|
||||
"workspace": claims["workspace"],
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -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{
|
||||
@@ -153,23 +154,34 @@ func (aH *AccessHandler) DeleteWorkspace(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, nil)
|
||||
return
|
||||
}
|
||||
|
||||
for _, u := range users {
|
||||
if u.Settings.Workspace == workspace.Name {
|
||||
u.Settings.Workspace = ""
|
||||
if u.WorkspaceID == nil {
|
||||
continue
|
||||
} else if *u.WorkspaceID == workspace.Id {
|
||||
u.WorkspaceID = 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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// crearemove folder
|
||||
// remove folder
|
||||
err = os.RemoveAll(workspace.Uuid.String())
|
||||
if err != nil {
|
||||
aH.logger.Error("DeleteWorkspace", err)
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
@@ -188,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)
|
||||
|
||||
@@ -15,7 +15,6 @@ type Settings struct {
|
||||
AppName string `json:"appName,omitempty"`
|
||||
DatabaseName string `json:"databaseName,omitempty"`
|
||||
DatabaseToken string `json:"databaseToken,omitempty"`
|
||||
Workspace string `json:"workspace,omitempty"`
|
||||
}
|
||||
|
||||
func (s *Settings) DefaultQuasarSettings() {
|
||||
|
||||
@@ -15,6 +15,7 @@ type User struct {
|
||||
Expiration string `gorm:"column:expiration" json:"expiration,omitempty"`
|
||||
Settings Settings `gorm:"type:json" json:"settings"`
|
||||
Workspaces []*Workspace `gorm:"many2many:users_workspaces;" json:"workspaces"`
|
||||
WorkspaceID *uint `gorm:"column:workspaceId" json:"workspaceId,omitempty"`
|
||||
}
|
||||
|
||||
func (u *User) IsValid() bool {
|
||||
|
||||
@@ -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;" json:"-"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user