def template_roles_remove_view(request, template_id): try: if request.method == 'POST': data = request.POST.dict() target = data.get('target') role_id = data.get('role_id') if target == 'user': status, msg = UserAndTeamRoleAPI.delete_role_from_user( request.user, int(data.get('user_id')), int(role_id)) if not status: return HttpResponse(msg) return HttpResponseRedirect( reverse('project:template_roles', kwargs={'template_id': template_id})) elif target == 'team': status, msg = UserAndTeamRoleAPI.delete_role_from_team( request.user, int(data.get('team_id')), int(role_id)) if not status: return HttpResponse(msg) return HttpResponseRedirect( reverse('project:template_roles', kwargs={'template_id': template_id})) else: return HttpResponse('404') except Exception as e: return HttpResponse(str(e))
def organization_user_role_remove_view(request): try: if request.is_ajax() and request.method == 'POST': user = request.user ajax_data = request.POST.get('data') data = json.loads(ajax_data) target_user_id = int(data.get('user_id')) role_id = int(data.get('role_id')) status, errmsg = UserAndTeamRoleAPI.delete_role_from_user( user=user, target_user_id=target_user_id, role_id=role_id) if not status: return JsonResponse({ARK_STATUS: False, ARK_ERRMSG: errmsg}) return JsonResponse({ARK_STATUS: True}) except Exception as e: return JsonResponse({ARK_STATUS: False, ARK_ERRMSG: str(e)})
def project_roles_remove_view(request, project_id): try: if request.is_ajax(): if request.method == 'POST': ajax_data = request.POST.get('data') data = json.loads(ajax_data) target = data.get('target') role_id = int(data.get('role_id')) if target == 'user': status, errmsg = UserAndTeamRoleAPI.delete_role_from_user( user=request.user, target_user_id=int(data.get('user_id')), role_id=role_id) if not status: return JsonResponse({ ARK_STATUS: False, ARK_ERRMSG: errmsg }) return JsonResponse({ARK_STATUS: True}) elif target == 'team': status, errmsg = UserAndTeamRoleAPI.delete_role_from_team( user=request.user, target_team_id=int(data.get('team_id')), role_id=role_id) if not status: return JsonResponse({ ARK_STATUS: False, ARK_ERRMSG: errmsg }) return JsonResponse({ARK_STATUS: True}) else: return JsonResponse({ ARK_STATUS: False, ARK_ERRMSG: '既不是User也不是Team' }) else: return render(request, 'error.html', {ARK_ERRMSG: 'Method is not post'}) except Exception as e: return JsonResponse({ARK_STATUS: False, ARK_ERRMSG: str(e)})