|
@@ -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
|