From 82b079ec4301f4683ce2773a34c7e9adbfcf413c Mon Sep 17 00:00:00 2001 From: MAhsenArif Date: Thu, 25 Jan 2018 19:53:03 +0500 Subject: [PATCH] [MNOE-857] Allowed organization to be added to staff divisions --- .../jpi/v1/admin/organizations_controller.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/api/app/controllers/mno_enterprise/jpi/v1/admin/organizations_controller.rb b/api/app/controllers/mno_enterprise/jpi/v1/admin/organizations_controller.rb index 2d45ead3d..5997a095f 100644 --- a/api/app/controllers/mno_enterprise/jpi/v1/admin/organizations_controller.rb +++ b/api/app/controllers/mno_enterprise/jpi/v1/admin/organizations_controller.rb @@ -50,6 +50,7 @@ def create # OPTIMIZE: move this into a delayed job? update_app_list + update_sub_tenants @organization_active_apps = @organization.app_instances @@ -141,5 +142,19 @@ def update_app_list existing_apps.reload end end + + def update_sub_tenants + return unless params[:organization].key?(:sub_tenant_ids) + + sub_tenants = MnoEnterprise::SubTenant.where({'id.in' => params[:organization][:sub_tenant_ids]}) + + sub_tenants.to_a.each do |sub_tnt| + new_client_ids = sub_tnt.client_ids + new_client_ids << @organization.id + new_client_ids = new_client_ids.collect(&:to_s) + + sub_tnt.update({"client_ids"=>new_client_ids}) + end + end end end