@@ -36,11 +36,11 @@ class AffiliationInvitation(BaseModel): # pylint: disable=too-many-instance-att
3636 __tablename__ = "affiliation_invitations"
3737
3838 id = Column (Integer , primary_key = True )
39- from_org_id = Column (ForeignKey ("orgs.id" ), nullable = False , index = True )
39+ from_org_id = Column (ForeignKey ("orgs.id" ), nullable = True , index = True )
4040 to_org_id = Column (ForeignKey ("orgs.id" ), nullable = True , index = True )
4141 entity_id = Column (ForeignKey ("entities.id" ), nullable = False , index = True )
4242 affiliation_id = Column (ForeignKey ("affiliations.id" ), nullable = True , index = True )
43- sender_id = Column (ForeignKey ("users.id" ), nullable = False )
43+ sender_id = Column (ForeignKey ("users.id" ), nullable = True )
4444 approver_id = Column (ForeignKey ("users.id" ), nullable = True )
4545 recipient_email = Column (String (8000 ), nullable = True )
4646 sent_date = Column (DateTime , nullable = False )
@@ -59,11 +59,18 @@ class AffiliationInvitation(BaseModel): # pylint: disable=too-many-instance-att
5959 to_org = relationship ("Org" , foreign_keys = [to_org_id ], lazy = "select" )
6060 affiliation = relationship ("Affiliation" , foreign_keys = [affiliation_id ], lazy = "select" )
6161
62+ def _get_expiry_minutes (self ):
63+ """Get expiry minutes based on invitation type."""
64+ config = get_named_config ()
65+ if self .type == AffiliationInvitationTypeEnum .UNAFFILIATED_EMAIL .value :
66+ return int (config .UNAFFILIATED_EMAIL_TOKEN_EXPIRY_PERIOD_MINS )
67+ return int (config .AFFILIATION_TOKEN_EXPIRY_PERIOD_MINS )
68+
6269 @hybrid_property
6370 def expires_on (self ):
6471 """Calculate the expiry date based on the config value."""
6572 if self .invitation_status_code == InvitationStatuses .PENDING .value :
66- return self .sent_date + timedelta (minutes = int ( get_named_config (). AFFILIATION_TOKEN_EXPIRY_PERIOD_MINS ))
73+ return self .sent_date + timedelta (minutes = self . _get_expiry_minutes ( ))
6774 return None
6875
6976 @hybrid_property
@@ -75,9 +82,7 @@ def status(self):
7582 return self .invitation_status_code
7683
7784 if self .invitation_status_code == InvitationStatuses .PENDING .value :
78- expiry_time = self .sent_date + timedelta (
79- minutes = int (get_named_config ().AFFILIATION_TOKEN_EXPIRY_PERIOD_MINS )
80- )
85+ expiry_time = self .sent_date + timedelta (minutes = self ._get_expiry_minutes ())
8186 if current_time >= expiry_time :
8287 return InvitationStatuses .EXPIRED .value
8388 return self .invitation_status_code
@@ -91,7 +96,7 @@ def create_from_dict(cls, invitation_info: dict, user_id, affiliation_id=None):
9196 affiliation_invitation = AffiliationInvitation ()
9297 affiliation_invitation .sender_id = user_id
9398 affiliation_invitation .affiliation_id = affiliation_id
94- affiliation_invitation .from_org_id = invitation_info [ "fromOrgId" ]
99+ affiliation_invitation .from_org_id = invitation_info . get ( "fromOrgId" )
95100 affiliation_invitation .to_org_id = invitation_info .get ("toOrgId" )
96101 affiliation_invitation .entity_id = invitation_info ["entityId" ]
97102 affiliation_invitation .recipient_email = invitation_info .get ("recipientEmail" )
0 commit comments