model

package
v0.0.0-...-aa1d88f Latest Latest
Warning

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

Go to latest
Published: May 3, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Admin

type Admin struct {
	ID     uint `gorm:"primarykey"`
	UserID string
}

type Base

type Base struct {
	Lang   string
	Config Config
	Tr     i18n.I18n
	Topics []Topic

	LoggedIn bool
	Name     string
	Email    string
	UID      string
	IsAdmin  bool
}

type Config

type Config struct {
	Port    int    `yaml:"port"`
	Mode    string `yaml:"mode"`
	Content struct {
		Title      i18n.Translatable `yaml:"title"`
		SubTitle   i18n.Translatable `yaml:"subtitle"`
		Logo       string            `yaml:"logo"`
		AdminUsers []string          `yaml:"adminUsers"` // e.g. ge42tum
	} `yaml:"content"`
	HTTPS struct {
		Port int    `yaml:"port"`
		Cert string `yaml:"cert"`
		Key  string `yaml:"key"`
	} `yaml:"https"`
	FileDir string `yaml:"fileDir"`
	URL     string `yaml:"URL"`
	Saml    struct {
		IdpMetadataURL string `yaml:"idpMetadataURL"`
		EntityID       string `yaml:"entityID"`
		RootURL        string `yaml:"rootURL"`
		Cert           struct {
			Org           string `yaml:"org"`
			Country       string `yaml:"country"`
			Province      string `yaml:"province"`
			Locality      string `yaml:"locality"`
			StreetAddress string `yaml:"streetAddress"`
			PostalCode    string `yaml:"postalCode"`
			Cn            string `yaml:"cn"`
		} `yaml:"cert"`
	} `yaml:"saml"`
	Mail struct {
		User       string `yaml:"user"`
		Password   string `yaml:"password"`
		SMTPServer string `yaml:"smtpServer"`
		SMTPPort   string `yaml:"smtpPort"`
		From       string `yaml:"from"`
		FromName   string `yaml:"fromName"`
	} `yaml:"mail"`
	Imprint string `yaml:"imprint"`
	Privacy string `yaml:"privacy"`
}

func (Config) GetImprint

func (c Config) GetImprint() template.HTML
func (c Config) GetLogo() template.HTML

func (Config) GetPrivacy

func (c Config) GetPrivacy() template.HTML

type EmailConfig

type EmailConfig struct {
	Relay  string `yaml:"relay"`
	Sender string `yaml:"sender"`
	Target string `yaml:"target"`
}

type EmailMessenger

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

func NewEmailMessenger

func NewEmailMessenger(config EmailConfig) *EmailMessenger

func (*EmailMessenger) SendMessage

func (m *EmailMessenger) SendMessage(title string, message Message, reportURL string) error

type Field

type Field struct {
	ID          uint `gorm:"primarykey"`
	TopicID     uint
	Name        i18n.Translatable `yaml:"name" gorm:"embedded;embeddedPrefix:name_"`
	Type        string            `yaml:"type"` // e.g. file, text, email, textarea,
	Required    bool              `yaml:"required"`
	Description i18n.Translatable `yaml:"description" gorm:"embedded;embeddedPrefix:description_"`

	// For select inputs:
	Choices    *[]string `yaml:"choices" gorm:"-"`
	ChoicesStr string    `gorm:"choices"`
}

func (*Field) AfterFind

func (f *Field) AfterFind(tx *gorm.DB) error

func (*Field) BeforeSave

func (f *Field) BeforeSave(tx *gorm.DB) error

type File

type File struct {
	ID       uint   `gorm:"primarykey"`
	UUID     string `gorm:"unique;not null"`
	Location string `gorm:"not null"`
	Name     string `gorm:"not null"`
}

func (*File) BeforeCreate

func (f *File) BeforeCreate(tx *gorm.DB) (err error)

type Index

type Index struct {
	Base
	Topic *Topic
	Token string
}

type InfoPage

type InfoPage struct {
	Base
	Content template.HTML
}

type MatrixConfig

type MatrixConfig struct {
	AccessToken string `yaml:"accessToken"`
	RoomID      string `yaml:"roomID"`
	HomeServer  string `yaml:"homeServer"`
}

type MatrixMessenger

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

func NewMatrixMessenger

func NewMatrixMessenger(config MatrixConfig) *MatrixMessenger

func (*MatrixMessenger) SendMessage

func (m *MatrixMessenger) SendMessage(title string, message Message, reportURL string) error

type Message

type Message struct {
	ID        uint `gorm:"primarykey"`
	CreatedAt time.Time

	Content string `gorm:"not null"`

	ReportID uint `gorm:"not null"`

	Files   []File `gorm:"many2many:message_files;"`
	IsAdmin bool   `gorm:"default:false"`
}

func (*Message) GetBody

func (m *Message) GetBody() template.HTML

type MessagingConfig

type MessagingConfig interface {
}

MessagingConfig is a generic type for a messenger configuration

type Messenger

type Messenger interface {
	SendMessage(title string, message Message, reportURL string) error
}

Messenger is an interface for all messaging clients capable of sending a message

func GetMessengers

func GetMessengers(t Topic) []Messenger

type NewTopicPage

type NewTopicPage struct {
	Base
}

type Report

type Report struct {
	ID        uint `gorm:"primarykey"`
	CreatedAt time.Time
	TopicID   uint

	ReporterToken      string `gorm:"type:varchar(255);not null"`
	AdministratorToken string `gorm:"type:varchar(255);not null"`

	Messages []Message `gorm:"foreignKey:ReportID;constraint:OnDelete:CASCADE"`

	State ReportState

	Creator *string `gorm:"type:varchar(512)"` // optional email address
}

func (*Report) BeforeCreate

func (r *Report) BeforeCreate(tx *gorm.DB) (err error)

func (*Report) DateFmt

func (r *Report) DateFmt() string

func (*Report) GetStatusColor

func (r *Report) GetStatusColor() template.CSS

func (*Report) GetStatusText

func (r *Report) GetStatusText() string

func (*Report) IsClosed

func (r *Report) IsClosed() bool

func (*Report) IsSpam

func (r *Report) IsSpam() bool

type ReportPage

type ReportPage struct {
	Base
	Report          *Report
	IsAdministrator bool
}

type ReportState

type ReportState string
const (
	ReportStateOpen ReportState = "open"
	ReportStateDone ReportState = "done"
	ReportStateSpam ReportState = "spam"
)

type ReportsOfTopicPage

type ReportsOfTopicPage struct {
	Base
	Topic   *Topic
	Reports []Report
}

type Role

type Role string
const (
	RoleAdmin Role = "admin"
)

type Topic

type Topic struct {
	ID       uint              `gorm:"primarykey"`
	Name     i18n.Translatable `yaml:"name" gorm:"embedded;embeddedPrefix:name_"`
	Summary  i18n.Translatable `yaml:"summary" gorm:"embedded;embeddedPrefix:summary_"`
	Fields   []Field           `yaml:"fields"`
	Contacts struct {
		Email   *EmailConfig   `yaml:"email"`
		Matrix  *MatrixConfig  `yaml:"matrix"`
		Webhook *WebhookConfig `yaml:"webhook"`
	} `yaml:"contacts" gorm:"-"`

	Admins []Admin `yaml:"admins" gorm:"many2many:topic_admins;"`

	Email string
}

func (*Topic) IsAdmin

func (t *Topic) IsAdmin(userid string) bool

type UserRole

type UserRole struct {
	UserID string
	Role   Role
}

type WebhookConfig

type WebhookConfig struct {
	Target string `yaml:"target"`
}

type WebhookMessenger

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

func NewWebhookMessenger

func NewWebhookMessenger(config WebhookConfig) *WebhookMessenger

func (*WebhookMessenger) SendMessage

func (m *WebhookMessenger) SendMessage(title string, message Message, reportURL string) error

Jump to

Keyboard shortcuts

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