Documentation
¶
Overview ¶
Package shared provides shared types and utilities across packages.
Index ¶
- Constants
- func EnsurePendingTime(untilTime int) int
- func GetEffectivePendingTime(untilTime int) time.Time
- func GetEffectivePendingTimeUnix(untilTime int) int64
- func GetJWTManager() *auth.JWTManager
- func GetLandingPage() string
- func GetSessionService() *service.SessionService
- func GetSystemSessionIdleTime() int
- func GetSystemSessionMaxTime() int
- func GetUserID(c *gin.Context) int
- func GetUserIDFromCtx(c *gin.Context, fallback int) int
- func GetUserIDFromCtxUint(c *gin.Context, fallback uint) uint
- func GetUserMapForTemplate(c *gin.Context) map[string]interface{}
- func IsAdmin(c *gin.Context) bool
- func IsAuthenticated(c *gin.Context) bool
- func IsPendingStateType(typeID int) bool
- func LoadTicketStatesForForm(db *sql.DB) ([]gin.H, map[string]gin.H, error)
- func ResolveSessionTimeout(userPref int) int
- func SendToastResponse(c *gin.Context, success bool, message, redirectPath string)
- func SessionServiceAvailable() bool
- func SetGlobalRenderer(renderer *TemplateRenderer)
- func SetHiddenMenuProvider(p HiddenMenuProvider)
- func SetLandingPageProvider(p LandingPageProvider)
- func SetPluginMenuProvider(p PluginMenuProvider)
- func SetTemplateOverrideProvider(p TemplateOverrideProvider)
- func ToInt(v interface{}, fallback int) int
- func ToString(v interface{}, fallback string) string
- func ToUint(v interface{}, fallback uint) uint
- type HiddenMenuProvider
- type LandingPageProvider
- type PluginMenuProvider
- type TemplateOverrideProvider
- type TemplateRenderer
- type UserContext
Constants ¶
const ( PendingReminderStateTypeID = 4 PendingAutoStateTypeID = 5 )
Pending state type IDs
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 ¶
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 ¶
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 ¶
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 GetLandingPage ¶ added in v0.7.0
func GetLandingPage() string
GetLandingPage returns the plugin-defined landing page URL, or empty string.
func GetSessionService ¶
func GetSessionService() *service.SessionService
GetSessionService returns the global session service singleton. Returns nil if database is not available.
func GetSystemSessionIdleTime ¶
func GetSystemSessionIdleTime() int
GetSystemSessionIdleTime returns the configured idle timeout in seconds.
func GetSystemSessionMaxTime ¶
func GetSystemSessionMaxTime() int
GetSystemSessionMaxTime returns the configured session lifetime in seconds.
func GetUserIDFromCtx ¶
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 ¶
GetUserIDFromCtxUint is like GetUserIDFromCtx but returns uint.
func GetUserMapForTemplate ¶
GetUserMapForTemplate builds a user context map for template rendering.
func IsAuthenticated ¶
IsAuthenticated checks if user is authenticated.
func IsPendingStateType ¶
IsPendingStateType returns true if the state type is a pending state (either pending reminder or pending auto-close).
func LoadTicketStatesForForm ¶
LoadTicketStatesForForm fetches valid ticket states and builds alias lookup data for forms.
func ResolveSessionTimeout ¶
ResolveSessionTimeout picks the effective timeout based on user preference.
func SendToastResponse ¶
sendToastResponse sends either an HTMX toast notification or redirects with success message.
func SessionServiceAvailable ¶
func SessionServiceAvailable() bool
SessionServiceAvailable returns true if the session service is available.
func SetGlobalRenderer ¶
func SetGlobalRenderer(renderer *TemplateRenderer)
SetGlobalRenderer sets the global template renderer instance.
func SetHiddenMenuProvider ¶ added in v0.7.0
func SetHiddenMenuProvider(p HiddenMenuProvider)
SetHiddenMenuProvider sets the global provider for hidden menu items in templates.
func SetLandingPageProvider ¶ added in v0.7.0
func SetLandingPageProvider(p LandingPageProvider)
SetLandingPageProvider sets the global provider for the plugin landing page.
func SetPluginMenuProvider ¶ added in v0.7.0
func SetPluginMenuProvider(p PluginMenuProvider)
SetPluginMenuProvider sets the global provider for plugin menu items in templates.
func SetTemplateOverrideProvider ¶
func SetTemplateOverrideProvider(p TemplateOverrideProvider)
SetTemplateOverrideProvider sets the global template override provider.
Types ¶
type HiddenMenuProvider ¶ added in v0.7.0
HiddenMenuProvider returns a map of menu item IDs that should be hidden.
type LandingPageProvider ¶ added in v0.7.0
type LandingPageProvider func() string
LandingPageProvider returns the plugin-defined landing page URL, or empty string.
type PluginMenuProvider ¶ added in v0.7.0
PluginMenuProvider returns plugin menu items for a given location (e.g. "admin", "agent"). This avoids import cycles between shared and api/plugin packages.
type TemplateOverrideProvider ¶
type TemplateOverrideProvider interface {
RenderOverride(ctx context.Context, templateName string, data map[string]any) (string, bool)
}
TemplateOverrideProvider allows plugins to override templates without import cycles.
type TemplateRenderer ¶
type TemplateRenderer struct {
// contains filtered or unexported fields
}
TemplateRenderer handles template rendering with pongo2.
func GetGlobalRenderer ¶
func GetGlobalRenderer() *TemplateRenderer
GetGlobalRenderer returns the global template renderer instance.
func NewTemplateRenderer ¶
func NewTemplateRenderer(templateDir string) (*TemplateRenderer, error)
NewTemplateRenderer creates a new template renderer.
func (*TemplateRenderer) HTML ¶
func (r *TemplateRenderer) HTML(c *gin.Context, code int, name string, data interface{})
HTML renders a template.
func (*TemplateRenderer) TemplateSet ¶
func (r *TemplateRenderer) TemplateSet() *pongo2.TemplateSet
TemplateSet returns the underlying pongo2 template set for modules that need direct access.
type UserContext ¶
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.