Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
093c55616c | ||
|
|
a99189b31a | ||
|
|
38a7660d41 | ||
|
|
7d604189af | ||
|
|
4b574d4486 | ||
|
|
a094b70b5b | ||
|
|
3eb40bc02f | ||
|
|
81959425a1 | ||
|
|
857d84d3a9 | ||
|
|
1f4f9a12aa | ||
|
|
206639cf72 | ||
|
|
9a47a74764 | ||
|
|
8cbf36c5b3 |
4
go.mod
4
go.mod
@@ -3,11 +3,12 @@ module gitea.tecamino.com/paadi/access-handler
|
|||||||
go 1.24.5
|
go 1.24.5
|
||||||
|
|
||||||
require (
|
require (
|
||||||
gitea.tecamino.com/paadi/dbHandler v1.1.7
|
gitea.tecamino.com/paadi/dbHandler v1.1.12
|
||||||
gitea.tecamino.com/paadi/tecamino-logger v0.2.1
|
gitea.tecamino.com/paadi/tecamino-logger v0.2.1
|
||||||
github.com/gin-gonic/gin v1.11.0
|
github.com/gin-gonic/gin v1.11.0
|
||||||
github.com/go-playground/assert/v2 v2.2.0
|
github.com/go-playground/assert/v2 v2.2.0
|
||||||
github.com/golang-jwt/jwt/v5 v5.3.0
|
github.com/golang-jwt/jwt/v5 v5.3.0
|
||||||
|
github.com/google/uuid v1.3.0
|
||||||
golang.org/x/crypto v0.43.0
|
golang.org/x/crypto v0.43.0
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -25,7 +26,6 @@ require (
|
|||||||
github.com/go-playground/validator/v10 v10.27.0 // indirect
|
github.com/go-playground/validator/v10 v10.27.0 // indirect
|
||||||
github.com/goccy/go-json v0.10.2 // indirect
|
github.com/goccy/go-json v0.10.2 // indirect
|
||||||
github.com/goccy/go-yaml v1.18.0 // indirect
|
github.com/goccy/go-yaml v1.18.0 // indirect
|
||||||
github.com/google/uuid v1.3.0 // indirect
|
|
||||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||||
github.com/jinzhu/now v1.1.5 // indirect
|
github.com/jinzhu/now v1.1.5 // indirect
|
||||||
github.com/json-iterator/go v1.1.12 // indirect
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -1,5 +1,5 @@
|
|||||||
gitea.tecamino.com/paadi/dbHandler v1.1.7 h1:NqVbxbUwd7EZX6HYntyLYwwPbyTPevOhIBTFqoCVqOU=
|
gitea.tecamino.com/paadi/dbHandler v1.1.12 h1:F1ARSTUm0MZmF84FfD/g5RQNMYyDYXHYrB3cXPSi4qw=
|
||||||
gitea.tecamino.com/paadi/dbHandler v1.1.7/go.mod h1:y/xn/POJg1DO++67uKvnO23lJQgh+XFQq7HZCS9Getw=
|
gitea.tecamino.com/paadi/dbHandler v1.1.12/go.mod h1:y/xn/POJg1DO++67uKvnO23lJQgh+XFQq7HZCS9Getw=
|
||||||
gitea.tecamino.com/paadi/tecamino-logger v0.2.1 h1:sQTBKYPdzn9mmWX2JXZBtGBvNQH7cuXIwsl4TD0aMgE=
|
gitea.tecamino.com/paadi/tecamino-logger v0.2.1 h1:sQTBKYPdzn9mmWX2JXZBtGBvNQH7cuXIwsl4TD0aMgE=
|
||||||
gitea.tecamino.com/paadi/tecamino-logger v0.2.1/go.mod h1:FkzRTldUBBOd/iy2upycArDftSZ5trbsX5Ira5OzJgM=
|
gitea.tecamino.com/paadi/tecamino-logger v0.2.1/go.mod h1:FkzRTldUBBOd/iy2upycArDftSZ5trbsX5Ira5OzJgM=
|
||||||
github.com/bytedance/sonic v1.14.0 h1:/OfKt8HFw0kh2rj8N0F6C/qPGRESq0BbaNZgcNXXzQQ=
|
github.com/bytedance/sonic v1.14.0 h1:/OfKt8HFw0kh2rj8N0F6C/qPGRESq0BbaNZgcNXXzQQ=
|
||||||
|
|||||||
@@ -15,8 +15,9 @@ import (
|
|||||||
// authentication and authorization operations can be performed
|
// authentication and authorization operations can be performed
|
||||||
// consistently across the application.
|
// consistently across the application.
|
||||||
type AccessHandler struct {
|
type AccessHandler struct {
|
||||||
dbHandler *dbHandler.DBHandler // Database handler used for managing users and roles
|
dbHandler *dbHandler.DBHandler // Database handler used for managing users and roles
|
||||||
logger *logging.Logger // Centralized application logger
|
logger *logging.Logger // Centralized application logger
|
||||||
|
NewDBCreated bool // inticator new user db created
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewAccessHandler
|
// NewAccessHandler
|
||||||
@@ -81,6 +82,17 @@ func NewAccessHandler(path string, logger *logging.Logger) (aH *AccessHandler, e
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.Debug("NewAccessHandler", "add workspace table")
|
||||||
|
// Add the role table to the database
|
||||||
|
err = aH.AddWorkspaceTable()
|
||||||
|
if err != nil {
|
||||||
|
aH.logger.Error("NewAccessHandler", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//indicator that user database was created
|
||||||
|
aH.NewDBCreated = aH.dbHandler.NewCreatedDB
|
||||||
|
|
||||||
logger.Debug("NewAccessHandler", "add default role")
|
logger.Debug("NewAccessHandler", "add default role")
|
||||||
// Add default roles to the system
|
// Add default roles to the system
|
||||||
err = aH.AddDefaultRole()
|
err = aH.AddDefaultRole()
|
||||||
|
|||||||
@@ -215,7 +215,13 @@ func (aH *AccessHandler) Me(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
claims := token.Claims.(jwt.MapClaims)
|
claims, ok := token.Claims.(jwt.MapClaims)
|
||||||
|
if !ok {
|
||||||
|
aH.logger.Error("Me", "error: token.Claims.(jwt.MapClaims)")
|
||||||
|
c.JSON(http.StatusInternalServerError, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"id": claims["id"],
|
"id": claims["id"],
|
||||||
"user": claims["username"],
|
"user": claims["username"],
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ func (aH *AccessHandler) AddDefaultUser() (err error) {
|
|||||||
if err := aH.dbHandler.GetByKey(role, "role", "admin", false); err != nil {
|
if err := aH.dbHandler.GetByKey(role, "role", "admin", false); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return aH.dbHandler.AddRelation(user, role, "Role")
|
return aH.dbHandler.AddRelation(user, role, "Role")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,6 +113,10 @@ func (aH *AccessHandler) AddUser(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(user.Workspaces) > 0 {
|
||||||
|
aH.dbHandler.AddRelation(&user, user.Workspaces, "Workspaces")
|
||||||
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"message": fmt.Sprintf("user '%s' successfully added", user.Name),
|
"message": fmt.Sprintf("user '%s' successfully added", user.Name),
|
||||||
})
|
})
|
||||||
@@ -128,7 +133,7 @@ func (aH *AccessHandler) ChangePassword(c *gin.Context) {
|
|||||||
|
|
||||||
// get user to check ChangePassword
|
// get user to check ChangePassword
|
||||||
var dbRecord models.User
|
var dbRecord models.User
|
||||||
err = aH.dbHandler.GetById(&dbRecord, user.Id, "Role")
|
err = aH.dbHandler.GetById(&dbRecord, user.Id, "Role", "Workspaces")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
aH.logger.Error("ChangePassword", err)
|
aH.logger.Error("ChangePassword", err)
|
||||||
c.JSON(http.StatusInternalServerError, nil)
|
c.JSON(http.StatusInternalServerError, nil)
|
||||||
@@ -154,7 +159,7 @@ func (aH *AccessHandler) ChangePassword(c *gin.Context) {
|
|||||||
aH.logger.Debug("ChangePassword", "change user "+user.Name+" password")
|
aH.logger.Debug("ChangePassword", "change user "+user.Name+" password")
|
||||||
|
|
||||||
// Update user
|
// Update user
|
||||||
aH.dbHandler.UpdateValuesById(&user, user.Id, "Role")
|
aH.dbHandler.UpdateValuesById(&user, user.Id, "Role", "Workspaces")
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"message": fmt.Sprintf("password of user '%s' changed", user.Name),
|
"message": fmt.Sprintf("password of user '%s' changed", user.Name),
|
||||||
@@ -178,12 +183,18 @@ func (aH *AccessHandler) GetUser(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var users []models.User
|
var users []models.User
|
||||||
err = aH.dbHandler.GetById(&users, uint(i), "Role")
|
err = aH.dbHandler.GetById(&users, uint(i), "Role", "Workspaces")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
aH.logger.Error("GetUser", err)
|
aH.logger.Error("GetUser", err)
|
||||||
c.JSON(http.StatusInternalServerError, nil)
|
c.JSON(http.StatusInternalServerError, nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//remove password
|
||||||
|
for i := range users {
|
||||||
|
users[i].Password = ""
|
||||||
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, users)
|
c.JSON(http.StatusOK, users)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,12 +205,29 @@ func (aH *AccessHandler) UpdateUser(c *gin.Context) {
|
|||||||
c.JSON(http.StatusInternalServerError, nil)
|
c.JSON(http.StatusInternalServerError, nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err := aH.dbHandler.UpdateValuesById(&user, user.Id, "Role")
|
|
||||||
|
var currentUser models.User
|
||||||
|
err := aH.dbHandler.GetById(¤tUser, user.Id, "Role", "Workspaces")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
aH.logger.Error("UpdateUser", err)
|
aH.logger.Error("UpdateUser", err)
|
||||||
c.JSON(http.StatusInternalServerError, nil)
|
c.JSON(http.StatusInternalServerError, nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = aH.dbHandler.ReplaceRelation(&user, "Workspaces", user.Workspaces)
|
||||||
|
if err != nil {
|
||||||
|
aH.logger.Error("UpdateUser", err)
|
||||||
|
c.JSON(http.StatusInternalServerError, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = aH.dbHandler.UpdateValuesById(&user, user.Id, "Role", "Workspaces")
|
||||||
|
if err != nil {
|
||||||
|
aH.logger.Error("UpdateUser", err)
|
||||||
|
c.JSON(http.StatusInternalServerError, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, models.NewJsonMessageResponse("successfully updated user '"+user.Email+"'"))
|
c.JSON(http.StatusOK, models.NewJsonMessageResponse("successfully updated user '"+user.Email+"'"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
208
handlers/workspace.go
Normal file
208
handlers/workspace.go
Normal file
@@ -0,0 +1,208 @@
|
|||||||
|
package handlers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"slices"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"gitea.tecamino.com/paadi/access-handler/models"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (aH *AccessHandler) AddWorkspaceTable() error {
|
||||||
|
return aH.dbHandler.AddNewTable(models.Workspace{})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (aH *AccessHandler) AddWorkspace(c *gin.Context) {
|
||||||
|
var workspace models.Workspace
|
||||||
|
err := c.BindJSON(&workspace)
|
||||||
|
if err != nil {
|
||||||
|
aH.logger.Error("AddWorkspace", err)
|
||||||
|
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if a workspace with this name already exists
|
||||||
|
if aH.dbHandler.Exists(&models.Workspace{}, "name", workspace.Name, false) {
|
||||||
|
aH.logger.Error("AddWorkspace", fmt.Sprintf("workspace with name %s already exists", workspace.Name))
|
||||||
|
c.JSON(http.StatusBadRequest, models.NewJsonMessageResponse(fmt.Sprintf("workspace with name %s already exists", workspace.Name)))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
uid, err := uuid.NewUUID()
|
||||||
|
if err != nil {
|
||||||
|
aH.logger.Error("AddWorkspace", err)
|
||||||
|
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// create new folder
|
||||||
|
err = os.MkdirAll(uid.String(), 0644)
|
||||||
|
if err != nil {
|
||||||
|
aH.logger.Error("AddWorkspace", err)
|
||||||
|
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert new workspace with provided permissions
|
||||||
|
aH.dbHandler.AddNewColum(&models.Workspace{
|
||||||
|
Name: workspace.Name,
|
||||||
|
Description: workspace.Description,
|
||||||
|
Uuid: uid,
|
||||||
|
})
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"message": fmt.Sprintf("workspace '%s' successfully added", workspace.Name),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (aH *AccessHandler) GetWorkspace(c *gin.Context) {
|
||||||
|
var i int
|
||||||
|
var err error
|
||||||
|
var workspaces []models.Workspace
|
||||||
|
|
||||||
|
workspace := c.Query("workspace")
|
||||||
|
id := c.Query("id")
|
||||||
|
|
||||||
|
if workspace != "" {
|
||||||
|
err = aH.dbHandler.GetByKey(&workspaces, "workspace", workspace, false)
|
||||||
|
} else if id != "" {
|
||||||
|
i, err = strconv.Atoi(id)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{
|
||||||
|
"message": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = aH.dbHandler.GetById(&workspaces, uint(i))
|
||||||
|
} else {
|
||||||
|
err = aH.dbHandler.GetById(&workspaces, 0)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
aH.logger.Error("GetWorkspace", err)
|
||||||
|
c.JSON(http.StatusInternalServerError, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, workspaces)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (aH *AccessHandler) UpdateWorkspace(c *gin.Context) {
|
||||||
|
var workspace models.Workspace
|
||||||
|
if err := c.BindJSON(&workspace); err != nil {
|
||||||
|
aH.logger.Error("UpdateWorkspace", err)
|
||||||
|
c.JSON(http.StatusInternalServerError, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if workspace.Id != 0 {
|
||||||
|
err := aH.dbHandler.UpdateValuesById(&workspace, workspace.Id)
|
||||||
|
if err != nil {
|
||||||
|
aH.logger.Error("UpdateWorkspace", err)
|
||||||
|
c.JSON(http.StatusInternalServerError, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err := aH.dbHandler.UpdateValuesByKey(&workspace, "", "workspace", workspace.Name)
|
||||||
|
if err != nil {
|
||||||
|
aH.logger.Error("UpdateWorkspace", err)
|
||||||
|
c.JSON(http.StatusInternalServerError, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, models.NewJsonMessageResponse("successfully updated workspace '"+workspace.Name+"'"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (aH *AccessHandler) DeleteWorkspace(c *gin.Context) {
|
||||||
|
|
||||||
|
var request struct {
|
||||||
|
Workspaces []models.Workspace `json:"workspaces"`
|
||||||
|
}
|
||||||
|
|
||||||
|
err := c.BindJSON(&request)
|
||||||
|
if err != nil {
|
||||||
|
aH.logger.Error("DeleteWorkspace", err)
|
||||||
|
c.JSON(http.StatusBadRequest, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(request.Workspaces) == 0 {
|
||||||
|
aH.logger.Error("DeleteWorkspace", "no ids given to be deleted")
|
||||||
|
c.JSON(http.StatusBadRequest, models.NewJsonMessageResponse("no workspaces given to be deleted"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, workspace := range request.Workspaces {
|
||||||
|
err = aH.dbHandler.DeleteByKey(&models.Workspace{}, "id", workspace.Id, false)
|
||||||
|
if err != nil {
|
||||||
|
aH.logger.Error("DeleteWorkspace", err)
|
||||||
|
c.JSON(http.StatusInternalServerError, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var users []models.User
|
||||||
|
if err := aH.dbHandler.GetById(&users, 0); err != nil {
|
||||||
|
aH.logger.Error("DeleteWorkspace", err)
|
||||||
|
c.JSON(http.StatusInternalServerError, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, u := range users {
|
||||||
|
if u.Settings.Workspace == workspace.Name {
|
||||||
|
u.Settings.Workspace = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
u.Workspaces = slices.DeleteFunc(u.Workspaces, func(w *models.Workspace) bool {
|
||||||
|
return w != nil && w.Name == workspace.Name
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// crearemove 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{
|
||||||
|
"message": "workspace(s) deleted",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (aH *AccessHandler) ReadWorkspaceData(c *gin.Context) {
|
||||||
|
|
||||||
|
var workspace models.Workspace
|
||||||
|
|
||||||
|
err := c.ShouldBindBodyWithJSON(&workspace)
|
||||||
|
if err != nil {
|
||||||
|
aH.logger.Error("ReadWorkspaceData", err)
|
||||||
|
c.JSON(http.StatusBadRequest, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
files, err := os.ReadDir(workspace.Uuid.String())
|
||||||
|
if err != nil {
|
||||||
|
aH.logger.Error("ReadWorkspaceData", err)
|
||||||
|
c.JSON(http.StatusBadRequest, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var response []string
|
||||||
|
for _, f := range files {
|
||||||
|
if f.IsDir() || !strings.Contains(filepath.Ext(f.Name()), ".db") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
response = append(response, f.Name())
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"data": response,
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -15,6 +15,7 @@ type Settings struct {
|
|||||||
AppName string `json:"appName,omitempty"`
|
AppName string `json:"appName,omitempty"`
|
||||||
DatabaseName string `json:"databaseName,omitempty"`
|
DatabaseName string `json:"databaseName,omitempty"`
|
||||||
DatabaseToken string `json:"databaseToken,omitempty"`
|
DatabaseToken string `json:"databaseToken,omitempty"`
|
||||||
|
Workspace string `json:"workspace,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Settings) DefaultQuasarSettings() {
|
func (s *Settings) DefaultQuasarSettings() {
|
||||||
|
|||||||
@@ -5,15 +5,16 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
Id uint `gorm:"primaryKey" json:"id"`
|
Id uint `gorm:"primaryKey" json:"id"`
|
||||||
Name string `gorm:"column:user_name" json:"user"`
|
Name string `gorm:"column:user_name" json:"user"`
|
||||||
Email string `gorm:"column:email" json:"email"`
|
Email string `gorm:"column:email" json:"email"`
|
||||||
RoleID *uint `gorm:"column:roleId" json:"roleId,omitempty"`
|
RoleID *uint `gorm:"column:roleId" json:"roleId,omitempty"`
|
||||||
Role *Role `gorm:"foreignKey:RoleID" json:"role,omitempty"`
|
Role *Role `gorm:"foreignKey:RoleID" json:"role,omitempty"`
|
||||||
Password string `gorm:"column:password" json:"password"`
|
Password string `gorm:"column:password" json:"password,omitempty"`
|
||||||
NewPassword string `gorm:"-" json:"newPassword,omitempty"`
|
NewPassword string `gorm:"-" json:"newPassword,omitempty"`
|
||||||
Expiration string `gorm:"column:expiration" json:"expiration,omitempty"`
|
Expiration string `gorm:"column:expiration" json:"expiration,omitempty"`
|
||||||
Settings Settings `gorm:"type:json" json:"settings"`
|
Settings Settings `gorm:"type:json" json:"settings"`
|
||||||
|
Workspaces []*Workspace `gorm:"many2many:users_workspaces;" json:"workspaces"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *User) IsValid() bool {
|
func (u *User) IsValid() bool {
|
||||||
|
|||||||
11
models/workspace.go
Normal file
11
models/workspace.go
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
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;" `
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user