Skip to content

Commit 5d2f7c9

Browse files
authored
Merge pull request #3113 from cozy/manifest
Remove explicit mapping for app manifests
2 parents f47c54e + 1af0330 commit 5d2f7c9

File tree

25 files changed

+461
-435
lines changed

25 files changed

+461
-435
lines changed

client/apps.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type AppManifest struct {
4545
Messages *json.RawMessage `json:"messages,omitempty"`
4646
OAuth *json.RawMessage `json:"oauth,omitempty"`
4747
TimeInterval *json.RawMessage `json:"time_interval,omitempty"`
48+
ClientSide bool `json:"clientSide,omitempty"`
4849

4950
Slug string `json:"slug"`
5051
State string `json:"state"`

model/app/apps.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,14 @@ type Manifest interface {
7878
LastUpdate() time.Time
7979
Terms() Terms
8080

81+
Name() string
82+
Icon() string
83+
Notifications() Notifications
84+
8185
SetError(err error)
8286
Error() error
8387

88+
SetSlug(slug string)
8489
SetSource(src *url.URL)
8590
SetState(state State)
8691
SetVersion(version string)

model/app/apps_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import (
88

99
func TestFindRoute(t *testing.T) {
1010
manifest := &WebappManifest{}
11-
manifest.Routes = make(Routes)
12-
manifest.Routes["/foo"] = Route{Folder: "/foo", Index: "index.html"}
13-
manifest.Routes["/foo/bar"] = Route{Folder: "/bar", Index: "index.html"}
14-
manifest.Routes["/foo/qux"] = Route{Folder: "/qux", Index: "index.html"}
15-
manifest.Routes["/public"] = Route{Folder: "/public", Index: "public.html", Public: true}
16-
manifest.Routes["/admin"] = Route{Folder: "/admin", Index: "admin.html"}
17-
manifest.Routes["/admin/special"] = Route{Folder: "/special", Index: "admin.html"}
11+
manifest.val.Routes = make(Routes)
12+
manifest.val.Routes["/foo"] = Route{Folder: "/foo", Index: "index.html"}
13+
manifest.val.Routes["/foo/bar"] = Route{Folder: "/bar", Index: "index.html"}
14+
manifest.val.Routes["/foo/qux"] = Route{Folder: "/qux", Index: "index.html"}
15+
manifest.val.Routes["/public"] = Route{Folder: "/public", Index: "public.html", Public: true}
16+
manifest.val.Routes["/admin"] = Route{Folder: "/admin", Index: "admin.html"}
17+
manifest.val.Routes["/admin/special"] = Route{Folder: "/special", Index: "admin.html"}
1818

1919
ctx, rest := manifest.FindRoute("/admin")
2020
assert.Equal(t, "/admin", ctx.Folder)
@@ -62,8 +62,8 @@ func TestFindRoute(t *testing.T) {
6262

6363
func TestNoRegression217(t *testing.T) {
6464
var man WebappManifest
65-
man.Routes = make(Routes)
66-
man.Routes["/"] = Route{
65+
man.val.Routes = make(Routes)
66+
man.val.Routes["/"] = Route{
6767
Folder: "/",
6868
Index: "index.html",
6969
Public: false,
@@ -79,7 +79,7 @@ func TestFindIntent(t *testing.T) {
7979
found := man.FindIntent("PICK", "io.cozy.files")
8080
assert.Nil(t, found)
8181

82-
man.Intents = []Intent{
82+
man.val.Intents = []Intent{
8383
{
8484
Action: "PICK",
8585
Types: []string{"io.cozy.contacts", "io.cozy.calendars"},
@@ -117,7 +117,7 @@ func TestFindIntent(t *testing.T) {
117117
assert.NotNil(t, found)
118118
assert.Equal(t, "EDIT", found.Action)
119119

120-
man.Intents = []Intent{
120+
man.val.Intents = []Intent{
121121
{
122122
Action: "PICK",
123123
Href: "/pick",

model/app/installer.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/cozy/cozy-stack/pkg/appfs"
1616
"github.com/cozy/cozy-stack/pkg/config/config"
1717
"github.com/cozy/cozy-stack/pkg/consts"
18+
"github.com/cozy/cozy-stack/pkg/couchdb"
1819
"github.com/cozy/cozy-stack/pkg/hooks"
1920
"github.com/cozy/cozy-stack/pkg/logger"
2021
"github.com/cozy/cozy-stack/pkg/prefixer"
@@ -46,7 +47,7 @@ type Installer struct {
4647
db prefixer.Prefixer
4748
endState State
4849

49-
overridenParameters *json.RawMessage
50+
overridenParameters map[string]interface{}
5051
permissionsAcked bool
5152

5253
man Manifest
@@ -73,7 +74,7 @@ type InstallerOptions struct {
7374
// Used to override the "Parameters" field of konnectors during installation.
7475
// This modification is useful to allow the parameterization of a konnector
7576
// at its installation as we do not have yet a registry up and running.
76-
OverridenParameters *json.RawMessage
77+
OverridenParameters map[string]interface{}
7778
}
7879

7980
// Fetcher interface should be implemented by the underlying transport
@@ -203,15 +204,24 @@ func initManifest(db prefixer.Prefixer, opts *InstallerOptions) (man Manifest, e
203204
switch opts.Type {
204205
case consts.WebappType:
205206
man = &WebappManifest{
206-
DocID: consts.Apps + "/" + slug,
207-
DocSlug: slug,
207+
doc: &couchdb.JSONDoc{
208+
Type: consts.Apps,
209+
M: map[string]interface{}{
210+
"_id": consts.Apps + "/" + slug,
211+
},
212+
},
208213
}
209214
case consts.KonnectorType:
210215
man = &KonnManifest{
211-
DocID: consts.Konnectors + "/" + slug,
212-
DocSlug: slug,
216+
doc: &couchdb.JSONDoc{
217+
Type: consts.Konnectors,
218+
M: map[string]interface{}{
219+
"_id": consts.Konnectors + "/" + slug,
220+
},
221+
},
213222
}
214223
}
224+
man.SetSlug(slug)
215225
} else {
216226
man, err = GetBySlug(db, slug, opts.Type)
217227
if err != nil {
@@ -436,7 +446,7 @@ func (i *Installer) update() error {
436446
i.man.SetState(i.endState)
437447
} else {
438448
if i.man.AppType() == consts.WebappType {
439-
i.man.(*WebappManifest).oldServices = i.man.(*WebappManifest).Services
449+
i.man.(*WebappManifest).oldServices = i.man.(*WebappManifest).val.Services
440450
}
441451
i.man.SetSource(i.src)
442452
if availableVersion != "" {
@@ -510,7 +520,7 @@ func (i *Installer) ReadManifest(state State) (Manifest, error) {
510520
i.src.Scheme != "registry")
511521
if shouldOverrideParameters {
512522
if m, ok := newManifest.(*KonnManifest); ok {
513-
m.Parameters = i.overridenParameters
523+
m.val.Parameters = i.overridenParameters
514524
}
515525
}
516526

model/app/installer_webapp_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,8 @@ func TestWebappInstallWithUpgrade(t *testing.T) {
306306
version1 := man.Version()
307307

308308
manWebapp := man.(*app.WebappManifest)
309-
if assert.NotNil(t, manWebapp.Services["service1"]) {
310-
service1 := manWebapp.Services["service1"]
309+
if assert.NotNil(t, manWebapp.Services()["service1"]) {
310+
service1 := manWebapp.Services()["service1"]
311311
assert.Equal(t, "/services/service1.js", service1.File)
312312
assert.Equal(t, "@cron 0 0 0 * * *", service1.TriggerOptions)
313313
assert.Equal(t, "node", service1.Type)
@@ -364,7 +364,7 @@ func TestWebappInstallWithUpgrade(t *testing.T) {
364364
assert.NoError(t, err)
365365
assert.True(t, ok, "The manifest has the right version")
366366
manWebapp = man.(*app.WebappManifest)
367-
assert.Nil(t, manWebapp.Services["service1"])
367+
assert.Nil(t, manWebapp.Services()["service1"])
368368
}
369369

370370
func TestWebappInstallAndUpgradeWithBranch(t *testing.T) {

0 commit comments

Comments
 (0)