75f3dd141c
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (actions) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
CI and Release / lint-frontend (push) Has been cancelled
CI and Release / dockerfile-scan (push) Has been cancelled
CI and Release / test-frontend (push) Has been cancelled
CI and Release / lint-verification-agent (push) Has been cancelled
CI and Release / test-verification-agent (push) Has been cancelled
CI and Release / e2e-verification-agent (push) Has been cancelled
CI and Release / test-backend (push) Has been cancelled
CI and Release / build-dev-image (push) Has been cancelled
CI and Release / push-dev-image (push) Has been cancelled
CI and Release / build-image (push) Has been cancelled
CI and Release / build-verification-image (push) Has been cancelled
CI and Release / determine-version (push) Has been cancelled
CI and Release / push-image (push) Has been cancelled
CI and Release / push-verification-image (12) (push) Has been cancelled
CI and Release / lint-backend (push) Has been cancelled
CI and Release / push-verification-image (17) (push) Has been cancelled
CI and Release / push-verification-image (18) (push) Has been cancelled
CI and Release / release (push) Has been cancelled
CI and Release / publish-helm-chart (push) Has been cancelled
CI and Release / push-verification-image (13) (push) Has been cancelled
CI and Release / push-verification-image (14) (push) Has been cancelled
CI and Release / push-verification-image (15) (push) Has been cancelled
CI and Release / push-verification-image (16) (push) Has been cancelled
59 lines
1.7 KiB
Go
59 lines
1.7 KiB
Go
package users_models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
users_enums "databasus-backend/internal/features/users/enums"
|
|
)
|
|
|
|
type User struct {
|
|
ID uuid.UUID `json:"id"`
|
|
Email string `json:"email"`
|
|
Name string `json:"name"`
|
|
HashedPassword *string `json:"-" gorm:"column:hashed_password"`
|
|
PasswordCreationTime time.Time `json:"-" gorm:"column:password_creation_time"`
|
|
Role users_enums.UserRole `json:"role"`
|
|
Status users_enums.UserStatus `json:"status"`
|
|
GitHubOAuthID *string `json:"-" gorm:"column:github_oauth_id"`
|
|
GoogleOAuthID *string `json:"-" gorm:"column:google_oauth_id"`
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
}
|
|
|
|
func (User) TableName() string {
|
|
return "users"
|
|
}
|
|
|
|
// Permission methods
|
|
func (u *User) CanInviteUsers(settings *UsersSettings) bool {
|
|
if u.Role == users_enums.UserRoleAdmin {
|
|
return true
|
|
}
|
|
|
|
return u.Role == users_enums.UserRoleMember && settings.IsAllowMemberInvitations
|
|
}
|
|
|
|
func (u *User) CanManageUsers() bool {
|
|
return u.Role == users_enums.UserRoleAdmin
|
|
}
|
|
|
|
func (u *User) CanUpdateSettings() bool {
|
|
return u.Role == users_enums.UserRoleAdmin
|
|
}
|
|
|
|
func (u *User) CanCreateWorkspaces(settings *UsersSettings) bool {
|
|
if u.Role == users_enums.UserRoleAdmin {
|
|
return true
|
|
}
|
|
return u.Role == users_enums.UserRoleMember && settings.IsMemberAllowedToCreateWorkspaces
|
|
}
|
|
|
|
func (u *User) IsActiveUser() bool {
|
|
return u.Status == users_enums.UserStatusActive
|
|
}
|
|
|
|
func (u *User) HasPassword() bool {
|
|
return u.HashedPassword != nil && *u.HashedPassword != ""
|
|
}
|