Skip to content

Commit 4d097f1

Browse files
authored
Add common settings (#4547)
2 parents fbf8a2c + 3ba9064 commit 4d097f1

File tree

14 files changed

+365
-1
lines changed

14 files changed

+365
-1
lines changed

client/instances.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ type InstanceOptions struct {
7070
Sponsorships []string
7171
Email string
7272
PublicName string
73+
Phone string
7374
Settings string
7475
BlockingReason string
7576
SwiftLayout int
@@ -156,6 +157,7 @@ func (ac *AdminClient) CreateInstance(opts *InstanceOptions) (*Instance, error)
156157
"ContextName": {opts.ContextName},
157158
"Email": {opts.Email},
158159
"PublicName": {opts.PublicName},
160+
"Phone": {opts.Phone},
159161
"Settings": {opts.Settings},
160162
"SwiftLayout": {strconv.Itoa(opts.SwiftLayout)},
161163
"CouchCluster": {strconv.Itoa(opts.CouchCluster)},
@@ -237,6 +239,7 @@ func (ac *AdminClient) ModifyInstance(opts *InstanceOptions) (*Instance, error)
237239
"ContextName": {opts.ContextName},
238240
"Email": {opts.Email},
239241
"PublicName": {opts.PublicName},
242+
"Phone": {opts.Phone},
240243
"Settings": {opts.Settings},
241244
"DiskQuota": {strconv.FormatInt(opts.DiskQuota, 10)},
242245
}

cmd/instances.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var flagLocale string
3131
var flagTimezone string
3232
var flagEmail string
3333
var flagPublicName string
34+
var flagPhone string
3435
var flagSettings string
3536
var flagDiskQuota string
3637
var flagApps []string
@@ -192,6 +193,7 @@ be used as the error message.
192193
Sponsorships: flagSponsorships,
193194
Email: flagEmail,
194195
PublicName: flagPublicName,
196+
Phone: flagPhone,
195197
Settings: flagSettings,
196198
SwiftLayout: flagSwiftLayout,
197199
CouchCluster: flagCouchCluster,
@@ -281,6 +283,7 @@ settings for a specified domain.
281283
Sponsorships: flagSponsorships,
282284
Email: flagEmail,
283285
PublicName: flagPublicName,
286+
Phone: flagPhone,
284287
Settings: flagSettings,
285288
BlockingReason: flagBlockingReason,
286289
DiskQuota: diskQuota,
@@ -1091,6 +1094,7 @@ func init() {
10911094
addInstanceCmd.Flags().StringSliceVar(&flagSponsorships, "sponsorships", nil, "Sponsorships of the instance (comma separated list)")
10921095
addInstanceCmd.Flags().StringVar(&flagEmail, "email", "", "The email of the owner")
10931096
addInstanceCmd.Flags().StringVar(&flagPublicName, "public-name", "", "The public name of the owner")
1097+
addInstanceCmd.Flags().StringVar(&flagPhone, "phone", "", "The phone number of the owner")
10941098
addInstanceCmd.Flags().StringVar(&flagSettings, "settings", "", "A list of settings (eg context:foo,offer:premium)")
10951099
addInstanceCmd.Flags().IntVar(&flagSwiftLayout, "swift-layout", -1, "Specify the layout to use for Swift (from 0 for layout V1 to 2 for layout V3, -1 means the default)")
10961100
addInstanceCmd.Flags().IntVar(&flagCouchCluster, "couch-cluster", -1, "Specify the CouchDB cluster where the instance will be created (-1 means the default)")
@@ -1112,6 +1116,7 @@ func init() {
11121116
modifyInstanceCmd.Flags().StringSliceVar(&flagSponsorships, "sponsorships", nil, "Sponsorships of the instance (comma separated list)")
11131117
modifyInstanceCmd.Flags().StringVar(&flagEmail, "email", "", "New email")
11141118
modifyInstanceCmd.Flags().StringVar(&flagPublicName, "public-name", "", "New public name")
1119+
modifyInstanceCmd.Flags().StringVar(&flagPhone, "phone", "", "New phone number")
11151120
modifyInstanceCmd.Flags().StringVar(&flagSettings, "settings", "", "New list of settings (eg offer:premium)")
11161121
modifyInstanceCmd.Flags().StringVar(&flagDiskQuota, "disk-quota", "", "Specify a new disk quota")
11171122
modifyInstanceCmd.Flags().StringVar(&flagBlockingReason, "blocking-reason", "", "Code that explains why the instance is blocked (PAYMENT_FAILED, LOGIN_FAILED, etc.)")

cozy.example.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,12 @@ office:
361361
# url: https://manager.example.org/
362362
# token: xxxxxx
363363

364+
# [internal usage] Common settings
365+
# common_settings:
366+
# default:
367+
# url: https://sign-up.example.org/
368+
# token: f95880b7fa9e8a51e103ac5383bc5956d849267e99b336f31df8bd86c2e9ec50
369+
364370
# All the deprecated apps listed here will see their OAUTH2 Authorization
365371
# flow interupted and redirected to a page proposing to move to the new
366372
# cozy application.

docs/cli/cozy-stack_instances_add.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ $ cozy-stack instances add --passphrase cozy --apps drive,photos,settings,home,s
3939
--magic_link Enable authentication with magic links sent by email
4040
--oidc_id string The identifier for checking authentication from OIDC
4141
--passphrase string Register the instance with this passphrase (useful for tests)
42+
--phone string The phone number of the owner
4243
--public-name string The public name of the owner
4344
--settings string A list of settings (eg context:foo,offer:premium)
4445
--sponsorships strings Sponsorships of the instance (comma separated list)

docs/cli/cozy-stack_instances_modify.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ cozy-stack instances modify <domain> [flags]
2929
--magic_link Enable authentication with magic links sent by email
3030
--oidc_id string New identifier for checking authentication from OIDC
3131
--onboarding-finished Force the finishing of the onboarding
32+
--phone string New phone number
3233
--public-name string New public name
3334
--settings string New list of settings (eg offer:premium)
3435
--sponsorships strings Sponsorships of the instance (comma separated list)

model/instance/instance.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ type Instance struct {
7373
BytesDiskQuota int64 `json:"disk_quota,string,omitempty"` // The total size in bytes allowed to the user
7474
IndexViewsVersion int `json:"indexes_version,omitempty"`
7575

76+
CommonSettingsVersion int `json:"common_settings_version,omitempty"`
77+
7678
// Swift layout number:
7779
// - 0 for layout v1
7880
// - 1 for layout v2

model/instance/lifecycle/create.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/cozy/cozy-stack/model/contact"
1515
"github.com/cozy/cozy-stack/model/instance"
16+
"github.com/cozy/cozy-stack/model/settings/common"
1617
"github.com/cozy/cozy-stack/pkg/config/config"
1718
"github.com/cozy/cozy-stack/pkg/consts"
1819
"github.com/cozy/cozy-stack/pkg/couchdb"
@@ -39,6 +40,7 @@ type Options struct {
3940
FeatureSets []string
4041
Email string
4142
PublicName string
43+
Phone string
4244
Settings string
4345
SettingsObj *couchdb.JSONDoc
4446
AuthMode string
@@ -268,6 +270,12 @@ func Create(opts *Options) (*instance.Instance, error) {
268270
}
269271
})
270272

273+
opts.trace("create common settings", func() {
274+
if err = common.CreateCommonSettings(i, settings); err != nil {
275+
i.Logger().Errorf("Failed to create common settings: %s", err)
276+
}
277+
})
278+
271279
return i, nil
272280
}
273281

@@ -368,6 +376,9 @@ func buildSettings(inst *instance.Instance, opts *Options) (*couchdb.JSONDoc, er
368376
if name := opts.PublicName; name != "" {
369377
settings.M["public_name"] = name
370378
}
379+
if phone := opts.Phone; phone != "" {
380+
settings.M["phone"] = phone
381+
}
371382

372383
if len(opts.TOSSigned) == 8 {
373384
opts.TOSSigned = "1.0.0-" + opts.TOSSigned

model/instance/lifecycle/patch.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/cozy/cozy-stack/model/cloudery"
1212
"github.com/cozy/cozy-stack/model/instance"
13+
"github.com/cozy/cozy-stack/model/settings/common"
1314
"github.com/cozy/cozy-stack/pkg/couchdb"
1415
"github.com/cozy/cozy-stack/pkg/logger"
1516
"github.com/labstack/echo/v4"
@@ -165,6 +166,7 @@ func Patch(i *instance.Instance, opts *Options) error {
165166
if err != nil {
166167
return err
167168
}
169+
168170
if needSharingReupload && AskReupload != nil {
169171
go func() {
170172
inst := i.Clone().(*instance.Instance)
@@ -198,6 +200,17 @@ func Patch(i *instance.Instance, opts *Options) error {
198200
}
199201
}
200202

203+
updated, err := common.UpdateCommonSettings(i, settings)
204+
if err != nil {
205+
i.Logger().Errorf("Failed to update common settings: %s", err)
206+
}
207+
if updated {
208+
// We need to persist the common settings version
209+
if err = update(i); err != nil {
210+
return err
211+
}
212+
}
213+
201214
if debug := opts.Debug; debug != nil {
202215
var err error
203216
if *debug {

0 commit comments

Comments
 (0)