Browse Source

Created no-consent add_child_org module and a bugfix

Nathan Schneider 2 years ago
parent
commit
509d2781f7
3 changed files with 68 additions and 1 deletions
  1. 1 0
      modpol_core/api.lua
  2. 66 0
      modpol_core/modules/add_child_org.lua
  3. 1 1
      modpol_core/orgs/base.lua

+ 1 - 0
modpol_core/api.lua

@@ -13,6 +13,7 @@ dofile (localdir .. "/interactions/interactions.lua")
 --modules
 --TODO make this automatic and directory-based
 dofile (localdir .. "/modules/add_child_org_consent.lua")
+dofile (localdir .. "/modules/add_child_org.lua")
 dofile (localdir .. "/modules/change_modules.lua")
 dofile (localdir .. "/modules/consent.lua")
 dofile (localdir .. "/modules/create_token.lua")

+ 66 - 0
modpol_core/modules/add_child_org.lua

@@ -0,0 +1,66 @@
+--- Adds a child org.
+-- @module add_child_org
+
+local add_child_org = {
+    name = "Add child org",
+    slug = "add_child_org",
+    desc = "Create a child org in the current one"
+}
+add_child_org.data = {
+   child_name = "",
+   result = nil
+}
+add_child_org.config = {
+}
+
+--- Initiate consent for new child org
+-- @function add_child_org:initiate(result)
+-- @param result Callback if this module is embedded in other modules
+function add_child_org:initiate(result)
+   modpol.interactions.text_query(
+      self.initiator,"Child org name: ",
+      function(input)
+         if input == "" then
+            modpol.interactions.message(
+               self.initiator,
+               "No name entered for child org")
+            modpol.interactions.org_dashboard(
+               self.initiator, self.org.name)
+            self.org:delete_process(self.id)            
+            return
+         elseif modpol.orgs.get_org(input) then
+            modpol.interactions.message(
+               self.initiator,
+               "Org name already in use")
+            modpol.interactions.org_dashboard(
+               self.initiator, self.org.name)
+            self.org:delete_process(self.id)
+            if result then result() end
+            return
+         end
+         self.data.child_name = input
+         modpol.interactions.message(
+               self.initiator,
+               "Proposed child org: " .. input)
+         -- create the org
+         self:create_child_org()
+         modpol.interactions.org_dashboard(
+            self.initiator, self.org.name)
+      end
+   )
+end
+
+--- Create a new child orgg
+-- @function add_child_org:create_child_org
+function add_child_org:create_child_org()
+   self.org:add_org(self.data.child_name, self.initiator)
+   modpol.interactions.message_org(
+      self.initiator,
+      self.org.name,
+      "Created child org "
+      ..self.data.child_name)
+   if self.data.result then self.data.result() end
+   self.org:delete_process(self.id)
+end
+      
+modpol.modules.add_child_org = add_child_org

+ 1 - 1
modpol_core/orgs/base.lua

@@ -215,7 +215,7 @@ function modpol.orgs:delete()
     if #self.children > 0 then
         for i, child_id in pairs(self.children) do
             local child = modpol.orgs.get_org(child_id)
-            modpol.ocutil.log(child_id, child)
+            modpol.ocutil.log("Deleting child org...")
             child:delete()
         end
     end