Documentation
¶
Index ¶
- Variables
- func AppendOrgFilter(query string, orgRole, orgID, tableAlias string, args []interface{}, ...) (string, []interface{}, int)
- func BuildPaginationInfo(page, pageSize, totalCount int) models.PaginationInfo
- func BuildPaginationInfoWithSorting(page, pageSize, totalCount int, sortBy, sortDirection string) models.PaginationInfo
- func CalculateTotalPages(totalCount int, pageSize int) int
- func CheckVATExists(vat, entityType, excludeID string) (bool, error)
- func EnsureSlice(v interface{}) interface{}
- func GeneratePassword() (string, error)
- func GetEffectiveUserID(user *models.User) string
- func GetPaginationAndSortingFromQuery(c *gin.Context) (int, int, string, string)
- func GetPaginationFromQuery(c *gin.Context) (int, int)
- func GetPasswordRequirements() []string
- func GetSortingFromQuery(c *gin.Context) (string, string)
- func GetUserContextExtended(c *gin.Context) (string, string, string, string)
- func GetUserFromContext(c *gin.Context) (*models.User, bool)
- func HandleAccessError(c *gin.Context, err error, entityType, entityID string) bool
- func HashSystemSecret(secret string) (string, error)
- func ValidatePasswordStrength(password string) (bool, []string)
- func VerifySystemSecret(secret, encodedHash string) (bool, error)
Constants ¶
This section is empty.
Variables ¶
var GetAllowedOrgIDsForFilter func(role, orgID string) []string
GetAllowedOrgIDsForFilter computes allowed org IDs for RBAC filtering. It uses the applications service cached lookup to get the correct hierarchy. This is a lightweight wrapper that avoids circular imports by using a callback.
Functions ¶
func AppendOrgFilter ¶
func AppendOrgFilter(query string, orgRole, orgID, tableAlias string, args []interface{}, nextArgIdx int) (string, []interface{}, int)
AppendOrgFilter appends RBAC hierarchical organization filtering to a SQL query. It handles all four organization roles: owner, distributor, reseller, and customer.
Parameters:
- query: the base SQL query to append to
- orgRole: the user's organization role (case-insensitive)
- orgID: the user's organization ID
- tableAlias: optional table alias prefix for organization_id (e.g. "s." for "s.organization_id")
- args: existing query arguments
- nextArgIdx: the next positional argument index ($1, $2, etc.)
Returns the modified query, updated args, and the next argument index.
func BuildPaginationInfo ¶
func BuildPaginationInfo(page, pageSize, totalCount int) models.PaginationInfo
BuildPaginationInfo creates a standard pagination info object
func BuildPaginationInfoWithSorting ¶
func BuildPaginationInfoWithSorting(page, pageSize, totalCount int, sortBy, sortDirection string) models.PaginationInfo
BuildPaginationInfoWithSorting creates a standard pagination info object with sorting information
func CalculateTotalPages ¶
CalculateTotalPages calculates the total number of pages based on total count and page size
func CheckVATExists ¶
CheckVATExists checks if a VAT exists in the specified entity table
func EnsureSlice ¶
func EnsureSlice(v interface{}) interface{}
EnsureSlice ensures a nil slice is returned as an empty slice for proper JSON serialization. In Go, nil slices serialize to `null` in JSON, while empty slices serialize to `[]`. This function converts nil slices to empty slices of the same type.
func GeneratePassword ¶
GeneratePassword generates a secure temporary password that passes our validation
func GetEffectiveUserID ¶
GetEffectiveUserID returns the effective user ID for a user For Owner users without a local database ID, returns "owner" as a fallback identifier This is used for audit logging and tracking operations by Owner users
func GetPaginationAndSortingFromQuery ¶
GetPaginationAndSortingFromQuery extracts page, pageSize, sortBy and sortDirection from query parameters
func GetPaginationFromQuery ¶
GetPaginationFromQuery extracts page and pageSize from query parameters
func GetPasswordRequirements ¶
func GetPasswordRequirements() []string
GetPasswordRequirements returns a list of password requirements for user display
func GetSortingFromQuery ¶
GetSortingFromQuery extracts sortBy and sortDirection from query parameters
func GetUserContextExtended ¶
GetUserContextExtended extracts user ID, organization ID, and role information from Gin context Returns userID, userOrgID, userOrgRole, userRole strings
func GetUserFromContext ¶
GetUserFromContext extracts user context data from Gin context Returns user object and boolean indicating success
func HandleAccessError ¶
HandleAccessError handles common entity access errors (not found, access denied, generic). Returns true if the error was handled and the caller should return.
func HashSystemSecret ¶
HashSystemSecret generates an Argon2id hash of the system secret The hash is stored in the PHC string format: $argon2id$v=19$m=65536,t=3,p=2$salt$hash
func ValidatePasswordStrength ¶
ValidatePasswordStrength validates password strength with simple, clear rules Returns only the first error found to guide user step by step
func VerifySystemSecret ¶
VerifySystemSecret verifies a system secret against an Argon2id hash Returns true if the secret matches the hash, false otherwise
Types ¶
This section is empty.