Skip to content

Commit

Permalink
feat(config): add support of logo and small_icon configurations, add …
Browse files Browse the repository at this point in the history
…social shares, add comment on deprecated attributes, fix API inconsistency on pointer parameters
  • Loading branch information
pandatix committed Apr 17, 2024
1 parent b14477b commit f54416f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
38 changes: 32 additions & 6 deletions api/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ type PatchConfigsParams struct {

// Theme

// TODO add logo & small icon
CTFTheme *string `json:"ctf_theme,omitempty"`
ThemeFooter *string `json:"theme_footer,omitempty"`
ThemeHeader *string `json:"theme_header,omitempty"`
Expand Down Expand Up @@ -64,7 +63,6 @@ type PatchConfigsParams struct {
RegistrationCode *string `json:"registration_code,omitempty"`

// Email
// TODO update for 3.6.0

MailPassword *string `json:"mail_password,omitempty"`
MailPort *string `json:"mail_port,omitempty"`
Expand All @@ -73,9 +71,6 @@ type PatchConfigsParams struct {
MailTLS *bool `json:"mail_tls,omitempty"`
MailUseAuth *bool `json:"mail_useauth,omitempty"`
MailUsername *string `json:"mail_username,omitempty"`
MailFromAddr *string `json:"mailfrom_addr,omitempty"`
MailGunAPIKey *string `json:"mailgun_api_key,omitempty"`
MailGunBaseURL *string `json:"mailgun_base_url,omitempty"`
PasswordChangelertBody *string `json:"password_change_alert_body,omitempty"`
PasswordChangeAlertSubject *string `json:"password_change_alert_subject,omitempty"`
PasswordResetBody *string `json:"password_reset_body,omitempty"`
Expand All @@ -87,13 +82,24 @@ type PatchConfigsParams struct {
VerificationEmailBody *string `json:"verification_email_body,omitempty"`
VerificationEmailSubject *string `json:"verification_email_subject,omitempty"`

// DEPRECATED
MailFromAddr *string `json:"mailfrom_addr,omitempty"`
// DEPRECATED
MailGunAPIKey *string `json:"mailgun_api_key,omitempty"`
// DEPRECATED
MailGunBaseURL *string `json:"mailgun_base_url,omitempty"`

// Time

End *string `json:"end,omitempty"`
Freeze *string `json:"freeze,omitempty"`
Start *string `json:"start,omitempty"`
ViewAfterCTF *bool `json:"view_after_ctf,omitempty"`

// Social

SocialShares *bool `json:"social_shares,omitempty"`

// Legal

PrivacyText *string `json:"privacy_text,omitempty"`
Expand Down Expand Up @@ -179,7 +185,7 @@ type PatchConfigsFieldParams struct {
Required bool `json:"required"`
}

func (client *Client) PatchConfigsField(id string, params PatchConfigsFieldParams, opts ...Option) (*ConfigField, error) {
func (client *Client) PatchConfigsField(id string, params *PatchConfigsFieldParams, opts ...Option) (*ConfigField, error) {
field := &ConfigField{}
if err := patch(client, "/configs/fields/"+id, params, &field, opts...); err != nil {
return nil, err
Expand Down Expand Up @@ -209,3 +215,23 @@ func (client *Client) PatchConfigsByKey(key string, params any, opts ...Option)
}
return config, nil
}

type PatchConfigsCTFLogo struct {
Value *string `json:"value"`
}

func (client *Client) PatchConfigsCTFLogo(params *PatchConfigsCTFLogo, opts ...Option) (*ThemeImage, error) {
var ti *ThemeImage
if err := patch(client, "/configs/ctf_logo", params, ti, opts...); err != nil {
return nil, err
}
return ti, nil
}

func (client *Client) PatchConfigsCTFSmallIcon(params *PatchConfigsCTFLogo, opts ...Option) (*ThemeImage, error) {
var ti *ThemeImage
if err := patch(client, "/configs/ctf_small_icon", params, ti, opts...); err != nil {
return nil, err
}
return ti, nil
}
6 changes: 6 additions & 0 deletions api/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,12 @@ type (
Value string `json:"value"` // seems could be int/bool/string, let CTFd interfer type
}

ThemeImage struct {
ID int `json:"id"`
Key string `json:"key"`
Value *string `json:"value"`
}

Page struct {
Files []any `json:"files"` // XXX find model
ID int `json:"id"`
Expand Down

0 comments on commit f54416f

Please sign in to comment.