From bf05cc314a2616d8fdb6f149fcc9900362663fd6 Mon Sep 17 00:00:00 2001 From: mkumar-02 Date: Mon, 12 Feb 2024 22:43:12 +0530 Subject: [PATCH] G2P Import DCI API: Modified authorization token flow. --- g2p_import_dci_api/models/constants.py | 2 + .../fetch_social_registry_beneficiary.py | 38 +++++++++++------- .../static/src/img/icons/contacts.png | Bin 591 -> 0 bytes 3 files changed, 26 insertions(+), 14 deletions(-) delete mode 100644 g2p_import_dci_api/static/src/img/icons/contacts.png diff --git a/g2p_import_dci_api/models/constants.py b/g2p_import_dci_api/models/constants.py index f763c88c..31c8af03 100644 --- a/g2p_import_dci_api/models/constants.py +++ b/g2p_import_dci_api/models/constants.py @@ -5,3 +5,5 @@ DATA_SOURCE_AUTH_PATH_NAME = "Authentication" REQUEST_TIMEOUT = 60 + +MAX_REGISTRANT = 150 diff --git a/g2p_import_dci_api/models/fetch_social_registry_beneficiary.py b/g2p_import_dci_api/models/fetch_social_registry_beneficiary.py index 9e506053..1ad0a38d 100644 --- a/g2p_import_dci_api/models/fetch_social_registry_beneficiary.py +++ b/g2p_import_dci_api/models/fetch_social_registry_beneficiary.py @@ -19,8 +19,6 @@ class G2PFetchSocialRegistryBeneficiary(models.Model): _name = "g2p.fetch.social.registry.beneficiary" _description = "Fetch Social Registry Beneficiary" - MAX_REGISTRANT_IN_FETCH = 150 - data_source_id = fields.Many2one("spp.data.source", required=True) name = fields.Char("Search Criteria Name", required=True) @@ -73,11 +71,13 @@ def get_social_registry_auth_url(self, paths): url = self.data_source_id.url auth_path = paths.get(constants.DATA_SOURCE_AUTH_PATH_NAME) - return f"{url}{auth_path}" + if auth_path.lstrip().startswith("/"): + return f"{url}{auth_path}" - def get_auth_token(self, auth_url): + else: + return auth_path - headers = self.get_headers_for_request() + def get_auth_token(self, auth_url): grant_type = ( self.env["ir.config_parameter"] @@ -94,20 +94,29 @@ def get_auth_token(self, auth_url): .sudo() .get_param("social_registry_client_secret") ) - db_name = ( - self.env["ir.config_parameter"].sudo().get_param("social_registry_db_name") + username = ( + self.env["ir.config_parameter"] + .sudo() + .get_param("social_registry_user_name") + ) + password = ( + self.env["ir.config_parameter"] + .sudo() + .get_param("social_registry_user_password") ) data = { "grant_type": grant_type, "client_id": client_id, "client_secret": client_secret, - "db_name": db_name, + "username": username, + "password": password, } + response = requests.post( auth_url, - headers=headers, - data=json.dumps(data), + headers={"Content-Type": "application/x-www-form-urlencoded"}, + data=data, timeout=constants.REQUEST_TIMEOUT, ) @@ -355,10 +364,10 @@ def process_registrants(self, partners): def process_registrants_async(self, partners, count): _logger.warning("Fetching Registrant Asynchronously!") jobs = [] - for i in range(0, count, self.MAX_REGISTRANT_IN_FETCH): + for i in range(0, count, constants.MAX_REGISTRANT): jobs.append( self.delayable().process_registrants( - partners[i : i + self.MAX_REGISTRANT_IN_FETCH] + partners[i : i + constants.MAX_REGISTRANT] ) ) main_job = group(*jobs) @@ -425,11 +434,12 @@ def fetch_social_registry_beneficiary(self): timeout=constants.REQUEST_TIMEOUT, ) + sticky = False + # Process response if response.ok: kind = "success" message = _("Successfully Imported Social Registry Beneficiaries") - sticky = False search_responses = ( response.json().get("message", {}).get("search_response", []) @@ -443,7 +453,7 @@ def fetch_social_registry_beneficiary(self): total_partners_count = reg_record.get("totalRegistrantCount", "") if total_partners_count: - if total_partners_count < self.MAX_REGISTRANT_IN_FETCH: + if total_partners_count < constants.MAX_REGISTRANT: self.process_registrants(partners) else: diff --git a/g2p_import_dci_api/static/src/img/icons/contacts.png b/g2p_import_dci_api/static/src/img/icons/contacts.png deleted file mode 100644 index 8582a80b512c4a483f1c062faa764ea4374b8e6e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 591 zcmV-V0QIvv$g9hz94FwCb!9II^_NB>4Ti83EH-7v4cI}XZq>m(bopWCS ztfCuSWm)#6YSQH|LI^*cbK4ySenpmLuAT*ep{i+-cU$Q zo!gF3sEH~Ae*vuYeV_d;Y>*?|F$tJB6*jp-*pit_mMUR z&H%v7CX$AdMrJn2&$ULwA{@^s!nL{dn;3{Dh9nP2-oNdq(6Cixh-?=mru zfeVr{v)c2bne9ZK^DYhC$M#!$QkJwDb*4@9n-<|G0C3LzsUzk%OHG7JPefJdqenE& zz*P(F%j75icR~R7!1HGFuM8CS`b8Kh{Fq1@o7pv<&wRZh|6@|ffOGD~d%q6g5Wu@e d(h&+@#}k~#Ae6(71VI1*002ovPDHLkV1nWE`quye