shared

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package shared provides shared types and utilities across packages.

Index

Constants

View Source
const (
	PendingReminderStateTypeID = 4
	PendingAutoStateTypeID     = 5
)

Pending state type IDs

View Source
const DefaultPendingDuration = 24 * time.Hour

DefaultPendingDuration is the default duration to use when a pending ticket has no explicit pending_until time set. This provides a fallback for legacy/migrated data that may be missing the date.

Variables

This section is empty.

Functions

func EnsurePendingTime added in v0.6.2

func EnsurePendingTime(untilTime int) int

EnsurePendingTime returns the provided untilTime if valid, or a default time (now + DefaultPendingDuration) as a unix timestamp. This is useful when setting the pending time on state changes.

func GetEffectivePendingTime added in v0.6.2

func GetEffectivePendingTime(untilTime int) time.Time

GetEffectivePendingTime returns the effective pending time for a ticket. If untilTime is set (> 0), it returns that time. If untilTime is not set (0 or negative), it returns now + DefaultPendingDuration. This ensures pending tickets always have a usable deadline.

func GetEffectivePendingTimeUnix added in v0.6.2

func GetEffectivePendingTimeUnix(untilTime int) int64

GetEffectivePendingTimeUnix returns the effective pending time as a unix timestamp. This is useful for SQL queries and comparisons.

func GetJWTManager

func GetJWTManager() *auth.JWTManager

This ensures auth service and middleware use the same JWT configuration.

func GetSessionService added in v0.6.0

func GetSessionService() *service.SessionService

GetSessionService returns the global session service singleton. Returns nil if database is not available.

func GetSystemSessionIdleTime added in v0.5.0

func GetSystemSessionIdleTime() int

GetSystemSessionIdleTime returns the configured idle timeout in seconds.

func GetSystemSessionMaxTime added in v0.5.0

func GetSystemSessionMaxTime() int

GetSystemSessionMaxTime returns the configured session lifetime in seconds.

func GetUserID added in v0.5.0

func GetUserID(c *gin.Context) int

GetUserID extracts user ID from request context.

func GetUserIDFromCtx added in v0.6.2

func GetUserIDFromCtx(c *gin.Context, fallback int) int

GetUserIDFromCtx extracts the authenticated user's ID from gin context. Handles multiple types since different auth middleware may set different types. Returns the fallback value if user_id is not found or cannot be converted.

func GetUserIDFromCtxUint added in v0.6.2

func GetUserIDFromCtxUint(c *gin.Context, fallback uint) uint

GetUserIDFromCtxUint is like GetUserIDFromCtx but returns uint.

func GetUserMapForTemplate added in v0.5.0

func GetUserMapForTemplate(c *gin.Context) map[string]interface{}

GetUserMapForTemplate builds a user context map for template rendering.

func IsAdmin added in v0.5.0

func IsAdmin(c *gin.Context) bool

IsAdmin checks if current user is admin.

func IsAuthenticated added in v0.5.0

func IsAuthenticated(c *gin.Context) bool

IsAuthenticated checks if user is authenticated.

func IsPendingStateType added in v0.6.2

func IsPendingStateType(typeID int) bool

IsPendingStateType returns true if the state type is a pending state (either pending reminder or pending auto-close).

func LoadTicketStatesForForm added in v0.5.0

func LoadTicketStatesForForm(db *sql.DB) ([]gin.H, map[string]gin.H, error)

LoadTicketStatesForForm fetches valid ticket states and builds alias lookup data for forms.

func ResolveSessionTimeout added in v0.5.0

func ResolveSessionTimeout(userPref int) int

ResolveSessionTimeout picks the effective timeout based on user preference.

func SendToastResponse added in v0.5.0

func SendToastResponse(c *gin.Context, success bool, message, redirectPath string)

sendToastResponse sends either an HTMX toast notification or redirects with success message.

func SessionServiceAvailable added in v0.6.0

func SessionServiceAvailable() bool

SessionServiceAvailable returns true if the session service is available.

func SetGlobalRenderer added in v0.5.0

func SetGlobalRenderer(renderer *TemplateRenderer)

SetGlobalRenderer sets the global template renderer instance.

func ToInt added in v0.6.3

func ToInt(v interface{}, fallback int) int

ToInt delegates to convert.ToInt for backward compatibility.

func ToString added in v0.6.3

func ToString(v interface{}, fallback string) string

ToString delegates to convert.ToString for backward compatibility.

func ToUint added in v0.6.3

func ToUint(v interface{}, fallback uint) uint

ToUint delegates to convert.ToUint for backward compatibility.

Types

type TemplateRenderer added in v0.5.0

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

TemplateRenderer handles template rendering with pongo2.

func GetGlobalRenderer added in v0.5.0

func GetGlobalRenderer() *TemplateRenderer

GetGlobalRenderer returns the global template renderer instance.

func NewTemplateRenderer added in v0.5.0

func NewTemplateRenderer(templateDir string) (*TemplateRenderer, error)

NewTemplateRenderer creates a new template renderer.

func (*TemplateRenderer) HTML added in v0.5.0

func (r *TemplateRenderer) HTML(c *gin.Context, code int, name string, data interface{})

HTML renders a template.

func (*TemplateRenderer) TemplateSet added in v0.5.0

func (r *TemplateRenderer) TemplateSet() *pongo2.TemplateSet

TemplateSet returns the underlying pongo2 template set for modules that need direct access.

type UserContext added in v0.5.0

type UserContext struct {
	ID              int    `json:"id"`
	Login           string `json:"login"`
	FirstName       string `json:"first_name"`
	LastName        string `json:"last_name"`
	Email           string `json:"email"`
	IsInAdminGroup  bool   `json:"is_in_admin_group"`
	GroupIDs        []int  `json:"group_ids"`
	RoleIDs         []int  `json:"role_ids"`
	CustomerCompany string `json:"customer_company"`
}

UserContext represents user information for templates.

Jump to

Keyboard shortcuts

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