def validationPage(request): if (request.method == 'POST'): # Reserved. Process special case: pager is blank. if not "pager" in request.POST or not request.POST["pager"]: if ('Provider' in request.session['MHL_Users']): Provider.objects.filter(id=request.user.id).update(pager_confirmed=False, pager='') elif ('OfficeStaff' in request.session['MHL_Users']): OfficeStaff.objects.filter(user__id=request.user.id).update(pager_confirmed=False, pager='') elif ('Broker' in request.session['MHL_Users']): Broker.objects.filter(user__id=request.user.id).update(pager_confirmed=False, pager='') if not "mobile_phone" in request.POST or not request.POST["mobile_phone"]: MHLUser.objects.filter(id=request.user.id).update(mobile_confirmed=False, mobile_phone='') return HttpResponseRedirect('/') user = getCurrentUserInfo(request) mhluser = request.session['MHL_Users']['MHLUser'] context = get_context(request) if not user or not user.needValidateContactInfo: return HttpResponseRedirect('/') context["form"] = ContactInfoForm(mhluser, user) context["mobile_required"] = 'Provider' in request.session['MHL_Users'] or \ 'Broker' in request.session['MHL_Users'] return render_to_response('Validates/validation.html', context)
def validationPage(request): if (request.method == 'POST'): # Reserved. Process special case: pager is blank. if not "pager" in request.POST or not request.POST["pager"]: if ('Provider' in request.session['MHL_Users']): Provider.objects.filter(id=request.user.id).update( pager_confirmed=False, pager='') elif ('OfficeStaff' in request.session['MHL_Users']): OfficeStaff.objects.filter(user__id=request.user.id).update( pager_confirmed=False, pager='') elif ('Broker' in request.session['MHL_Users']): Broker.objects.filter(user__id=request.user.id).update( pager_confirmed=False, pager='') if not "mobile_phone" in request.POST or not request.POST[ "mobile_phone"]: MHLUser.objects.filter(id=request.user.id).update( mobile_confirmed=False, mobile_phone='') return HttpResponseRedirect('/') user = getCurrentUserInfo(request) mhluser = request.session['MHL_Users']['MHLUser'] context = get_context(request) if not user or not user.needValidateContactInfo: return HttpResponseRedirect('/') context["form"] = ContactInfoForm(mhluser, user) context["mobile_required"] = 'Provider' in request.session['MHL_Users'] or \ 'Broker' in request.session['MHL_Users'] return render_to_response('Validates/validation.html', context)
def process_view(self, request, view_func, view_args, view_kwargs): # No need to process URLs if user already logged in if request.user.is_authenticated(): for url in termsExceptions: if url.match(request.path): return None mhluser = MHLUser.objects.get(id=request.user.id) if (not mhluser.tos_accepted): return HttpResponseRedirect(reverse('MHLogin.MHLogin_Main.views.terms_acceptance')) #if (not mhluser.billing_account_accepted): # return HttpResponseRedirect(reverse('MHLogin.Billing.views.billing_edit')) #if (not mhluser.email_confirmed): # pass user = getCurrentUserInfo(request) if user and user.needValidateContactInfo: return HttpResponseRedirect(reverse('MHLogin.Validates.views.validationPage')) # See if this user is a provider or broker. If so, make sure they have a doctorcom number if (user and user.needConfigureProvisionLocalNumber): return HttpResponseRedirect(reverse( 'MHLogin.DoctorCom.NumberProvisioner.views.provisionLocalNumber')) return None # An exception match should immediately return None for url in exceptions: if url.match(request.path): return None # Requests matching a restricted URL pattern are returned # wrapped with the login_required decorator for url in required: if url.match(request.path): return login_required(view_func)(request, *view_args, **view_kwargs) # Explicitly return None for all non-matching requests return None
def provisionLocalNumber(request): # basic checks to ensure that the user may request a new phone number here #user = user_is_provider(request.user) user = getCurrentUserInfo(request) if (not user or not user.needConfigureProvisionLocalNumber): return HttpResponseRedirect('/') context = get_context(request) context['ajaxPageURL'] = reverse('MHLogin.DoctorCom.NumberProvisioner.views.AJAX_provisionLocalNumber') return render_to_response('DoctorCom/NumberProvisioner/provision_number.html', context)
def set_practices_result(practices, request): current_user = getCurrentUserInfo(request) current_user_mobile = getCurrentUserMobile(current_user) if (practices): for practice in practices: has_manager = Office_Manager.active_objects.filter(practice__id=practice.id).exists() practice.has_manager = has_manager if current_user_mobile and settings.CALL_ENABLE: practice.call_available = bool(practice.practice_phone)\ or (practice.backline_phone) else: practice.call_available = False return practices
def set_practices_result(practices, request): current_user = getCurrentUserInfo(request) current_user_mobile = getCurrentUserMobile(current_user) if (practices): for practice in practices: has_manager = Office_Manager.active_objects.filter( practice__id=practice.id).exists() practice.has_manager = has_manager if current_user_mobile and settings.CALL_ENABLE: practice.call_available = bool(practice.practice_phone)\ or (practice.backline_phone) else: practice.call_available = False return practices
def AJAX_provisionLocalNumber(request): """ Displays and handles the form to provision a new number. This only returns an HTML snippet pertaining to phone number allocation. .. document private functions .. autofunction:: _removeNumberPoolNumber """ # basic checks to ensure that the user may request a new phone number here #user = user_is_provider(request.user) # /user/ gets used later for setting the mdcom phone value user = getCurrentUserInfo(request) if (not user or not user.needConfigureProvisionLocalNumber): return HttpResponseRedirect('/') context = get_context(request) if (settings.DEBUG): context['debug'] = True if (request.method == 'POST'): numberForm = LocalNumberForm(request.POST) if (numberForm.is_valid()): pin = request.POST['pin'] # LocalNumberForm, area_code, pin, mdcom_phone, mdcom_phone_sid mdcom_phone = numberForm.mdcom_phone mdcom_phone_sid = numberForm.mdcom_phone_sid user.mdcom_phone = mdcom_phone user.mdcom_phone_sid = mdcom_phone_sid #add doctorcom number if settings.CALL_ENABLE: user_type = ContentType.objects.get_for_model(user) config = VMBox_Config.objects.get(owner_type=user_type, owner_id=user.pk) config.change_pin(request, new_pin=pin) config.save() twilio_ConfigureProviderLocalNumber(user, user.mdcom_phone) user.save() context['new_number'] = "(%s) %s-%s" % (mdcom_phone[0:3], mdcom_phone[3:6], mdcom_phone[6:],) context['pin'] = pin return render_to_response('DoctorCom/NumberProvisioner/provision_complete.html', context) else: numberForm = LocalNumberForm() context['form'] = numberForm return render_to_response('DoctorCom/NumberProvisioner/local_number_form.html', context)
def process_view(self, request, view_func, view_args, view_kwargs): # No need to process URLs if user already logged in if request.user.is_authenticated(): for url in termsExceptions: if url.match(request.path): return None mhluser = MHLUser.objects.get(id=request.user.id) if (not mhluser.tos_accepted): return HttpResponseRedirect( reverse('MHLogin.MHLogin_Main.views.terms_acceptance')) #if (not mhluser.billing_account_accepted): # return HttpResponseRedirect(reverse('MHLogin.Billing.views.billing_edit')) #if (not mhluser.email_confirmed): # pass user = getCurrentUserInfo(request) if user and user.needValidateContactInfo: return HttpResponseRedirect( reverse('MHLogin.Validates.views.validationPage')) # See if this user is a provider or broker. If so, make sure they have a doctorcom number if (user and user.needConfigureProvisionLocalNumber): return HttpResponseRedirect( reverse( 'MHLogin.DoctorCom.NumberProvisioner.views.provisionLocalNumber' )) return None # An exception match should immediately return None for url in exceptions: if url.match(request.path): return None # Requests matching a restricted URL pattern are returned # wrapped with the login_required decorator for url in required: if url.match(request.path): return login_required(view_func)(request, *view_args, **view_kwargs) # Explicitly return None for all non-matching requests return None
def message_view(request, message_id, type): """Process message view request: :param request: The HTTP message view request :type request: django.core.handlers.wsgi.WSGIRequest :param message_id: The message id :type message_id: int :returns: django.http.HttpResponse -- the JSON result in an HttpResonse object :raises: None """ resolved = request.GET['resolved'] thread_uuid = Message.objects.get(uuid=message_id).thread_uuid msgs = MessageBodyUserStatus.objects.filter(user=request.user, delete_flag=False, msg_body__message__thread_uuid=thread_uuid).order_by( '-msg_body__message__send_timestamp').\ select_related('msg_body', 'msg_body__message', 'msg_body__message__sender')\ .extra(select={'sender_title':"SELECT MHLUsers_mhluser.title \ FROM MHLUsers_mhluser INNER JOIN Messaging_message ON \ MHLUsers_mhluser.user_ptr_id = Messaging_message.sender_id \ INNER JOIN Messaging_messagebody ON \ Messaging_message.id = Messaging_messagebody.message_id \ WHERE Messaging_messagebody.id = Messaging_messagebodyuserstatus.msg_body_id" }) if (resolved == ''): pass elif str(resolved).lower() in ("true"): msgs = msgs.filter(msg_body__message__in=[ m.msg_body.message for m in msgs if m.msg_body.message.resolved_by != None ]) else: msgs = msgs.filter(msg_body__message__in=[ m.msg_body.message for m in msgs if m.msg_body.message.resolved_by == None ]) msgs.select_related( 'msg_body', 'msg_body__message', 'msg_body__message__sender', ) msgs = list(msgs) context = get_context(request) user = request.session['MHL_Users']['MHLUser'] local_tz = getCurrentTimeZoneForUser( user, current_practice=context['current_practice']) is_received = type == 'received' current_user = getCurrentUserInfo(request) current_user_mobile = getCurrentUserMobile(current_user) call_enable = bool(current_user_mobile) and settings.CALL_ENABLE msgs_list = [] audio_list = [] for status_obj in msgs: try: read_flag = status_obj.read_flag body = decrypt_object(request, status_obj.msg_body) # TODO, this function need to refactor, when get threading message list, # don't need to decrypt every message body in the threading message. # When refactors, use following line while reading message body. # body = read_message(request, status_obj.msg_body) if not read_flag: status_obj.read_flag = read_flag status_obj.save() except KeyInvalidException: mail_admins( _('Message Body Decryption Error'), ''.join([('An error occurred decryption data for user '), request.user.username, (' on server '), settings.SERVER_ADDRESS, '.\n', ('Message ID: '), message_id])) callbacks = CallbackLog.objects.filter(message=status_obj.msg_body.message).\ order_by('time').values('time') callbacks = [{ 'timestamp': _get_system_time_as_tz(c['time'], local_tz).strftime('%m/%d/%y %H:%M'), 'caller_name': 'Joe Bloggs', 'caller_id': 123, } for c in callbacks] msg_cc_maps = MessageCC.objects.filter(message=status_obj.msg_body.message).\ select_related('user').extra(select={'title':'SELECT title FROM MHLUsers_mhluser \ WHERE MHLUsers_mhluser.user_ptr_id = Messaging_message_ccs.user_id' })\ .only('user__first_name', 'user__last_name', 'message') ccs = '; '.join([get_fullname_bystr(msg_cc_map.user.last_name,\ msg_cc_map.user.first_name,msg_cc_map.title)\ for msg_cc_map in msg_cc_maps]) msg_to_maps = MessageRecipient.objects.filter(message=status_obj.msg_body.message).\ select_related('user').extra(select={'title':'SELECT title FROM MHLUsers_mhluser \ WHERE MHLUsers_mhluser.user_ptr_id = Messaging_message_recipients.user_id' })\ .only('user__first_name', 'user__last_name', 'message') recipients = '; '.join([get_fullname_bystr(msg_to_map.user.last_name,\ msg_to_map.user.first_name,msg_to_map.title)\ for msg_to_map in msg_to_maps]) to_recipient_ids = [] msg_sender = status_obj.msg_body.message.sender msg_sender_id = None if msg_sender: msg_sender_id = msg_sender.id to_recipient_ids.append(str(msg_sender_id)) for rec in msg_to_maps: if rec.user.id != request.user.id: to_recipient_ids.append(str(rec.user.id)) cc_recipient_ids = [] for cc in msg_cc_maps: cc_recipient_ids.append(str(cc.user.id)) is_read = status_obj.read_flag user_id = request.user.id read_recipients = [ r.id for r in status_obj.msg_body.message.recipients.all() ] read_ccs = [c.id for c in status_obj.msg_body.message.ccs.all()] if not is_read: if is_received: if user_id not in read_recipients + read_ccs: is_read = True else: if msg_sender_id != request.user.id: is_read = True is_sender = request.user.id == msg_sender_id if is_received and (request.user.id == msg_sender_id and user_id in read_recipients + read_ccs): is_sender = False result = { 'id': status_obj.msg_body.message.uuid, 'sender': sender_name_safe(status_obj.msg_body.message, title=status_obj.sender_title), 'sender_id': msg_sender_id, 'thread_uuid': status_obj.msg_body.message.thread_uuid, 'timestamp': formatTimeSetting(user, status_obj.msg_body.message.send_timestamp, local_tz), 'subject': conditional_escape(status_obj.msg_body.message.subject), 'body': replace_number(status_obj.msg_body.clear_data, call_enable), 'answering_service': status_obj.msg_body.message.message_type == 'ANS', 'callback_number': replace_number(status_obj.msg_body.message.callback_number, call_enable), 'callbacks': callbacks, 'urgent': status_obj.msg_body.message.urgent, 'ccs': ccs, 'recipients': recipients, 'to_recipient_ids': ','.join(to_recipient_ids), 'cc_recipient_ids': ','.join(cc_recipient_ids), 'is_sender': is_sender, 'is_resolved': status_obj.msg_body.message.resolved_by != None, 'read': 'true' if is_read else '' } attachments = MessageAttachment.objects.filter( message=status_obj.msg_body.message) result["attachments"] = [] for att in attachments: attach_dict = { 'id': att.uuid, 'suffix': att.suffix, 'size': att.size, 'metadata': att.metadata, 'filename': att.decrypt_filename(request), 'msgId': status_obj.msg_body.message.uuid } result["attachments"].append(attach_dict) if att.suffix and att.suffix.lower() in ['mp3', 'wav']: audio_list.append(attach_dict) result["refer"] = _get_refer_from_mbus(status_obj, call_enable=call_enable) result["action_history"] = get_message_action_history( status_obj.msg_body.message.id, user, time_zone=local_tz) msgs_list.append(result) context['msgs'] = msgs_list context['audio_list'] = audio_list context['type'] = type return HttpResponse( render_to_string('DoctorCom/Messaging/MessageBody.html', context))
def message_view(request, message_id, type): """Process message view request: :param request: The HTTP message view request :type request: django.core.handlers.wsgi.WSGIRequest :param message_id: The message id :type message_id: int :returns: django.http.HttpResponse -- the JSON result in an HttpResonse object :raises: None """ resolved = request.GET['resolved'] thread_uuid = Message.objects.get(uuid=message_id).thread_uuid msgs = MessageBodyUserStatus.objects.filter(user=request.user, delete_flag=False, msg_body__message__thread_uuid=thread_uuid).order_by( '-msg_body__message__send_timestamp').\ select_related('msg_body', 'msg_body__message', 'msg_body__message__sender')\ .extra(select={'sender_title':"SELECT MHLUsers_mhluser.title \ FROM MHLUsers_mhluser INNER JOIN Messaging_message ON \ MHLUsers_mhluser.user_ptr_id = Messaging_message.sender_id \ INNER JOIN Messaging_messagebody ON \ Messaging_message.id = Messaging_messagebody.message_id \ WHERE Messaging_messagebody.id = Messaging_messagebodyuserstatus.msg_body_id"}) if (resolved == ''): pass elif str(resolved).lower() in ("true"): msgs = msgs.filter(msg_body__message__in=[m.msg_body.message for m in msgs if m.msg_body.message.resolved_by != None]) else: msgs = msgs.filter(msg_body__message__in=[m.msg_body.message for m in msgs if m.msg_body.message.resolved_by == None]) msgs.select_related('msg_body', 'msg_body__message', 'msg_body__message__sender',) msgs = list(msgs) context = get_context(request) user = request.session['MHL_Users']['MHLUser'] local_tz = getCurrentTimeZoneForUser(user, current_practice=context['current_practice']) is_received = type == 'received' current_user = getCurrentUserInfo(request) current_user_mobile = getCurrentUserMobile(current_user) call_enable = bool(current_user_mobile) and settings.CALL_ENABLE msgs_list = [] audio_list = [] for status_obj in msgs: try: read_flag = status_obj.read_flag body = decrypt_object(request, status_obj.msg_body) # TODO, this function need to refactor, when get threading message list, # don't need to decrypt every message body in the threading message. # When refactors, use following line while reading message body. # body = read_message(request, status_obj.msg_body) if not read_flag: status_obj.read_flag = read_flag status_obj.save() except KeyInvalidException: mail_admins(_('Message Body Decryption Error'), ''.join([ ('An error occurred decryption data for user '), request.user.username, (' on server '), settings.SERVER_ADDRESS, '.\n', ('Message ID: '), message_id ])) callbacks = CallbackLog.objects.filter(message=status_obj.msg_body.message).\ order_by('time').values('time') callbacks = [ { 'timestamp': _get_system_time_as_tz(c['time'], local_tz).strftime('%m/%d/%y %H:%M'), 'caller_name': 'Joe Bloggs', 'caller_id': 123, } for c in callbacks] msg_cc_maps = MessageCC.objects.filter(message=status_obj.msg_body.message).\ select_related('user').extra(select={'title':'SELECT title FROM MHLUsers_mhluser \ WHERE MHLUsers_mhluser.user_ptr_id = Messaging_message_ccs.user_id'})\ .only('user__first_name', 'user__last_name', 'message') ccs = '; '.join([get_fullname_bystr(msg_cc_map.user.last_name,\ msg_cc_map.user.first_name,msg_cc_map.title)\ for msg_cc_map in msg_cc_maps]) msg_to_maps = MessageRecipient.objects.filter(message=status_obj.msg_body.message).\ select_related('user').extra(select={'title':'SELECT title FROM MHLUsers_mhluser \ WHERE MHLUsers_mhluser.user_ptr_id = Messaging_message_recipients.user_id'})\ .only('user__first_name', 'user__last_name', 'message') recipients = '; '.join([get_fullname_bystr(msg_to_map.user.last_name,\ msg_to_map.user.first_name,msg_to_map.title)\ for msg_to_map in msg_to_maps]) to_recipient_ids = [] msg_sender = status_obj.msg_body.message.sender msg_sender_id = None if msg_sender: msg_sender_id = msg_sender.id to_recipient_ids.append(str(msg_sender_id)) for rec in msg_to_maps: if rec.user.id != request.user.id: to_recipient_ids.append(str(rec.user.id)) cc_recipient_ids = [] for cc in msg_cc_maps: cc_recipient_ids.append(str(cc.user.id)) is_read = status_obj.read_flag user_id = request.user.id read_recipients = [r.id for r in status_obj.msg_body.message.recipients.all()] read_ccs = [c.id for c in status_obj.msg_body.message.ccs.all()] if not is_read: if is_received: if user_id not in read_recipients + read_ccs: is_read = True else: if msg_sender_id != request.user.id: is_read = True is_sender = request.user.id == msg_sender_id if is_received and (request.user.id == msg_sender_id and user_id in read_recipients + read_ccs): is_sender = False result = { 'id':status_obj.msg_body.message.uuid, 'sender':sender_name_safe(status_obj.msg_body.message,title=status_obj.sender_title), 'sender_id':msg_sender_id, 'thread_uuid':status_obj.msg_body.message.thread_uuid, 'timestamp':formatTimeSetting(user, status_obj.msg_body.message.send_timestamp, local_tz), 'subject':conditional_escape(status_obj.msg_body.message.subject), 'body':replace_number(status_obj.msg_body.clear_data, call_enable), 'answering_service':status_obj.msg_body.message.message_type == 'ANS', 'callback_number': replace_number( status_obj.msg_body.message.callback_number, call_enable), 'callbacks': callbacks, 'urgent':status_obj.msg_body.message.urgent, 'ccs':ccs, 'recipients':recipients, 'to_recipient_ids':','.join(to_recipient_ids), 'cc_recipient_ids':','.join(cc_recipient_ids), 'is_sender':is_sender, 'is_resolved':status_obj.msg_body.message.resolved_by != None, 'read': 'true' if is_read else '' } attachments = MessageAttachment.objects.filter(message=status_obj.msg_body.message) result["attachments"] = [] for att in attachments: attach_dict = {'id': att.uuid, 'suffix': att.suffix, 'size': att.size, 'metadata': att.metadata, 'filename': att.decrypt_filename(request), 'msgId': status_obj.msg_body.message.uuid } result["attachments"].append(attach_dict) if att.suffix and att.suffix.lower() in ['mp3', 'wav']: audio_list.append(attach_dict) result["refer"] = _get_refer_from_mbus(status_obj, call_enable=call_enable) result["action_history"] = get_message_action_history( status_obj.msg_body.message.id, user, time_zone=local_tz) msgs_list.append(result) context['msgs'] = msgs_list context['audio_list'] = audio_list context['type'] = type return HttpResponse(render_to_string('DoctorCom/Messaging/MessageBody.html', context))