leadguru-jobs 0.705.0__py3-none-any.whl → 0.707.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {leadguru_jobs-0.705.0.dist-info → leadguru_jobs-0.707.0.dist-info}/METADATA +1 -1
- {leadguru_jobs-0.705.0.dist-info → leadguru_jobs-0.707.0.dist-info}/RECORD +6 -6
- lgt_jobs/jobs/workspace_connect.py +73 -67
- lgt_jobs/lgt_data/mongo_repository.py +2 -2
- {leadguru_jobs-0.705.0.dist-info → leadguru_jobs-0.707.0.dist-info}/WHEEL +0 -0
- {leadguru_jobs-0.705.0.dist-info → leadguru_jobs-0.707.0.dist-info}/top_level.txt +0 -0
@@ -24,7 +24,7 @@ lgt_jobs/jobs/mass_message.py,sha256=1mFcBlL2MhzLbj5yrd_NyJc7TXDWCcROAzGDnr0miMU
|
|
24
24
|
lgt_jobs/jobs/send_code.py,sha256=dIlLPkG3GgGKIEqGiElyzrtdrnJNTL1Ak2V0xnE-WIQ,824
|
25
25
|
lgt_jobs/jobs/send_slack_message.py,sha256=eiSN-yZ7XJ2WLUTQOkViSYOCYwaEwLry0ldGAcONNsM,1708
|
26
26
|
lgt_jobs/jobs/update_slack_profile.py,sha256=GU28azaNz1zYsCAAF_BShJxLUecQb7AbO5XPgiv7yHg,3654
|
27
|
-
lgt_jobs/jobs/workspace_connect.py,sha256=
|
27
|
+
lgt_jobs/jobs/workspace_connect.py,sha256=3uGxI0gTXVloZWxo32uhRmHjVwCGzET2CLUNjN4CcS8,7829
|
28
28
|
lgt_jobs/lgt_common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
29
29
|
lgt_jobs/lgt_common/helpers.py,sha256=3T47_Abw7datSIxVqIHTCB-sh-rnahWrmrFG8sSY9ZE,178
|
30
30
|
lgt_jobs/lgt_common/discord_client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -45,7 +45,7 @@ lgt_jobs/lgt_data/engine.py,sha256=GY8FOl3dl7euKjQRML_H3ophaSTgfQ8ICMRv1NpE2oE,7
|
|
45
45
|
lgt_jobs/lgt_data/enums.py,sha256=SN2eLoB2m-bVswgLVuY46v0DhPj8IurgHY6R-KRsd6s,2621
|
46
46
|
lgt_jobs/lgt_data/helpers.py,sha256=S_1P7pnx14dllmen-TzjA9pkKWQr39x8-v6iv7FUYnQ,423
|
47
47
|
lgt_jobs/lgt_data/model.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
48
|
-
lgt_jobs/lgt_data/mongo_repository.py,sha256=
|
48
|
+
lgt_jobs/lgt_data/mongo_repository.py,sha256=q3H9bV5qKXj2tbHQot5XwmLvlHo23XF7nusCMTQt3oc,57400
|
49
49
|
lgt_jobs/lgt_data/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
50
50
|
lgt_jobs/lgt_data/models/base.py,sha256=YaiceCaaF45snOLx-bQoYJ1aTWrfgMQeHWjAaRnzGKE,592
|
51
51
|
lgt_jobs/lgt_data/models/boards/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -108,7 +108,7 @@ lgt_jobs/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU
|
|
108
108
|
lgt_jobs/services/k8_manager.py,sha256=bXpka9psIQ5UJ6QG_e4xolmE_3gtmNrzzZeL03bJ62I,995
|
109
109
|
lgt_jobs/services/web_client.py,sha256=oMyWJxwGeIe3f40fPT7xcisjDg3BhA3Ipf8dr1jVT-Y,1549
|
110
110
|
lgt_jobs/templates/new_message.html,sha256=dZl8UmdAOOMq4nidvAgMFroSrTV7Pw0RWt2yLp_2idg,6989
|
111
|
-
leadguru_jobs-0.
|
112
|
-
leadguru_jobs-0.
|
113
|
-
leadguru_jobs-0.
|
114
|
-
leadguru_jobs-0.
|
111
|
+
leadguru_jobs-0.707.0.dist-info/METADATA,sha256=c2DeRNVH71gISNSQRtBrmVQ6dH5bJCTAIHCEdM_5zfY,1399
|
112
|
+
leadguru_jobs-0.707.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
113
|
+
leadguru_jobs-0.707.0.dist-info/top_level.txt,sha256=rIuw1DqwbnZyeoarBSC-bYeGOhv9mZBs7_afl9q4_JI,9
|
114
|
+
leadguru_jobs-0.707.0.dist-info/RECORD,,
|
@@ -42,78 +42,84 @@ class ConnectSlackAccountJob(BaseBackgroundJob, ABC):
|
|
42
42
|
current_user.slack_users.append(slack_user)
|
43
43
|
slack_user.status = StatusConnection.IN_PROGRESS
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
UserMongoRepository().set(current_user.id, slack_users=[user.to_dic() for user in current_user.slack_users])
|
51
|
-
return
|
52
|
-
|
53
|
-
code_confirmed = code_confirmed_response.json().get('ok', False)
|
54
|
-
if not code_confirmed:
|
55
|
-
slack_user.status = StatusConnection.FAILED
|
56
|
-
UserMongoRepository().set(current_user.id, slack_users=[user.to_dic() for user in current_user.slack_users])
|
57
|
-
log.warning(f'Invalid code')
|
58
|
-
return
|
59
|
-
|
60
|
-
slack_user.cookies = client.client.cookies = code_confirmed_response.cookies.get_dict()
|
61
|
-
|
62
|
-
workspaces_response = None
|
63
|
-
attempt = 1
|
64
|
-
while attempt <= 5:
|
65
|
-
workspaces_response = client.find_workspaces(data.user_agent)
|
66
|
-
if workspaces_response.status_code != 200:
|
45
|
+
try:
|
46
|
+
client = SlackWebClient('')
|
47
|
+
code_confirmed_response = client.confirm_code(data.slack_email, data.code, data.user_agent)
|
48
|
+
if code_confirmed_response.status_code != 200:
|
49
|
+
log.warning(f'Unable to confirm code due to error: {code_confirmed_response.content}')
|
67
50
|
slack_user.status = StatusConnection.FAILED
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
51
|
+
UserMongoRepository().set(current_user.id, slack_users=[user.to_dic() for user in current_user.slack_users])
|
52
|
+
return
|
53
|
+
|
54
|
+
code_confirmed = code_confirmed_response.json().get('ok', False)
|
55
|
+
if not code_confirmed:
|
72
56
|
slack_user.status = StatusConnection.FAILED
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
57
|
+
UserMongoRepository().set(current_user.id, slack_users=[user.to_dic() for user in current_user.slack_users])
|
58
|
+
log.warning(f'Invalid code')
|
59
|
+
return
|
60
|
+
|
61
|
+
slack_user.cookies = client.client.cookies = code_confirmed_response.cookies.get_dict()
|
62
|
+
|
63
|
+
workspaces_response = None
|
64
|
+
attempt = 1
|
65
|
+
while attempt <= 5:
|
66
|
+
workspaces_response = client.find_workspaces(data.user_agent)
|
67
|
+
if workspaces_response.status_code != 200:
|
68
|
+
slack_user.status = StatusConnection.FAILED
|
69
|
+
log.warning(f'Attempt: {attempt}. Unable to get workspaces due to error: {workspaces_response.content}')
|
70
|
+
attempt += 1
|
71
|
+
time.sleep(60)
|
72
|
+
if not workspaces_response.json().get('ok', False):
|
73
|
+
slack_user.status = StatusConnection.FAILED
|
74
|
+
log.warning(f'Attempt: {attempt}. Unable to get workspaces due to error: {workspaces_response.json()}')
|
75
|
+
attempt += 1
|
76
|
+
time.sleep(60)
|
77
|
+
else:
|
78
|
+
slack_user.status = StatusConnection.IN_PROGRESS
|
79
|
+
break
|
79
80
|
|
80
|
-
|
81
|
+
UserMongoRepository().set(current_user.id, slack_users=[user.to_dic() for user in current_user.slack_users])
|
81
82
|
|
82
|
-
|
83
|
+
if attempt > 5:
|
84
|
+
return
|
85
|
+
|
86
|
+
log.info(f'{slack_user.email}: got workspaces data {workspaces_response.json()}')
|
87
|
+
user_workspaces = next((user for user in workspaces_response.json()['current_teams']
|
88
|
+
if user['email'] == data.slack_email), {}).get('teams', [])
|
89
|
+
user_workspaces = [UserWorkspace.from_dic(ws) for ws in user_workspaces]
|
90
|
+
user_workspaces = sorted(user_workspaces, key=lambda ws: ws.domain)
|
91
|
+
|
92
|
+
session = requests.Session()
|
93
|
+
session.cookies = code_confirmed_response.cookies
|
94
|
+
session.headers.update({'User-Agent': data.user_agent})
|
95
|
+
log.info(f'{slack_user.email}: started getting of tokens for {len(user_workspaces)} workspaces')
|
96
|
+
for workspace in user_workspaces:
|
97
|
+
if not workspace.magic_login_code:
|
98
|
+
continue
|
99
|
+
login_url = f"https://app.slack.com/t/{workspace.domain}/login/{workspace.magic_login_code}"
|
100
|
+
magic_response = session.post(login_url, cookies=session.cookies, headers=session.headers)
|
101
|
+
content = magic_response.content.decode('utf-8')
|
102
|
+
start_token_index = content.find("xox")
|
103
|
+
sliced_content = content[start_token_index:]
|
104
|
+
end_token_index = sliced_content.find('"')
|
105
|
+
token = sliced_content[:end_token_index]
|
106
|
+
workspace.magic_login_url = login_url
|
107
|
+
workspace.token = token
|
108
|
+
workspace.domain = workspace.domain
|
109
|
+
time.sleep(random.uniform(0.2, 0.5))
|
110
|
+
|
111
|
+
slack_user.cookies = session.cookies.get_dict()
|
112
|
+
slack_user.workspaces = user_workspaces
|
113
|
+
slack_user.status = StatusConnection.COMPLETE
|
114
|
+
|
115
|
+
slack_users_dict = [user.to_dic() for user in current_user.slack_users]
|
116
|
+
UserMongoRepository().set(current_user.id, slack_users=slack_users_dict)
|
117
|
+
|
118
|
+
except:
|
119
|
+
slack_user.status = StatusConnection.FAILED
|
120
|
+
UserMongoRepository().set(current_user.id, slack_users=[user.to_dic() for user in current_user.slack_users])
|
83
121
|
return
|
84
122
|
|
85
|
-
log.info(f'{slack_user.email}: got workspaces data {workspaces_response.json()}')
|
86
|
-
user_workspaces = next((user for user in workspaces_response.json()['current_teams']
|
87
|
-
if user['email'] == data.slack_email), {}).get('teams', [])
|
88
|
-
user_workspaces = [UserWorkspace.from_dic(ws) for ws in user_workspaces]
|
89
|
-
user_workspaces = sorted(user_workspaces, key=lambda ws: ws.domain)
|
90
|
-
|
91
|
-
session = requests.Session()
|
92
|
-
session.cookies = code_confirmed_response.cookies
|
93
|
-
session.headers.update({'User-Agent': data.user_agent})
|
94
|
-
log.info(f'{slack_user.email}: started getting of tokens for {len(user_workspaces)} workspaces')
|
95
|
-
for workspace in user_workspaces:
|
96
|
-
if not workspace.magic_login_code:
|
97
|
-
continue
|
98
|
-
login_url = f"https://app.slack.com/t/{workspace.domain}/login/{workspace.magic_login_code}"
|
99
|
-
magic_response = session.post(login_url, cookies=session.cookies, headers=session.headers)
|
100
|
-
content = magic_response.content.decode('utf-8')
|
101
|
-
start_token_index = content.find("xox")
|
102
|
-
sliced_content = content[start_token_index:]
|
103
|
-
end_token_index = sliced_content.find('"')
|
104
|
-
token = sliced_content[:end_token_index]
|
105
|
-
workspace.magic_login_url = login_url
|
106
|
-
workspace.token = token
|
107
|
-
workspace.domain = workspace.domain
|
108
|
-
time.sleep(random.uniform(0.2, 0.5))
|
109
|
-
|
110
|
-
slack_user.cookies = session.cookies.get_dict()
|
111
|
-
slack_user.workspaces = user_workspaces
|
112
|
-
slack_user.status = StatusConnection.COMPLETE
|
113
|
-
|
114
|
-
slack_users_dict = [user.to_dic() for user in current_user.slack_users]
|
115
|
-
UserMongoRepository().set(current_user.id, slack_users=slack_users_dict)
|
116
|
-
|
117
123
|
dedicated_bots_repository = DedicatedBotRepository()
|
118
124
|
dedicated_bots = dedicated_bots_repository.get_all(user_id=current_user.id, user_name=data.slack_email,
|
119
125
|
source_type=SourceType.SLACK, include_deleted=True)
|
@@ -141,4 +147,4 @@ class ConnectSlackAccountJob(BaseBackgroundJob, ABC):
|
|
141
147
|
dedicated_bot.invalid_creds = True
|
142
148
|
for server in dedicated_bot.servers:
|
143
149
|
server.deleted = True
|
144
|
-
dedicated_bots_repository.add_or_update(dedicated_bot)
|
150
|
+
dedicated_bots_repository.add_or_update(dedicated_bot)
|
@@ -1418,7 +1418,7 @@ class MessageRequestsRepository(BaseMongoRepository):
|
|
1418
1418
|
self.collection().update_one({'user_id': to_object_id(user_id), 'sender_id': sender_id},
|
1419
1419
|
{'$set': message_request.to_dic()}, upsert=True)
|
1420
1420
|
|
1421
|
-
def get_many(self, user_id: str, viewed: bool = False):
|
1421
|
+
def get_many(self, user_id: str, viewed: bool = False, sort_direction: int = pymongo.ASCENDING):
|
1422
1422
|
pipeline = [
|
1423
1423
|
{
|
1424
1424
|
'$match': {'user_id': to_object_id(user_id), 'viewed': viewed}
|
@@ -1435,7 +1435,7 @@ class MessageRequestsRepository(BaseMongoRepository):
|
|
1435
1435
|
'$addFields': {'user': {'$first': '$user'}}
|
1436
1436
|
},
|
1437
1437
|
{
|
1438
|
-
'$sort': {'created_at':
|
1438
|
+
'$sort': {'created_at': sort_direction}
|
1439
1439
|
}
|
1440
1440
|
]
|
1441
1441
|
return self.collection().aggregate(pipeline)
|
File without changes
|
File without changes
|