예제 #1
0
def _send_order_confirmation(service_user, lang, message_flow_run_id, member,
                             steps, end_id, end_message_flow_id,
                             parent_message_key, tag, result_key, flush_id,
                             flush_message_flow_id, service_identity,
                             user_details, order_details):
    if now() - steps[-1].acknowledged_timestamp < 10:
        alert_flags = Message.ALERT_FLAG_SILENT
    else:
        alert_flags = Message.ALERT_FLAG_VIBRATE

    users.set_user(service_user)
    try:
        messaging.send(
            parent_key=parent_message_key,
            parent_message_key=parent_message_key,
            message=u'%s\n\n%s:\n%s' %
            (translate(lang, SOLUTION_COMMON, u'order_complete_will_notify'),
             translate(lang, SOLUTION_COMMON, u'usage-detail'), order_details),
            answers=list(),
            flags=Message.FLAG_ALLOW_DISMISS | Message.FLAG_AUTO_LOCK,
            members=[
                MemberTO.from_user(user_details[0].toAppUser(), alert_flags)
            ],
            branding=get_solution_main_branding(service_user).branding_key,
            tag=None,
            service_identity=service_identity,
            alert_flags=alert_flags,
            step_id=u'order_complete')
    finally:
        users.clear_user()
예제 #2
0
def broadcast_group_purchase(service_user, service_identity, group_purchase_id,
                             message):
    service_identity_user = create_service_identity_user_wo_default(
        service_user, service_identity)
    sln_settings = get_solution_settings(service_user)
    sgp = SolutionGroupPurchase.get_by_id(
        group_purchase_id,
        parent_key_unsafe(service_identity_user, sln_settings.solution))

    sln_main_branding = get_solution_main_branding(service_user)
    branding = sln_main_branding.branding_key if sln_main_branding else None

    members = dict()
    for e in sgp.subscriptions:
        if e.sender:
            member = MemberTO()
            member.alert_flags = Message.ALERT_FLAG_VIBRATE
            member.member = e.sender.email
            member.app_id = e.sender.app_id
            members["%s:%s" % (member.member, member.app_id)] = member

    if members:
        messaging.send(parent_key=None,
                       parent_message_key=None,
                       message=message,
                       answers=[],
                       flags=Message.FLAG_ALLOW_DISMISS,
                       members=members.values(),
                       branding=branding,
                       tag=None,
                       service_identity=service_identity)
예제 #3
0
def test_form(service_user, form_id, testers):
    # type: (users.User, int, list[users.User]) -> None
    form = get_form(form_id, service_user)
    request = TestFormRequestTO(id=form_id, version=form.version)
    to_put = []
    prof = get_service_profile(service_user)
    branding = prof.broadcastBranding
    caption = localize(prof.defaultLanguage, 'forms.test_form')
    answers = [AnswerTO(id_=u'test',
                        caption=caption,
                        action=u'form://%d?version=%d&test=true' % (form_id, form.version))]
    flags = Message.FLAG_AUTO_LOCK
    alert_flags = Message.ALERT_FLAG_VIBRATE
    tag = None
    message = localize(prof.defaultLanguage, 'forms.click_button_to_test')
    for user_profile in get_profile_infos(testers):
        mobiles = db.get([get_mobile_key_by_account(mobile_detail.account) for mobile_detail in user_profile.mobiles])
        has_other = False
        android_mobile = None
        for mobile in mobiles:
            if mobile.is_android:
                android_mobile = mobile
            else:
                has_other = True
        if has_other:
            messaging.send(None, None, message, answers, flags, [MemberTO.from_user(user_profile.user)], branding, tag,
                           alert_flags=alert_flags)
        else:
            title = localize(prof.defaultLanguage, 'forms.test_form_x', title=form.title)
            body = localize(prof.defaultLanguage, 'forms.click_to_test_your_form')
            kwargs = {CAPI_KEYWORD_PUSH_DATA: TestFormNotification(title, body, form.id, form.version)}
            to_put.extend(testForm(test_form_response_handler, logError, user_profile.user, request=request,
                                   MOBILE_ACCOUNT=android_mobile, DO_NOT_SAVE_RPCCALL_OBJECTS=True, **kwargs))
    db.put(to_put)
예제 #4
0
def send_expired_voucher_message(voucher_key, sln_settings, days):
    voucher = SolutionCityVoucher.get(voucher_key)
    if not voucher or days in voucher.expiration_reminders_sent:
        return

    language = sln_settings.main_language
    service_user = sln_settings.service_user
    branding = get_solution_main_branding(service_user).branding_key

    if voucher.owner:
        activation_date = format_timestamp(voucher.activation_date,
                                           sln_settings,
                                           format='medium')
        message = common_translate(language,
                                   SOLUTION_COMMON,
                                   u'voucher_expiration_message',
                                   days=days,
                                   date=activation_date)
        with users.set_user(sln_settings.service_user):
            member = MemberTO()
            member.alert_flags = Message.ALERT_FLAG_VIBRATE
            member.member = voucher.owner.email()
            member.app_id = voucher.app_id
            messaging.send(parent_key=None,
                           parent_message_key=None,
                           message=message,
                           answers=[],
                           flags=Message.FLAG_ALLOW_DISMISS,
                           members=[member],
                           branding=branding,
                           tag=None)

        voucher.expiration_reminders_sent.append(days)
        db.put(voucher)
예제 #5
0
def send_message_for_pharmacy_order(service_user, order_key, order_status, message):
    from solutions.common.bizz.messaging import send_inbox_forwarders_message

    azzert(order_status in SolutionPharmacyOrder.ORDER_STATUSES)

    def txn():
        m = SolutionPharmacyOrder.get(order_key)
        azzert(service_user == m.service_user)
        if m.status == SolutionPharmacyOrder.STATUS_RECEIVED and m.status != order_status:
            m.status = order_status
            m.put()
        return m
    order = db.run_in_transaction(txn)

    sm_data = []
    sm_data.append({u"type": u"solutions.common.pharmacy_orders.update"})

    sln_settings = get_solution_settings(service_user)
    if message:
        if order.solution_inbox_message_key:
            sim_parent, _ = add_solution_inbox_message(
                service_user, order.solution_inbox_message_key, True, None, now(), message, mark_as_unread=False, mark_as_read=True)
            send_inbox_forwarders_message(service_user, sim_parent.service_identity, None, message, {
                'if_name': sim_parent.sender.name,
                'if_email': sim_parent.sender.email
            }, message_key=sim_parent.solution_inbox_message_key, reply_enabled=sim_parent.reply_enabled)
            sln_i_settings = get_solution_settings_or_identity_settings(sln_settings, order.service_identity)
            sm_data.append({u"type": u"solutions.common.messaging.update",
                            u"message": serialize_complex_value(SolutionInboxMessageTO.fromModel(sim_parent, sln_settings, sln_i_settings, True), SolutionInboxMessageTO, False)})
        else:
            sln_main_branding = get_solution_main_branding(service_user)
            branding = sln_main_branding.branding_key if sln_main_branding else None

            member = MemberTO()
            member.alert_flags = Message.ALERT_FLAG_VIBRATE
            member.member = order.sender.email
            member.app_id = order.sender.app_id

            messaging.send(parent_key=None,
                           parent_message_key=None,
                           message=message,
                           answers=[],
                           flags=Message.FLAG_ALLOW_DISMISS,
                           members=[member],
                           branding=branding,
                           tag=None,
                           service_identity=order.service_identity)

    elif order.solution_inbox_message_key:
        sim_parent = SolutionInboxMessage.get(order.solution_inbox_message_key)
        if not sim_parent.read:
            sim_parent.read = True
            sim_parent.put()
            deferred.defer(update_user_data_admins, service_user, order.service_identity)
        sln_i_settings = get_solution_settings_or_identity_settings(sln_settings, order.service_identity)
        sm_data.append({u"type": u"solutions.common.messaging.update",
                        u"message": serialize_complex_value(SolutionInboxMessageTO.fromModel(sim_parent, sln_settings, sln_i_settings, True), SolutionInboxMessageTO, False)})

    send_message(service_user, sm_data, service_identity=order.service_identity)
예제 #6
0
def delete_sandwich_order(service_user, service_identity, sandwich_id, message):
    from solutions.common.bizz.messaging import send_inbox_forwarders_message

    sln_settings = get_solution_settings(service_user)

    def txn():
        m = SandwichOrder.get_by_order_id(service_user, service_identity, sln_settings.solution, sandwich_id)
        azzert(service_user == m.service_user)
        m.deleted = True
        m.put()
        return m

    xg_on = db.create_transaction_options(xg=True)
    sandwich_order = db.run_in_transaction_options(xg_on, txn)

    sm_data = [{u"type": u"solutions.common.sandwich.orders.deleted", u'sandwich_id': sandwich_id}]

    if message:
        if sandwich_order.solution_inbox_message_key:
            sim_parent, _ = add_solution_inbox_message(service_user, sandwich_order.solution_inbox_message_key, True, None, now(), message, mark_as_unread=False, mark_as_read=True, mark_as_trashed=True)
            send_inbox_forwarders_message(service_user, sim_parent.service_identity, None, message, {
                        'if_name': sim_parent.sender.name,
                        'if_email':sim_parent.sender.email
                    }, message_key=sim_parent.solution_inbox_message_key, reply_enabled=sim_parent.reply_enabled)
            sln_i_settings = get_solution_settings_or_identity_settings(sln_settings, sandwich_order.service_identity)
            sm_data.append({u"type": u"solutions.common.messaging.update",
                         u"message": serialize_complex_value(SolutionInboxMessageTO.fromModel(sim_parent, sln_settings, sln_i_settings, True), SolutionInboxMessageTO, False)})

        else:
            branding = get_solution_main_branding(service_user).branding_key
            member = MemberTO()
            member.alert_flags = Message.ALERT_FLAG_VIBRATE
            member.member = sandwich_order.sender.email
            member.app_id = sandwich_order.sender.app_id

            messaging.send(parent_key=None,
                           parent_message_key=None,
                           message=message,
                           answers=[],
                           flags=Message.FLAG_ALLOW_DISMISS,
                           members=[member],
                           branding=branding,
                           tag=None,
                           service_identity=sandwich_order.service_identity)

    elif sandwich_order.solution_inbox_message_key:
        sim_parent = SolutionInboxMessage.get(sandwich_order.solution_inbox_message_key)
        if not sim_parent.trashed and not sim_parent.deleted:
            sim_parent.trashed = True
            sim_parent.put()
            deferred.defer(update_user_data_admins, service_user, sandwich_order.service_identity)
        sln_i_settings = get_solution_settings_or_identity_settings(sln_settings, sandwich_order.service_identity)
        sm_data.append({u"type": u"solutions.common.messaging.update",
                     u"message": serialize_complex_value(SolutionInboxMessageTO.fromModel(sim_parent, sln_settings, sln_i_settings, True), SolutionInboxMessageTO, False)})

    send_message(service_user, sm_data, service_identity=sandwich_order.service_identity)
예제 #7
0
def _process_event_reminder(reminder_key):
    reminder = EventReminder.get(reminder_key)

    service_user = reminder.service_user
    settings = get_solution_settings(service_user)
    event = Event.get_by_id(reminder.event_id,
                            parent_key(service_user, settings.solution))

    if event and reminder.event_start_epoch in event.start_dates:
        now_ = now()
        if (now_ +
                reminder.remind_before) > (reminder.event_start_epoch +
                                           timezone_offset(settings.timezone)):
            if event.place:
                place = "\n@ " + event.place + "\n"
            else:
                place = ""

            dt = datetime.datetime.fromtimestamp(reminder.event_start_epoch)
            language = settings.main_language or DEFAULT_LANGUAGE
            when = "%s, %s" % (format_date(dt, format='full', locale=language),
                               format_time(dt, format='short',
                                           locale=language))
            reminderMessage = "Reminder:\n\nTitle:\n%s\n\nWhen:\n%s\n%s\nDescription:\n%s" % (
                event.title, when, place, event.description)
            main_branding = get_solution_main_branding(service_user)

            human_user = get_human_user_from_app_user(reminder.human_user)
            members = list()
            members.append(human_user.email())
            users.set_user(reminder.service_user)
            try:
                messaging.send(parent_key=None,
                               parent_message_key=None,
                               message=reminderMessage,
                               answers=[],
                               flags=Message.FLAG_ALLOW_DISMISS,
                               members=members,
                               branding=main_branding.branding_key,
                               tag=None,
                               service_identity=reminder.service_identity)
            finally:
                users.clear_user()

            reminder.status = EventReminder.STATUS_REMINDED
            reminder.put()
    else:
        reminder.status = EventReminder.STATUS_REMINDED
        reminder.put()
예제 #8
0
def reply_sandwich_order(service_user, service_identity, sandwich_id, message=unicode):
    from solutions.common.bizz.messaging import send_inbox_forwarders_message

    sln_settings = get_solution_settings(service_user)
    sandwich_order = SandwichOrder.get_by_order_id(service_user, service_identity, sln_settings.solution, sandwich_id)
    azzert(service_user == sandwich_order.service_user)
    sandwich_order.status = SandwichOrder.STATUS_REPLIED
    sandwich_order.put()

    sm_data = []
    sm_data.append({u"type": u"solutions.common.sandwich.orders.update"})

    if sandwich_order.solution_inbox_message_key:
        sim_parent, _ = add_solution_inbox_message(service_user, sandwich_order.solution_inbox_message_key, True, None, now(), message, mark_as_unread=False, mark_as_read=True)
        send_inbox_forwarders_message(service_user, sim_parent.service_identity, None, message, {
                    'if_name': sim_parent.sender.name,
                    'if_email':sim_parent.sender.email
                }, message_key=sim_parent.solution_inbox_message_key, reply_enabled=sim_parent.reply_enabled)
        sln_i_settings = get_solution_settings_or_identity_settings(sln_settings, sandwich_order.service_identity)
        sm_data.append({u"type": u"solutions.common.messaging.update",
                     u"message": serialize_complex_value(SolutionInboxMessageTO.fromModel(sim_parent, sln_settings, sln_i_settings, True), SolutionInboxMessageTO, False)})
    else:
        sln_main_branding = get_solution_main_branding(service_user)
        branding = sln_main_branding.branding_key if sln_main_branding else None

        member = MemberTO()
        member.alert_flags = Message.ALERT_FLAG_VIBRATE
        member.member = sandwich_order.sender.email
        member.app_id = sandwich_order.sender.app_id

        messaging.send(parent_key=None,
                       parent_message_key=None,
                       message=message,
                       answers=[],
                       flags=Message.FLAG_ALLOW_DISMISS,
                       members=[member],
                       branding=branding,
                       tag=None,
                       service_identity=sandwich_order.service_identity)

    send_message(service_user, sm_data, service_identity=sandwich_order.service_identity)
    def testServiceIdentities(self):
        from rogerthat.service.api.messaging import send

        legacy_svc_identity_user = users.User(u"*****@*****.**")

        create_service_profile(legacy_svc_identity_user, legacy_svc_identity_user.email())
        assert is_service_identity_user(legacy_svc_identity_user)
        set_current_user(legacy_svc_identity_user)

        geert = users.User(u"*****@*****.**")

        create_user_profile(geert, geert.email())

        # Send message
        message = u"De kat krabt de krollen van de trap!"
        self.assertRaises(CanOnlySendToFriendsException, send, parent_key=None, message=message, answers=[], flags=1,
                          members=[u'*****@*****.**'], branding=None, tag=None, accept_missing=None)

        self.assertRaises(CanOnlySendToFriendsException, send, parent_message_key=None, message=message, answers=[], flags=1,
                          members=[u'*****@*****.**'], branding=None, tag=None, accept_missing=None)

        self.assertRaises(MissingArgumentException, send, message=message, answers=[], flags=1, members=[u'*****@*****.**'],
                          branding=None, tag=None, accept_missing=None)

        makeFriends(legacy_svc_identity_user, geert, None, None, None, False, False)

        send(parent_key=None, message=message, answers=[], flags=1,
                          members=[u'*****@*****.**'], branding=None, tag=None, accept_missing=None)

        send(parent_key=None, message=message, answers=[], flags=1,
                          members=[u'*****@*****.**'], branding=None, tag=None, accept_missing=None, service_identity=None)

        send(parent_key=None, message=message, answers=[], flags=1,
                          members=[u'*****@*****.**'], branding=None, tag=None, accept_missing=None, service_identity='')

        send(parent_key=None, message=message, answers=[], flags=1,
                          members=[u'*****@*****.**'], branding=None, tag=None, accept_missing=None, service_identity=ServiceIdentity.DEFAULT)

        breakFriendShip(geert, legacy_svc_identity_user)


        makeFriends(geert, legacy_svc_identity_user, None, None, None, False, False)

        send(parent_key=None, message=message, answers=[], flags=1,
                          members=[u'*****@*****.**'], branding=None, tag=None, accept_missing=None)

        send(parent_key=None, message=message, answers=[], flags=1,
                          members=[u'*****@*****.**'], branding=None, tag=None, accept_missing=None, service_identity=None)

        send(parent_key=None, message=message, answers=[], flags=1,
                          members=[u'*****@*****.**'], branding=None, tag=None, accept_missing=None, service_identity='')

        send(parent_key=None, message=message, answers=[], flags=1,
                          members=[u'*****@*****.**'], branding=None, tag=None, accept_missing=None, service_identity=ServiceIdentity.DEFAULT)

        breakFriendShip(legacy_svc_identity_user, geert)


        self.assertRaises(CanOnlySendToFriendsException, send, parent_key=None, message=message, answers=[], flags=1,
                          members=[u'*****@*****.**'], branding=None, tag=None, accept_missing=None)


        svc_identity_user = users.User(u"[email protected]/+default+")


        makeFriends(svc_identity_user, geert, None, None, None, False, False)

        send(parent_key=None, message=message, answers=[], flags=1,
                          members=[u'*****@*****.**'], branding=None, tag=None, accept_missing=None)

        breakFriendShip(svc_identity_user, geert)


        makeFriends(geert, svc_identity_user, None, None, None, False, False)

        send(parent_key=None, message=message, answers=[], flags=1,
                          members=[u'*****@*****.**'], branding=None, tag=None, accept_missing=None)

        breakFriendShip(geert, svc_identity_user)

        svc_user = users.User(u'*****@*****.**')
        svc_identity_user2 = create_service_identity_user(svc_user, 'subservice')

        to = ServiceIdentityDetailsTO()
        to.app_data = None
        to.identifier = u'subservice'
        to.name = u'Sub service'
        to.created = 100000
        to.qualified_identifier = to.description = to.description_branding = to.menu_branding = to.phone_number = \
            to.phone_call_popup = to.search_config = to.home_branding_hash = None
        to.admin_emails = list()
        to.recommend_enabled = False
        to.description_use_default = to.description_branding_use_default = to.menu_branding_use_default = \
            to.phone_number_use_default = to.phone_call_popup_use_default = to.search_use_default = \
            to.email_statistics_use_default = to.app_ids_use_default = to.home_branding_use_default = False
        to.email_statistics = False
        to.app_ids = list()
        to.content_branding_hash = None
        create_service_identity(svc_user, to)
        assert is_service_identity_user(svc_identity_user2)

        makeFriends(geert, svc_identity_user2, None, None, None, False, False)
        breakFriendShip(geert, svc_identity_user2)
        makeFriends(svc_identity_user2, geert, None, None, None, False, False)
        breakFriendShip(svc_identity_user2, geert)

        self.assertRaises(CanOnlySendToFriendsException, send, parent_key=None, message=message, answers=[], flags=1,
                          members=[u'*****@*****.**'], branding=None, tag=None, accept_missing=None, service_identity='subservice')

        makeFriends(geert, svc_identity_user, None, None, None, False, False)

        self.assertRaises(CanOnlySendToFriendsException, send, parent_key=None, message=message, answers=[], flags=1,
                          members=[u'*****@*****.**'], branding=None, tag=None, accept_missing=None, service_identity='subservice')

        makeFriends(geert, svc_identity_user2, None, None, None, False, False)

        send(parent_key=None, message=message, answers=[], flags=1,
                          members=[u'*****@*****.**'], branding=None, tag=None, accept_missing=None, service_identity='subservice')

        breakFriendShip(geert, svc_identity_user)

        send(parent_key=None, message=message, answers=[], flags=1,
                          members=[u'*****@*****.**'], branding=None, tag=None, accept_missing=None, service_identity='subservice')

        self.assertRaises(CanOnlySendToFriendsException, send, parent_key=None, message=message, answers=[], flags=1,
                          members=[u'*****@*****.**'], branding=None, tag=None, accept_missing=None, service_identity=None)

        breakFriendShip(geert, svc_identity_user2)

        breakFriendShip(geert, svc_identity_user)  # No error when breaking again

        breakFriendShip(geert, svc_identity_user2)  # No error when breaking again
예제 #10
0
                            reason=e.message)
    except:
        logging.error("Failure when adding new group_purchase subscription",
                      exc_info=1)
        r.result = None
        r.error = u"An unknown error occurred"
        sgp = SolutionGroupPurchase.get_by_id(
            group_purchase_id,
            parent_key_unsafe(service_identity_user, sln_settings.solution))
        message = translate(sln_settings.main_language,
                            SOLUTION_COMMON,
                            'group-subscription-failure-unknown-title',
                            title=sgp.title)

    member = MemberTO()
    member.alert_flags = Message.ALERT_FLAG_VIBRATE
    member.member = user_details[0].email
    member.app_id = user_details[0].app_id

    main_branding = get_solution_main_branding(service_user)
    messaging.send(parent_key=None,
                   parent_message_key=None,
                   message=message,
                   answers=[],
                   flags=Message.FLAG_ALLOW_DISMISS,
                   members=[member],
                   branding=main_branding.branding_key,
                   tag=None,
                   service_identity=service_identity)
    return r