ubdata

package
v0.0.25 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataAdapter

type DataAdapter interface {

	// User operations
	AddUser(ctx context.Context, userID int64, firstName, lastName, displayName, email string, verified bool, createdAt int64, updatedAt int64) error
	GetUser(ctx context.Context, userID int64) (User, error)
	GetUserByEmail(ctx context.Context, email string) (User, error)
	SearchUsers(ctx context.Context, searchTerm string, limit, offset int) ([]User, error)
	UpdateUser(ctx context.Context, userID int64, firstName, lastName, displayName, email string, verified bool, updatedAt int64) error
	AddOrganization(ctx context.Context, id int64, name string, systemName string, status string) error
	GetOrganization(ctx context.Context, organizationID int64) (Organization, error)
	ListOrganizations(ctx context.Context) ([]Organization, error)
	GetOrganizationBySystemName(ctx context.Context, systemName string) (Organization, error)
	UpdateOrganization(ctx context.Context, id int64, name string, systemName string, status string) error

	// Role operations
	AddRole(ctx context.Context, roleID int64, organizationID int64, name string, systemName string) error
	UpdateRole(ctx context.Context, roleID int64, name string, systemName string) error
	DeleteRole(ctx context.Context, roleID int64) error
	GetOrganizationRoles(ctx context.Context, organizationID int64) ([]RoleRow, error)

	AddPermissionToRole(ctx context.Context, roleID int64, permission string) error
	RemovePermissionFromRole(ctx context.Context, roleID int64, permission string) error
	GetRolePermissions(ctx context.Context, roleID int64) ([]string, error)

	// User-Role operations
	AddUserToRole(ctx context.Context, userID int64, roleID int64) error
	RemoveUserFromRole(ctx context.Context, userID int64, roleID int64) error
	RemoveAllRolesFromUser(ctx context.Context, userID int64) error
	GetUserOrganizationRoles(ctx context.Context, userID int64, organizationId int64) ([]RoleRow, error)
	GetAllUserOrganizationRoles(ctx context.Context, userID int64) ([]ListUserOrganizationRolesRow, error)
	ListUserOrganizationRoles(ctx context.Context, userID int64) ([]ListUserOrganizationRolesRow, error)

	OrganizationsCount(ctx context.Context) (int64, error)
	UsersCount(ctx context.Context) (int64, error)
	UpdateUserLoginStats(ctx context.Context, userID int64, lastLogin int64, loginCount int64) error

	ListOrganizationsRolesWithUserCounts(ctx context.Context, organizationId int64) ([]ListRolesWithUserCountsRow, error)
	GetUsersInRole(ctx context.Context, roleID int64) ([]User, error)
	GetRolesForUser(ctx context.Context, userID int64) ([]RoleRow, error)

	UserAddApiKey(ctx context.Context, userID int64, organizationId int64, apiKeyId string, apiKeyHash, name string, createdAt time.Time, expiresAt time.Time) error
	UserDeleteApiKey(ctx context.Context, userID int64, apiKeyId string) error
	UserListApiKeys(ctx context.Context, userID int64) ([]UserApiKeyNoHash, error)
	UserGetApiKey(ctx context.Context, apiKeyId string) (UserApiKeyWithHash, error)
}

DataAdapter defines the common interface for user/role/permission operations

func NewDatabase

func NewDatabase(dbType ubconst.DatabaseType, db *sql.DB) DataAdapter

type ListRolesWithUserCountsRow added in v0.0.16

type ListRolesWithUserCountsRow struct {
	ID         int64
	Name       string
	SystemName string
	UserCount  int64
}

type ListUserOrganizationRolesRow added in v0.0.7

type ListUserOrganizationRolesRow struct {
	OrganizationID         int64
	Organization           string
	OrganizationSystemName string
	RoleID                 int64
	RoleName               string
	RoleSystemName         string
}

type Organization added in v0.0.7

type Organization struct {
	ID         int64
	Name       string
	SystemName string
	Status     string
}

type Permission

type Permission struct {
	PermissionID int64
	SystemName   string
}

Permission represents a permission in the system

type PostgresAdapter

type PostgresAdapter struct {
	// contains filtered or unexported fields
}

func NewPostgresAdapter

func NewPostgresAdapter(db *sql.DB) *PostgresAdapter

func (*PostgresAdapter) AddOrganization added in v0.0.7

func (a *PostgresAdapter) AddOrganization(ctx context.Context, id int64, name string, systemName string, status string) error

func (*PostgresAdapter) AddPermissionToRole

func (a *PostgresAdapter) AddPermissionToRole(ctx context.Context, roleID int64, permission string) error

func (*PostgresAdapter) AddRole

func (a *PostgresAdapter) AddRole(ctx context.Context, roleID int64, organizationID int64, name string, systemName string) error

func (*PostgresAdapter) AddUser

func (a *PostgresAdapter) AddUser(ctx context.Context, userID int64, firstName, lastName, displayName, email string, verified bool, createdAt int64, updatedAt int64) error

func (*PostgresAdapter) AddUserToRole added in v0.0.7

func (a *PostgresAdapter) AddUserToRole(ctx context.Context, userID int64, roleID int64) error

func (*PostgresAdapter) DeleteRole added in v0.0.7

func (a *PostgresAdapter) DeleteRole(ctx context.Context, roleID int64) error

func (*PostgresAdapter) GetAllUserOrganizationRoles added in v0.0.16

func (a *PostgresAdapter) GetAllUserOrganizationRoles(ctx context.Context, userID int64) ([]ListUserOrganizationRolesRow, error)

func (*PostgresAdapter) GetOrganization added in v0.0.7

func (a *PostgresAdapter) GetOrganization(ctx context.Context, organizationID int64) (Organization, error)

func (*PostgresAdapter) GetOrganizationBySystemName added in v0.0.7

func (a *PostgresAdapter) GetOrganizationBySystemName(ctx context.Context, systemName string) (Organization, error)

func (*PostgresAdapter) GetOrganizationRoles added in v0.0.7

func (a *PostgresAdapter) GetOrganizationRoles(ctx context.Context, organizationID int64) ([]RoleRow, error)

func (*PostgresAdapter) GetRolePermissions

func (a *PostgresAdapter) GetRolePermissions(ctx context.Context, roleID int64) ([]string, error)

func (*PostgresAdapter) GetRolesForUser added in v0.0.18

func (a *PostgresAdapter) GetRolesForUser(ctx context.Context, userID int64) ([]RoleRow, error)

func (*PostgresAdapter) GetUser

func (a *PostgresAdapter) GetUser(ctx context.Context, userID int64) (User, error)

func (*PostgresAdapter) GetUserByEmail

func (a *PostgresAdapter) GetUserByEmail(ctx context.Context, email string) (User, error)

func (*PostgresAdapter) GetUserOrganizationRoles added in v0.0.7

func (a *PostgresAdapter) GetUserOrganizationRoles(ctx context.Context, userID int64, organizationId int64) ([]RoleRow, error)

func (*PostgresAdapter) GetUsersInRole added in v0.0.18

func (a *PostgresAdapter) GetUsersInRole(ctx context.Context, roleID int64) ([]User, error)

func (*PostgresAdapter) ListOrganizations added in v0.0.7

func (a *PostgresAdapter) ListOrganizations(ctx context.Context) ([]Organization, error)

func (*PostgresAdapter) ListOrganizationsRolesWithUserCounts added in v0.0.16

func (a *PostgresAdapter) ListOrganizationsRolesWithUserCounts(ctx context.Context, organizationId int64) ([]ListRolesWithUserCountsRow, error)

func (*PostgresAdapter) ListUserOrganizationRoles added in v0.0.7

func (a *PostgresAdapter) ListUserOrganizationRoles(ctx context.Context, userID int64) ([]ListUserOrganizationRolesRow, error)

func (*PostgresAdapter) OrganizationsCount added in v0.0.16

func (a *PostgresAdapter) OrganizationsCount(ctx context.Context) (int64, error)

func (*PostgresAdapter) RemoveAllRolesFromUser

func (a *PostgresAdapter) RemoveAllRolesFromUser(ctx context.Context, userID int64) error

func (*PostgresAdapter) RemovePermissionFromRole

func (a *PostgresAdapter) RemovePermissionFromRole(ctx context.Context, roleID int64, permission string) error

func (*PostgresAdapter) RemoveUserFromRole added in v0.0.7

func (a *PostgresAdapter) RemoveUserFromRole(ctx context.Context, userID int64, roleID int64) error

func (*PostgresAdapter) SearchUsers added in v0.0.18

func (a *PostgresAdapter) SearchUsers(ctx context.Context, searchTerm string, limit, offset int) ([]User, error)

func (*PostgresAdapter) UpdateOrganization added in v0.0.7

func (a *PostgresAdapter) UpdateOrganization(ctx context.Context, id int64, name string, systemName string, status string) error

func (*PostgresAdapter) UpdateRole

func (a *PostgresAdapter) UpdateRole(ctx context.Context, roleID int64, name string, systemName string) error

func (*PostgresAdapter) UpdateUser

func (a *PostgresAdapter) UpdateUser(ctx context.Context, userID int64, firstName, lastName, displayName, email string, verified bool, updatedAt int64) error

func (*PostgresAdapter) UpdateUserLoginStats added in v0.0.16

func (a *PostgresAdapter) UpdateUserLoginStats(ctx context.Context, userID int64, lastLogin int64, loginCount int64) error

func (*PostgresAdapter) UserAddApiKey added in v0.0.18

func (a *PostgresAdapter) UserAddApiKey(ctx context.Context, userID int64, organizationId int64, apiKeyId string, secretHash string, name string, createdAt time.Time, expiresAt time.Time) error

func (*PostgresAdapter) UserDeleteApiKey added in v0.0.18

func (a *PostgresAdapter) UserDeleteApiKey(ctx context.Context, userID int64, apiKeyId string) error

func (*PostgresAdapter) UserGetApiKey added in v0.0.18

func (a *PostgresAdapter) UserGetApiKey(ctx context.Context, apiKeyHash string) (UserApiKeyWithHash, error)

func (*PostgresAdapter) UserListApiKeys added in v0.0.18

func (a *PostgresAdapter) UserListApiKeys(ctx context.Context, userID int64) ([]UserApiKeyNoHash, error)

func (*PostgresAdapter) UsersCount added in v0.0.16

func (a *PostgresAdapter) UsersCount(ctx context.Context) (int64, error)

type RoleRow added in v0.0.7

type RoleRow struct {
	ID         int64
	Name       string
	SystemName string
}

type SQLiteAdapter

type SQLiteAdapter struct {
	// contains filtered or unexported fields
}

func NewSQLiteAdapter

func NewSQLiteAdapter(db *sql.DB) *SQLiteAdapter

func (*SQLiteAdapter) AddOrganization added in v0.0.7

func (a *SQLiteAdapter) AddOrganization(ctx context.Context, id int64, name string, systemName string, status string) error

func (*SQLiteAdapter) AddPermissionToRole

func (a *SQLiteAdapter) AddPermissionToRole(ctx context.Context, roleID int64, permission string) error

func (*SQLiteAdapter) AddRole

func (a *SQLiteAdapter) AddRole(ctx context.Context, roleID int64, organizationID int64, name string, systemName string) error

func (*SQLiteAdapter) AddUser

func (a *SQLiteAdapter) AddUser(ctx context.Context, userID int64, firstName, lastName, displayName, email string, verified bool, createdAt int64, updatedAt int64) error

func (*SQLiteAdapter) AddUserToRole added in v0.0.7

func (a *SQLiteAdapter) AddUserToRole(ctx context.Context, userID int64, roleID int64) error

func (*SQLiteAdapter) DeleteRole added in v0.0.7

func (a *SQLiteAdapter) DeleteRole(ctx context.Context, roleID int64) error

func (*SQLiteAdapter) GetAllUserOrganizationRoles added in v0.0.16

func (a *SQLiteAdapter) GetAllUserOrganizationRoles(ctx context.Context, userID int64) ([]ListUserOrganizationRolesRow, error)

func (*SQLiteAdapter) GetOrganization added in v0.0.7

func (a *SQLiteAdapter) GetOrganization(ctx context.Context, organizationID int64) (Organization, error)

func (*SQLiteAdapter) GetOrganizationBySystemName added in v0.0.7

func (a *SQLiteAdapter) GetOrganizationBySystemName(ctx context.Context, systemName string) (Organization, error)

func (*SQLiteAdapter) GetOrganizationRoles added in v0.0.7

func (a *SQLiteAdapter) GetOrganizationRoles(ctx context.Context, organizationID int64) ([]RoleRow, error)

func (*SQLiteAdapter) GetRolePermissions

func (a *SQLiteAdapter) GetRolePermissions(ctx context.Context, roleID int64) ([]string, error)

func (*SQLiteAdapter) GetRolesForUser added in v0.0.18

func (a *SQLiteAdapter) GetRolesForUser(ctx context.Context, userID int64) ([]RoleRow, error)

func (*SQLiteAdapter) GetUser

func (a *SQLiteAdapter) GetUser(ctx context.Context, userID int64) (User, error)

func (*SQLiteAdapter) GetUserByEmail

func (a *SQLiteAdapter) GetUserByEmail(ctx context.Context, email string) (User, error)

func (*SQLiteAdapter) GetUserOrganizationRoles added in v0.0.7

func (a *SQLiteAdapter) GetUserOrganizationRoles(ctx context.Context, userID int64, organizationId int64) ([]RoleRow, error)

func (*SQLiteAdapter) GetUsersInRole added in v0.0.18

func (a *SQLiteAdapter) GetUsersInRole(ctx context.Context, roleID int64) ([]User, error)

func (*SQLiteAdapter) ListOrganizations added in v0.0.7

func (a *SQLiteAdapter) ListOrganizations(ctx context.Context) ([]Organization, error)

func (*SQLiteAdapter) ListOrganizationsRolesWithUserCounts added in v0.0.16

func (a *SQLiteAdapter) ListOrganizationsRolesWithUserCounts(ctx context.Context, organizationId int64) ([]ListRolesWithUserCountsRow, error)

func (*SQLiteAdapter) ListUserOrganizationRoles added in v0.0.7

func (a *SQLiteAdapter) ListUserOrganizationRoles(ctx context.Context, userID int64) ([]ListUserOrganizationRolesRow, error)

func (*SQLiteAdapter) OrganizationsCount added in v0.0.16

func (a *SQLiteAdapter) OrganizationsCount(ctx context.Context) (int64, error)

func (*SQLiteAdapter) RemoveAllRolesFromUser

func (a *SQLiteAdapter) RemoveAllRolesFromUser(ctx context.Context, userID int64) error

func (*SQLiteAdapter) RemovePermissionFromRole

func (a *SQLiteAdapter) RemovePermissionFromRole(ctx context.Context, roleID int64, permission string) error

func (*SQLiteAdapter) RemoveUserFromRole added in v0.0.7

func (a *SQLiteAdapter) RemoveUserFromRole(ctx context.Context, userID int64, roleID int64) error

func (*SQLiteAdapter) SearchUsers added in v0.0.18

func (a *SQLiteAdapter) SearchUsers(ctx context.Context, searchTerm string, limit, offset int) ([]User, error)

func (*SQLiteAdapter) UpdateOrganization added in v0.0.7

func (a *SQLiteAdapter) UpdateOrganization(ctx context.Context, id int64, name string, systemName string, status string) error

func (*SQLiteAdapter) UpdateRole

func (a *SQLiteAdapter) UpdateRole(ctx context.Context, roleID int64, name string, systemName string) error

func (*SQLiteAdapter) UpdateUser

func (a *SQLiteAdapter) UpdateUser(ctx context.Context, userID int64, firstName, lastName, displayName, email string, verified bool, updatedAt int64) error

func (*SQLiteAdapter) UpdateUserLoginStats added in v0.0.16

func (a *SQLiteAdapter) UpdateUserLoginStats(ctx context.Context, userID int64, lastLogin int64, loginCount int64) error

func (*SQLiteAdapter) UserAddApiKey added in v0.0.18

func (a *SQLiteAdapter) UserAddApiKey(ctx context.Context, userID int64, organizationId int64, apiKeyId string, secretHash string, name string, createdAt time.Time, expiresAt time.Time) error

func (*SQLiteAdapter) UserDeleteApiKey added in v0.0.18

func (a *SQLiteAdapter) UserDeleteApiKey(ctx context.Context, userID int64, apiKeyId string) error

func (*SQLiteAdapter) UserGetApiKey added in v0.0.18

func (a *SQLiteAdapter) UserGetApiKey(ctx context.Context, apiKeyHash string) (UserApiKeyWithHash, error)

func (*SQLiteAdapter) UserListApiKeys added in v0.0.18

func (a *SQLiteAdapter) UserListApiKeys(ctx context.Context, userID int64) ([]UserApiKeyNoHash, error)

func (*SQLiteAdapter) UsersCount added in v0.0.16

func (a *SQLiteAdapter) UsersCount(ctx context.Context) (int64, error)

type User

type User struct {
	UserID      int64
	FirstName   string
	LastName    string
	DisplayName string
	Email       string
	Verified    bool
}

User represents a user in the system

type UserApiKeyNoHash added in v0.0.18

type UserApiKeyNoHash struct {
	Id             string
	Name           string
	UserID         int64
	OrganizationID int64
	CreatedAt      time.Time
	ExpiresAt      time.Time
}

type UserApiKeyWithHash added in v0.0.18

type UserApiKeyWithHash struct {
	Id             string
	SecretHash     string
	Name           string
	UserID         int64
	OrganizationID int64
	CreatedAt      time.Time
	ExpiresAt      time.Time
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL