helpers

package
v0.0.0-...-ed12b2f Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func CalculateTotalPages(totalCount int, pageSize int) int

CalculateTotalPages calculates the total number of pages based on total count and page size

func CheckVATExists

func CheckVATExists(vat, entityType, excludeID string) (bool, error)

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

func GeneratePassword() (string, error)

GeneratePassword generates a secure temporary password that passes our validation

func GetEffectiveUserID

func GetEffectiveUserID(user *models.User) string

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

func GetPaginationAndSortingFromQuery(c *gin.Context) (int, int, string, string)

GetPaginationAndSortingFromQuery extracts page, pageSize, sortBy and sortDirection from query parameters

func GetPaginationFromQuery

func GetPaginationFromQuery(c *gin.Context) (int, int)

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

func GetSortingFromQuery(c *gin.Context) (string, string)

GetSortingFromQuery extracts sortBy and sortDirection from query parameters

func GetUserContextExtended

func GetUserContextExtended(c *gin.Context) (string, string, string, string)

GetUserContextExtended extracts user ID, organization ID, and role information from Gin context Returns userID, userOrgID, userOrgRole, userRole strings

func GetUserFromContext

func GetUserFromContext(c *gin.Context) (*models.User, bool)

GetUserFromContext extracts user context data from Gin context Returns user object and boolean indicating success

func HandleAccessError

func HandleAccessError(c *gin.Context, err error, entityType, entityID string) bool

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

func HashSystemSecret(secret string) (string, error)

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

func ValidatePasswordStrength(password string) (bool, []string)

ValidatePasswordStrength validates password strength with simple, clear rules Returns only the first error found to guide user step by step

func VerifySystemSecret

func VerifySystemSecret(secret, encodedHash string) (bool, error)

VerifySystemSecret verifies a system secret against an Argon2id hash Returns true if the secret matches the hash, false otherwise

Types

This section is empty.

Jump to

Keyboard shortcuts

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