From 0e27832f47547f9c8314fff5f5b44e95689944ff Mon Sep 17 00:00:00 2001 From: metalwolf Date: Mon, 25 Jan 2021 18:39:53 -0600 Subject: [PATCH] patch v2021.01.25 --- README.md | 5 ++ adminmenu/adminmenu.go | 5 +- adminmenu/init.go | 88 ++++++++++++++-------- adminmenu/messages.go | 106 +++++++++++++++++++++++++++ adminmenu/util.go | 138 +++++++++++++++++++++++------------ base/container.go | 2 +- base/init.go | 70 +++++++++--------- base/installation.go | 56 ++++++++++++++ base/messages.go | 43 +++++++---- base/util.go | 69 +++++++++++++----- tools/configset.go | 19 +++++ tools/lang.go | 1 - user/access.go | 44 +++++++++-- user/assets/access.go | 12 ++- user/assets/moduleentries.go | 7 +- user/init.go | 68 +++++++++++------ user/messages.go | 58 +++++++-------- user/security.go | 11 ++- user/util.go | 49 +++++++------ useradmin/init.go | 59 +++++++++------ useradmin/messages.go | 54 ++++++-------- useradmin/util.go | 21 ++++-- xmodules.go | 2 +- 23 files changed, 682 insertions(+), 305 deletions(-) create mode 100644 adminmenu/messages.go create mode 100644 base/installation.go create mode 100644 tools/configset.go diff --git a/README.md b/README.md index 54f90f2..0f05792 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,11 @@ import "github.com/webability-go/xmodules/ingredient" import "github.com/webability-go/xmodules/material" +v2021-01-25: +- base, user, adminmenu and useradmin support now transactions to setup the modules. +- Errors control and messages enhanced during the installation of the modules. +- Separation of basic installation functions into the xmodules/base/installation.go + v2021-01-20: - All the modules: enhancement to meet the new main structures and mmodules definition for Xamboo (use of datasource interface, use of bridge and assets modules entries) diff --git a/adminmenu/adminmenu.go b/adminmenu/adminmenu.go index 2141b0e..0c80d03 100644 --- a/adminmenu/adminmenu.go +++ b/adminmenu/adminmenu.go @@ -41,9 +41,10 @@ func AddOption(ds serverassets.Datasource, data *xdominion.XRecord) error { // Verify if it exists already - _, err := adminmenu_option.Insert(data) + key, _ := data.GetString("key") + _, err := adminmenu_option.Upsert(key, data) if err != nil { - ds.Log("main", "Error inserting in adminmenu_option", err) + ds.Log("main", "Error upserting in adminmenu_option", err) return err } return nil diff --git a/adminmenu/init.go b/adminmenu/init.go index f436d79..aaeb719 100644 --- a/adminmenu/init.go +++ b/adminmenu/init.go @@ -10,6 +10,7 @@ import ( "github.com/webability-go/xmodules/adminmenu/assets" "github.com/webability-go/xmodules/base" + "github.com/webability-go/xmodules/tools" ) const ( @@ -18,6 +19,7 @@ const ( DATASOURCE = "adminmenudatasource" ) +var Needs = []string{"base", "user"} var ModuleAdminMenu = assets.ModuleEntries{ AddGroup: AddGroup, GetGroup: GetGroup, @@ -27,11 +29,16 @@ var ModuleAdminMenu = assets.ModuleEntries{ } func init() { + messages = tools.BuildMessages(smessages) m := &base.Module{ - ID: MODULEID, - Version: VERSION, - Languages: map[language.Tag]string{language.English: "Administration menu", language.Spanish: "Menu de administración", language.French: "Menu pour l'administration"}, - Needs: []string{"base", "user"}, + ID: MODULEID, + Version: VERSION, + Languages: map[language.Tag]string{ + language.English: tools.Message(messages, "MODULENAME", language.English), + language.Spanish: tools.Message(messages, "MODULENAME", language.Spanish), + language.French: tools.Message(messages, "MODULENAME", language.French), + }, + Needs: Needs, FSetup: Setup, // Called once at the main system startup, once PER CREATED xmodule CONTEXT (if set) FSynchronize: Synchronize, // Called only to create/rebuild database objects and others on demand (if set) FStartContext: StartContext, // Called each time a new Server context is created (if set) @@ -43,49 +50,66 @@ func init() { // adds tables and caches to sitecontext::database func Setup(ds serverassets.Datasource, prefix string) ([]string, error) { - lds := ds.(*base.Datasource) - buildTables(lds) - createCache(lds) - lds.SetModule(MODULEID, VERSION) - - go buildCache(lds) + linkTables(ds) + ds.SetModule(MODULEID, VERSION) return []string{}, nil } func Synchronize(ds serverassets.Datasource, prefix string) ([]string, error) { - messages := []string{} + result := []string{} - lds := ds.(*base.Datasource) - // Needed modules: context and translation - vc := base.ModuleInstalledVersion(ds, "base") - if vc == "" { - messages = append(messages, "xmodules/base need to be installed before installing xmodules/adminmenu.") - return messages, nil + ok, res := base.VerifyNeeds(ds, Needs) + result = append(result, res...) + if !ok { + return result, nil } - vc = base.ModuleInstalledVersion(ds, "user") - if vc == "" { - messages = append(messages, "xmodules/user need to be installed before installing xmodules/adminmenu.") - return messages, nil + installed := base.ModuleInstalledVersion(ds, MODULEID) + + // synchro tables + err, r := synchroTables(ds, installed) + result = append(result, r...) + if err != nil { + return result, err } - // create tables - messages = append(messages, createTables(lds)...) - // fill super admin - messages = append(messages, loadTables(lds)...) + // The rest of the process with a transaction + // lets clone ds to begin a transaction + cds := ds.CloneShell() + _, err = cds.StartTransaction() + if err != nil { + result = append(result, err.Error()) + return result, err + } - // Inserting into context-modules - // Be sure context module is on db: fill context module (we should get this from xmodule.conf) - err := base.AddModule(ds, MODULEID, "Administration Admin menu", VERSION) - if err == nil { - messages = append(messages, "The entry "+MODULEID+" was modified successfully in the modules table.") + // installation or upgrade ? + if installed != "" { + err, r = upgrade(cds, installed) } else { - messages = append(messages, "Error modifying the entry "+MODULEID+" in the modules table: "+err.Error()) + err, r = install(cds) + } + result = append(result, r...) + if err == nil { + err = base.AddModule(cds, MODULEID, tools.Message(messages, "MODULENAME"), VERSION) + if err == nil { + result = append(result, tools.Message(messages, "modulemodified", MODULEID)) + result = append(result, tools.Message(messages, "commit")) + err = cds.Commit() + if err != nil { + result = append(result, err.Error()) + } + return result, err + } + } + result = append(result, tools.Message(messages, "rollback", err)) + err1 := cds.Rollback() + if err1 != nil { + result = append(result, err1.Error()) } - return messages, nil + return result, err } func StartContext(ds serverassets.Datasource, ctx *serverassets.Context) error { diff --git a/adminmenu/messages.go b/adminmenu/messages.go new file mode 100644 index 0000000..3a0432e --- /dev/null +++ b/adminmenu/messages.go @@ -0,0 +1,106 @@ +package adminmenu + +import ( + "golang.org/x/text/language" + + "github.com/webability-go/xcore/v2" +) + +// Do no forget to call tools.BuildMessages from the init +var messages *map[language.Tag]*xcore.XLanguage + +var smessages = map[language.Tag]map[string]string{ + language.English: { + // Module installation messages + // init.go + "MODULENAME": "Administration menu", + "modulemodified": "The entry %s was modified successfully in the base_module table.", + "commit": "Installation successfull.", + "rollback": "Installation aborted with error: %s", + + // util.go + "MAINMENU": "Default Administration menu", + "accessgroup.name": "Access group for menu administration", + "accessgroup.description": "Group of all accesses for menu administration", + "access.name": "Access for menu administration", + "access.description": "Access for menu administration", + "menufolder.name": "Menu constructor", + "menufolder.description1": "Click on this line to see the different options for the administration of menus", + "adminmenugroup.name": "Menu groups", + "adminmenugroup.description1": "Menu groups", + "adminmenuoption.name": "Menu options", + "adminmenuoption.description1": "Menu options", + + "moduleerror": "Error modifying the entry %s in the base_module table: %s", + // Datasources transactions + "transaction.exist": "Error creating a transaction: There is already a started transaction.", + "transaction.none": "Error searching the transaction: There is no available transaction.", + "transaction.commitnone": "Error searching the transaction to commit: There is no available transaction.", + "transaction.rollbacknone": "Error searching the transaction to rollback: There is no available transaction.", + "transaction.error": "Error in the transaction: %s", + // Containers + "database.none": "There is no available database in the datasource", + }, + language.Spanish: { + // Module installation messages + // init.go + "MODULENAME": "Menu de administración", + "modulemodified": "La entrada %s fue modificada con exito en la tabla base_module.", + "commit": "Instalación exitosa.", + "rollback": "Instalación con error: %s", + + // util.go + "MAINMENU": "Menú de administración por defecto", + "accessgroup.name": "Grupos de accesos de la administración de menús", + "accessgroup.description": "Grupos de accesos de la administración de menús", + "access.name": "Acceso de la administración de menús", + "access.description": "Acceso de la administración de menús", + "menufolder.name": "Constructor de menús", + "menufolder.description1": "Haz clic sobre esta linea para ver las diferentes opciones para la administración de menús.", + "adminmenugroup.name": "Grupos de menús", + "adminmenugroup.description1": "Grupos de menús", + "adminmenuoption.name": "Opciones de menús", + "adminmenuoption.description1": "Opciones de menús", + + "moduleerror": "Error modificando la entrada %s en la tabla base_module: %s", + // Datasources transactions + "transaction.exist": "Error creating a transaction: There is already a started transaction.", + "transaction.none": "Error searching the transaction: There is no available transaction.", + "transaction.commitnone": "Error searching the transaction to commit: There is no available transaction.", + "transaction.rollbacknone": "Error searching the transaction to rollback: There is no available transaction.", + "transaction.error": "Error in the transaction: %s", + // Containers + "database.none": "There is no available database in the datasource", + }, + language.French: { + // Module installation messages + // init.go + "MODULENAME": "Menu pour l'administration", + "modulemodified": "L'entrée %s a été modifiée avec succès dans la table base_module.", + "commit": "Instalation réussie.", + "rollback": "Instalation avec erreur: %s", + + // util.go + "MAINMENU": "Menu d'administration par défaut", + "accessgroup.name": "Groupe des accès d'administration de menus", + "accessgroup.description": "Groupe des accès d'administration de menus", + "access.name": "Accès d'administration de menus", + "access.description": "Accès d'administration de menus", + "menufolder.name": "Constructeur de menus", + "menufolder.description1": "Constructeur de menus", + "adminmenugroup.name": "Groupes de menus", + "adminmenugroup.description1": "Groupes de menus", + "adminmenuoption.name": "Options de menus", + "adminmenuoption.description1": "Options de menus", + + "moduleerror": "Erreur en modifiant l'entrée %s dans la table base_module: %s", + // Datasources transactions + "transaction.exist": "Error creating a transaction: There is already a started transaction.", + "transaction.none": "Error searching the transaction: There is no available transaction.", + "transaction.commitnone": "Error searching the transaction to commit: There is no available transaction.", + "transaction.rollbacknone": "Error searching the transaction to rollback: There is no available transaction.", + "transaction.error": "Error in the transaction: %s", + // Containers + "database.none": "There is no available database in the datasource", + }, +} diff --git a/adminmenu/util.go b/adminmenu/util.go index 321a305..4c0fd8d 100644 --- a/adminmenu/util.go +++ b/adminmenu/util.go @@ -4,9 +4,14 @@ import ( "fmt" // "time" + serverassets "github.com/webability-go/xamboo/assets" + // "github.com/webability-go/xcore/v2" "github.com/webability-go/xdominion" "github.com/webability-go/xmodules/base" + "github.com/webability-go/xmodules/tools" + "github.com/webability-go/xmodules/user" + userassets "github.com/webability-go/xmodules/user/assets" ) // Order to load/synchronize tables: @@ -21,7 +26,7 @@ var moduletables = map[string]func() *xdominion.XTable{ "adminmenu_option": adminmenuOption, } -func buildTables(ds *base.Datasource) { +func linkTables(ds serverassets.Datasource) { for _, tbl := range moduletablesorder { table := moduletables[tbl]() @@ -30,67 +35,110 @@ func buildTables(ds *base.Datasource) { } } -func createCache(ds *base.Datasource) []string { - - return []string{} -} - -func buildCache(ds *base.Datasource) []string { +func synchroTables(ds serverassets.Datasource, oldversion string) (error, []string) { - return []string{} -} - -func createTables(ds *base.Datasource) []string { - - messages := []string{} + result := []string{} for _, tbl := range moduletablesorder { - table := ds.GetTable(tbl) - if table == nil { - return []string{"xmodules::adminmenu::createTables: Error, the table is not available on this datasource:" + tbl} + err, res := base.SynchroTable(ds, tbl) + result = append(result, res...) + if err != nil { + return err, result } + } - messages = append(messages, "Analysing "+tbl+" table.") - num, err := table.Count(nil) - if err != nil || num == 0 { - err1 := table.Synchronize() - if err1 != nil { - messages = append(messages, "The table "+tbl+" was not created: "+err1.Error()) - } else { - messages = append(messages, "The table "+tbl+" was created (again)") - } - } else { - messages = append(messages, "The table "+tbl+" was not created because it contains data.") - } + if oldversion < "0.0.1" { + // do things } - return messages + return nil, result } -func loadTables(ds *base.Datasource) []string { +func install(ds serverassets.Datasource) (error, []string) { - adminmenu_group := ds.GetTable("adminmenu_group") - if adminmenu_group == nil { - return []string{"xmodules::adminmenu::createTables: Error, the table adminmenu_group is not available on this datasource"} - } + result := []string{} - adminmenu_option := ds.GetTable("adminmenu_option") - if adminmenu_option == nil { - return []string{"xmodules::adminmenu::createTables: Error, the table adminmenu_option is not available on this datasource"} + // Group, just in case (upsert) + err := AddGroup(ds, "_admin", tools.Message(messages, "MAINMENU")) + if err != nil { + return err, result + } + // Accesses + err = user.AddAccessGroup(ds, &userassets.AccessGroup{ + Key: "_adminmenu", + Name: tools.Message(messages, "accessgroup.name"), + Description: tools.Message(messages, "accessgroup.description"), + }) + if err != nil { + return err, result } - // insert admin group - _, err := adminmenu_group.Upsert("admin", xdominion.XRecord{ - "key": "admin", - "name": "Administration menu", + err = user.AddAccess(ds, &userassets.Access{ + Key: "_adminmenu", + Name: tools.Message(messages, "access.name"), + Group: "_adminmenu", + Description: tools.Message(messages, "access.description"), }) if err != nil { - ds.Log("main", "Error inserting admin adminmenu_group", err) - return []string{"xmodules::adminmenu::loadTables: Error upserting the admin adminmenu group"} + return err, result } - return []string{ - fmt.Sprint(adminmenu_option.Count(nil)) + " admin menu options added", + mainoption := xdominion.XRecord{ + "key": "_adminmenu", + "group": "_admin", + "father": nil, + "name": tools.Message(messages, "menufolder.name"), + "access": "_adminmenu", + "icon1": "folder.png", + "call1": "openclose", + "description1": tools.Message(messages, "menufolder.description1"), + } + err = AddOption(ds, &mainoption) + if err != nil { + return err, result } + + option := xdominion.XRecord{ + "key": "_adminmenu_group", + "group": "_admin", + "father": "_adminmenu", + "name": tools.Message(messages, "adminmenugroup.name"), + "access": "_adminmenu", + "icon1": "option.png", + "call1": "adminmenu/group", + "description1": tools.Message(messages, "adminmenugroup.description1"), + } + err = AddOption(ds, &option) + if err != nil { + return err, result + } + + option = xdominion.XRecord{ + "key": "_adminmenu_option", + "group": "_admin", + "father": "_adminmenu", + "name": tools.Message(messages, "adminmenuoption.name"), + "access": "_adminmenu", + "icon1": "option.png", + "call1": "adminmenu/option", + "description1": tools.Message(messages, "adminmenuoption.description1"), + } + err = AddOption(ds, &option) + if err != nil { + return err, result + } + + return nil, []string{ + fmt.Sprint(" admin menu options added"), + } +} + +func upgrade(ds serverassets.Datasource, oldversion string) (error, []string) { + + if oldversion < "0.0.1" { + // do things + } + + return nil, []string{} } diff --git a/base/container.go b/base/container.go index 0d2f81e..03cccb8 100644 --- a/base/container.go +++ b/base/container.go @@ -274,7 +274,7 @@ func GetDatasourceStats(ds *Datasource) *xcore.XDataset { } subdata["tables"] = tables - subdata["config"] = buildConfigSet(ds.Config) + subdata["config"] = tools.BuildConfigSet(ds.Config) // analiza los módulos instalados modules := map[string]interface{}{} diff --git a/base/init.go b/base/init.go index 1aa5536..21d1194 100644 --- a/base/init.go +++ b/base/init.go @@ -4,8 +4,6 @@ package base import ( - "fmt" - "golang.org/x/text/language" serverassets "github.com/webability-go/xamboo/assets" @@ -19,6 +17,7 @@ const ( VERSION = "0.1.1" ) +var Needs = []string{} var ModuleBase = assets.ModuleEntries{ TryDatasource: TryDatasource, } @@ -33,7 +32,7 @@ func init() { language.Spanish: tools.Message(messages, "MODULENAME", language.Spanish), language.French: tools.Message(messages, "MODULENAME", language.French), }, - Needs: []string{}, + Needs: Needs, FSetup: setup, FSynchronize: synchronize, FStartContext: startContext, @@ -58,31 +57,23 @@ func setup(ds serverassets.Datasource, prefix string) ([]string, error) { func synchronize(ds serverassets.Datasource, prefix string) ([]string, error) { result := []string{} - tablename := "base_module" - - result = append(result, tools.Message(messages, "analyze", tablename)) - base_module := ds.GetTable(tablename) - if base_module == nil { - result = append(result, tools.Message(messages, "notable", tablename)) + ok, res := VerifyNeeds(ds, Needs) + result = append(result, res...) + if !ok { return result, nil } - num, err := base_module.Count(nil) - if err != nil || num == 0 { - if err != nil { - result = append(result, tools.Message(messages, "tablenoexist", tablename, err)) - } - err1 := base_module.Synchronize() - if err1 != nil { - result = append(result, tools.Message(messages, "tableerror", tablename, err1)) - } else { - result = append(result, tools.Message(messages, "tablecreated", tablename)) - } - } else { - result = append(result, tools.Message(messages, "tablenotmodified", tablename)) + + installed := ModuleInstalledVersion(ds, MODULEID) + + // synchro tables + err, r := synchroTables(ds, installed) + result = append(result, r...) + if err != nil { + return result, err } - // Be sure context module is on db: fill context module (we should get this from xmodule.conf) + // The rest of the process with a transaction // lets clone ds to begin a transaction cds := ds.CloneShell() _, err = cds.StartTransaction() @@ -91,19 +82,32 @@ func synchronize(ds serverassets.Datasource, prefix string) ([]string, error) { return result, err } - err = AddModule(cds, MODULEID, tools.Message(messages, "MODULENAME"), VERSION) - fmt.Println("Adds the module in table") - if err == nil { - result = append(result, tools.Message(messages, "modulemodified", MODULEID)) - result = append(result, tools.Message(messages, "commit")) - cds.Commit() - // TODO(Phil) should we also get the commit error if any? + // installation or upgrade ? + if installed != "" { + err, r = upgrade(cds, installed) } else { - result = append(result, tools.Message(messages, "rollback", err)) - cds.Rollback() + err, r = install(cds) + } + result = append(result, r...) + if err == nil { + err = AddModule(cds, MODULEID, tools.Message(messages, "MODULENAME"), VERSION) + if err == nil { + result = append(result, tools.Message(messages, "modulemodified", MODULEID)) + result = append(result, tools.Message(messages, "commit")) + err = cds.Commit() + if err != nil { + result = append(result, err.Error()) + } + return result, err + } + } + result = append(result, tools.Message(messages, "rollback", err)) + err1 := cds.Rollback() + if err1 != nil { + result = append(result, err1.Error()) } - return result, nil + return result, err } func startContext(ds serverassets.Datasource, ctx *serverassets.Context) error { diff --git a/base/installation.go b/base/installation.go new file mode 100644 index 0000000..4e0a9ae --- /dev/null +++ b/base/installation.go @@ -0,0 +1,56 @@ +package base + +import ( + "errors" + + serverassets "github.com/webability-go/xamboo/assets" + + "github.com/webability-go/xmodules/tools" +) + +func VerifyNeeds(ds serverassets.Datasource, needs []string) (bool, []string) { + + result := []string{} + flag := true + + for _, need := range needs { + // Needed modules: context and translation + vc := ModuleInstalledVersion(ds, need) + if vc == "" { + result = append(result, tools.Message(messages, "moduleneeded", MODULEID, need)) + flag = false + } else { + result = append(result, tools.Message(messages, "moduleok", MODULEID, need)) + } + } + + return flag, []string{} +} + +func SynchroTable(ds serverassets.Datasource, tablename string) (error, []string) { + + result := []string{} + result = append(result, tools.Message(messages, "analyze", tablename)) + + table := ds.GetTable(tablename) + if table == nil { + result = append(result, tools.Message(messages, "notable", tablename)) + return errors.New(tools.Message(messages, "notable", tablename)), result + } + + _, err := table.Count(nil) // num + if err != nil { //|| num == 0 + // if err != nil { + result = append(result, tools.Message(messages, "tablenoexist", tablename, err)) + // } + err1 := table.Synchronize() + if err1 != nil { + result = append(result, tools.Message(messages, "tableerror", tablename, err1)) + return err1, result // we stop HERE, error creating the table + } + result = append(result, tools.Message(messages, "tablecreated", tablename)) + } else { + result = append(result, tools.Message(messages, "tablenotmodified", tablename)) + } + return nil, result +} diff --git a/base/messages.go b/base/messages.go index ac67be9..e85a951 100644 --- a/base/messages.go +++ b/base/messages.go @@ -12,17 +12,22 @@ var messages *map[language.Tag]*xcore.XLanguage var smessages = map[language.Tag]map[string]string{ language.English: { // Module installation messages - "MODULENAME": "XModules base", + // init.go + "MODULENAME": "XModules base", + "modulemodified": "The entry %s was modified successfully in the base_module table.", + "commit": "Installation successfull.", + "rollback": "Installation aborted with error: %s", + // installatin.go + "moduleneeded": "Verifying '%s': The module '%s' is not installed: ERROR.", + "moduleok": "Verifying '%s': The module '%s' is installed: PASSED.", "analyze": "Analysing %s table.", "notable": "Critical Error: the module 'base' table '%s' does not exist.", "tablenoexist": "The table %s does not exist in the database: %s", "tableerror": "The table %s was not created: %s", "tablecreated": "The table %s was created (again).", "tablenotmodified": "The table %s was not created because it contains data.", - "modulemodified": "The entry %s was modified successfully in the base_module table.", - "moduleerror": "Error modifying the entry %s in the base_module table: %s", - "commit": "Installation successfull.", - "rollback": "Installation aborted with error: %s", + + "moduleerror": "Error modifying the entry %s in the base_module table: %s", // Datasources transactions "transaction.exist": "Error creating a transaction: There is already a started transaction.", "transaction.none": "Error searching the transaction: There is no available transaction.", @@ -34,17 +39,21 @@ var smessages = map[language.Tag]map[string]string{ }, language.Spanish: { // Module installation messages - "MODULENAME": "base XModules", + "MODULENAME": "base XModules", + "modulemodified": "La entrada %s fue modificada con exito en la tabla base_module.", + "commit": "Instalación exitosa.", + "rollback": "Instalación con error: %s", + // installatin.go + "moduleneeded": "Verificando '%s': El módulo '%s' no esta instalado: ERROR.", + "moduleok": "Verificando '%s': El módulo '%s' esta instalado: OK.", "analyze": "Analizando la tabla %s.", "notable": "Error crítico: la tabla del módulo 'base', '%s' no existe.", "tablenoexist": "La tabla %s no existe en base de datos: %s", "tableerror": "La tabla %s no pudo ser creada: %s", "tablecreated": "La tabla %s fue creada (de nuevo).", "tablenotmodified": "La tabla %s no fue creada porque ya existe y contiene datos.", - "modulemodified": "La entrada %s fue modificada con exito en la tabla base_module.", - "moduleerror": "Error modificando la entrada %s en la tabla base_module: %s", - "commit": "Instalación exitosa.", - "rollback": "Instalación con error: %s", + + "moduleerror": "Error modificando la entrada %s en la tabla base_module: %s", // Datasources transactions "transaction.exist": "Error creating a transaction: There is already a started transaction.", "transaction.none": "Error searching the transaction: There is no available transaction.", @@ -56,17 +65,21 @@ var smessages = map[language.Tag]map[string]string{ }, language.French: { // Module installation messages - "MODULENAME": "base XModules", + "MODULENAME": "base XModules", + "modulemodified": "L'entrée %s a été modifiée avec succès dans la table base_module.", + "commit": "Instalation réussie.", + "rollback": "Instalation avec erreur: %s", + // installatin.go + "moduleneeded": "Verification '%s': Le module '%s' n'est pas installé: ERREUR.", + "moduleok": "Verification '%s': Le module '%s' est installé: OK.", "analyze": "Analyze de la table %s.", "notable": "Erreur critique: la table du module 'base', '%s' n'existe pas.", "tablenoexist": "La table %s n'existe pas dans la base de données: %s", "tableerror": "La table %s pe peux pas être créée: %s", "tablecreated": "La table %s a été créée (de nouveau).", "tablenotmodified": "La table %s n'a pas été créée car elle existe déjà et contient des données.", - "modulemodified": "L'entrée %s a été modifiée avec succès dans la table base_module.", - "moduleerror": "Erreur en modifiant l'entrée %s dans la table base_module: %s", - "commit": "Instalation réussie.", - "rollback": "Instalation avec erreur: %s", + + "moduleerror": "Erreur en modifiant l'entrée %s dans la table base_module: %s", // Datasources transactions "transaction.exist": "Error creating a transaction: There is already a started transaction.", "transaction.none": "Error searching the transaction: There is no available transaction.", diff --git a/base/util.go b/base/util.go index 7087898..4e81bb2 100644 --- a/base/util.go +++ b/base/util.go @@ -1,31 +1,62 @@ package base import ( - "golang.org/x/text/language" + "github.com/webability-go/xdominion" - "github.com/webability-go/xconfig" - "github.com/webability-go/xcore/v2" - - "github.com/webability-go/xamboo/assets" + serverassets "github.com/webability-go/xamboo/assets" ) -func linkTables(ds assets.Datasource) { +// Order to load/synchronize tables: +var moduletablesorder = []string{ + "base_module", +} + +// map[string] does not respect order +var moduletables = map[string]func() *xdominion.XTable{ + "base_module": baseModule, +} + +func linkTables(ds serverassets.Datasource) { - table := baseModule() - table.SetBase(ds.GetDatabase()) - table.SetLanguage(language.English) - ds.SetTable("base_module", table) + for _, tbl := range moduletablesorder { + table := moduletables[tbl]() + table.SetBase(ds.GetDatabase()) + ds.SetTable(tbl, table) + } } -func buildConfigSet(config *xconfig.XConfig) xcore.XDataset { - data := xcore.XDataset{} - for id := range config.Parameters { - d, _ := config.Get(id) - if val, ok := d.(*xconfig.XConfig); ok { - data[id] = buildConfigSet(val) - } else { - data[id] = d +func synchroTables(ds serverassets.Datasource, oldversion string) (error, []string) { + + result := []string{} + + for _, tbl := range moduletablesorder { + + err, res := SynchroTable(ds, tbl) + result = append(result, res...) + if err != nil { + return err, result } } - return data + + if oldversion < "0.0.1" { + // do things + } + + return nil, result +} + +func install(ds serverassets.Datasource) (error, []string) { + + // do things + + return nil, []string{} +} + +func upgrade(ds serverassets.Datasource, oldversion string) (error, []string) { + + if oldversion < "0.0.1" { + // do things + } + + return nil, []string{} } diff --git a/tools/configset.go b/tools/configset.go new file mode 100644 index 0000000..2dfa78b --- /dev/null +++ b/tools/configset.go @@ -0,0 +1,19 @@ +package tools + +import ( + "github.com/webability-go/xconfig" + "github.com/webability-go/xcore/v2" +) + +func BuildConfigSet(config *xconfig.XConfig) xcore.XDataset { + data := xcore.XDataset{} + for id := range config.Parameters { + d, _ := config.Get(id) + if val, ok := d.(*xconfig.XConfig); ok { + data[id] = BuildConfigSet(val) + } else { + data[id] = d + } + } + return data +} diff --git a/tools/lang.go b/tools/lang.go index e9daefd..645b12f 100644 --- a/tools/lang.go +++ b/tools/lang.go @@ -33,7 +33,6 @@ func Message(messages *map[language.Tag]*xcore.XLanguage, id string, params ...i } if len(params) > 0 { - fmt.Println(params) msg = fmt.Sprintf(msg, params...) } return msg diff --git a/user/access.go b/user/access.go index 71d6771..c22cd23 100644 --- a/user/access.go +++ b/user/access.go @@ -5,22 +5,56 @@ import ( "github.com/webability-go/xdominion" - "github.com/webability-go/xmodules/base" + serverassets "github.com/webability-go/xamboo/assets" + + "github.com/webability-go/xmodules/tools" "github.com/webability-go/xmodules/user/assets" ) -func AddAccess(ds *base.Datasource, access *assets.Access) error { +func AddAccessGroup(ds serverassets.Datasource, accessgroup *assets.AccessGroup) error { + + user_accessgroup := ds.GetTable("user_accessgroup") + if user_accessgroup == nil { + errmsg := tools.Message(messages, "notable", "user_accessgroup", ds.GetName()) + ds.Log(errmsg) + return errors.New(errmsg) + } + + _, err := user_accessgroup.Upsert(accessgroup.Key, xdominion.XRecord{ + "key": accessgroup.Key, + "name": accessgroup.Name, + "description": accessgroup.Description, + }) + if err != nil { + ds.Log("main", tools.Message(messages, "errorupsert", "user_accessgroup", err)) + return err + } + return nil +} + +func AddAccess(ds serverassets.Datasource, access *assets.Access) error { user_access := ds.GetTable("user_access") if user_access == nil { - errmsg := "xmodules::user::AddAccess: Error, the user_access table is not available on this datasource " + ds.Name + errmsg := tools.Message(messages, "notable", "user_access", ds.GetName()) ds.Log(errmsg) return errors.New(errmsg) } + + _, err := user_access.Upsert(access.Key, xdominion.XRecord{ + "key": access.Key, + "name": access.Name, + "group": access.Group, + "description": access.Description, + }) + if err != nil { + ds.Log("main", tools.Message(messages, "errorupsert", "user_access", err)) + return err + } return nil } -func GetCountAccesses(ds *base.Datasource, cond *xdominion.XConditions) int { +func GetCountAccesses(ds serverassets.Datasource, cond *xdominion.XConditions) int { user_access := ds.GetTable("user_access") if user_access == nil { @@ -31,7 +65,7 @@ func GetCountAccesses(ds *base.Datasource, cond *xdominion.XConditions) int { return cnt } -func GetAccessesList(ds *base.Datasource, cond *xdominion.XConditions, orderby *xdominion.XOrderBy, quantity int, first int) *xdominion.XRecords { +func GetAccessesList(ds serverassets.Datasource, cond *xdominion.XConditions, orderby *xdominion.XOrderBy, quantity int, first int) *xdominion.XRecords { user_access := ds.GetTable("user_access") if user_access == nil { diff --git a/user/assets/access.go b/user/assets/access.go index 410576e..cf55982 100644 --- a/user/assets/access.go +++ b/user/assets/access.go @@ -1,6 +1,14 @@ package assets +type AccessGroup struct { + Key string + Name string + Description string +} + type Access struct { - Key string - Name string + Key string + Name string + Group string + Description string } diff --git a/user/assets/moduleentries.go b/user/assets/moduleentries.go index 6e21c98..3978938 100644 --- a/user/assets/moduleentries.go +++ b/user/assets/moduleentries.go @@ -4,10 +4,11 @@ import ( "github.com/webability-go/xdominion" // "github.com/webability-go/xamboo/assets" - "github.com/webability-go/xmodules/base" + serverassets "github.com/webability-go/xamboo/assets" + // "github.com/webability-go/xmodules/base" ) type ModuleEntries struct { - GetAccessesCount func(ds *base.Datasource, cond *xdominion.XConditions) int - GetAccessesList func(ds *base.Datasource, cond *xdominion.XConditions, orderby *xdominion.XOrderBy, quantity int, first int) *xdominion.XRecords + GetAccessesCount func(ds serverassets.Datasource, cond *xdominion.XConditions) int + GetAccessesList func(ds serverassets.Datasource, cond *xdominion.XConditions, orderby *xdominion.XOrderBy, quantity int, first int) *xdominion.XRecords } diff --git a/user/init.go b/user/init.go index 7432b5f..6ac7743 100644 --- a/user/init.go +++ b/user/init.go @@ -46,7 +46,7 @@ func init() { // adds tables and caches to sitecontext::database func Setup(ds serverassets.Datasource, prefix string) ([]string, error) { - buildTables(ds) + linkTables(ds) createCache(ds) ds.SetModule(MODULEID, VERSION) @@ -59,16 +59,20 @@ func Synchronize(ds serverassets.Datasource, prefix string) ([]string, error) { result := []string{} - // Needed modules: context and translation - vc := base.ModuleInstalledVersion(ds, "base") - if vc == "" { - result = append(result, "xmodules/base need to be installed before installing xmodules/user.") + ok, res := base.VerifyNeeds(ds, Needs) + result = append(result, res...) + if !ok { return result, nil } - // create tables - r, err := createTables(ds) + installed := base.ModuleInstalledVersion(ds, MODULEID) + + // synchro tables + err, r := synchroTables(ds, installed) result = append(result, r...) + if err != nil { + return result, err + } cds := ds.CloneShell() _, err = cds.StartTransaction() @@ -77,30 +81,48 @@ func Synchronize(ds serverassets.Datasource, prefix string) ([]string, error) { return result, err } - // fill super admin - r, err = loadTables(cds) + // installation or upgrade ? + if installed != "" { + err, r = upgrade(cds, installed) + } else { + err, r = install(cds) + } result = append(result, r...) - - // Inserting into context-modules - // Be sure context module is on db: fill context module (we should get this from xmodule.conf) - err = base.AddModule(cds, MODULEID, "Administration users", VERSION) if err == nil { - result = append(result, "The entry "+MODULEID+" was modified successfully in the modules table.") - result = append(result, tools.Message(messages, "commit")) - cds.Commit() - } else { - result = append(result, tools.Message(messages, "rollback", err)) - cds.Rollback() + err = base.AddModule(cds, MODULEID, tools.Message(messages, "MODULENAME"), VERSION) + if err == nil { + result = append(result, tools.Message(messages, "modulemodified", MODULEID)) + result = append(result, tools.Message(messages, "commit")) + err = cds.Commit() + if err != nil { + result = append(result, err.Error()) + } + return result, err + } + } + result = append(result, tools.Message(messages, "rollback", err)) + err1 := cds.Rollback() + if err1 != nil { + result = append(result, err1.Error()) } - return result, nil + return result, err } func StartContext(ds serverassets.Datasource, ctx *serverassets.Context) error { - // TODO(phil) implement site, device (from CTX) + sitecontextname, _ := ctx.Sysparams.GetString("sitecontext") + // if browser module is activated, then ctx.Version has the device. + // Order preference to seek the device: + // 1. into ctx.Sessionparams["device"] + // 2. ctx.Version if sessionparam is not set. + // NOTE: device is ONLY informative + // If you use this module, the browser extension for Xamboo should always be activated to set ctx.Version correctly + device, _ := ctx.Sessionparams.GetString("device") + if device == "" { + device = ctx.Version + } - lds := ds.(*base.Datasource) - VerifyUserSession(ctx, lds, "xmodules", "pc") + VerifyUserSession(ctx, ds, sitecontextname, device) return nil } diff --git a/user/messages.go b/user/messages.go index 127ac41..5b3609f 100644 --- a/user/messages.go +++ b/user/messages.go @@ -12,17 +12,17 @@ var messages *map[language.Tag]*xcore.XLanguage var smessages = map[language.Tag]map[string]string{ language.English: { // Module installation messages - "MODULENAME": "XModules base", - "analyze": "Analysing %s table.", - "notable": "Critical Error: the module 'base' table '%s' does not exist.", - "tablenoexist": "The table %s does not exist in the database: %s", - "tableerror": "The table %s was not created: %s", - "tablecreated": "The table %s was created (again).", - "tablenotmodified": "The table %s was not created because it contains data.", - "modulemodified": "The entry %s was modified successfully in the base_module table.", - "moduleerror": "Error modifying the entry %s in the base_module table: %s", - "commit": "Installation successfull.", - "rollback": "Installation aborted with error: %s", + // init.go + "MODULENAME": "Users for administration", + "modulemodified": "The entry %s was modified successfully in the base_module table.", + "commit": "Installation successfull.", + "rollback": "Installation aborted with error: %s", + + // access.go + "notable": "Error, the table %s is not available on the datasource %s.", + "errorupsert": "Error upserting in %s: %s", + + "moduleerror": "Error modifying the entry %s in the base_module table: %s", // Datasources transactions "transaction.exist": "Error creating a transaction: There is already a started transaction.", "transaction.none": "Error searching the transaction: There is no available transaction.", @@ -34,17 +34,13 @@ var smessages = map[language.Tag]map[string]string{ }, language.Spanish: { // Module installation messages - "MODULENAME": "base XModules", - "analyze": "Analizando la tabla %s.", - "notable": "Error crítico: la tabla del módulo 'base', '%s' no existe.", - "tablenoexist": "La tabla %s no existe en base de datos: %s", - "tableerror": "La tabla %s no pudo ser creada: %s", - "tablecreated": "La tabla %s fue creada (de nuevo).", - "tablenotmodified": "La tabla %s no fue creada porque ya existe y contiene datos.", - "modulemodified": "La entrada %s fue modificada con exito en la tabla base_module.", - "moduleerror": "Error modificando la entrada %s en la tabla base_module: %s", - "commit": "Instalación exitosa.", - "rollback": "Instalación con error: %s", + // init.go + "MODULENAME": "Usuarios administradores", + "modulemodified": "La entrada %s fue modificada con exito en la tabla base_module.", + "commit": "Instalación exitosa.", + "rollback": "Instalación con error: %s", + + "moduleerror": "Error modificando la entrada %s en la tabla base_module: %s", // Datasources transactions "transaction.exist": "Error creating a transaction: There is already a started transaction.", "transaction.none": "Error searching the transaction: There is no available transaction.", @@ -56,17 +52,13 @@ var smessages = map[language.Tag]map[string]string{ }, language.French: { // Module installation messages - "MODULENAME": "base XModules", - "analyze": "Analyze de la table %s.", - "notable": "Erreur critique: la table du module 'base', '%s' n'existe pas.", - "tablenoexist": "La table %s n'existe pas dans la base de données: %s", - "tableerror": "La table %s pe peux pas être créée: %s", - "tablecreated": "La table %s a été créée (de nouveau).", - "tablenotmodified": "La table %s n'a pas été créée car elle existe déjà et contient des données.", - "modulemodified": "L'entrée %s a été modifiée avec succès dans la table base_module.", - "moduleerror": "Erreur en modifiant l'entrée %s dans la table base_module: %s", - "commit": "Instalation réussie.", - "rollback": "Instalation avec erreur: %s", + // init.go + "MODULENAME": "Utilisateurs pour l'administration", + "modulemodified": "L'entrée %s a été modifiée avec succès dans la table base_module.", + "commit": "Instalation réussie.", + "rollback": "Instalation avec erreur: %s", + + "moduleerror": "Erreur en modifiant l'entrée %s dans la table base_module: %s", // Datasources transactions "transaction.exist": "Error creating a transaction: There is already a started transaction.", "transaction.none": "Error searching the transaction: There is no available transaction.", diff --git a/user/security.go b/user/security.go index f320382..550881a 100644 --- a/user/security.go +++ b/user/security.go @@ -11,11 +11,12 @@ import ( "github.com/webability-go/xmodules/tools" ) -func VerifyUserSession(ctx *assets.Context, ds *base.Datasource, origin string, device string) { +func VerifyUserSession(ctx *assets.Context, xds assets.Datasource, origin string, device string) { - if !ds.IsModuleAuthorized("user") { + if !xds.IsModuleAuthorized("user") { return } + ds := xds.(*base.Datasource) config := ds.Config // Any sent session ? @@ -84,8 +85,9 @@ func VerifyUserSession(ctx *assets.Context, ds *base.Datasource, origin string, ctx.Sessionparams.Set("userdata", userdata.Data) } -func CreateSessionUser(ctx *assets.Context, ds *base.Datasource, sessionid string, IP string, origin string, device string, user *StructureUser) string { +func CreateSessionUser(ctx *assets.Context, xds assets.Datasource, sessionid string, IP string, origin string, device string, user *StructureUser) string { + ds := xds.(*base.Datasource) config := ds.Config match, _ := regexp.MatchString("[a-zA-Z0-9]{24}", sessionid) @@ -105,8 +107,9 @@ func CreateSessionUser(ctx *assets.Context, ds *base.Datasource, sessionid strin return sessionid } -func DestroySessionUser(ctx *assets.Context, ds *base.Datasource, sessionid string) { +func DestroySessionUser(ctx *assets.Context, xds assets.Datasource, sessionid string) { + ds := xds.(*base.Datasource) config := ds.Config cookiedomain, _ := config.GetString("cookiedomain") cookiename, _ := config.GetString("cookiename") diff --git a/user/util.go b/user/util.go index 7c0d9d0..e078b5c 100644 --- a/user/util.go +++ b/user/util.go @@ -11,6 +11,8 @@ import ( "github.com/webability-go/xdominion" serverassets "github.com/webability-go/xamboo/assets" + + "github.com/webability-go/xmodules/base" ) // Order to load/synchronize tables: @@ -41,7 +43,7 @@ var moduletables = map[string]func() *xdominion.XTable{ "user_sessionhistory": userSessionHistory, } -func buildTables(ds serverassets.Datasource) { +func linkTables(ds serverassets.Datasource) { for _, tbl := range moduletablesorder { table := moduletables[tbl]() @@ -83,39 +85,31 @@ func buildCache(ds serverassets.Datasource) []string { return []string{} } -func createTables(ds serverassets.Datasource) ([]string, error) { +func synchroTables(ds serverassets.Datasource, oldversion string) (error, []string) { result := []string{} for _, tbl := range moduletablesorder { - table := ds.GetTable(tbl) - if table == nil { - return []string{"xmodules::user::createTables: Error, the table is not available on this datasource:" + tbl}, errors.New("Error") + err, res := base.SynchroTable(ds, tbl) + result = append(result, res...) + if err != nil { + return err, result } + } - result = append(result, "Analysing "+tbl+" table.") - num, err := table.Count(nil) - if err != nil || num == 0 { - err1 := table.Synchronize() - if err1 != nil { - result = append(result, "The table "+tbl+" was not created: "+err1.Error()) - } else { - result = append(result, "The table "+tbl+" was created (again)") - } - } else { - result = append(result, "The table "+tbl+" was not created because it contains data.") - } + if oldversion < "0.0.1" { + // do things } - return result, nil + return nil, result } -func loadTables(ds serverassets.Datasource) ([]string, error) { +func install(ds serverassets.Datasource) (error, []string) { user_user := ds.GetTable("user_user") if user_user == nil { - return []string{"xmodules::user::createTables: Error, the table user_user is not available on this datasource"}, errors.New("error") + return errors.New("error"), []string{"xmodules::user::createTables: Error, the table user_user is not available on this datasource"} } bmd5 := md5.Sum([]byte("manager")) @@ -133,9 +127,18 @@ func loadTables(ds serverassets.Datasource) ([]string, error) { }) if err != nil { ds.Log("main", "Error inserting admin user", err) - return []string{"xmodules::user::loadTables: Error upserting the admin user"}, errors.New("Error") + return errors.New("Error"), []string{"xmodules::user::loadTables: Error upserting the admin user"} } - return []string{ + return nil, []string{ fmt.Sprint(user_user.Count(nil)) + " admin user added", - }, nil + } +} + +func upgrade(ds serverassets.Datasource, oldversion string) (error, []string) { + + if oldversion < "0.0.1" { + // do things + } + + return nil, []string{} } diff --git a/useradmin/init.go b/useradmin/init.go index 6ef8df3..f93525c 100644 --- a/useradmin/init.go +++ b/useradmin/init.go @@ -19,15 +19,18 @@ const ( ) var Needs = []string{"base", "user", "adminmenu"} - var ModuleUserAdmin = assets.ModuleEntries{} func init() { messages = tools.BuildMessages(smessages) m := &base.Module{ - ID: MODULEID, - Version: VERSION, - Languages: map[language.Tag]string{language.English: "Administration of users", language.Spanish: "Adminitración de usuarios", language.French: "Administration des utilisateurs"}, + ID: MODULEID, + Version: VERSION, + Languages: map[language.Tag]string{ + language.English: tools.Message(messages, "MODULENAME", language.English), + language.Spanish: tools.Message(messages, "MODULENAME", language.Spanish), + language.French: tools.Message(messages, "MODULENAME", language.French), + }, Needs: Needs, FSetup: Setup, // Called once at the main system startup, once PER CREATED xmodule CONTEXT (if set) FSynchronize: Synchronize, // Called only to create/rebuild database objects and others on demand (if set) @@ -50,16 +53,14 @@ func Synchronize(ds serverassets.Datasource, prefix string) ([]string, error) { result := []string{} - lds := ds.(*base.Datasource) - for _, need := range Needs { - // Needed modules: context and translation - vc := base.ModuleInstalledVersion(lds, need) - if vc == "" { - result = append(result, "xmodules/"+need+" need to be installed before installing xmodules/"+MODULEID) - return result, nil - } + ok, res := base.VerifyNeeds(ds, Needs) + result = append(result, res...) + if !ok { + return result, nil } + installed := base.ModuleInstalledVersion(ds, MODULEID) + cds := ds.CloneShell() _, err := cds.StartTransaction() if err != nil { @@ -67,20 +68,30 @@ func Synchronize(ds serverassets.Datasource, prefix string) ([]string, error) { return result, err } - // fill super admin - r, err := loadTables(cds) + var r []string + // installation or upgrade ? + if installed != "" { + err, r = upgrade(cds, installed) + } else { + err, r = install(cds) + } result = append(result, r...) - - // Inserting into context-modules - // Be sure context module is on db: fill context module (we should get this from xmodule.conf) - err = base.AddModule(cds, MODULEID, "Administration users", VERSION) if err == nil { - result = append(result, "The entry "+MODULEID+" was modified successfully in the modules table.") - result = append(result, tools.Message(messages, "commit")) - cds.Commit() - } else { - result = append(result, tools.Message(messages, "rollback", err)) - cds.Rollback() + err = base.AddModule(cds, MODULEID, tools.Message(messages, "MODULENAME"), VERSION) + if err == nil { + result = append(result, tools.Message(messages, "modulemodified", MODULEID)) + result = append(result, tools.Message(messages, "commit")) + err = cds.Commit() + if err != nil { + result = append(result, err.Error()) + } + } else { + result = append(result, tools.Message(messages, "rollback", err)) + err = cds.Rollback() + if err != nil { + result = append(result, err.Error()) + } + } } return result, nil diff --git a/useradmin/messages.go b/useradmin/messages.go index 87bc5b4..8e1c8ec 100644 --- a/useradmin/messages.go +++ b/useradmin/messages.go @@ -12,17 +12,13 @@ var messages *map[language.Tag]*xcore.XLanguage var smessages = map[language.Tag]map[string]string{ language.English: { // Module installation messages - "MODULENAME": "XModules base", - "analyze": "Analysing %s table.", - "notable": "Critical Error: the module 'base' table '%s' does not exist.", - "tablenoexist": "The table %s does not exist in the database: %s", - "tableerror": "The table %s was not created: %s", - "tablecreated": "The table %s was created (again).", - "tablenotmodified": "The table %s was not created because it contains data.", - "modulemodified": "The entry %s was modified successfully in the base_module table.", - "moduleerror": "Error modifying the entry %s in the base_module table: %s", - "commit": "Installation successfull.", - "rollback": "Installation aborted with error: %s", + // init.go + "MODULENAME": "Users Administration tools", + "modulemodified": "The entry %s was modified successfully in the base_module table.", + "commit": "Installation successfull.", + "rollback": "Installation aborted with error: %s", + + "moduleerror": "Error modifying the entry %s in the base_module table: %s", // Datasources transactions "transaction.exist": "Error creating a transaction: There is already a started transaction.", "transaction.none": "Error searching the transaction: There is no available transaction.", @@ -34,17 +30,13 @@ var smessages = map[language.Tag]map[string]string{ }, language.Spanish: { // Module installation messages - "MODULENAME": "base XModules", - "analyze": "Analizando la tabla %s.", - "notable": "Error crítico: la tabla del módulo 'base', '%s' no existe.", - "tablenoexist": "La tabla %s no existe en base de datos: %s", - "tableerror": "La tabla %s no pudo ser creada: %s", - "tablecreated": "La tabla %s fue creada (de nuevo).", - "tablenotmodified": "La tabla %s no fue creada porque ya existe y contiene datos.", - "modulemodified": "La entrada %s fue modificada con exito en la tabla base_module.", - "moduleerror": "Error modificando la entrada %s en la tabla base_module: %s", - "commit": "Instalación exitosa.", - "rollback": "Instalación con error: %s", + // init.go + "MODULENAME": "Herramientas para administrar usuarios", + "modulemodified": "La entrada %s fue modificada con exito en la tabla base_module.", + "commit": "Instalación exitosa.", + "rollback": "Instalación con error: %s", + + "moduleerror": "Error modificando la entrada %s en la tabla base_module: %s", // Datasources transactions "transaction.exist": "Error creating a transaction: There is already a started transaction.", "transaction.none": "Error searching the transaction: There is no available transaction.", @@ -56,17 +48,13 @@ var smessages = map[language.Tag]map[string]string{ }, language.French: { // Module installation messages - "MODULENAME": "base XModules", - "analyze": "Analyze de la table %s.", - "notable": "Erreur critique: la table du module 'base', '%s' n'existe pas.", - "tablenoexist": "La table %s n'existe pas dans la base de données: %s", - "tableerror": "La table %s pe peux pas être créée: %s", - "tablecreated": "La table %s a été créée (de nouveau).", - "tablenotmodified": "La table %s n'a pas été créée car elle existe déjà et contient des données.", - "modulemodified": "L'entrée %s a été modifiée avec succès dans la table base_module.", - "moduleerror": "Erreur en modifiant l'entrée %s dans la table base_module: %s", - "commit": "Instalation réussie.", - "rollback": "Instalation avec erreur: %s", + // init.go + "MODULENAME": "Outils pour administrer les utilisateurs", + "modulemodified": "L'entrée %s a été modifiée avec succès dans la table base_module.", + "commit": "Instalation réussie.", + "rollback": "Instalation avec erreur: %s", + + "moduleerror": "Erreur en modifiant l'entrée %s dans la table base_module: %s", // Datasources transactions "transaction.exist": "Error creating a transaction: There is already a started transaction.", "transaction.none": "Error searching the transaction: There is no available transaction.", diff --git a/useradmin/util.go b/useradmin/util.go index b460584..c572987 100644 --- a/useradmin/util.go +++ b/useradmin/util.go @@ -8,10 +8,10 @@ import ( "github.com/webability-go/xmodules/adminmenu" ) -func loadTables(ds serverassets.Datasource) ([]string, error) { +func install(ds serverassets.Datasource) (error, []string) { - // Insert menu - adminmenu.AddGroup(ds, "admin", "System Administration") + // Group, just in case (upsert) + adminmenu.AddGroup(ds, "_admin", "System Administration") mainoption := xdominion.XRecord{ "key": "user", @@ -27,7 +27,7 @@ func loadTables(ds serverassets.Datasource) ([]string, error) { if err != nil { ds.Log("main", "Error inserting admin adminmenu_option", err) - return []string{"xmodules::adminmenu::loadTables: Error upserting the admin adminmenu group"}, err + return err, []string{"xmodules::adminmenu::loadTables: Error upserting the admin adminmenu group"} } option := xdominion.XRecord{ @@ -44,8 +44,17 @@ func loadTables(ds serverassets.Datasource) ([]string, error) { if err != nil { ds.Log("main", "Error inserting admin adminmenu_option", err) - return []string{"xmodules::adminmenu::loadTables: Error upserting the admin adminmenu group"}, err + return err, []string{"xmodules::adminmenu::loadTables: Error upserting the admin adminmenu group"} } - return []string{"ok"}, nil + return nil, []string{"ok"} +} + +func upgrade(ds serverassets.Datasource, oldversion string) (error, []string) { + + if oldversion < "0.0.1" { + // do things + } + + return nil, []string{} } diff --git a/xmodules.go b/xmodules.go index 4b4f7e1..5168e2b 100644 --- a/xmodules.go +++ b/xmodules.go @@ -1,3 +1,3 @@ package xmodules -const VERSION = "2021.01.20" +const VERSION = "2021.01.25"