Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix/chat 1.2.2 #6209

Merged
merged 2 commits into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/app/local.env
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ GITHUB_API_TOKEN=
GITHUB_CLIENT_ID=
GITHUB_CLIENT_SECRET=
GITHUB_APP_NAME=

CHAT_SERVER_URL=chat
CHAT_URL=localhost
# Etherscan API to get ETH and token trasaction history from an account address
ETHERSCAN_API_KEY=

Expand Down
20 changes: 11 additions & 9 deletions app/app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,17 @@ def sync_profile(handle, user=None, hide_profile=True):
profile.handle = data['login']
profile.email = user.email
profile.save()

if profile is not None and (profile.chat_id is '' or profile.gitcoin_chat_access_token is ''):

try:
from chat.tasks import associate_chat_to_profile
created, profile = associate_chat_to_profile(profile)

except Exception as e:
logger.error(str(e))
raise ValueError(e)

except UserSocialAuth.DoesNotExist:
pass
else:
Expand Down Expand Up @@ -458,15 +469,6 @@ def get_profile(request):
if is_authed and not profile:
profile = sync_profile(request.user.username, request.user, hide_profile=False)

if profile is not None and (profile.chat_id is '' or profile.gitcoin_chat_access_token is ''):

try:
from chat.tasks import associate_chat_to_profile
created, profile = associate_chat_to_profile(profile)

except Exception as e:
logger.error(str(e))
raise ValueError(e)

return profile

Expand Down
12 changes: 9 additions & 3 deletions app/assets/v2/js/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,8 @@ if (document.contxt.chat_access_token && document.contxt.chat_id) {
// setup polling check for any updated data
// scope our polling function so any potential js crashes won't affect it.
(($) => {
setInterval(() => {

const checkChatNotifications = () => {
$.ajax({
beforeSend: function(request) {
request.setRequestHeader('Authorization', `Bearer ${document.contxt.chat_access_token}`);
Expand All @@ -455,7 +456,7 @@ if (document.contxt.chat_access_token && document.contxt.chat_id) {
let notified = false;

JSONUnread.forEach((team) => {
if ((team.msg_count || team.mention_count) && !notified) {
if ((team.msg_count > 0 || team.mention_count > 0) && !notified) {
$('#chat-notification-dot').addClass('notification__dot_active');
notified = true;
}
Expand All @@ -466,7 +467,12 @@ if (document.contxt.chat_access_token && document.contxt.chat_id) {
console.log(error);
})
});
}, 30000);
};

setInterval(() => {
checkChatNotifications();
}, 15000);
checkChatNotifications();
})(jQuery);
}
// carousel/collabs/... inside menu
Expand Down
14 changes: 9 additions & 5 deletions app/chat/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,12 @@ def associate_chat_to_profile(profile):
break
except Exception as e:
logger.error(str(e))
profile_access_token = chat_driver.users.create_user_access_token(user_id=profile.chat_id, options={
'description': "Grants Gitcoin access to modify your account"})
try:
profile_access_token = chat_driver.users.create_user_access_token(user_id=profile.chat_id, options={
'description': "Grants Gitcoin access to modify your account"})
except Exception as e:
logger.info('Failed to create access token')
logger.error(str(e))

profile.gitcoin_chat_access_token = profile_access_token['token']

Expand Down Expand Up @@ -238,7 +242,7 @@ def hackathon_chat_sync(self, hackathon_id: str, profile_handle: str = None, ret
else:
profiles_to_connect.append(reg.registrant.chat_id)
else:
profile = Profile.objects.get(handle=profile_handle)
profile = Profile.objects.get(handle__iexact=profile_handle)
if profile.chat_id is '' or profile.chat_id is None:
created, updated_profile = associate_chat_to_profile(profile)
profiles_to_connect.append(updated_profile.chat_id)
Expand Down Expand Up @@ -314,7 +318,7 @@ def create_user(self, options, params, profile_handle='', retry: bool = True):
params=params
)
if profile_handle:
profile = Profile.objects.get(handle=profile_handle)
profile = Profile.objects.get(handle__iexact=profile_handle)
profile.chat_id = create_user_response['id']

profile_access_token = chat_driver.users.create_user_access_token(user_id=profile.chat_id, options={
Expand Down Expand Up @@ -354,7 +358,7 @@ def patch_chat_user(self, query_opts, update_opts, retry: bool = True) -> None:
try:
chat_user = chat_driver.users.get_user_by_username(query_opts['handle'])
chat_id = chat_user['id']
user_profile = Profile.objects.filter(handle=query_opts['handle'])
user_profile = Profile.objects.filter(handle__iexact=query_opts['handle'])
user_profile.chat_id = chat_id
user_profile.save()
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion app/dashboard/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def bounty_emails(self, emails, msg, profile_handle, invite_url=None, kudos_invi
"""
with redis.lock("tasks:bounty_email:%s" % invite_url, timeout=LOCK_TIMEOUT):
# need to look at how to send bulk emails with SG
profile = Profile.objects.get(handle=profile_handle)
profile = Profile.objects.get(handle__iexact=profile_handle)
try:
for email in emails:
to_email = email
Expand Down
17 changes: 12 additions & 5 deletions app/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3944,6 +3944,14 @@ def hackathon_save_project(request):
'work_url': clean(request.POST.get('work_url'), strip=True)
}

try:

if profile.chat_id is '' or profile.chat_id is None:
created, profile = associate_chat_to_profile(profile)
except Exception as e:
logger.info("Bounty Profile owner not apart of gitcoin")
profiles_to_connect = [profile.chat_id]

if project_id:
try:

Expand All @@ -3954,9 +3962,9 @@ def hackathon_save_project(request):
})

project.update(**kwargs)
profiles_to_connect = []

try:
bounty_profile = Profile.objects.get(handle=project.bounty.bounty_owner_github_username)
bounty_profile = Profile.objects.get(handle__iexact=project.bounty.bounty_owner_github_username)
if bounty_profile.chat_id is '' or bounty_profile.chat_id is None:
created, bounty_profile = associate_chat_to_profile(bounty_profile)

Expand All @@ -3970,7 +3978,7 @@ def hackathon_save_project(request):
created, curr_profile = associate_chat_to_profile(curr_profile)
profiles_to_connect.append(curr_profile.chat_id)

add_to_channel.delay(project.chat_channel_id, profiles_to_connect)
add_to_channel.delay(project.first().chat_channel_id, profiles_to_connect)

profiles.append(str(profile.id))
project.first().profiles.set(profiles)
Expand All @@ -3993,9 +4001,8 @@ def hackathon_save_project(request):
'channel_name': project_channel_name[:60],
'channel_type': 'P'
})
profiles_to_connect = []
try:
bounty_profile = Profile.objects.get(handle=bounty_obj.bounty_owner_github_username)
bounty_profile = Profile.objects.get(handle__iexact=bounty_obj.bounty_owner_github_username)
if bounty_profile.chat_id is '' or bounty_profile.chat_id is None:
created, bounty_profile = associate_chat_to_profile(bounty_profile)

Expand Down