change user db structure for workspaces
This commit is contained in:
@@ -127,6 +127,7 @@ func (aH *AccessHandler) Login(c *gin.Context) {
|
||||
"user": user.Name,
|
||||
"role": user.Role.Role,
|
||||
"settings": user.Settings,
|
||||
"workspace": user.WorkspaceID,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -226,6 +227,7 @@ func (aH *AccessHandler) Me(c *gin.Context) {
|
||||
"id": claims["id"],
|
||||
"user": claims["username"],
|
||||
"role": claims["role"],
|
||||
"workspace": claims["workspace"],
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -156,10 +156,10 @@ func (aH *AccessHandler) DeleteWorkspace(c *gin.Context) {
|
||||
}
|
||||
|
||||
for _, u := range users {
|
||||
if u.Settings.Workspace == nil {
|
||||
if u.WorkspaceID == nil {
|
||||
continue
|
||||
} else if u.Settings.Workspace.Uuid.String() == workspace.Uuid.String() {
|
||||
u.Settings.Workspace = nil
|
||||
} else if *u.WorkspaceID == workspace.Id {
|
||||
u.WorkspaceID = nil
|
||||
}
|
||||
|
||||
u.Workspaces = slices.DeleteFunc(u.Workspaces, func(w *models.Workspace) bool {
|
||||
|
||||
@@ -15,7 +15,6 @@ type Settings struct {
|
||||
AppName string `json:"appName,omitempty"`
|
||||
DatabaseName string `json:"databaseName,omitempty"`
|
||||
DatabaseToken string `json:"databaseToken,omitempty"`
|
||||
Workspace *Workspace `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 {
|
||||
|
||||
Reference in New Issue
Block a user