mirror of
https://github.com/phishingclub/phishingclub.git
synced 2026-05-15 21:28:17 +02:00
36ee621f1a
Signed-off-by: Ronni Skansing <rskansing@gmail.com>
83 lines
2.4 KiB
Go
83 lines
2.4 KiB
Go
package model
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/oapi-codegen/nullable"
|
|
"github.com/phishingclub/phishingclub/validate"
|
|
"github.com/phishingclub/phishingclub/vo"
|
|
)
|
|
|
|
// RemoteBrowser is a saved remote browser script with its connection config.
|
|
type RemoteBrowser struct {
|
|
ID nullable.Nullable[uuid.UUID] `json:"id"`
|
|
CreatedAt *time.Time `json:"createdAt"`
|
|
UpdatedAt *time.Time `json:"updatedAt"`
|
|
CompanyID nullable.Nullable[uuid.UUID] `json:"companyID"`
|
|
Name nullable.Nullable[vo.String64] `json:"name"`
|
|
Description nullable.Nullable[vo.OptionalString1024] `json:"description"`
|
|
Script nullable.Nullable[vo.String1MB] `json:"script"`
|
|
Config nullable.Nullable[vo.String1MB] `json:"config"`
|
|
|
|
Company *Company `json:"-"`
|
|
}
|
|
|
|
// Validate checks required fields.
|
|
func (m *RemoteBrowser) Validate() error {
|
|
if err := validate.NullableFieldRequired("name", m.Name); err != nil {
|
|
return err
|
|
}
|
|
if err := validate.NullableFieldRequired("script", m.Script); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ToDBMap returns the fields that should be persisted.
|
|
func (m *RemoteBrowser) ToDBMap() map[string]any {
|
|
dbMap := map[string]any{}
|
|
if m.Name.IsSpecified() {
|
|
dbMap["name"] = nil
|
|
if name, err := m.Name.Get(); err == nil {
|
|
dbMap["name"] = name.String()
|
|
}
|
|
}
|
|
if m.Description.IsSpecified() {
|
|
dbMap["description"] = nil
|
|
if description, err := m.Description.Get(); err == nil {
|
|
dbMap["description"] = description.String()
|
|
}
|
|
}
|
|
if m.Script.IsSpecified() {
|
|
dbMap["script"] = nil
|
|
if script, err := m.Script.Get(); err == nil {
|
|
dbMap["script"] = script.String()
|
|
}
|
|
}
|
|
if m.Config.IsSpecified() {
|
|
dbMap["config"] = nil
|
|
if config, err := m.Config.Get(); err == nil {
|
|
dbMap["config"] = config.String()
|
|
}
|
|
}
|
|
if m.CompanyID.IsSpecified() {
|
|
if m.CompanyID.IsNull() {
|
|
dbMap["company_id"] = nil
|
|
} else {
|
|
dbMap["company_id"] = m.CompanyID.MustGet()
|
|
}
|
|
}
|
|
return dbMap
|
|
}
|
|
|
|
// RemoteBrowserOverview is a lightweight listing model.
|
|
type RemoteBrowserOverview struct {
|
|
ID uuid.UUID `json:"id,omitempty"`
|
|
CreatedAt *time.Time `json:"createdAt"`
|
|
UpdatedAt *time.Time `json:"updatedAt"`
|
|
Name string `json:"name"`
|
|
Description string `json:"description"`
|
|
CompanyID *uuid.UUID `json:"companyID"`
|
|
}
|