Add default app creation on setup

This commit is contained in:
Denis Arh
2019-06-19 18:26:52 +02:00
parent 6020381de1
commit 1960fd7a51
2 changed files with 57 additions and 0 deletions
+56
View File
@@ -4,9 +4,13 @@ import (
"context"
"github.com/spf13/cobra"
"github.com/titpetric/factory"
"go.uber.org/zap"
"github.com/cortezaproject/corteza-server/pkg/cli"
"github.com/cortezaproject/corteza-server/system/internal/repository"
"github.com/cortezaproject/corteza-server/system/internal/service"
"github.com/cortezaproject/corteza-server/system/types"
)
func accessControlSetup(ctx context.Context, cmd *cobra.Command, c *cli.Config) error {
@@ -15,3 +19,55 @@ func accessControlSetup(ctx context.Context, cmd *cobra.Command, c *cli.Config)
var ac = service.DefaultAccessControl
return p.Grant(ctx, ac.Whitelist(), ac.DefaultRules()...)
}
func makeDefaultApplications(ctx context.Context, cmd *cobra.Command, c *cli.Config) error {
db, err := factory.Database.Get(system)
if err != nil {
return err
}
repo := repository.Application(ctx, db)
aa, err := repo.Find()
if err != nil {
return err
}
// List of apps to create.
//
// We use Unify.Url field for matching,
// so make sure it's always present!
defApps := types.ApplicationSet{
&types.Application{
Name: "CRM",
Enabled: true,
Unify: &types.ApplicationUnify{
Name: "CRM",
Listed: true,
Icon: "/applications/crust_favicon.png",
Logo: "/applications/crust.jpg",
Url: "/compose/ns/crm",
},
},
}
return defApps.Walk(func(defApp *types.Application) error {
for _, a := range aa {
if a.Unify != nil && a.Unify.Url == defApp.Unify.Url {
// App already added.
return nil
}
}
defApp, err = repo.Create(defApp)
c.Log.Info(
"creating default application",
zap.String("name", defApp.Name),
zap.Uint64("name", defApp.ID),
zap.Error(err),
)
return err
return nil
})
}
+1
View File
@@ -33,6 +33,7 @@ func Configure() *cli.Config {
if c.ProvisionOpt.AutoSetup {
cli.HandleError(accessControlSetup(ctx, cmd, c))
cli.HandleError(makeDefaultApplications(ctx, cmd, c))
// Run auto configuration
commands.SettingsAutoConfigure(cmd, "", "", "", "")