Skip to content

Commit 4f59205

Browse files
Merge pull request #194 from mkumar-02/15.0-develop
G2P Import DCI API: Modified authorization token flow.
2 parents 85759f8 + 265e564 commit 4f59205

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

g2p_import_dci_api/models/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
DATA_SOURCE_AUTH_PATH_NAME = "Authentication"
66

77
REQUEST_TIMEOUT = 60
8+
9+
MAX_REGISTRANT = 150

g2p_import_dci_api/models/fetch_social_registry_beneficiary.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ class G2PFetchSocialRegistryBeneficiary(models.Model):
1919
_name = "g2p.fetch.social.registry.beneficiary"
2020
_description = "Fetch Social Registry Beneficiary"
2121

22-
MAX_REGISTRANT_IN_FETCH = 150
23-
2422
data_source_id = fields.Many2one("spp.data.source", required=True)
2523

2624
name = fields.Char("Search Criteria Name", required=True)
@@ -73,11 +71,13 @@ def get_social_registry_auth_url(self, paths):
7371
url = self.data_source_id.url
7472
auth_path = paths.get(constants.DATA_SOURCE_AUTH_PATH_NAME)
7573

76-
return f"{url}{auth_path}"
74+
if auth_path.lstrip().startswith("/"):
75+
return f"{url}{auth_path}"
7776

78-
def get_auth_token(self, auth_url):
77+
else:
78+
return auth_path
7979

80-
headers = self.get_headers_for_request()
80+
def get_auth_token(self, auth_url):
8181

8282
grant_type = (
8383
self.env["ir.config_parameter"]
@@ -94,20 +94,29 @@ def get_auth_token(self, auth_url):
9494
.sudo()
9595
.get_param("social_registry_client_secret")
9696
)
97-
db_name = (
98-
self.env["ir.config_parameter"].sudo().get_param("social_registry_db_name")
97+
username = (
98+
self.env["ir.config_parameter"]
99+
.sudo()
100+
.get_param("social_registry_user_name")
101+
)
102+
password = (
103+
self.env["ir.config_parameter"]
104+
.sudo()
105+
.get_param("social_registry_user_password")
99106
)
100107

101108
data = {
102109
"grant_type": grant_type,
103110
"client_id": client_id,
104111
"client_secret": client_secret,
105-
"db_name": db_name,
112+
"username": username,
113+
"password": password,
106114
}
115+
107116
response = requests.post(
108117
auth_url,
109-
headers=headers,
110-
data=json.dumps(data),
118+
headers={"Content-Type": "application/x-www-form-urlencoded"},
119+
data=data,
111120
timeout=constants.REQUEST_TIMEOUT,
112121
)
113122

@@ -355,10 +364,10 @@ def process_registrants(self, partners):
355364
def process_registrants_async(self, partners, count):
356365
_logger.warning("Fetching Registrant Asynchronously!")
357366
jobs = []
358-
for i in range(0, count, self.MAX_REGISTRANT_IN_FETCH):
367+
for i in range(0, count, constants.MAX_REGISTRANT):
359368
jobs.append(
360369
self.delayable().process_registrants(
361-
partners[i : i + self.MAX_REGISTRANT_IN_FETCH]
370+
partners[i : i + constants.MAX_REGISTRANT]
362371
)
363372
)
364373
main_job = group(*jobs)
@@ -425,11 +434,12 @@ def fetch_social_registry_beneficiary(self):
425434
timeout=constants.REQUEST_TIMEOUT,
426435
)
427436

437+
sticky = False
438+
428439
# Process response
429440
if response.ok:
430441
kind = "success"
431442
message = _("Successfully Imported Social Registry Beneficiaries")
432-
sticky = False
433443

434444
search_responses = (
435445
response.json().get("message", {}).get("search_response", [])
@@ -443,7 +453,7 @@ def fetch_social_registry_beneficiary(self):
443453
total_partners_count = reg_record.get("totalRegistrantCount", "")
444454

445455
if total_partners_count:
446-
if total_partners_count < self.MAX_REGISTRANT_IN_FETCH:
456+
if total_partners_count < constants.MAX_REGISTRANT:
447457
self.process_registrants(partners)
448458

449459
else:
-591 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)