From 94341a69076470ff864f8b2bebe801510478b47d Mon Sep 17 00:00:00 2001 From: David Deal Date: Thu, 13 Aug 2020 14:44:39 -0700 Subject: [PATCH] [#1533] Resolved CORS API Issue - Signed at Foundation Flag - Added conditional around signed at foundation flag logic - Refactored signed_at_foundation() function Signed-off-by: David Deal --- cla-backend/cla/models/dynamo_models.py | 19 ++++++++++--------- cla-backend/cla/routes.py | 8 +++++++- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/cla-backend/cla/models/dynamo_models.py b/cla-backend/cla/models/dynamo_models.py index 00b9130b9..88e59b593 100644 --- a/cla-backend/cla/models/dynamo_models.py +++ b/cla-backend/cla/models/dynamo_models.py @@ -2819,16 +2819,17 @@ def delete(self): self.model.delete() @property - def signed_at_foundation(self): - cla_group = {} + def signed_at_foundation(self) -> bool: + # use a 'set' so that we don't have any duplicates + unique_cla_groups = set() if self.model.foundation_sfid: - project_cla_groups = self.get_by_foundation_sfid(self.model.foundation_sfid) - for pcg in project_cla_groups: - if cla_group.get(self.model.cla_group_id): - cla_group[self.model.cla_group_id] = cla_group[self.model.cla_group_id].append(self.model.project_sfid) - else: - cla_group[self.model.cla_group_id] = [self.model.project_sfid] - return len(cla_group) == 1 + # Get all records that might have the same foundation ID (including this current record) + for mapping in self.get_by_foundation_sfid(self.model.foundation_sfid): + # Add the CLA Group ID - no duplicates + unique_cla_groups.add(mapping.get_cla_group_id()) + + # if only CLA Group - we consider this at the Foundation Level + return len(unique_cla_groups) == 1 def get_project_sfid(self): return self.model.project_sfid diff --git a/cla-backend/cla/routes.py b/cla-backend/cla/routes.py index 699422676..f54285cfb 100755 --- a/cla-backend/cla/routes.py +++ b/cla-backend/cla/routes.py @@ -759,7 +759,13 @@ def get_project(project_id: hug.types.uuid): for project_cla_group in project_cla_group_list: sf_projects.append(project_cla_group.to_dict()) project["projects"] = sf_projects - project["signed_at_foundation_level"] = project_cla_group_list[0].signed_at_foundation + + # if we have at least one SF Project associated with this CLA Group + if len(project_cla_group_list) > 0: + project["signed_at_foundation_level"] = project_cla_group_list[0].signed_at_foundation + else: + # Default is false, common for v1 not to have any mappings + project["signed_at_foundation_level"] = False return project