Skip to content

Commit

Permalink
Fix AnonymousUser post on status (#9261)
Browse files Browse the repository at this point in the history
* block user to submit if not logged and fix error

* remove print
  • Loading branch information
octavioamu authored Jul 19, 2021
1 parent 62deca4 commit fe23823
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
8 changes: 6 additions & 2 deletions app/assets/v2/js/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,10 @@ $(document).ready(function() {
return;
}

if (!document.contxt.github_handle) {
return;
}

if (typeof ga !== 'undefined') {
ga('send', 'event', 'Submit Status Update', 'click', 'Person');
}
Expand Down Expand Up @@ -501,7 +505,7 @@ $(document).ready(function() {
localStorage.setItem(lskey, the_message);
_alert(
{ message: gettext('An error occurred. Please try again.') },
'error'
'danger'
);
};

Expand Down Expand Up @@ -547,7 +551,7 @@ $(document).ready(function() {
} else {
_alert(
{ message: gettext('An error occurred. Please try again.') },
'error'
'danger'
);
}
}).catch(err => fail_callback());
Expand Down
18 changes: 11 additions & 7 deletions app/retail/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,12 @@ def create_status_update(request):
issue_re = re.compile(r'^(?:https?://)?(?:github\.com)/(?:[\w,\-,\_]+)/(?:[\w,\-,\_]+)/issues/(?:[\d]+)')
response = {}

if request.POST:
if request.POST and request.user.is_authenticated:
if (request.user.profile.is_blocked or request.user.profile.shadowbanned):
response['status'] = 400
response['message'] = 'Status updated!'
return JsonResponse(response, status=400)

profile = request.user.profile
title = request.POST.get('data')
resource = request.POST.get('resource', '')
Expand All @@ -919,12 +924,6 @@ def create_status_update(request):
attach_token_name = request.POST.get('attachTokenName', '')
tx_id = request.POST.get('attachTxId', '')

if request.user.is_authenticated and (request.user.profile.is_blocked or request.user.profile.shadowbanned):
response['status'] = 200
response['message'] = 'Status updated!'
return JsonResponse(response, status=400)


kwargs = {
'activity_type': 'status_update',
'metadata': {
Expand Down Expand Up @@ -1015,6 +1014,11 @@ def create_status_update(request):
response['message'] = 'Bad Request'
logger.error('Status Update error - Error: (%s) - Handle: (%s)', e, profile.handle if profile else '')
return JsonResponse(response, status=400)
else:
response['status'] = 401
response['message'] = 'Not logged in!'
return JsonResponse(status=response['status'], data={'status': 401,'message':response['message']})

return JsonResponse(response)


Expand Down

0 comments on commit fe23823

Please sign in to comment.