@@ -8,11 +8,14 @@ class SlackBot(models.Model):
88 client_id = models .TextField (null = False )
99 app_id = models .TextField (null = False )
1010 enterprise_id = models .TextField (null = True )
11+ enterprise_name = models .TextField (null = True )
1112 team_id = models .TextField (null = True )
13+ team_name = models .TextField (null = True )
1214 bot_token = models .TextField (null = True )
1315 bot_id = models .TextField (null = True )
1416 bot_user_id = models .TextField (null = True )
1517 bot_scopes = models .TextField (null = True )
18+ is_enterprise_install = models .BooleanField (null = True )
1619 installed_at = models .DateTimeField (null = False )
1720
1821 class Meta :
@@ -27,7 +30,10 @@ class SlackInstallation(models.Model):
2730 client_id = models .TextField (null = False )
2831 app_id = models .TextField (null = False )
2932 enterprise_id = models .TextField (null = True )
33+ enterprise_name = models .TextField (null = True )
34+ enterprise_url = models .TextField (null = True )
3035 team_id = models .TextField (null = True )
36+ team_name = models .TextField (null = True )
3137 bot_token = models .TextField (null = True )
3238 bot_id = models .TextField (null = True )
3339 bot_user_id = models .TextField (null = True )
@@ -36,8 +42,11 @@ class SlackInstallation(models.Model):
3642 user_token = models .TextField (null = True )
3743 user_scopes = models .TextField (null = True )
3844 incoming_webhook_url = models .TextField (null = True )
45+ incoming_webhook_channel = models .TextField (null = True )
3946 incoming_webhook_channel_id = models .TextField (null = True )
4047 incoming_webhook_configuration_url = models .TextField (null = True )
48+ is_enterprise_install = models .BooleanField (null = True )
49+ token_type = models .TextField (null = True )
4150 installed_at = models .DateTimeField (null = False )
4251
4352 class Meta :
@@ -95,11 +104,16 @@ def save(self, installation: Installation):
95104 SlackBot (** b ).save ()
96105
97106 def find_bot (
98- self , * , enterprise_id : Optional [str ], team_id : Optional [str ]
107+ self , * , enterprise_id : Optional [str ], team_id : Optional [str ],
108+ is_enterprise_install : Optional [bool ] = False
99109 ) -> Optional [Bot ]:
110+ e_id = enterprise_id or None
111+ t_id = team_id or None
112+ if is_enterprise_install :
113+ t_id = None
100114 rows = (
101- SlackBot .objects .filter (enterprise_id = enterprise_id )
102- .filter (team_id = team_id )
115+ SlackBot .objects .filter (enterprise_id = e_id )
116+ .filter (team_id = t_id )
103117 .order_by (F ("installed_at" ).desc ())[:1 ]
104118 )
105119 if len (rows ) > 0 :
@@ -116,6 +130,47 @@ def find_bot(
116130 )
117131 return None
118132
133+ def find_installation (
134+ self ,
135+ * ,
136+ enterprise_id : Optional [str ],
137+ team_id : Optional [str ],
138+ user_id : Optional [str ] = None ,
139+ is_enterprise_install : Optional [bool ] = False ,
140+ ) -> Optional [Installation ]:
141+ e_id = enterprise_id or None
142+ t_id = team_id or None
143+ if is_enterprise_install :
144+ t_id = None
145+ if user_id is None :
146+ rows = (SlackInstallation .objects .filter (
147+ enterprise_id = e_id ).filter (team_id = t_id ).order_by (
148+ F ("installed_at" ).desc ())[:1 ])
149+ else :
150+ rows = (SlackInstallation .objects .filter (
151+ enterprise_id = e_id ).filter (team_id = t_id ).filter (
152+ user_id = user_id ).order_by (F ("installed_at" ).desc ())[:1 ])
153+
154+ if len (rows ) > 0 :
155+ i = rows [0 ]
156+ return Installation (
157+ app_id = i .app_id ,
158+ enterprise_id = i .enterprise_id ,
159+ team_id = i .team_id ,
160+ bot_token = i .bot_token ,
161+ bot_id = i .bot_id ,
162+ bot_user_id = i .bot_user_id ,
163+ bot_scopes = i .bot_scopes ,
164+ user_id = i .user_id ,
165+ user_token = i .user_token ,
166+ user_scopes = i .user_scopes ,
167+ incoming_webhook_url = i .incoming_webhook_url ,
168+ incoming_webhook_channel_id = i .incoming_webhook_channel_id ,
169+ incoming_webhook_configuration_url = i .incoming_webhook_configuration_url ,
170+ installed_at = i .installed_at .timestamp (),
171+ )
172+ return None
173+
119174
120175class DjangoOAuthStateStore (OAuthStateStore ):
121176 expiration_seconds : int
0 commit comments