From f64705671a62f9d8d05304fab3bca1761c3aa64a Mon Sep 17 00:00:00 2001 From: metalwolf Date: Tue, 16 Feb 2021 12:47:25 -0600 Subject: [PATCH] patch v2021.02.16 --- README.md | 3 +++ adminmenu/adminmenu.go | 12 ++++++------ adminmenu/assets/moduleentries.go | 12 ++++++------ adminmenu/init.go | 9 +++++---- adminmenu/util.go | 12 +++++------- base/assets/moduleentries.go | 5 +++-- base/container.go | 23 ++++++++++++----------- base/datasource.go | 4 ++-- base/init.go | 9 +++++---- base/installation.go | 6 +++--- base/module.go | 29 +++++++++++++++-------------- base/structure.go | 6 +++--- base/util.go | 10 +++++----- user/access.go | 10 +++++----- user/assets/moduleentries.go | 17 ++++++++++++----- user/init.go | 19 +++++++++++++++---- user/parameters.go | 29 +++++++++++++++++++++++++---- user/security.go | 23 +++++++++++++++++------ user/structure.go | 10 +++++----- user/user_access.go | 1 + user/util.go | 14 +++++++------- useradmin/init.go | 9 +++++---- useradmin/util.go | 6 +++--- xmodules.go | 2 +- 24 files changed, 169 insertions(+), 111 deletions(-) diff --git a/README.md b/README.md index 0f05792..e9824de 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,9 @@ import "github.com/webability-go/xmodules/ingredient" import "github.com/webability-go/xmodules/material" +v2021-02-16: +- All the modules have been changed to meet new Xamboo applications interfaces + 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. diff --git a/adminmenu/adminmenu.go b/adminmenu/adminmenu.go index 0c80d03..5268ca5 100644 --- a/adminmenu/adminmenu.go +++ b/adminmenu/adminmenu.go @@ -5,10 +5,10 @@ import ( "github.com/webability-go/xdominion" - serverassets "github.com/webability-go/xamboo/assets" + "github.com/webability-go/xamboo/applications" ) -func AddGroup(ds serverassets.Datasource, key string, name string) error { +func AddGroup(ds applications.Datasource, key string, name string) error { adminmenu_group := ds.GetTable("adminmenu_group") if adminmenu_group == nil { errmessage := "xmodules::adminmenu::AddGroup: Error, the adminmenu_group table is not available on this datasource" @@ -26,11 +26,11 @@ func AddGroup(ds serverassets.Datasource, key string, name string) error { return nil } -func GetGroup(ds serverassets.Datasource, key string) (*xdominion.XRecord, error) { +func GetGroup(ds applications.Datasource, key string) (*xdominion.XRecord, error) { return nil, nil } -func AddOption(ds serverassets.Datasource, data *xdominion.XRecord) error { +func AddOption(ds applications.Datasource, data *xdominion.XRecord) error { adminmenu_option := ds.GetTable("adminmenu_option") if adminmenu_option == nil { @@ -50,11 +50,11 @@ func AddOption(ds serverassets.Datasource, data *xdominion.XRecord) error { return nil } -func GetOption(ds serverassets.Datasource, key string) (*xdominion.XRecord, error) { +func GetOption(ds applications.Datasource, key string) (*xdominion.XRecord, error) { return nil, nil } -func GetMenu(ds serverassets.Datasource, group string, father string) (*xdominion.XRecords, error) { +func GetMenu(ds applications.Datasource, group string, father string) (*xdominion.XRecords, error) { adminmenu_option := ds.GetTable("adminmenu_option") if adminmenu_option == nil { diff --git a/adminmenu/assets/moduleentries.go b/adminmenu/assets/moduleentries.go index 47d7b4e..0eb1148 100644 --- a/adminmenu/assets/moduleentries.go +++ b/adminmenu/assets/moduleentries.go @@ -3,14 +3,14 @@ package assets import ( "github.com/webability-go/xdominion" - "github.com/webability-go/xamboo/assets" + "github.com/webability-go/xamboo/applications" ) type ModuleEntries struct { - AddGroup func(ds assets.Datasource, key string, name string) error - GetGroup func(ds assets.Datasource, key string) (*xdominion.XRecord, error) - AddOption func(ds assets.Datasource, data *xdominion.XRecord) error - GetOption func(ds assets.Datasource, key string) (*xdominion.XRecord, error) + AddGroup func(ds applications.Datasource, key string, name string) error + GetGroup func(ds applications.Datasource, key string) (*xdominion.XRecord, error) + AddOption func(ds applications.Datasource, data *xdominion.XRecord) error + GetOption func(ds applications.Datasource, key string) (*xdominion.XRecord, error) - GetMenu func(ds assets.Datasource, group string, father string) (*xdominion.XRecords, error) + GetMenu func(ds applications.Datasource, group string, father string) (*xdominion.XRecords, error) } diff --git a/adminmenu/init.go b/adminmenu/init.go index aaeb719..f6a2be9 100644 --- a/adminmenu/init.go +++ b/adminmenu/init.go @@ -6,7 +6,8 @@ package adminmenu import ( "golang.org/x/text/language" - serverassets "github.com/webability-go/xamboo/assets" + "github.com/webability-go/xamboo/applications" + "github.com/webability-go/xamboo/cms/context" "github.com/webability-go/xmodules/adminmenu/assets" "github.com/webability-go/xmodules/base" @@ -48,7 +49,7 @@ func init() { // InitModule is called during the init phase to link the module with the system // adds tables and caches to sitecontext::database -func Setup(ds serverassets.Datasource, prefix string) ([]string, error) { +func Setup(ds applications.Datasource, prefix string) ([]string, error) { linkTables(ds) ds.SetModule(MODULEID, VERSION) @@ -56,7 +57,7 @@ func Setup(ds serverassets.Datasource, prefix string) ([]string, error) { return []string{}, nil } -func Synchronize(ds serverassets.Datasource, prefix string) ([]string, error) { +func Synchronize(ds applications.Datasource, prefix string) ([]string, error) { result := []string{} @@ -112,7 +113,7 @@ func Synchronize(ds serverassets.Datasource, prefix string) ([]string, error) { return result, err } -func StartContext(ds serverassets.Datasource, ctx *serverassets.Context) error { +func StartContext(ds applications.Datasource, ctx *context.Context) error { return nil } diff --git a/adminmenu/util.go b/adminmenu/util.go index 4c0fd8d..b49f69c 100644 --- a/adminmenu/util.go +++ b/adminmenu/util.go @@ -2,11 +2,9 @@ package adminmenu import ( "fmt" - // "time" - serverassets "github.com/webability-go/xamboo/assets" + "github.com/webability-go/xamboo/applications" - // "github.com/webability-go/xcore/v2" "github.com/webability-go/xdominion" "github.com/webability-go/xmodules/base" "github.com/webability-go/xmodules/tools" @@ -26,7 +24,7 @@ var moduletables = map[string]func() *xdominion.XTable{ "adminmenu_option": adminmenuOption, } -func linkTables(ds serverassets.Datasource) { +func linkTables(ds applications.Datasource) { for _, tbl := range moduletablesorder { table := moduletables[tbl]() @@ -35,7 +33,7 @@ func linkTables(ds serverassets.Datasource) { } } -func synchroTables(ds serverassets.Datasource, oldversion string) (error, []string) { +func synchroTables(ds applications.Datasource, oldversion string) (error, []string) { result := []string{} @@ -55,7 +53,7 @@ func synchroTables(ds serverassets.Datasource, oldversion string) (error, []stri return nil, result } -func install(ds serverassets.Datasource) (error, []string) { +func install(ds applications.Datasource) (error, []string) { result := []string{} @@ -134,7 +132,7 @@ func install(ds serverassets.Datasource) (error, []string) { } } -func upgrade(ds serverassets.Datasource, oldversion string) (error, []string) { +func upgrade(ds applications.Datasource, oldversion string) (error, []string) { if oldversion < "0.0.1" { // do things diff --git a/base/assets/moduleentries.go b/base/assets/moduleentries.go index 4f4589a..6497d9a 100644 --- a/base/assets/moduleentries.go +++ b/base/assets/moduleentries.go @@ -1,9 +1,10 @@ package assets import ( - "github.com/webability-go/xamboo/assets" + "github.com/webability-go/xamboo/applications" + "github.com/webability-go/xamboo/cms/context" ) type ModuleEntries struct { - TryDatasource func(ctx *assets.Context, datasourcename string) assets.Datasource + TryDatasource func(ctx *context.Context, datasourcename string) applications.Datasource } diff --git a/base/container.go b/base/container.go index 03cccb8..b23950e 100644 --- a/base/container.go +++ b/base/container.go @@ -17,7 +17,8 @@ import ( "github.com/webability-go/xcore/v2" "github.com/webability-go/xdominion" - "github.com/webability-go/xamboo/assets" + "github.com/webability-go/xamboo/applications" + "github.com/webability-go/xamboo/cms/context" "github.com/webability-go/xmodules/tools" ) @@ -35,7 +36,7 @@ import ( // every line can be repeated for each dbid or logid type Container struct { mdatasources sync.RWMutex - datasources map[string]assets.Datasource + datasources map[string]applications.Datasource CoreLog *log.Logger } @@ -51,22 +52,22 @@ func (cntl *ContainersList) GetContainer(id string) *Container { return (*cntl)[id] } -func (cnt *Container) SetDatasource(id string, ds assets.Datasource) { +func (cnt *Container) SetDatasource(id string, ds applications.Datasource) { cnt.mdatasources.Lock() cnt.datasources[id] = ds cnt.mdatasources.Unlock() } -func (cnt *Container) GetDatasource(id string) assets.Datasource { +func (cnt *Container) GetDatasource(id string) applications.Datasource { cnt.mdatasources.RLock() ds := cnt.datasources[id] cnt.mdatasources.RUnlock() return ds } -func (cnt *Container) GetDatasources() map[string]assets.Datasource { +func (cnt *Container) GetDatasources() map[string]applications.Datasource { cnt.mdatasources.RLock() - dss := make(map[string]assets.Datasource) + dss := make(map[string]applications.Datasource) for i, v := range cnt.datasources { dss[i] = v } @@ -75,7 +76,7 @@ func (cnt *Container) GetDatasources() map[string]assets.Datasource { } // Createdatasource will create a new datasource, link databases and logs based on XConfig data -func (cnt *Container) CreateDatasource(name string, config *xconfig.XConfig) (assets.Datasource, error) { +func (cnt *Container) CreateDatasource(name string, config *xconfig.XConfig) (applications.Datasource, error) { // Crear los datasourceos basados en el CoreConfig ds := &Datasource{ Name: name, @@ -178,10 +179,10 @@ func (cnt *Container) CreateDatasource(name string, config *xconfig.XConfig) (as } // TryDatasource will create a new datasource, link databases and logs based on XConfig data -func (cnt *Container) TryDatasource(ctx *assets.Context, datasourcename string) assets.Datasource { +func (cnt *Container) TryDatasource(ctx *context.Context, datasourcename string) applications.Datasource { var dsn string - var datasource assets.Datasource + var datasource applications.Datasource if datasourcename != "" { dsn, _ = ctx.Sysparams.GetString(datasourcename) datasource = cnt.GetDatasource(dsn) @@ -222,7 +223,7 @@ func Create(configfile string) *Container { CoreLog.Println("xmodules::base::Create: Starting Core Log") cnt := &Container{ - datasources: map[string]assets.Datasource{}, + datasources: map[string]applications.Datasource{}, CoreLog: CoreLog, } @@ -239,7 +240,7 @@ func Create(configfile string) *Container { return cnt } -func TryDatasource(ctx *assets.Context, datasourcename string) assets.Datasource { +func TryDatasource(ctx *context.Context, datasourcename string) applications.Datasource { dscn, _ := ctx.Sysparams.GetString("datasourcecontainername") cnt := Containers.GetContainer(dscn) diff --git a/base/datasource.go b/base/datasource.go index c3b5788..c95f0ba 100644 --- a/base/datasource.go +++ b/base/datasource.go @@ -13,7 +13,7 @@ import ( "github.com/webability-go/xcore/v2" "github.com/webability-go/xdominion" - "github.com/webability-go/xamboo/assets" + "github.com/webability-go/xamboo/applications" "github.com/webability-go/xmodules/tools" ) @@ -181,7 +181,7 @@ func (ds *Datasource) IsModuleAuthorized(id string) bool { return ds.GetModule(id) != "" } -func (ds *Datasource) CloneShell() assets.Datasource { +func (ds *Datasource) CloneShell() applications.Datasource { if ds.cloned { return ds } diff --git a/base/init.go b/base/init.go index 21d1194..ca9694f 100644 --- a/base/init.go +++ b/base/init.go @@ -6,7 +6,8 @@ package base import ( "golang.org/x/text/language" - serverassets "github.com/webability-go/xamboo/assets" + "github.com/webability-go/xamboo/applications" + "github.com/webability-go/xamboo/cms/context" "github.com/webability-go/xmodules/base/assets" "github.com/webability-go/xmodules/tools" @@ -46,7 +47,7 @@ func init() { // It must be called AFTER GetContainer // adds tables and caches to sitecontext::database // It should be called AFTER createContext -func setup(ds serverassets.Datasource, prefix string) ([]string, error) { +func setup(ds applications.Datasource, prefix string) ([]string, error) { linkTables(ds) ds.SetModule(MODULEID, VERSION) @@ -54,7 +55,7 @@ func setup(ds serverassets.Datasource, prefix string) ([]string, error) { return []string{}, nil } -func synchronize(ds serverassets.Datasource, prefix string) ([]string, error) { +func synchronize(ds applications.Datasource, prefix string) ([]string, error) { result := []string{} @@ -110,6 +111,6 @@ func synchronize(ds serverassets.Datasource, prefix string) ([]string, error) { return result, err } -func startContext(ds serverassets.Datasource, ctx *serverassets.Context) error { +func startContext(ds applications.Datasource, ctx *context.Context) error { return nil } diff --git a/base/installation.go b/base/installation.go index 4e0a9ae..f62aaaa 100644 --- a/base/installation.go +++ b/base/installation.go @@ -3,12 +3,12 @@ package base import ( "errors" - serverassets "github.com/webability-go/xamboo/assets" + "github.com/webability-go/xamboo/applications" "github.com/webability-go/xmodules/tools" ) -func VerifyNeeds(ds serverassets.Datasource, needs []string) (bool, []string) { +func VerifyNeeds(ds applications.Datasource, needs []string) (bool, []string) { result := []string{} flag := true @@ -27,7 +27,7 @@ func VerifyNeeds(ds serverassets.Datasource, needs []string) (bool, []string) { return flag, []string{} } -func SynchroTable(ds serverassets.Datasource, tablename string) (error, []string) { +func SynchroTable(ds applications.Datasource, tablename string) (error, []string) { result := []string{} result = append(result, tools.Message(messages, "analyze", tablename)) diff --git a/base/module.go b/base/module.go index a37cde7..ee8fe8a 100644 --- a/base/module.go +++ b/base/module.go @@ -8,21 +8,22 @@ import ( "github.com/webability-go/xcore/v2" "github.com/webability-go/xdominion" - "github.com/webability-go/xamboo/assets" + "github.com/webability-go/xamboo/applications" + "github.com/webability-go/xamboo/cms/context" "github.com/webability-go/xmodules/tools" ) var ModulesList = &Modules{} -type Modules map[string]assets.Module +type Modules map[string]applications.Module -func (ml *Modules) Register(m assets.Module) { +func (ml *Modules) Register(m applications.Module) { id := m.GetID() (*ml)[id] = m } -func (ml *Modules) Get(id string) assets.Module { +func (ml *Modules) Get(id string) applications.Module { return (*ml)[id] } @@ -33,9 +34,9 @@ type Module struct { Languages map[language.Tag]string Needs []string - FSetup func(assets.Datasource, string) ([]string, error) - FSynchronize func(assets.Datasource, string) ([]string, error) - FStartContext func(assets.Datasource, *assets.Context) error + FSetup func(applications.Datasource, string) ([]string, error) + FSynchronize func(applications.Datasource, string) ([]string, error) + FStartContext func(applications.Datasource, *context.Context) error } func (m *Module) GetID() string { @@ -54,25 +55,25 @@ func (m *Module) GetNeeds() []string { return m.Needs } -func (m *Module) GetInstalledVersion(ds assets.Datasource) string { +func (m *Module) GetInstalledVersion(ds applications.Datasource) string { return ModuleInstalledVersion(ds, m.ID) } -func (m *Module) Setup(ds assets.Datasource, prefix string) ([]string, error) { +func (m *Module) Setup(ds applications.Datasource, prefix string) ([]string, error) { if m.FSetup != nil { return m.FSetup(ds, prefix) } return []string{}, nil } -func (m *Module) Synchronize(ds assets.Datasource, prefix string) ([]string, error) { +func (m *Module) Synchronize(ds applications.Datasource, prefix string) ([]string, error) { if m.FSynchronize != nil { return m.FSynchronize(ds, prefix) } return []string{}, nil } -func (m *Module) StartContext(ds assets.Datasource, ctx *assets.Context) error { +func (m *Module) StartContext(ds applications.Datasource, ctx *context.Context) error { if m.FStartContext != nil { return m.FStartContext(ds, ctx) } @@ -82,7 +83,7 @@ func (m *Module) StartContext(ds assets.Datasource, ctx *assets.Context) error { // ModuleStatus returns status of the module: // "" not installed // "version.number" version installed -func ModuleInstalledVersion(ds assets.Datasource, id string) string { +func ModuleInstalledVersion(ds applications.Datasource, id string) string { base_module := ds.GetTable("base_module") if base_module == nil { ds.Log("main", tools.Message(messages, "notable", "base_module")) @@ -96,7 +97,7 @@ func ModuleInstalledVersion(ds assets.Datasource, id string) string { return v } -func GetModule(ds assets.Datasource, id string) *xcore.XDataset { +func GetModule(ds applications.Datasource, id string) *xcore.XDataset { data := xcore.XDataset{} data["name"] = ds.GetName() @@ -107,7 +108,7 @@ func GetModule(ds assets.Datasource, id string) *xcore.XDataset { } // AddModule will insert a record in the modules table and sends back status error -func AddModule(ds assets.Datasource, id string, name string, version string) error { +func AddModule(ds applications.Datasource, id string, name string, version string) error { base_module := ds.GetTable("base_module") if base_module == nil { msgerror := tools.Message(messages, "notable", "base_module") diff --git a/base/structure.go b/base/structure.go index f2ccb1e..06233ac 100644 --- a/base/structure.go +++ b/base/structure.go @@ -3,17 +3,17 @@ package base import ( "github.com/webability-go/xdominion" - serverassets "github.com/webability-go/xamboo/assets" + "github.com/webability-go/xamboo/applications" ) // Structure interface is made to implement a standarized object to use cross modules, graph, memory caches etc. type Structure interface { // ComplementData adds all the needed data from other objects /duplicable in the thread since the object will be destroyed at the end - ComplementData(ds serverassets.Datasource) + ComplementData(ds applications.Datasource) // IsAuthorized returns true if the structure can be used on this site/language/device - IsAuthorized(ds serverassets.Datasource, site string, language string, device string) bool + IsAuthorized(ds applications.Datasource, site string, language string, device string) bool // GetData Returns the raw data GetData() *xdominion.XRecord diff --git a/base/util.go b/base/util.go index 4e81bb2..172fdc1 100644 --- a/base/util.go +++ b/base/util.go @@ -3,7 +3,7 @@ package base import ( "github.com/webability-go/xdominion" - serverassets "github.com/webability-go/xamboo/assets" + "github.com/webability-go/xamboo/applications" ) // Order to load/synchronize tables: @@ -16,7 +16,7 @@ var moduletables = map[string]func() *xdominion.XTable{ "base_module": baseModule, } -func linkTables(ds serverassets.Datasource) { +func linkTables(ds applications.Datasource) { for _, tbl := range moduletablesorder { table := moduletables[tbl]() @@ -25,7 +25,7 @@ func linkTables(ds serverassets.Datasource) { } } -func synchroTables(ds serverassets.Datasource, oldversion string) (error, []string) { +func synchroTables(ds applications.Datasource, oldversion string) (error, []string) { result := []string{} @@ -45,14 +45,14 @@ func synchroTables(ds serverassets.Datasource, oldversion string) (error, []stri return nil, result } -func install(ds serverassets.Datasource) (error, []string) { +func install(ds applications.Datasource) (error, []string) { // do things return nil, []string{} } -func upgrade(ds serverassets.Datasource, oldversion string) (error, []string) { +func upgrade(ds applications.Datasource, oldversion string) (error, []string) { if oldversion < "0.0.1" { // do things diff --git a/user/access.go b/user/access.go index c22cd23..e4ce81b 100644 --- a/user/access.go +++ b/user/access.go @@ -5,13 +5,13 @@ import ( "github.com/webability-go/xdominion" - serverassets "github.com/webability-go/xamboo/assets" + "github.com/webability-go/xamboo/applications" "github.com/webability-go/xmodules/tools" "github.com/webability-go/xmodules/user/assets" ) -func AddAccessGroup(ds serverassets.Datasource, accessgroup *assets.AccessGroup) error { +func AddAccessGroup(ds applications.Datasource, accessgroup *assets.AccessGroup) error { user_accessgroup := ds.GetTable("user_accessgroup") if user_accessgroup == nil { @@ -32,7 +32,7 @@ func AddAccessGroup(ds serverassets.Datasource, accessgroup *assets.AccessGroup) return nil } -func AddAccess(ds serverassets.Datasource, access *assets.Access) error { +func AddAccess(ds applications.Datasource, access *assets.Access) error { user_access := ds.GetTable("user_access") if user_access == nil { @@ -54,7 +54,7 @@ func AddAccess(ds serverassets.Datasource, access *assets.Access) error { return nil } -func GetCountAccesses(ds serverassets.Datasource, cond *xdominion.XConditions) int { +func GetCountAccesses(ds applications.Datasource, cond *xdominion.XConditions) int { user_access := ds.GetTable("user_access") if user_access == nil { @@ -65,7 +65,7 @@ func GetCountAccesses(ds serverassets.Datasource, cond *xdominion.XConditions) i return cnt } -func GetAccessesList(ds serverassets.Datasource, cond *xdominion.XConditions, orderby *xdominion.XOrderBy, quantity int, first int) *xdominion.XRecords { +func GetAccessesList(ds applications.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/moduleentries.go b/user/assets/moduleentries.go index 3978938..f27f644 100644 --- a/user/assets/moduleentries.go +++ b/user/assets/moduleentries.go @@ -3,12 +3,19 @@ package assets import ( "github.com/webability-go/xdominion" - // "github.com/webability-go/xamboo/assets" - serverassets "github.com/webability-go/xamboo/assets" - // "github.com/webability-go/xmodules/base" + "github.com/webability-go/xamboo/applications" ) type ModuleEntries struct { - 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 + // Accesses + GetAccessesCount func(ds applications.Datasource, cond *xdominion.XConditions) int + GetAccessesList func(ds applications.Datasource, cond *xdominion.XConditions, orderby *xdominion.XOrderBy, quantity int, first int) *xdominion.XRecords + + // User Params + SetUserParam func(ds applications.Datasource, user int, param string, value interface{}) + AddUserParam func(ds applications.Datasource, user int, param string, value interface{}) + GetUserParam func(ds applications.Datasource, user int, param string) string + DelUserParam func(ds applications.Datasource, user int, param string) + + HasAccess func(ds applications.Datasource, user int, access string, extra string) bool } diff --git a/user/init.go b/user/init.go index 6ac7743..9597989 100644 --- a/user/init.go +++ b/user/init.go @@ -6,7 +6,8 @@ package user import ( "golang.org/x/text/language" - serverassets "github.com/webability-go/xamboo/assets" + "github.com/webability-go/xamboo/applications" + "github.com/webability-go/xamboo/cms/context" "github.com/webability-go/xmodules/base" "github.com/webability-go/xmodules/tools" @@ -20,8 +21,18 @@ const ( var Needs = []string{"base"} var ModuleUser = assets.ModuleEntries{ + // accesses GetAccessesCount: GetCountAccesses, GetAccessesList: GetAccessesList, + + // Security + HasAccess: HasAccess, + + // Params + SetUserParam: SetUserParam, + AddUserParam: AddUserParam, + GetUserParam: GetUserParam, + DelUserParam: DelUserParam, } func init() { @@ -44,7 +55,7 @@ func init() { // InitModule is called during the init phase to link the module with the system // adds tables and caches to sitecontext::database -func Setup(ds serverassets.Datasource, prefix string) ([]string, error) { +func Setup(ds applications.Datasource, prefix string) ([]string, error) { linkTables(ds) createCache(ds) @@ -55,7 +66,7 @@ func Setup(ds serverassets.Datasource, prefix string) ([]string, error) { return []string{}, nil } -func Synchronize(ds serverassets.Datasource, prefix string) ([]string, error) { +func Synchronize(ds applications.Datasource, prefix string) ([]string, error) { result := []string{} @@ -109,7 +120,7 @@ func Synchronize(ds serverassets.Datasource, prefix string) ([]string, error) { return result, err } -func StartContext(ds serverassets.Datasource, ctx *serverassets.Context) error { +func StartContext(ds applications.Datasource, ctx *context.Context) error { sitecontextname, _ := ctx.Sysparams.GetString("sitecontext") // if browser module is activated, then ctx.Version has the device. diff --git a/user/parameters.go b/user/parameters.go index 869895e..055ab82 100644 --- a/user/parameters.go +++ b/user/parameters.go @@ -5,10 +5,10 @@ import ( "github.com/webability-go/xdominion" - "github.com/webability-go/xmodules/base" + "github.com/webability-go/xamboo/applications" ) -func SetUserParam(ds *base.Datasource, user int, param string, value interface{}) { +func SetUserParam(ds applications.Datasource, user int, param string, value interface{}) { user_parameter := ds.GetTable("user_parameter") if user_parameter == nil { @@ -40,7 +40,25 @@ func SetUserParam(ds *base.Datasource, user int, param string, value interface{} } } -func GetUserParam(ds *base.Datasource, user int, param string) string { +func AddUserParam(ds applications.Datasource, user int, param string, value interface{}) { + + user_parameter := ds.GetTable("user_parameter") + if user_parameter == nil { + ds.Log("xmodules::user::SetUserParam: Error, the user_parameter table is not available on this datasource") + return + } + _, err := user_parameter.Insert(xdominion.XRecord{ + "key": 0, + "user": user, + "id": param, + "value": value, + }) + if err != nil { + ds.Log("xmodules::user::AddUserParam: Error inserting in the user_parameter table", err) + } +} + +func GetUserParam(ds applications.Datasource, user int, param string) string { user_parameter := ds.GetTable("user_parameter") if user_parameter == nil { @@ -51,12 +69,15 @@ func GetUserParam(ds *base.Datasource, user int, param string) string { xdominion.NewXCondition("id", "=", param), xdominion.NewXCondition("user", "=", user, "and"), }) + if data == nil { + return "" + } value, _ := data.GetString("value") return strings.TrimSpace(value) } -func DelUserParam(ds *base.Datasource, user int, param string) { +func DelUserParam(ds applications.Datasource, user int, param string) { user_parameter := ds.GetTable("user_parameter") if user_parameter == nil { diff --git a/user/security.go b/user/security.go index 550881a..587680f 100644 --- a/user/security.go +++ b/user/security.go @@ -4,14 +4,16 @@ import ( "net/http" "regexp" - "github.com/webability-go/xamboo" - "github.com/webability-go/xamboo/assets" + // "github.com/webability-go/xamboo" + "github.com/webability-go/xamboo/applications" + "github.com/webability-go/xamboo/cms/context" "github.com/webability-go/xmodules/base" "github.com/webability-go/xmodules/tools" ) -func VerifyUserSession(ctx *assets.Context, xds assets.Datasource, origin string, device string) { +// SESSIONS +func VerifyUserSession(ctx *context.Context, xds applications.Datasource, origin string, device string) { if !xds.IsModuleAuthorized("user") { return @@ -27,7 +29,7 @@ func VerifyUserSession(ctx *assets.Context, xds assets.Datasource, origin string if cookie != nil && len(cookie.Value) != 0 { sessionid = cookie.Value } - IP := ctx.Writer.(*xamboo.CoreWriter).RequestStat.IP + IP := "ip" // ctx.Writer.(*xamboo.CoreWriter).RequestStat.IP // verify username, password, OrderSecurity connect/disconnect order := ctx.Request.Form.Get("OrderSecurity") @@ -85,7 +87,7 @@ func VerifyUserSession(ctx *assets.Context, xds assets.Datasource, origin string ctx.Sessionparams.Set("userdata", userdata.Data) } -func CreateSessionUser(ctx *assets.Context, xds assets.Datasource, sessionid string, IP string, origin string, device string, user *StructureUser) string { +func CreateSessionUser(ctx *context.Context, xds applications.Datasource, sessionid string, IP string, origin string, device string, user *StructureUser) string { ds := xds.(*base.Datasource) config := ds.Config @@ -107,7 +109,7 @@ func CreateSessionUser(ctx *assets.Context, xds assets.Datasource, sessionid str return sessionid } -func DestroySessionUser(ctx *assets.Context, xds assets.Datasource, sessionid string) { +func DestroySessionUser(ctx *context.Context, xds applications.Datasource, sessionid string) { ds := xds.(*base.Datasource) config := ds.Config @@ -288,3 +290,12 @@ func DestroySessionUser(ctx *assets.Context, sessionid string) { * / } */ + +// SECURITY Access +func HasAccess(ds applications.Datasource, clientid int, access string, extra string) bool { + + // 1. profile + // 2. direct acceses + + return true +} diff --git a/user/structure.go b/user/structure.go index 7d0a829..c17e820 100644 --- a/user/structure.go +++ b/user/structure.go @@ -3,7 +3,7 @@ package user import ( "github.com/webability-go/xdominion" - serverassets "github.com/webability-go/xamboo/assets" + "github.com/webability-go/xamboo/applications" "github.com/webability-go/xmodules/base" ) @@ -13,7 +13,7 @@ type StructureUser struct { Data *xdominion.XRecord } -func CreateStructureUserByKey(ds serverassets.Datasource, key int) base.Structure { +func CreateStructureUserByKey(ds applications.Datasource, key int) base.Structure { user_user := ds.GetTable("user_user") if user_user == nil { @@ -28,7 +28,7 @@ func CreateStructureUserByKey(ds serverassets.Datasource, key int) base.Structur return CreateStructureUserByData(ds, data) } -func CreateStructureUserByData(ds serverassets.Datasource, data xdominion.XRecordDef) base.Structure { +func CreateStructureUserByData(ds applications.Datasource, data xdominion.XRecordDef) base.Structure { key, _ := data.GetInt("key") @@ -38,12 +38,12 @@ func CreateStructureUserByData(ds serverassets.Datasource, data xdominion.XRecor } // ComplementData adds all the needed data from other objects /duplicable in the thread since the object will be destroyed at the end -func (sm *StructureUser) ComplementData(ds serverassets.Datasource) { +func (sm *StructureUser) ComplementData(ds applications.Datasource) { } // IsAuthorized returns true if the structure can be used on this site/language/device -func (sm *StructureUser) IsAuthorized(ds serverassets.Datasource, site string, language string, device string) bool { +func (sm *StructureUser) IsAuthorized(ds applications.Datasource, site string, language string, device string) bool { return true } diff --git a/user/user_access.go b/user/user_access.go index 3499d05..0f61c85 100644 --- a/user/user_access.go +++ b/user/user_access.go @@ -23,6 +23,7 @@ func userAccess() *xdominion.XTable { t.AddField(xdominion.XFieldVarChar{Name: "group", Size: 30, Constraints: xdominion.XConstraints{ xdominion.XConstraint{Type: xdominion.FK, Data: []string{"user_accessgroup", "user_acg_key"}}, xdominion.XConstraint{Type: xdominion.IN}, + xdominion.XConstraint{Type: xdominion.NN}, }}) // description diff --git a/user/util.go b/user/util.go index e078b5c..b5b3709 100644 --- a/user/util.go +++ b/user/util.go @@ -10,7 +10,7 @@ import ( "github.com/webability-go/xcore/v2" "github.com/webability-go/xdominion" - serverassets "github.com/webability-go/xamboo/assets" + "github.com/webability-go/xamboo/applications" "github.com/webability-go/xmodules/base" ) @@ -43,7 +43,7 @@ var moduletables = map[string]func() *xdominion.XTable{ "user_sessionhistory": userSessionHistory, } -func linkTables(ds serverassets.Datasource) { +func linkTables(ds applications.Datasource) { for _, tbl := range moduletablesorder { table := moduletables[tbl]() @@ -52,14 +52,14 @@ func linkTables(ds serverassets.Datasource) { } } -func createCache(ds serverassets.Datasource) []string { +func createCache(ds applications.Datasource) []string { ds.SetCache("user:users", xcore.NewXCache("user:users", 0, 0)) return []string{} } -func buildCache(ds serverassets.Datasource) []string { +func buildCache(ds applications.Datasource) []string { user_user := ds.GetTable("user_user") if user_user == nil { @@ -85,7 +85,7 @@ func buildCache(ds serverassets.Datasource) []string { return []string{} } -func synchroTables(ds serverassets.Datasource, oldversion string) (error, []string) { +func synchroTables(ds applications.Datasource, oldversion string) (error, []string) { result := []string{} @@ -105,7 +105,7 @@ func synchroTables(ds serverassets.Datasource, oldversion string) (error, []stri return nil, result } -func install(ds serverassets.Datasource) (error, []string) { +func install(ds applications.Datasource) (error, []string) { user_user := ds.GetTable("user_user") if user_user == nil { @@ -134,7 +134,7 @@ func install(ds serverassets.Datasource) (error, []string) { } } -func upgrade(ds serverassets.Datasource, oldversion string) (error, []string) { +func upgrade(ds applications.Datasource, oldversion string) (error, []string) { if oldversion < "0.0.1" { // do things diff --git a/useradmin/init.go b/useradmin/init.go index f93525c..e8a95e4 100644 --- a/useradmin/init.go +++ b/useradmin/init.go @@ -6,7 +6,8 @@ package useradmin import ( "golang.org/x/text/language" - serverassets "github.com/webability-go/xamboo/assets" + "github.com/webability-go/xamboo/applications" + "github.com/webability-go/xamboo/cms/context" "github.com/webability-go/xmodules/base" "github.com/webability-go/xmodules/tools" @@ -41,7 +42,7 @@ func init() { // InitModule is called during the init phase to link the module with the system // adds tables and caches to sitecontext::database -func Setup(ds serverassets.Datasource, prefix string) ([]string, error) { +func Setup(ds applications.Datasource, prefix string) ([]string, error) { // no tables on this module ds.SetModule(MODULEID, VERSION) @@ -49,7 +50,7 @@ func Setup(ds serverassets.Datasource, prefix string) ([]string, error) { return []string{}, nil } -func Synchronize(ds serverassets.Datasource, prefix string) ([]string, error) { +func Synchronize(ds applications.Datasource, prefix string) ([]string, error) { result := []string{} @@ -97,6 +98,6 @@ func Synchronize(ds serverassets.Datasource, prefix string) ([]string, error) { return result, nil } -func StartContext(ds serverassets.Datasource, ctx *serverassets.Context) error { +func StartContext(ds applications.Datasource, ctx *context.Context) error { return nil } diff --git a/useradmin/util.go b/useradmin/util.go index c572987..3108029 100644 --- a/useradmin/util.go +++ b/useradmin/util.go @@ -1,14 +1,14 @@ package useradmin import ( - serverassets "github.com/webability-go/xamboo/assets" + "github.com/webability-go/xamboo/applications" // "github.com/webability-go/xcore/v2" "github.com/webability-go/xdominion" "github.com/webability-go/xmodules/adminmenu" ) -func install(ds serverassets.Datasource) (error, []string) { +func install(ds applications.Datasource) (error, []string) { // Group, just in case (upsert) adminmenu.AddGroup(ds, "_admin", "System Administration") @@ -50,7 +50,7 @@ func install(ds serverassets.Datasource) (error, []string) { return nil, []string{"ok"} } -func upgrade(ds serverassets.Datasource, oldversion string) (error, []string) { +func upgrade(ds applications.Datasource, oldversion string) (error, []string) { if oldversion < "0.0.1" { // do things diff --git a/xmodules.go b/xmodules.go index 5168e2b..94082bc 100644 --- a/xmodules.go +++ b/xmodules.go @@ -1,3 +1,3 @@ package xmodules -const VERSION = "2021.01.25" +const VERSION = "2021.02.16"