starting refactor, simple functionality works atm
This commit is contained in:
parent
cd8770eb98
commit
66c4e63adb
@ -6,10 +6,10 @@ local localdir = modpol.topdir
|
||||
dofile (localdir .. "/users/users.lua")
|
||||
|
||||
--orgs
|
||||
dofile (localdir .. "/orgs/orgs.lua")
|
||||
dofile (localdir .. "/orgs/new_orgs.lua")
|
||||
|
||||
--interactions
|
||||
dofile (localdir .. "/interactions/interactions.lua")
|
||||
|
||||
-- messaging functions
|
||||
dofile (localdir .. "/processes/processes.lua")
|
||||
dofile (localdir .. "/processes/processes.lua")
|
@ -77,9 +77,9 @@ dofile (topdir .. "/api.lua")
|
||||
-- Final checks
|
||||
|
||||
-- create instance if not present
|
||||
if not modpol.get_org_id_by_name('instance') then
|
||||
modpol.add_org("instance", modpol.list_users())
|
||||
end
|
||||
-- if not modpol.get_org_id_by_name('instance') then
|
||||
-- modpol.add_org("instance", modpol.list_users())
|
||||
-- end
|
||||
|
||||
modpol.ocutil.log ("modpol loaded")
|
||||
|
||||
|
74
modpol/orgs/new_orgs.lua
Normal file
74
modpol/orgs/new_orgs.lua
Normal file
@ -0,0 +1,74 @@
|
||||
modpol.orgs =
|
||||
{
|
||||
count = 1,
|
||||
list = {}
|
||||
}
|
||||
|
||||
-- sets modpol.orgs as it's own callback
|
||||
modpol.orgs.__index = modpol.orgs
|
||||
|
||||
function modpol.orgs:init_instance()
|
||||
if modpol.orgs.list[1] then
|
||||
print('Error: instance has already been initialized')
|
||||
return false
|
||||
end
|
||||
|
||||
local instance = {
|
||||
id = 1,
|
||||
name = "instance",
|
||||
policies = {},
|
||||
members = {},
|
||||
ledger = {},
|
||||
parent = nil,
|
||||
children = {},
|
||||
properties = {},
|
||||
old_names = {}
|
||||
}
|
||||
setmetatable(instance, modpol.orgs)
|
||||
|
||||
-- adding instance to org list
|
||||
modpol.orgs.list[1] = instance
|
||||
return instance
|
||||
end
|
||||
|
||||
function modpol.orgs:add_org(name)
|
||||
if self.id == nil then
|
||||
print('Error: add_org can only be run by a parent org')
|
||||
return false
|
||||
end
|
||||
|
||||
if modpol.ocutil.str_empty(name) then
|
||||
print('Error: name is required')
|
||||
return false
|
||||
end
|
||||
|
||||
-- creating the child sub org
|
||||
modpol.orgs.count = modpol.orgs.count + 1
|
||||
local child_org = {
|
||||
id = modpol.orgs.count,
|
||||
name = name,
|
||||
policies = {},
|
||||
members = {},
|
||||
ledger = {},
|
||||
parent = self.id,
|
||||
children = {},
|
||||
properties = {},
|
||||
old_names = {}
|
||||
}
|
||||
setmetatable(child_org, modpol.orgs)
|
||||
|
||||
-- adding child id to list of children
|
||||
table.insert(self.children, child_org.id)
|
||||
|
||||
-- adding child to org list
|
||||
modpol.orgs.list[child_org.id] = child_org
|
||||
return child_org
|
||||
end
|
||||
|
||||
function modpol.orgs:add_member(user)
|
||||
table.insert(self.members, user)
|
||||
end
|
||||
|
||||
function modpol.orgs:list_member()
|
||||
print(self.members[1])
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user