Skip to content

Commit

Permalink
Rename sponsors in sponsorships
Browse files Browse the repository at this point in the history
  • Loading branch information
nono committed Dec 14, 2023
1 parent b227e0d commit 5d5139b
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 47 deletions.
12 changes: 6 additions & 6 deletions client/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Instance struct {
UUID string `json:"uuid,omitempty"`
OIDCID string `json:"oidc_id,omitempty"`
ContextName string `json:"context,omitempty"`
Sponsors []string `json:"sponsors,omitempty"`
Sponsorships []string `json:"sponsorships,omitempty"`
TOSSigned string `json:"tos,omitempty"`
TOSLatest string `json:"tos_latest,omitempty"`
AuthMode int `json:"auth_mode,omitempty"`
Expand Down Expand Up @@ -66,7 +66,7 @@ type InstanceOptions struct {
TOSLatest string
Timezone string
ContextName string
Sponsors []string
Sponsorships []string
Email string
PublicName string
Settings string
Expand Down Expand Up @@ -166,8 +166,8 @@ func (ac *AdminClient) CreateInstance(opts *InstanceOptions) (*Instance, error)
if opts.DomainAliases != nil {
q.Add("DomainAliases", strings.Join(opts.DomainAliases, ","))
}
if opts.Sponsors != nil {
q.Add("Sponsors", strings.Join(opts.Sponsors, ","))
if opts.Sponsorships != nil {
q.Add("Sponsorships", strings.Join(opts.Sponsorships, ","))
}
if opts.MagicLink != nil && *opts.MagicLink {
q.Add("MagicLink", "true")
Expand Down Expand Up @@ -242,8 +242,8 @@ func (ac *AdminClient) ModifyInstance(opts *InstanceOptions) (*Instance, error)
if opts.DomainAliases != nil {
q.Add("DomainAliases", strings.Join(opts.DomainAliases, ","))
}
if opts.Sponsors != nil {
q.Add("Sponsors", strings.Join(opts.Sponsors, ","))
if opts.Sponsorships != nil {
q.Add("Sponsorships", strings.Join(opts.Sponsorships, ","))
}
if opts.MagicLink != nil {
q.Add("MagicLink", strconv.FormatBool(*opts.MagicLink))
Expand Down
10 changes: 5 additions & 5 deletions cmd/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var flagTOSSigned string
var flagTOS string
var flagTOSLatest string
var flagContextName string
var flagSponsors []string
var flagSponsorships []string
var flagOnboardingFinished bool
var flagTTL time.Duration
var flagExpire time.Duration
Expand Down Expand Up @@ -189,7 +189,7 @@ be used as the error message.
TOSSigned: flagTOSSigned,
Timezone: flagTimezone,
ContextName: flagContextName,
Sponsors: flagSponsors,
Sponsorships: flagSponsorships,
Email: flagEmail,
PublicName: flagPublicName,
Settings: flagSettings,
Expand Down Expand Up @@ -278,7 +278,7 @@ settings for a specified domain.
TOSLatest: flagTOSLatest,
Timezone: flagTimezone,
ContextName: flagContextName,
Sponsors: flagSponsors,
Sponsorships: flagSponsorships,
Email: flagEmail,
PublicName: flagPublicName,
Settings: flagSettings,
Expand Down Expand Up @@ -1088,7 +1088,7 @@ func init() {
addInstanceCmd.Flags().StringVar(&flagTOS, "tos", "", "The TOS version signed")
addInstanceCmd.Flags().StringVar(&flagTimezone, "tz", "", "The timezone for the user")
addInstanceCmd.Flags().StringVar(&flagContextName, "context-name", "", "Context name of the instance")
addInstanceCmd.Flags().StringSliceVar(&flagSponsors, "sponsors", nil, "Sponsors of the instance (comma separated list)")
addInstanceCmd.Flags().StringSliceVar(&flagSponsorships, "sponsorships", nil, "Sponsorships of the instance (comma separated list)")
addInstanceCmd.Flags().StringVar(&flagEmail, "email", "", "The email of the owner")
addInstanceCmd.Flags().StringVar(&flagPublicName, "public-name", "", "The public name of the owner")
addInstanceCmd.Flags().StringVar(&flagSettings, "settings", "", "A list of settings (eg context:foo,offer:premium)")
Expand All @@ -1109,7 +1109,7 @@ func init() {
modifyInstanceCmd.Flags().StringVar(&flagTOSLatest, "tos-latest", "", "Update the latest TOS version")
modifyInstanceCmd.Flags().StringVar(&flagTimezone, "tz", "", "New timezone")
modifyInstanceCmd.Flags().StringVar(&flagContextName, "context-name", "", "New context name")
modifyInstanceCmd.Flags().StringSliceVar(&flagSponsors, "sponsors", nil, "Sponsors of the instance (comma separated list)")
modifyInstanceCmd.Flags().StringSliceVar(&flagSponsorships, "sponsorships", nil, "Sponsorships of the instance (comma separated list)")
modifyInstanceCmd.Flags().StringVar(&flagEmail, "email", "", "New email")
modifyInstanceCmd.Flags().StringVar(&flagPublicName, "public-name", "", "New public name")
modifyInstanceCmd.Flags().StringVar(&flagSettings, "settings", "", "New list of settings (eg offer:premium)")
Expand Down
2 changes: 1 addition & 1 deletion docs/cli/cozy-stack_instances_add.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ $ cozy-stack instances add --passphrase cozy --apps drive,photos,settings,home,s
--passphrase string Register the instance with this passphrase (useful for tests)
--public-name string The public name of the owner
--settings string A list of settings (eg context:foo,offer:premium)
--sponsors strings Sponsors of the instance (comma separated list)
--sponsorships strings Sponsorships of the instance (comma separated list)
--swift-layout int Specify the layout to use for Swift (from 0 for layout V1 to 2 for layout V3, -1 means the default) (default -1)
--tos string The TOS version signed
--trace Show where time is spent
Expand Down
2 changes: 1 addition & 1 deletion docs/cli/cozy-stack_instances_modify.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ cozy-stack instances modify <domain> [flags]
--onboarding-finished Force the finishing of the onboarding
--public-name string New public name
--settings string New list of settings (eg offer:premium)
--sponsors strings Sponsors of the instance (comma separated list)
--sponsorships strings Sponsorships of the instance (comma separated list)
--tos string Update the TOS version signed
--tos-latest string Update the latest TOS version
--tz string New timezone
Expand Down
2 changes: 1 addition & 1 deletion docs/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ Cookie: sessionid=xxxx
"auth_mode": "basic",
"default_redirection": "drive/#/folder",
"context": "dev",
"sponsors": ["springfield"]
"sponsorships": ["springfield"]
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion model/instance/instance.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Package instance is for the instance model, with domain, locale, settings,
// etc.
package instance

import (
Expand Down Expand Up @@ -52,7 +54,7 @@ type Instance struct {
OIDCID string `json:"oidc_id,omitempty"` // An identifier to check authentication from OIDC
FranceConnectID string `json:"franceconnect_id,omitempty"` // An identifier to check authentication from FranceConnect
ContextName string `json:"context,omitempty"` // The context attached to the instance
Sponsors []string `json:"sponsors,omitempty"` // The list of sponsors for the instance
Sponsorships []string `json:"sponsorships,omitempty"` // The list of sponsorships for the instance
TOSSigned string `json:"tos,omitempty"` // Terms of Service signed version
TOSLatest string `json:"tos_latest,omitempty"` // Terms of Service latest version
AuthMode AuthMode `json:"auth_mode,omitempty"` // 2 factor authentication
Expand Down
10 changes: 5 additions & 5 deletions model/instance/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestInstance(t *testing.T) {
assert.Equal(t, "my-app", claims["sub"])
})

t.Run("GetContextWithSponsors", func(t *testing.T) {
t.Run("GetContextWithSponsorships", func(t *testing.T) {
cfg := config.GetConfig()
was := cfg.Contexts
defer func() { cfg.Contexts = was }()
Expand Down Expand Up @@ -121,11 +121,11 @@ func TestInstance(t *testing.T) {
}

inst := &instance.Instance{
Domain: "foo.example.com",
ContextName: "context",
Sponsors: []string{"sponsor1", "sponsor2"},
Domain: "foo.example.com",
ContextName: "context",
Sponsorships: []string{"sponsor1", "sponsor2"},
}
result := inst.GetContextWithSponsors()
result := inst.GetContextWithSponsorships()
bytes, err := json.MarshalIndent(result, "", " ")
require.NoError(t, err)
expected := `{
Expand Down
10 changes: 5 additions & 5 deletions model/instance/lifecycle/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Options struct {
TOSLatest string
Timezone string
ContextName string
Sponsors []string
Sponsorships []string
Email string
PublicName string
Settings string
Expand Down Expand Up @@ -120,7 +120,7 @@ func Create(opts *Options) (*instance.Instance, error) {
i.TOSSigned = opts.TOSSigned
i.TOSLatest = opts.TOSLatest
i.ContextName = opts.ContextName
i.Sponsors = opts.Sponsors
i.Sponsorships = opts.Sponsorships
i.BytesDiskQuota = opts.DiskQuota
i.IndexViewsVersion = couchdb.IndexViewsVersion
opts.trace("generate secrets", func() {
Expand Down Expand Up @@ -313,9 +313,9 @@ func buildSettings(inst *instance.Instance, opts *Options) (*couchdb.JSONDoc, er
opts.ContextName = contextName
delete(settings.M, "context")
}
if sponsors, ok := settings.M["sponsors"].([]string); ok {
opts.Sponsors = sponsors
delete(settings.M, "sponsors")
if sponsorships, ok := settings.M["sponsorships"].([]string); ok {
opts.Sponsorships = sponsorships
delete(settings.M, "sponsorships")
}
if locale, ok := settings.M["locale"].(string); ok {
opts.Locale = locale
Expand Down
4 changes: 2 additions & 2 deletions model/instance/lifecycle/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ func Patch(i *instance.Instance, opts *Options) error {
needUpdate = true
}

if len(opts.Sponsors) != 0 {
i.Sponsors = opts.Sponsors
if len(opts.Sponsorships) != 0 {
i.Sponsorships = opts.Sponsorships
needUpdate = true
}

Expand Down
8 changes: 4 additions & 4 deletions model/instance/sponsors.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ type LogoItem struct {
Type string `json:"type,omitempty"`
}

func (inst *Instance) GetContextWithSponsors() map[string]interface{} {
context, ok := inst.SettingsContext()
func (i *Instance) GetContextWithSponsorships() map[string]interface{} {
context, ok := i.SettingsContext()
if !ok {
context = map[string]interface{}{}
}
if len(inst.Sponsors) == 0 {
if len(i.Sponsorships) == 0 {
return context
}

Expand All @@ -42,7 +42,7 @@ func (inst *Instance) GetContextWithSponsors() map[string]interface{} {
if contexts == nil {
return context
}
for _, sponsor := range inst.Sponsors {
for _, sponsor := range i.Sponsorships {
if sponsorCtx, ok := contexts[sponsor].(map[string]interface{}); ok {
addHomeLogosForSponsor(context, sponsorCtx, sponsor)
}
Expand Down
16 changes: 8 additions & 8 deletions scripts/completion/cozy-stack.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2333,10 +2333,10 @@ _cozy-stack_instances_add()
two_word_flags+=("--settings")
local_nonpersistent_flags+=("--settings")
local_nonpersistent_flags+=("--settings=")
flags+=("--sponsors=")
two_word_flags+=("--sponsors")
local_nonpersistent_flags+=("--sponsors")
local_nonpersistent_flags+=("--sponsors=")
flags+=("--sponsorships=")
two_word_flags+=("--sponsorships")
local_nonpersistent_flags+=("--sponsorships")
local_nonpersistent_flags+=("--sponsorships=")
flags+=("--swift-layout=")
two_word_flags+=("--swift-layout")
local_nonpersistent_flags+=("--swift-layout")
Expand Down Expand Up @@ -2849,10 +2849,10 @@ _cozy-stack_instances_modify()
two_word_flags+=("--settings")
local_nonpersistent_flags+=("--settings")
local_nonpersistent_flags+=("--settings=")
flags+=("--sponsors=")
two_word_flags+=("--sponsors")
local_nonpersistent_flags+=("--sponsors")
local_nonpersistent_flags+=("--sponsors=")
flags+=("--sponsorships=")
two_word_flags+=("--sponsorships")
local_nonpersistent_flags+=("--sponsorships")
local_nonpersistent_flags+=("--sponsorships=")
flags+=("--tos=")
two_word_flags+=("--tos")
local_nonpersistent_flags+=("--tos")
Expand Down
8 changes: 4 additions & 4 deletions web/instances/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ func createHandler(c echo.Context) error {
if domainAliases := c.QueryParam("DomainAliases"); domainAliases != "" {
opts.DomainAliases = strings.Split(domainAliases, ",")
}
if sponsors := c.QueryParam("sponsors"); sponsors != "" {
opts.Sponsors = strings.Split(sponsors, ",")
if sponsorships := c.QueryParam("sponsorships"); sponsorships != "" {
opts.Sponsorships = strings.Split(sponsorships, ",")
}
if autoUpdate := c.QueryParam("AutoUpdate"); autoUpdate != "" {
b, err := strconv.ParseBool(autoUpdate)
Expand Down Expand Up @@ -174,8 +174,8 @@ func modifyHandler(c echo.Context) error {
if domainAliases := c.QueryParam("DomainAliases"); domainAliases != "" {
opts.DomainAliases = strings.Split(domainAliases, ",")
}
if sponsors := c.QueryParam("Sponsors"); sponsors != "" {
opts.Sponsors = strings.Split(sponsors, ",")
if sponsorships := c.QueryParam("Sponsorships"); sponsorships != "" {
opts.Sponsorships = strings.Split(sponsorships, ",")
}
if quota := c.QueryParam("DiskQuota"); quota != "" {
i, err := strconv.ParseInt(quota, 10, 64)
Expand Down
2 changes: 1 addition & 1 deletion web/settings/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,6 @@ func (h *HTTPHandler) context(c echo.Context) error {
}

i := middlewares.GetInstance(c)
doc := &apiContext{i.GetContextWithSponsors()}
doc := &apiContext{i.GetContextWithSponsorships()}
return jsonapi.Data(c, http.StatusOK, doc, nil)
}
6 changes: 3 additions & 3 deletions web/settings/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ func (h *HTTPHandler) getInstance(c echo.Context) error {
doc.M["uuid"] = inst.UUID
doc.M["oidc_id"] = inst.OIDCID
doc.M["context"] = inst.ContextName
if len(inst.Sponsors) > 0 {
doc.M["sponsors"] = inst.Sponsors
if len(inst.Sponsorships) > 0 {
doc.M["sponsorships"] = inst.Sponsorships
}
// XXX we had a bug where the default_redirection was filled by a full URL
// instead of slug+path, and we fix it when this endpoint is called.
Expand Down Expand Up @@ -102,7 +102,7 @@ func (h *HTTPHandler) updateInstance(c echo.Context) error {
delete(doc.M, "tos_latest")
delete(doc.M, "uuid")
delete(doc.M, "context")
delete(doc.M, "sponsors")
delete(doc.M, "sponsorships")
delete(doc.M, "oidc_id")
}

Expand Down

0 comments on commit 5d5139b

Please sign in to comment.