Example #1
0
def solution_coupon_resolve(service_user, email, method, params, tag,
                            service_identity, user_details):
    data = json.loads(params)
    coupon_id = data.get('coupon_id')
    redeeming_user = users.User(data.get('redeeming_user'))
    response = SendApiCallCallbackResultTO()
    service_identity_user = get_and_validate_service_identity_user(
        service_user, service_identity)
    try:
        coupon = get_and_validate_news_coupon(coupon_id, service_identity_user,
                                              redeeming_user)
        response.result = u'%s' % json.dumps(
            serialize_complex_value(coupon, NewsCouponTO, False))
    except NewsCouponNotFoundException:
        lang = get_solution_settings(service_user).main_language
        response.error = t(lang, 'coupon_not_found')
    except NewsCouponAlreadyUsedException:
        lang = get_solution_settings(service_user).main_language
        response.error = t(lang, 'you_have_already_used_this_coupon')
        user, app_id = get_app_user_tuple(redeeming_user)
        member = BaseMemberTO(user.email(), app_id)
        disable_news_with_coupon(coupon_id, service_identity_user, member)
    except Exception as exception:
        logging.exception(exception)
        lang = get_solution_settings(service_user).main_language
        response.error = t(lang, 'error-occured-unknown')
    return response
Example #2
0
def delete_appointment_weekday_timeframe(service_user, appointment_id):
    sln_settings = get_solution_settings(service_user)
    sawt = SolutionAppointmentWeekdayTimeframe.get_by_id(appointment_id, parent_key(service_user, sln_settings.solution))
    if sawt:
        sawt.delete()
        sln_settings = get_solution_settings(service_user)
        sln_settings.updates_pending = True
        put_and_invalidate_cache(sln_settings)

        broadcast_updates_pending(sln_settings)
        send_message(service_user, u"solutions.common.appointment.settings.timeframe.update")
Example #3
0
    def _test_dynamic_flex_service(self, language):
        self.set_datastore_hr_probability(1)

        print 'Test %s service creation with all modules' % language
        email = u'*****@*****.**'
        r = create_flex_service(email,
                                name="test",
                                address="Antwerpsesteenweg 19\n9080 Lochristi",
                                phone_number="+32 9 324 25 64",
                                languages=[language],
                                currency=u"€",
                                modules=SolutionModule.visible_modules(),
                                broadcast_types=['test1', 'test2', 'test3'],
                                apps=[a.app_id for a in App.all()],
                                allow_redeploy=False,
                                organization_type=random.choice([
                                    x for x in OrganizationType.all() if x > 0
                                ]))

        service_user = users.User(r.login)
        set_current_user(service_user)

        print 'Setting order type to advanced'
        _put_default_menu(service_user)

        sln_settings = get_solution_settings(service_user)
        sln_order_settings = SolutionOrderSettings(
            key=SolutionOrderSettings.create_key(service_user))
        sln_order_settings.text_1 = 'text_1'
        sln_order_settings.order_type = SolutionOrderSettings.TYPE_ADVANCED
        sln_order_settings.leap_time = 1
        sln_order_settings.leap_time_type = 86400
        sln_order_settings.put()
        SolutionOrderWeekdayTimeframe.create_default_timeframes_if_nessecary(
            service_user, sln_settings.solution)

        print 'Test provisioning of all modules'
        common_provision(service_user)

        print 'Test rendering the home page'
        FlexHomeHandler({}, webapp2.Response()).get()

        print 'Test deletion of all modules'
        solution_settings = get_solution_settings(service_user)
        solution_settings.modules = []
        solution_settings.put()
        common_provision(service_user)

        print 'Test rendering the home page'
        FlexHomeHandler({}, webapp2.Response()).get()
Example #4
0
def get_service(service_email):
    city_service_user = users.get_current_user()
    city_customer = get_customer(city_service_user)
    service_user = users.User(email=service_email)
    customer = Customer.get_by_service_email(service_email)
    if not city_customer.can_edit_service(customer):
        logging.warn(u'Service %s tried to save service information for customer %d', city_service_user, customer.id)
        lang = get_solution_settings(city_service_user).main_language
        return ReturnStatusTO.create(False, translate(lang, SOLUTION_COMMON, 'no_permission'))
    contact = Contact.get_one(customer.key())
    solution_settings = get_solution_settings(service_user)
    return ServiceTO(customer.id, customer.name, customer.address1, customer.address2, customer.zip_code, customer.city,
                     customer.user_email, contact.phone_number, solution_settings.main_language,
                     solution_settings.modules, solution_settings.broadcast_types, customer.organization_type,
                     customer.vat, customer.website, customer.facebook_page)
Example #5
0
def set_service_disabled(customer_or_id, disabled_reason_int):
    """
    Disables the customer his service, disconnects all users and sets the service invisible.

    Args:
        customer_or_id (int, long, Customer): customer or id
        disabled_reason_int (int, long): reason why the service has been disabled

    Raises:
        NoSubscriptionException
        BusinessException
    """
    if isinstance(customer_or_id, Customer):
        customer = customer_or_id
    else:
        customer = Customer.get_by_id(customer_or_id)

    if not customer.service_email:
        raise NoSubscriptionException(customer)
    if disabled_reason_int not in Customer.DISABLED_REASONS:
        raise BusinessException('Invalid disable service reason')

    service_user = users.User(customer.service_email)
    sln_settings = get_solution_settings(service_user)
    customer.default_app_id = None
    customer.app_ids = []
    customer.service_disabled_at = now()
    customer.disabled_reason_int = disabled_reason_int
    customer.subscription_cancel_pending_date = 0
    sln_settings.search_enabled = False
    sln_settings.service_disabled = True
    db.put([customer, sln_settings])

    rogerthat_set_service_disabled(service_user)
Example #6
0
        def trans(loyalty_type):
            sln_settings = get_solution_settings(service_user)
            if SolutionModule.HIDDEN_CITY_WIDE_LOTTERY in sln_settings.modules:
                loyalty_type = SolutionLoyaltySettings.LOYALTY_TYPE_CITY_WIDE_LOTTERY
            sln_settings.updates_pending = True

            sln_loyalty_settings = SolutionLoyaltySettings.get_by_user(service_user)

            if sln_loyalty_settings.loyalty_type != loyalty_type:
                sln_loyalty_settings.branding_key = None
                sln_settings.loyalty_branding_hash = None
                sln_loyalty_settings.loyalty_type = loyalty_type

            if sln_loyalty_settings.website != loyalty_website:
                sln_loyalty_settings.modification_time = now()

            sln_loyalty_settings.website = loyalty_website

            if loyalty_type == SolutionLoyaltySettings.LOYALTY_TYPE_REVENUE_DISCOUNT:
                sln_loyalty_settings.x_visits = loyalty_settings.x_visits
                sln_loyalty_settings.x_discount = loyalty_settings.x_discount
            elif loyalty_type == SolutionLoyaltySettings.LOYALTY_TYPE_STAMPS:
                sln_loyalty_settings.x_stamps = loyalty_settings.x_stamps
                sln_loyalty_settings.stamps_type = loyalty_settings.stamps_type
                sln_loyalty_settings.stamps_winnings = loyalty_settings.stamps_winnings
                sln_loyalty_settings.stamps_auto_redeem = loyalty_settings.stamps_auto_redeem

            put_and_invalidate_cache(sln_loyalty_settings, sln_settings)
            return sln_settings
Example #7
0
    def get(self):
        customer_id = int(self.request.get("customer_id"))
        try:
            customer = Customer.get_by_id(customer_id)
        except CustomerNotFoundException:
            self.abort(404)

        current_user = users.get_current_user()
        current_customer = get_customer(current_user)
        sln_settings = get_solution_settings(current_user)
        if not sln_settings.can_edit_services(
                current_customer) or not current_customer.can_edit_service(
                    customer):
            logging.warn(
                'Service or user %s is trying to login to the dashboard of %s',
                current_user.email(), customer.name)
            self.abort(401)

        service_identity_user = create_service_identity_user(
            users.User(customer.service_email))
        current_session = users.get_current_session()
        new_secret, new_session = create_session(service_identity_user,
                                                 ignore_expiration=True)
        set_cookie(self.response,
                   get_server_settings().cookieSessionName, new_secret)
        new_session = switch_to_service_identity(new_session,
                                                 service_identity_user,
                                                 read_only=False,
                                                 shop=current_session.shop,
                                                 layout_only=True)
        new_session.parent_session_secret = current_session.secret
        new_session.put()
        self.redirect("/")
Example #8
0
def is_in_holiday(service_user, service_identity, date):
    if is_default_service_identity(service_identity):
        sln_i_settings = get_solution_settings(service_user)
    else:
        sln_i_settings = get_solution_identity_settings(
            service_user, service_identity)
    return sln_i_settings.is_in_holiday_for_date(date)
Example #9
0
def solution_calendar_broadcast(service_user, email, method, params, tag,
                                service_identity, user_details):
    from solutions.common.bizz.messaging import broadcast_send
    sln_settings = get_solution_settings(service_user)

    jsondata = json.loads(params)

    calendar_id = long(jsondata['calendarId'])
    message = jsondata['message']

    sc = SolutionCalendar.get_by_id(
        calendar_id, parent_key(service_user, sln_settings.solution))
    r = SendApiCallCallbackResultTO()
    if sc:
        broadcast_type = translate(sln_settings.main_language,
                                   SOLUTION_COMMON,
                                   u'calendar-broadcast-type',
                                   name=sc.name)
        broadcast_send(service_user,
                       service_identity,
                       broadcast_type,
                       message,
                       broadcast_on_facebook=False,
                       broadcast_on_twitter=False,
                       broadcast_to_all_locations=True)
        r.result = u"successfully broadcast"
    else:
        r.result = u"Calendar not found. Broadcast failed."
    r.error = None
    return r
Example #10
0
    def trans():
        sln_settings = get_solution_settings(service_user)
        new_coords = map(int, [
            static_content.position.x, static_content.position.y,
            static_content.position.z
        ])
        if static_content.id is MISSING or static_content.id is None:
            sc = SolutionStaticContent(parent=parent_key(
                service_user, SOLUTION_COMMON),
                                       deleted=False)
            sc.old_coords = new_coords
        else:
            sc = SolutionStaticContent.get(
                SolutionStaticContent.create_key(service_user,
                                                 static_content.id))
            if sc.old_coords != new_coords and sc.provisioned:
                sc.old_coords = sc.coords
        sc.icon_label = static_content.icon_label
        sc.icon_name = static_content.icon_name
        if static_content.sc_type == SolutionStaticContent.TYPE_OWN:
            sc.text_color = static_content.text_color
            sc.background_color = static_content.background_color
            sc.html_content = static_content.html_content
            sc.branding_hash = branding_hash
        elif static_content.sc_type == SolutionStaticContent.TYPE_WEBSITE:
            sc.website = static_content.website
        sc.sc_type = static_content.sc_type
        sc.visible = static_content.visible
        sc.provisioned = False
        sc.coords = new_coords
        sc.put()

        sln_settings.updates_pending = True
        put_and_invalidate_cache(sc, sln_settings)
        return sln_settings
Example #11
0
def can_edit_city_postal_codes():
    service_user = users.get_current_user()
    sln_settings = get_solution_settings(service_user)
    if SolutionModule.CITY_APP not in sln_settings.modules:
        raise BusinessException(common_translate(sln_settings.main_language,
                                                 SOLUTION_COMMON, u'insufficient-permissions'))
    return sln_settings
 def trans():
     sln_loyalty_settings = db.get(sls_key)
     sln_loyalty_settings.modification_time = now()
     sln_loyalty_settings.put()
     sln_settings = get_solution_settings(sln_loyalty_settings.service_user)
     if not sln_settings.updates_pending:
         deferred.defer(_set_content_branding, sln_settings, _transactional=True)
Example #13
0
def uitdatabank_check_cityapp_settings():
    service_user = users.get_current_user()

    cap = get_cityapp_profile(service_user)
    sln_settings = get_solution_settings(service_user)
    try:
        success, result = get_uitdatabank_events(cap, 1, 50)
        if not success:
            try:
                result = translate(sln_settings.main_language, SOLUTION_COMMON,
                                   result)
            except ValueError:
                pass
    except Exception:
        logging.debug('Failed to check uitdatabank.be settings: %s',
                      dict(key=cap.uitdatabank_key,
                           regions=cap.uitdatabank_regions),
                      exc_info=1)
        success, result = False, translate(sln_settings.main_language,
                                           SOLUTION_COMMON,
                                           'error-occured-unknown-try-again')

    def trans():
        cap = get_cityapp_profile(service_user)
        if success:
            cap.uitdatabank_enabled = True
            cap.put()
            return RETURNSTATUS_TO_SUCCESS

        cap.uitdatabank_enabled = False
        cap.put()
        return ReturnStatusTO.create(False, result)

    return db.run_in_transaction(trans)
Example #14
0
def add_city_wide_lottery_info(city_app_id, winnings, date, x_winners):
    service_user = users.get_current_user()
    sln_settings = get_solution_settings(service_user)
    try:
        now_ = now()
        end_timestamp = date.toEpoch()
        if end_timestamp <= (now_ + 24 * 3600):
            raise BusinessException("end-date-24h-in-future")

        ll_info = SolutionCityWideLottery.load_pending(city_app_id)
        if ll_info:
            logging.warn("end_timestamp: %s", end_timestamp)
            logging.warn("ll_info.end_timestamp: %s", ll_info.end_timestamp)
            if end_timestamp <= ll_info.end_timestamp:
                raise BusinessException("lottery-time-bigger-first-upcoming")

        ll_info = SolutionCityWideLottery(parent=SolutionCityWideLottery.create_parent_key(city_app_id))
        ll_info.timestamp = now_
        ll_info.end_timestamp = end_timestamp
        ll_info.schedule_loot_time = ll_info.end_timestamp - 24 * 3600
        ll_info.winnings = winnings
        ll_info.x_winners = x_winners
        ll_info.winners = []
        ll_info.winner_info = []
        ll_info.skip_winners = []
        ll_info.deleted = False
        ll_info.pending = True
        ll_info.put()

        send_message(service_user, u"solutions.common.loyalty.lottery.update")

        return RETURNSTATUS_TO_SUCCESS
    except BusinessException, e:
        return ReturnStatusTO.create(False, common_translate(sln_settings.main_language, SOLUTION_COMMON, e.message))
Example #15
0
def enable_or_disable_solution_module(service_user, module, enabled):
    """Add or remove the module from solution settings"""
    if module not in SolutionModule.FUNCTIONALITY_MODUELS:
        return

    sln_settings = get_solution_settings(service_user)
    # for broadcast module, it can be enabled only
    if module == SolutionModule.BROADCAST:
        if enabled:
            set_default_broadcast_types(sln_settings)
        else:
            return

    to_put = []
    if enabled:
        activate_solution_module(sln_settings, module)
        if module == SolutionModule.ORDER:
            order_settings = set_advanced_order_settings(sln_settings)
            if order_settings:
                to_put.append(order_settings)
        elif module == SolutionModule.HIDDEN_CITY_WIDE_LOTTERY:
            deactivate_solution_module(sln_settings, SolutionModule.LOYALTY)
        # don't enable loyalty if this is a city service
        if module == SolutionModule.LOYALTY and SolutionModule.CITY_APP in sln_settings.modules:
            return
    else:
        deactivate_solution_module(sln_settings, module)

    sln_settings.updates_pending = True
    to_put.append(sln_settings)
    put_and_invalidate_cache(*to_put)
    broadcast_updates_pending(sln_settings)
Example #16
0
    def trans():
        sln_settings = get_solution_settings(service_user)
        service_identity_user = create_service_identity_user_wo_default(
            service_user, service_identity)
        if group_purchase.id:
            sgp = SolutionGroupPurchase.get_by_id(
                group_purchase.id,
                parent_key_unsafe(service_identity_user,
                                  sln_settings.solution))
            if group_purchase.new_picture:
                sgp.picture_version += 1
        else:
            sgp = SolutionGroupPurchase(parent=parent_key_unsafe(
                service_identity_user, sln_settings.solution))
            sgp.picture_version = 0

        sgp.title = group_purchase.title
        sgp.description = group_purchase.description
        sgp.units = group_purchase.units
        sgp.unit_description = group_purchase.unit_description
        sgp.unit_price = group_purchase.unit_price
        sgp.min_units_pp = group_purchase.min_units_pp
        sgp.max_units_pp = group_purchase.max_units_pp
        sgp.time_from = group_purchase.time_from
        sgp.time_until = group_purchase.time_until
        sgp.picture = picture

        sln_settings.updates_pending = True
        put_and_invalidate_cache(sgp, sln_settings)
        return sln_settings
Example #17
0
def solution_group_purchcase_purchase(service_user, email, method, params, tag,
                                      service_identity, user_details):
    service_identity_user = create_service_identity_user_wo_default(
        service_user, service_identity)
    jsondata = json.loads(params)

    group_purchase_id = int(jsondata['groupPurchaseId'])
    units = int(jsondata['units'])

    r = SendApiCallCallbackResultTO()
    sln_settings = get_solution_settings(service_user)
    try:
        sgp = new_group_purchase_subscription(service_user, service_identity,
                                              group_purchase_id,
                                              user_details[0].name,
                                              user_details[0], units)
        r.result = u"Successfully purchased %s units" % units
        r.error = None
        message = translate(sln_settings.main_language,
                            SOLUTION_COMMON,
                            'group-subscription-successful-title',
                            units=units,
                            title=sgp.title)
    except BusinessException, e:
        r.result = e.message
        r.error = None
        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-title-reason',
                            units=units,
                            title=sgp.title,
                            reason=e.message)
Example #18
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)
Example #19
0
def order_sandwich_received(service_user, 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):
    type_ = get_first_fmr_step_result_value(steps, u'message_type')
    topping = get_first_fmr_step_result_value(steps, u'message_topping')
    customizations = get_first_fmr_step_result_value(steps, u'message_customize')
    remark = get_first_fmr_step_result_value(steps, u'message_remark')
    takeaway_time = get_first_fmr_step_result_value(steps, u'message_takeaway_time')

    deferred.defer(process_sandwich_order, service_user, service_identity, user_details, type_, topping, customizations,
                   remark, takeaway_time, parent_message_key)

    sln_settings = get_solution_settings(service_user)
    main_branding = get_solution_main_branding(service_user)

    result = FlowMemberResultCallbackResultTO()
    result.type = TYPE_MESSAGE
    result.value = MessageCallbackResultTypeTO()
    result.value.flags = Message.FLAG_ALLOW_DISMISS | Message.FLAG_AUTO_LOCK
    result.value.answers = []
    result.value.alert_flags = Message.ALERT_FLAG_SILENT
    result.value.attachments = []
    result.value.branding = main_branding.branding_key
    result.value.dismiss_button_ui_flags = 0
    result.value.tag = None
    result.value.message = common_translate(sln_settings.main_language, SOLUTION_COMMON, u'order-sandwich-received')
    result.value.step_id = u'message_sandwich_ordered'
    return result
Example #20
0
def delete_loyalty_lottery_info(key):
    ll_info_delete = SolutionLoyaltyLottery.get(key)
    if not ll_info_delete:
        return RETURNSTATUS_TO_SUCCESS

    service_user = users.get_current_user()
    session_ = users.get_current_session()
    service_identity = session_.service_identity
    sln_settings = get_solution_settings(service_user)

    try:
        ll_info = SolutionLoyaltyLottery.load_pending(service_user, service_identity)
        if ll_info_delete.key() == ll_info.key():
            raise RETURNSTATUS_TO_SUCCESS
        if ll_info_delete.schedule_loot_time > 0:
            ll_info_delete.delete()

        sln_settings.updates_pending = True
        put_and_invalidate_cache(sln_settings)
        broadcast_updates_pending(sln_settings)

        send_message(service_user, u"solutions.common.loyalty.lottery.update", service_identity=service_identity)

        return RETURNSTATUS_TO_SUCCESS
    except BusinessException, e:
        return ReturnStatusTO.create(False, common_translate(sln_settings.main_language, SOLUTION_COMMON, e.message))
Example #21
0
def solution_remind_event(service_user, email, method, params, tag,
                          service_identity, user_details):
    settings = get_solution_settings(service_user)
    jsondata = json.loads(params)

    app_user = create_app_user_by_email(email, user_details[0].app_id)
    event_id = long(jsondata['eventId'])
    remind_before = int(jsondata['remindBefore'])
    if jsondata.get("eventStartEpoch", None):
        event_start_epoch = int(jsondata['eventStartEpoch'])
    else:
        event_start_epoch = get_event_by_id(service_user, settings.solution,
                                            event_id).start_dates[0]

    r = SendApiCallCallbackResultTO()
    if is_reminder_set(app_user, event_id, event_start_epoch,
                       remind_before) is False:
        er = EventReminder()
        er.service_identity_user = create_service_identity_user(
            users.get_current_user(), service_identity)
        er.human_user = app_user
        er.remind_before = remind_before
        er.event_id = event_id
        er.event_start_epoch = event_start_epoch
        er.put()
        r.result = u"successfully reminded"
    else:
        r.result = u"already reminded"
    r.error = None
    return r
Example #22
0
def edit_city_wide_lottery_info(key, winnings, date, x_winners):
    ll_info_edit = SolutionCityWideLottery.get(key)
    if not ll_info_edit:
        return RETURNSTATUS_TO_SUCCESS

    service_user = users.get_current_user()
    sln_settings = get_solution_settings(service_user)

    try:
        now_ = now()
        end_timestamp = date.toEpoch()
        if end_timestamp <= (now_ + 24 * 3600):
            raise BusinessException("end-date-24h-in-future")

        ll_info = SolutionCityWideLottery.load_pending(ll_info_edit.app_id)
        if ll_info_edit.key() != ll_info.key() and end_timestamp <= ll_info.end_timestamp:
            raise BusinessException("lottery-time-bigger-first-upcoming")

        ll_info_edit.end_timestamp = end_timestamp
        ll_info_edit.schedule_loot_time = ll_info_edit.end_timestamp - 24 * 3600
        ll_info_edit.winnings = winnings
        ll_info_edit.x_winners = x_winners
        ll_info_edit.put()

        send_message(service_user, u"solutions.common.loyalty.lottery.update")

        return RETURNSTATUS_TO_SUCCESS
    except BusinessException, e:
        return ReturnStatusTO.create(False, common_translate(sln_settings.main_language, SOLUTION_COMMON, e.message))
Example #23
0
def solution_event_guest_status(service_user, email, method, params, tag,
                                service_identity, user_details):
    sln_settings = get_solution_settings(service_user)
    app_user = create_app_user_by_email(email, user_details[0].app_id)

    jsondata = json.loads(params)
    event_id = long(jsondata['eventId'])
    status = int(jsondata['status'])

    event = get_event_by_id(service_user, sln_settings.solution, event_id)
    r = SendApiCallCallbackResultTO()
    if event:
        eg_key = EventGuest.createKey(app_user, event.key())
        eg = EventGuest.get(eg_key)
        if not eg:
            eg = EventGuest(key=eg_key)
        eg.guest = SolutionUser.fromTO(user_details[0])
        eg.status = status
        eg.timestamp = now()
        eg.put()
        r.result = u"Succesfully update event status"

        if sln_settings.event_notifications_enabled and (
                eg.status == EventGuest.STATUS_GOING or eg.chat_key):
            _send_event_notification(sln_settings,
                                     service_user,
                                     service_identity,
                                     user_details,
                                     event=event,
                                     event_guest=eg)
    else:
        r.result = u"Event not found. Update status failed."
    r.error = None
    return r
Example #24
0
def set_customer_signup_status(city_customer, signup, approved, reason=None):
    """Set the customer signup to done and move the inbox message to trash"""
    def trans():
        to_put = [signup]
        inbox_message = None
        signup.done = approved
        if signup.inbox_message_key:
            inbox_message = db.get(signup.inbox_message_key)
            if inbox_message:
                if approved:
                    inbox_message.trashed = True
                else:
                    inbox_message.read = True
                to_put.append(inbox_message)

        db.put(to_put)
        return inbox_message

    message = run_in_xg_transaction(trans)
    if message:
        service_user = signup.parent().service_user
        sln_settings = get_solution_settings(service_user)

        if approved:
            _send_approved_signup_email(signup)
        else:
            _send_denied_signup_email(city_customer, signup,
                                      sln_settings.main_language, reason)

        status_reply_message = _send_signup_status_inbox_reply(
            sln_settings, signup.inbox_message_key, approved, reason)
        send_signup_update_messages(sln_settings, message,
                                    status_reply_message)
Example #25
0
    def get(self):
        service_user = users.get_current_user()
        sln_settings = get_solution_settings(service_user)
        if SolutionModule.CITY_VOUCHERS not in sln_settings.modules:
            self.response.set_status(404)
            return

        app_id = self.request.get('a')
        customer = get_customer(service_user)
        if app_id != customer.app_id:
            self.response.set_status(404)
            return

        year = self.request.get('y')
        month = self.request.get('m')

        sln_city_voucher_export_key = SolutionCityVoucherExport.create_key(
            app_id, year, month)
        export = SolutionCityVoucherExport.get(sln_city_voucher_export_key)
        if export:
            self.response.headers['Content-Type'] = 'application/vnd.ms-excel'
            filename = get_exported_filename(sln_settings.main_language, year,
                                             month)
            self.response.headers['Content-Disposition'] = str(
                'attachment; filename=%s' % filename)
            self.response.write(export.xls)
        else:
            self.response.set_status(404)
Example #26
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)
Example #27
0
 def trans():
     sln_settings = get_solution_settings(service_user)
     sln_i_settings = get_solution_settings_or_identity_settings(
         sln_settings, service_identity)
     sln_i_settings.holiday_out_of_office_message = db.Text(message)
     sln_settings.updates_pending = True
     put_and_invalidate_cache(sln_settings, sln_i_settings)
     return sln_settings
Example #28
0
 def txn():
     sln_settings = get_solution_settings(service_user)
     m = SolutionGroupPurchase.get_by_id(
         group_purchase_id,
         parent_key_unsafe(service_identity_user, sln_settings.solution))
     azzert(service_user == m.service_user)
     m.deleted = True
     m.put()
Example #29
0
def delete_loyalty_visit(key):
    service_user = users.get_current_user()
    try:
        delete_visit(service_user, key)
        return RETURNSTATUS_TO_SUCCESS
    except BusinessException, e:
        sln_settings = get_solution_settings(service_user)
        return ReturnStatusTO.create(False, common_translate(sln_settings.main_language, SOLUTION_COMMON, e.message))
Example #30
0
def _repair_order_received(service_user, 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):
    from solutions.common.bizz.messaging import send_inbox_forwarders_message


    logging.info("_flow_member_result_repair_order: \n %s" % steps)

    remarks = _get_value(steps[0], u'message_remarks')
    if steps[1].answer_id == u"positive":
        picture_url = _get_value(steps[1], u'message_picture')
    else:
        picture_url = None

    sln_settings = get_solution_settings(service_user)

    logging.info("Saving repair order from %s" % user_details[0].email)
    service_identity_user = create_service_identity_user_wo_default(service_user, service_identity)
    o = SolutionRepairOrder(parent=parent_key_unsafe(service_identity_user, sln_settings.solution))
    o.description = remarks
    o.sender = SolutionUser.fromTO(user_details[0])
    o.timestamp = steps[1].received_timestamp
    o.status = SolutionRepairOrder.STATUS_RECEIVED
    o.picture_url = picture_url
    o.user = user_details[0].toAppUser() if user_details else None

    msg = common_translate(sln_settings.main_language, SOLUTION_COMMON, 'if-repair-order-received',
                           remarks=remarks)

    message = create_solution_inbox_message(service_user, service_identity, SolutionInboxMessage.CATEGORY_REPAIR, None, False, user_details, steps[1].received_timestamp, msg, True, [picture_url] if picture_url else [])
    o.solution_inbox_message_key = message.solution_inbox_message_key
    o.put()
    message.category_key = unicode(o.key())
    message.put()

    sln_i_settings = get_solution_settings_or_identity_settings(sln_settings, service_identity)

    sm_data = []
    sm_data.append({u"type": u"solutions.common.repair_orders.update"})
    sm_data.append({u"type": u"solutions.common.messaging.update",
                 u"message": serialize_complex_value(SolutionInboxMessageTO.fromModel(message, sln_settings, sln_i_settings, True), SolutionInboxMessageTO, False)})

    send_message(service_user, sm_data, service_identity=service_identity)

    attachments = []
    if picture_url:
        att = AttachmentTO()
        att.content_type = AttachmentTO.CONTENT_TYPE_IMG_JPG
        att.download_url = picture_url
        att.name = common_translate(sln_settings.main_language, SOLUTION_COMMON, u'picture')
        att.size = 0
        attachments = [att]

    app_user = user_details[0].toAppUser()

    send_inbox_forwarders_message(service_user, service_identity, app_user, msg, {
            'if_name': user_details[0].name,
            'if_email':user_details[0].email
        }, message_key=message.solution_inbox_message_key, attachments=attachments, reply_enabled=message.reply_enabled)