コード例 #1
0
ファイル: handlers.py プロジェクト: MarijkeDM/oca-backend
        def trans():
            beacon = Beacon.all().ancestor(parent_key(si.service_user)).get()
            if beacon:
                return beacon.uuid, beacon.name
            app = App.get(App.create_key(si.app_id))
            app.beacon_last_minor = app.beacon_last_minor + 1
            name = "%s|%s" % (app.beacon_major, app.beacon_last_minor)
            logging.info("add_new_beacon: %s", name)
            if not add_new_beacon(app.beacon_uuid, name, u'Autoconnect',
                                  si.service_identity_user):
                raise Exception("Beacon already exists")

            app.put()
            return app.beacon_uuid, name
コード例 #2
0
    def get(self):
        url_app_id = self.request.get('id')
        if url_app_id:
            app = get_app_by_id(url_app_id)
            if app:
                self.write_app_details(app)
                return

        url_new_app = self.request.get('new_app')
        if url_new_app:
            self.write_app_details(None)
            return

        rogerthat_app = get_app_by_id(App.APP_ID_ROGERTHAT)
        if rogerthat_app is None:
            rogerthat_app = App(key=App.create_key(App.APP_ID_ROGERTHAT))
            rogerthat_app.name = "Rogerthat"
            rogerthat_app.type = App.APP_TYPE_ROGERTHAT
            rogerthat_app.creation_time = now()
            rogerthat_app.visible = False
            rogerthat_app.put()

        template = JINJA_ENVIRONMENT.get_template('apps.html')
        context = self.get_request_params()
        context['apps'] = sorted(get_visible_apps(), key=lambda app: (app.is_default, app.name))
        self.response.out.write(template.render(context))
コード例 #3
0
    def test_static_flex_service(self):
        self.set_datastore_hr_probability(1)

        print 'Test service creation with static modules'
        email = u'test1.flex.foo.com'
        r = create_flex_service(email,
                                name="test",
                                address="Antwerpsesteenweg 19\n9080 Lochristi",
                                phone_number="+32 9 324 25 64",
                                languages=["en", "nl"],
                                currency=u"€",
                                modules=list(SolutionModule.STATIC_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 'Test provisioning of static modules'
        common_provision(service_user)

        print 'Test rendering the home page'
        FlexHomeHandler({}, webapp2.Response()).get()
コード例 #4
0
    def run(self, bucket_name, key, current_date):
        # type: (str, str, long) -> GeneratorType
        shards = max(2, int(App.all(keys_only=True).count() / 100))  # A maximum of 100 apps will be logged per shard
        logging.info('Starting ServiceStatsPipeline with %d shards', shards)
        params = {
            'mapper_spec': 'rogerthat.bizz.job.service_stats.mapper',
            'mapper_params': {
                'bucket_name': bucket_name,
                'entity_kind': 'rogerthat.models.ServiceIdentity',
                'filters': []
            },
            'combiner_spec': 'rogerthat.bizz.job.service_stats.combiner',
            'reducer_spec': 'rogerthat.bizz.job.service_stats.reducer',
            'reducer_params': {
                'output_writer': {
                    'bucket_name': bucket_name
                }
            },
            'input_reader_spec': 'mapreduce.input_readers.DatastoreInputReader',
            'output_writer_spec': 'mapreduce.output_writers.GoogleCloudStorageConsistentOutputWriter',
            'shards': shards
        }

        output = yield mapreduce_pipeline.MapreducePipeline(key, **params)

        process_output_pipeline = yield ProcessOutputPipeline(output, current_date)
        with pipeline.After(process_output_pipeline):
            yield CleanupGoogleCloudStorageFiles(output)
コード例 #5
0
def get_available_apps_for_customer(customer, demo_only=False):
    if not customer:
        return []
    app_ids = (a for a in customer.sorted_app_ids
               if a != App.APP_ID_OSA_LOYALTY)
    available_apps = list(App.get(map(App.create_key, app_ids)))
    azzert(all(available_apps))
    if available_apps[0].orderable_app_ids:
        extra_app_ids = set(available_apps[0].orderable_app_ids).difference(
            customer.sorted_app_ids)
        if extra_app_ids:
            available_apps += App.get(map(App.create_key, extra_app_ids))
    if demo_only:
        available_apps = filter(lambda x: x.demo, available_apps)
    available_apps.sort(key=lambda app: app.name.upper())
    return available_apps
コード例 #6
0
 def get(self, app_id):
     template = JINJA_ENVIRONMENT.get_template('app_translations.html')
     js_template = JINJA_ENVIRONMENT.get_template('app_translations_part.html').render()
     app = App.get(App.create_key(app_id))
     if not app:
         self.response.out.write('app %s does not exist' % app_id)
         return
     app_translations_key = AppTranslations.create_key(app_id)
     translations = AppTranslations.get_or_insert(app_translations_key.name(), parent=app_translations_key.parent())
     parameters = {
         'templates': json.dumps({'app_translations_part': js_template}),
         'translations': json.dumps(
             zlib.decompress(translations.translations) if translations.translations else None),
         'app': json.dumps(serialize_complex_value(AppTO.fromModel(app), AppTO, False))
     }
     self.response.out.write(template.render(parameters))
コード例 #7
0
    def test_association_creation(self):
        self.set_datastore_hr_probability(1)
        apps = [a.app_id for a in App.all()]
        r = create_flex_service(email=u'*****@*****.**',
                                name=u"test",
                                address=u"Antwerpsesteenweg 19\n9080 Lochristi",
                                phone_number=u"+32 9 324 25 64",
                                languages=[u"en", u"nl"],
                                currency=u"€",
                                modules=[SolutionModule.CITY_APP, SolutionModule.BROADCAST, SolutionModule.ASK_QUESTION,
                                         SolutionModule.WHEN_WHERE],
                                broadcast_types=['News', 'test'],
                                apps=apps,
                                allow_redeploy=False,
                                organization_type=OrganizationType.CITY)
        # Create city customer
        shop_user = users.User(u'*****@*****.**') 
        customer_id = None
        vat = u''
        name = u'Town Lochristi'
        address1 = u'Dorp - West 52'
        address2 = u''
        zip_code = u'9080'
        city = u'Lochristi'
        country = u'BE'
        language = u'nl'
        organization_type = OrganizationType.CITY
        prospect_id = None
        city_customer = create_or_update_customer(shop_user, customer_id, vat, name, address1, address2, zip_code, city,
                                                  country, language, organization_type, prospect_id,
                                                  team_id=RegioManagerTeam.all().get().id)
        city_customer.service_email = city_customer.user_email = r.login
        city_customer.default_app_id = apps[0]
        city_customer.app_ids = apps
        city_customer.put()

        # Create city contact
        first_name = u'Firstname'
        last_name = u'Lastname'
        email_address = u'*****@*****.**'
        phone_number = u'+3293268806'

        create_contact(city_customer, first_name, last_name, email_address, phone_number)

        name = u'test-Test association'
        address1 = u'Antwerpsesteenweg 19'
        address2 = u''
        zip_code = u'9080'
        city = u'Lochristi'
        user_email = u'*****@*****.**'
        telephone = u'+32 9 324 25 64'
        language = u'nl'
        modules = [u'agenda', u'bulk_invite', u'static_content', u'ask_question', u'broadcast']
        broadcast_types = [u'Evenementen', u'Nieuws']
        set_current_user(users.User(r.login), set_google_user=False)
        output = rest_put_service(name, address1, address2, zip_code, city, user_email, telephone, language, modules,
                                 broadcast_types)
        self.assertTrue(output.success, output.errormsg)
        self.assertFalse(output.errormsg)
コード例 #8
0
    def setup_qr_templates(self, app_id):
        app = App.get(App.create_key(app_id))
        app.qrtemplate_keys = list()

        description = u"DEFAULT"
        key_name = create_qr_template_key_name(app_id, description)
        store_template(None, DEFAULT_QR_CODE_OVERLAY, description, u"".join(("%X" % c).rjust(2, '0')
                                                                            for c in DEFAULT_QR_CODE_COLOR), key_name)
        app.qrtemplate_keys.append(key_name)

        description = u"HAND"
        key_name = create_qr_template_key_name(app_id, description)
        store_template(None, HAND_ONLY_QR_CODE_OVERLAY, description, u"".join(("%X" % c).rjust(2, '0')
                                                                              for c in DEFAULT_QR_CODE_COLOR), key_name)
        app.qrtemplate_keys.append(key_name)

        put_and_invalidate_cache(app)
コード例 #9
0
def migrate():
    for app in App.all():
        settings_key = AppSettings.create_key(app.app_id)
        new_settings = AppSettings(key=settings_key,
                                   background_fetch_timestamps=[21600] if app.type == App.APP_TYPE_CITY_APP else [])
        settings = AppSettings.get(settings_key) or new_settings
        settings.put()
        get_app_settings.invalidate_cache(app.app_id)  # @UndefinedVariable
コード例 #10
0
 def trans(create_app_to):
     app_key = App.create_key(create_app_to.app_id)
     if App.get(app_key):
         raise DuplicateAppIdException(create_app_to.app_id)
     app = App(
         key=app_key,
         type=data.type,
         name=create_app_to.name,
         is_default=False,
         android_app_id=u'com.mobicage.rogerthat.%s' % create_app_to.app_id.replace('-', '.'),
         dashboard_email_address=data.dashboard_email_address,
         creation_time=now(),
     )
     app_settings = AppSettings(key=AppSettings.create_key(app.app_id),
                                background_fetch_timestamps=[21600] if app.type == App.APP_TYPE_CITY_APP else [])
     db.put((app, app_settings))
     return app
コード例 #11
0
def validate_delete_service(service_user):
    # type: (users.User) -> None
    all_app_ids = set()
    for service_identity in get_service_identities(service_user):
        all_app_ids.update(service_identity.appIds)
    apps = get_apps_by_keys([App.create_key(app_id) for app_id in all_app_ids])
    for app in apps:
        if app.main_service == service_user.email():
            raise BusinessException('Cannot delete main service of app %s' % app.app_id)
コード例 #12
0
def generate_all_stats():
    apps = App.all().fetch(None)
    app_ids = [a.app_id for a in apps]
    d = datetime.now()
    date = datetime(year=d.year, month=d.month, day=d.day)
    results = [
        generate_created_app_stats(apps),
        generate_released_app_stats(apps),
        generate_users_per_app_stats(app_ids)
    ]
    for type_, result in results:
        log_offload.create_log(None, type_, result, None, timestamp=time.mktime(date.timetuple()))
コード例 #13
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()
コード例 #14
0
 def get(self):
     expired_apps = [(app.app_id, time.ctime(app.apple_push_cert_valid_until))
                     for app in App.all() \
                         .filter('apple_push_cert_valid_until !=', None) \
                         .filter('apple_push_cert_valid_until <', now() + 60 * 86400) \
                         .order('apple_push_cert_valid_until')]
     if expired_apps:
         expired_apps_str = pprint.pformat(expired_apps)
         settings = get_server_settings()
         send_mail(settings.dashboardEmail,
                   settings.supportWorkers,
                   "There are APN certs that are about to expire",
                   "The following APN certs are about to expire:\n%s" % expired_apps_str)
         logging.error("The following APN certs are about to expire:\n%s" % expired_apps_str)
    def get(self):
        data_dict, app_user = self.get_user_info()
        if not data_dict or not app_user:
            return

        azzert(data_dict['a'] == "unsubscribe deactivate")

        app, user_profile = db.get([App.create_key(get_app_id_from_app_user(app_user)),
                                    UserProfile.createKey(app_user)])

        if not user_profile:
            self.redirect("/")
            return

        mobiles = list(get_user_active_mobiles(app_user))
        if mobiles:
            mobile = mobiles[0]
            if mobile.type in Mobile.ANDROID_TYPES:
                page_type = "android"
            elif mobile.type in Mobile.IOS_TYPES:
                page_type = "ios"
            else:
                return self.return_error()
        else:
            mobile = None
            page_type = "web"

        page_type = self.request.get("page_type", page_type)
        language = self.request.get("language", user_profile.language)

        ActivationLog(timestamp=now(), email=app_user.email(), mobile=mobile,
                      description="Visit unsubscribe page %s %s" % (page_type, user_profile.language)).put()

        jinja_template = self.get_jinja_environment().get_template('unsubscribe_deactivate.html')

        params = {
            'name': data_dict['n'],
            'app_name': get_app_by_user(app_user).name,
            'hide_header': True,
            'data': self.request.get("data"),
            'app_email': app_user.email(),
            'email': get_human_user_from_app_user(app_user).email(),
            'action': data_dict['a'],
            'page_type': page_type,
            'language': language,
            'is_city_app': app.type == App.APP_TYPE_CITY_APP
        }

        self.response.out.write(jinja_template.render(params))
コード例 #16
0
    def trans(old_default_app_key):
        new_default_app = get_app_by_id(app_id)
        if new_default_app.key() == old_default_app_key:
            return

        new_default_app.is_default = True

        if old_default_app_key:
            old_default_app = App.get(old_default_app_key)
            old_default_app.is_default = False
            put_and_invalidate_cache(new_default_app, old_default_app)
            on_trans_committed(logging.info, "Default app updated from %s (%s) to %s (%s)", old_default_app.app_id,
                               old_default_app.name, new_default_app.app_id, new_default_app.name)
        else:
            put_and_invalidate_cache(new_default_app)
コード例 #17
0
def generate_app_stats_history(log_type):
    if log_type == 'rogerthat.created_apps':
        stats_func = _generate_created_app_stats
    elif log_type == 'rogerthat.released_apps':
        stats_func = _generate_released_app_stats
    else:
        raise Exception('Invalid log type')
    d = datetime.utcfromtimestamp(1410963082)
    date = datetime(year=d.year, month=d.month, day=d.day)
    all_apps = App.all().fetch(None)
    now = datetime.now()
    while date < now:
        ts = time.mktime(date.timetuple())
        result = stats_func([app for app in all_apps if app.creation_time <= ts])
        log_offload.create_log(None, log_type, result, None, timestamp=ts)
        date = date + relativedelta(days=1)
コード例 #18
0
def delete_app(app_id):
    app = get_app(app_id)
    validate_can_delete_app(app)
    to_delete = [
        AppSettings.create_key(app_id),
        app.key()
    ]
    to_put = []
    for profile_key in UserProfile.all(keys_only=True).filter('app_id', app_id):
        delete_account(users.User(profile_key.parent().name()))
    for other_app in App.all():
        if app_id in other_app.orderable_app_ids:
            other_app.orderable_app_ids.remove(app_id)
            to_put.append(other_app)
    db.delete(to_delete)
    if to_put:
        put_and_invalidate_cache(to_put)
コード例 #19
0
def get_all_signup_enabled_apps():
    signup_enabled_app_keys = ShopApp.all(keys_only=True).filter(
        'signup_enabled', True)
    signup_enabled_apps = filter(
        lambda app: app.main_service,
        db.get([
            App.create_key(app_key.name())
            for app_key in signup_enabled_app_keys
        ]))

    for app in reversed(signup_enabled_apps):
        # TODO: cache Customer.get_by_service_email(app.main_service)
        customer = Customer.get_by_service_email(app.main_service)
        if not customer:
            signup_enabled_apps.remove(app)
            continue
        app.customer_id = customer.id
        app.country = customer.country

    return signup_enabled_apps
コード例 #20
0
def _validate_job(from_service_user, to_service_user):
    # FROM != TO
    bizz_check(from_service_user.email() != to_service_user.email(),
               'FROM and TO should not be equal')

    # FROM should exist and be a ServiceProfile
    from_service_profile = _get_profile_not_cached(from_service_user)
    bizz_check(from_service_profile,
               'ServiceProfile %s not found' % from_service_user)
    bizz_check(isinstance(from_service_profile, ServiceProfile),
               'Profile %s is not of expected type ServiceProfile, but of type %s' % (from_service_user,
                                                                                      from_service_profile.kind()))

    # TO should not exist
    to_profile = _get_profile_not_cached(to_service_user)
    if to_profile:
        raise BusinessException('%s %s already exists' % (to_profile.kind(), to_service_user))

    # FROM should not be an auto_connected_service in an App
    for app in App.all():
        if from_service_user.email() in app.admin_services:
            raise BusinessException('FROM should not be an app admin service (found in app %s)' % app.app_id)

        for acs in app.auto_connected_services:
            acs_si_user = users.User(acs.service_identity_email)
            if get_service_user_from_service_identity_user(acs_si_user).email() == from_service_user.email():
                raise BusinessException('FROM should not be an AutoConnectedService (found %s in app %s)'
                                        % (acs_si_user, app.app_id))

    # Validate that there are no running jobs for <from_service> or <to_service>
    def get_base_query():
        return MigrateServiceJob.all().filter('phase !=', MigrateServiceJob.PHASE_DONE)

    for service_user in (from_service_user, to_service_user):
        for prop in ('from_service_user', 'to_service_user'):
            job = get_base_query().filter(prop, service_user).get()
            if job:
                raise BusinessException('There already is a MigrateServiceJob with %s=%s\n%s'
                                        % (prop, service_user, db.to_dict(job)))

    return from_service_profile
コード例 #21
0
def _send_export_email(result_path, human_user_email, app_id, data_export_email, download_url):
    logging.info(download_url)
    app_user = create_app_user_by_email(human_user_email, app_id)
    user_profile, app = db.get([get_profile_key(app_user), App.create_key(app_id)])

    subject = localize(user_profile.language, "user_data_download_ready_summary")
    variables = dict(name=user_profile.name,
                     link=download_url,
                     app=app)
    body = render("data_download_ready_email", [user_profile.language], variables)
    html = render("data_download_ready_email_html", [user_profile.language], variables)
    server_settings = get_server_settings()

    email_receivers = [data_export_email]
    if app.is_default:
        email_sender = server_settings.senderEmail
    else:
        email_sender = ("%s <%s>" % (app.name, app.dashboard_email_address))

    send_mail(email_sender, email_receivers, subject, body, html=html)
    deferred.defer(_cleanup_export, result_path, _countdown=4 * DAY, _queue=DATA_EXPORT_QUEUE)
コード例 #22
0
def _get_all_apps():
    return App.all(keys_only=True)
コード例 #23
0
ファイル: app.py プロジェクト: our-city-app/mobicage-backend
def get_apps_by_type(app_type):
    # type: (list[int]) -> list[App]
    qry = App.all(keys_only=True).filter('type', app_type)
    return get_apps_by_keys(qry.fetch(None))
コード例 #24
0
ファイル: app.py プロジェクト: our-city-app/mobicage-backend
def get_all_apps():
    return App.all()
コード例 #25
0
def _get_all_apps_keys_query():
    return App.all(keys_only=True)
コード例 #26
0
ファイル: app.py プロジェクト: our-city-app/mobicage-backend
def get_apps_by_id(app_ids):
    # type: (list[unicode]) -> list[App]
    return get_cached_models([App.create_key(app_id) for app_id in app_ids])
コード例 #27
0
ファイル: app.py プロジェクト: our-city-app/mobicage-backend
def get_visible_apps():
    return App.all().filter("visible =", True)
コード例 #28
0
ファイル: app.py プロジェクト: our-city-app/mobicage-backend
def get_extra_apps():
    return App.all().filter("demo =", False).filter("visible =", True)
コード例 #29
0
    def post(self):
        success = False
        app_id = self.request.POST.get("app_id", None)
        name = self.request.POST.get("name", None)
        app_type = self.request.POST.get("app_type", None)
        fb_app_id = self.request.POST.get("fb_app_id", None)
        ios_app_id = self.request.POST.get("ios_app_id", None)
        android_app_id = self.request.POST.get("android_app_id", None)
        dashboard_email_address = self.request.POST.get('dashboard_email_address', None)
        contact_email_address = self.request.POST.get("contact_email_address", None)
        user_regex = self.request.POST.get("user_regex", None)
        qr_templates_count = int(self.request.POST.get("qr_templates_count", 0))
        default_qr_template_index = int(self.request.POST.get("default_qr_template_index", 0))
        auto_connected_services_string = self.request.POST.get("auto_connected_services", "[]")
        logging.debug("auto_connected_services = %s", auto_connected_services_string)
        beacon_major_str = self.request.POST.get("beacon_major", 0)
        beacon_major = int(beacon_major_str) if beacon_major_str else 0
        demo = bool(self.request.POST.get("demo", ''))
        beta = bool(self.request.POST.get("beta", ''))
        mdp_client_id = self.request.POST.get('mdp_client_id', None)
        mdp_client_secret = self.request.POST.get('mdp_client_secret', None)
        orderable_apps = self.request.get_all('orderable_apps')
        auto_connected_services = parse_complex_value(AutoConnectedService,
                                                      json.loads(auto_connected_services_string),
                                                      True)
        admin_services = json.loads(self.request.POST.get('admin_services', '[]'))
        beacon_regions = json.loads(self.request.POST.get("beacon_regions", "[]"))

        try:
            app_type = None if not app_type else int(app_type)
        except Exception:
            app_type = None

        try:
            fb_app_id = None if not fb_app_id else int(fb_app_id)
        except Exception:
            fb_app_id = None

        if not app_id:
            result = "Failed to create new app (app_id was empty)!"
        elif [c for c in app_id if c not in '-abcdefghijklmnopqrstuvwxyz0123456789']:
            result = "App ids should only contain (-, lower case alphabet characters and numbers)"
        elif not name:
            result = "Failed to create new app (name was empty)!"
        elif app_type is None:
            result = "Failed to create new app (app_type was empty)!"
        elif not ios_app_id:
            result = "Failed to create new app (ios_app_id was empty)!"
        elif not android_app_id:
            result = "Failed to create new app (android_app_id was empty)!"
        elif not dashboard_email_address:
            result = "Failed to create new app (dashboard_email_address was empty)!"
        else:
            try:
                if user_regex:
                    validate_user_regex(user_regex)

                zip_stream = self.request.POST.get('core_branding').file
                zip_stream.seek(0)
                try:
                    zip_ = ZipFile(zip_stream)
                except BadZipfile, e:
                    raise BrandingValidationException(e.message)

                branding = store_branding_zip(None, zip_, u"Core branding of %s" % app_id)

                app = App(key=App.create_key(app_id))
                to_be_put = []
                app.qrtemplate_keys = []
                for i in xrange(qr_templates_count):
                    file_ = self.request.POST.get('qr_template_%s' % i)
                    description = self.request.POST.get("qr_template_description_%s" % i)
                    color = self.request.POST.get("qr_template_color_%s" % i)
                    file_ = file_.file.getvalue() if isinstance(file_, FieldStorage) else None
                    key_name = create_qr_template_key_name(app_id, description)
                    store_template(None, file_, description, color, key_name)
                    if default_qr_template_index == i:
                        app.qrtemplate_keys.insert(0, key_name)
                    else:
                        app.qrtemplate_keys.append(key_name)

                app.name = name
                app.type = app_type
                app.core_branding_hash = branding.hash
                app.facebook_app_id = fb_app_id
                app.ios_app_id = ios_app_id
                app.android_app_id = android_app_id
                app.dashboard_email_address = dashboard_email_address
                app.contact_email_address = contact_email_address
                app.user_regex = user_regex
                app.creation_time = now()
                app.is_default = get_default_app_key() is None
                app.demo = demo
                app.beta = beta
                app.mdp_client_id = mdp_client_id or None
                app.mdp_client_secret = mdp_client_secret or None

                app.auto_connected_services = AutoConnectedServices()
                for acs in auto_connected_services:
                    service_identity_user = add_slash_default(users.User(acs.service_identity_email))
                    si = get_service_identity(service_identity_user)
                    bizz_check(si, "ServiceIdentity %s not found" % service_identity_user)
                    if app_id not in si.appIds:
                        si.appIds.append(app_id)
                        to_be_put.append(si)

                    acs.service_identity_email = service_identity_user.email()
                    app.auto_connected_services.add(acs)

                admin_profiles = db.get([get_profile_key(u) for u in map(users.User, admin_services)])
                non_existing = list()
                for admin_email, admin_profile in zip(admin_services, admin_profiles):
                    if not admin_profile:
                        non_existing.append(admin_email)
                bizz_check(not non_existing, "Non existing services specified: %s" % non_existing)
                app.admin_services = admin_services
                app.beacon_major = beacon_major
                app.beacon_last_minor = 0
                put_and_invalidate_cache(*to_be_put)

                to_be_put = []
                for beacon_region in beacon_regions:
                    uuid = beacon_region.get("uuid")
                    major = beacon_region.get("major")
                    minor = beacon_region.get("minor")
                    br = BeaconRegion(key=BeaconRegion.create_key(app.key(), uuid, major, minor))
                    br.uuid = uuid.lower()
                    br.major = major
                    br.minor = minor
                    br.creation_time = now()
                    to_be_put.append(br)

                app.orderable_app_ids = list(orderable_apps)
                apps = db.get(map(App.create_key, app.orderable_app_ids))
                for a in apps:
                    a.orderable_app_ids.append(app_id)
                    to_be_put.append(a)
                to_be_put.append(app)
                put_and_invalidate_cache(*to_be_put)

                for acs in app.auto_connected_services:
                    logging.info("There is a new auto-connected service: %s", acs.service_identity_email)
                    run_job(get_user_profile_keys_by_app_id, [app_id],
                            hookup_with_default_services.run_for_auto_connected_service, [acs, None])

                result = "Created new app!"
                success = True
            except BusinessException, e:
                logging.info("BusinessException: %s", e, exc_info=1)
                result = e.message
コード例 #30
0
 def trans():
     app = App.get(App.create_key(app_id))
     if not app:
         raise AppDoesNotExistException(app_id)
     return app
コード例 #31
0
def re_index_all_vouchers_all_apps(queue=HIGH_LOAD_WORKER_QUEUE):
    for app_key in App.all(keys_only=True):
        _re_index_all_vouchers(app_key.name(), queue)
コード例 #32
0
ファイル: app.py プロジェクト: our-city-app/mobicage-backend
 def f():
     return App.all().filter('is_default =', True).get()
コード例 #33
0
ファイル: news.py プロジェクト: MarijkeDM/oca-backend
def create_and_pay_news_order(service_user, news_item_id, order_items_to):
    """
    Creates an order, orderitems, charge and executes the charge. Should be executed in a transaction.
    Args:
        service_user (users.User)
        news_item_id (long)
        order_items_to (ist of OrderItemTO)

    Raises:
        NoCreditCardException
        ProductNotFoundException
    """
    @db.non_transactional
    def _get_customer():
        return get_customer(service_user)

    @db.non_transactional
    def _get_contact():
        return Contact.get_one(customer)

    customer = _get_customer()
    azzert(customer)
    contact = _get_contact()
    azzert(contact)
    if not customer.stripe_valid:
        raise NoCreditCardException(customer)
    extra_city_product_key = Product.create_key(Product.PRODUCT_EXTRA_CITY)
    news_product_key = Product.create_key(Product.PRODUCT_NEWS_PROMOTION)
    rmt_key = RegioManagerTeam.create_key(customer.team_id)
    extra_city_product, news_promotion_product, team = db.get(
        (extra_city_product_key, news_product_key, rmt_key))
    azzert(extra_city_product)
    azzert(news_promotion_product)
    azzert(team)
    new_order_key = Order.create_key(customer.id,
                                     OrderNumber.next(team.legal_entity_key))
    vat_pct = get_vat_pct(customer, team)

    total_amount = 0
    added_app_ids = []
    for order_item in order_items_to:
        if order_item.product == Product.PRODUCT_EXTRA_CITY:
            total_amount += extra_city_product.price * order_item.count
            added_app_ids.append(order_item.app_id)
            order_item.price = extra_city_product.price
        elif order_item.product == Product.PRODUCT_NEWS_PROMOTION:
            total_amount += news_promotion_product.price * order_item.count
            order_item.price = news_promotion_product.price
        else:
            raise BusinessException('Invalid product \'%s\'' %
                                    order_item.product)
    si = get_default_service_identity(users.User(customer.service_email))
    if added_app_ids:
        keys = [App.create_key(app_id) for app_id in added_app_ids]
        apps = db.get(keys)
        for app_id, app in zip(added_app_ids, apps):
            if not app:
                raise AppNotFoundException(app_id)
            if app_id in si.appIds:
                raise BusinessException('Customer %s already has app_id %s' %
                                        (customer.id, app_id))

    vat = int(round(vat_pct * total_amount / 100))
    total_amount_vat_incl = int(round(total_amount + vat))
    now_ = now()
    to_put = []
    order = Order(key=new_order_key,
                  date=now_,
                  amount=total_amount,
                  vat_pct=vat_pct,
                  vat=vat,
                  total_amount=total_amount_vat_incl,
                  contact_id=contact.id,
                  status=Order.STATUS_SIGNED,
                  is_subscription_order=False,
                  is_subscription_extension_order=False,
                  date_signed=now_,
                  manager=STORE_MANAGER,
                  team_id=team.id)
    to_put.append(order)
    azzert(order.total_amount >= 0)

    for item in order_items_to:
        order_item = OrderItem(parent=new_order_key,
                               number=item.number,
                               product_code=item.product,
                               count=item.count,
                               comment=item.comment,
                               price=item.price)
        order_item.app_id = item.app_id
        if order_item.product_code == Product.PRODUCT_NEWS_PROMOTION:
            order_item.news_item_id = news_item_id
        to_put.append(order_item)

    db.put(to_put)

    # Not sure if this is necessary
    deferred.defer(generate_and_put_order_pdf_and_send_mail,
                   customer,
                   new_order_key,
                   service_user,
                   _transactional=True)

    # No need for signing here, immediately create a charge.
    to_put = []
    charge = Charge(parent=new_order_key)
    charge.date = now()
    charge.type = Charge.TYPE_ORDER_DELIVERY
    charge.amount = order.amount
    charge.vat_pct = order.vat_pct
    charge.vat = order.vat
    charge.total_amount = order.total_amount
    charge.manager = order.manager
    charge.team_id = order.team_id
    charge.status = Charge.STATUS_PENDING
    charge.date_executed = now()
    charge.currency_code = team.legal_entity.currency_code
    to_put.append(charge)

    # Update the regiomanager statistics so these kind of orders show up in the monthly statistics
    deferred.defer(update_regiomanager_statistic,
                   gained_value=order.amount / 100,
                   manager=order.manager,
                   _transactional=True)

    # Update the customer service
    si.appIds.extend(added_app_ids)
    to_put.append(si)

    # Update the customer object so the newly added apps are added.
    customer.app_ids.extend(added_app_ids)
    customer.extra_apps_count += len(added_app_ids)
    to_put.append(customer)
    db.put(to_put)
    deferred.defer(re_index, si.user)

    # charge the credit card
    if charge.total_amount > 0:
        get_payed(customer.id, order, charge)
        server_settings = get_server_settings()
        send_to = server_settings.supportWorkers
        send_to.append(MC_DASHBOARD.email())
        channel_data = {
            'customer': customer.name,
            'no_manager': True,
            'amount': charge.amount / 100,
            'currency': charge.currency
        }
        channel.send_message(map(users.User, send_to),
                             'shop.monitoring.signed_order',
                             info=channel_data)
    else:
        charge.status = Charge.STATUS_EXECUTED
        charge.date_executed = now()
        charge.put()
    channel.send_message(service_user, 'common.billing.orders.update')
コード例 #34
0
def prepare_app_statistics_cache():
    for app_key in list(App.all(keys_only=True)):
        app_id = app_key.name()
        invalidate_cache(get_user_count_in_app, app_id)
        get_user_count_in_app(app_id)
コード例 #35
0
ファイル: store.py プロジェクト: MarijkeDM/oca-backend
    def trans():
        to_put = list()
        customer_store_order_key = Order.create_key(
            customer.id, Order.CUSTOMER_STORE_ORDER_NUMBER)
        subscription_order_key = Order.create_key(
            customer.id, customer.subscription_order_number)
        team_key = RegioManagerTeam.create_key(customer.team_id)
        product_key = Product.create_key(item.code)

        if item.app_id is not MISSING:
            app_key = App.create_key(item.app_id)
            product, customer_store_order, sub_order, app, team = db.get([
                product_key, customer_store_order_key, subscription_order_key,
                app_key, team_key
            ])
            if sub_order.status != Order.STATUS_SIGNED:
                raise BusinessException(
                    translate(lang, SOLUTION_COMMON, u'no_unsigned_order'))
            # check if the provided app does exist
            azzert(app)
        else:
            product, customer_store_order, team = db.get(
                [product_key, customer_store_order_key, team_key])

        # Check if the item has a correct count.
        # Should never happen unless the user manually recreates the ajax request..
        azzert(
            not product.possible_counts
            or item.count in product.possible_counts
            or item.code == Product.PRODUCT_EXTRA_CITY,
            u'Invalid amount of items supplied')
        number = 0
        existing_order_items = list()
        vat_pct = get_vat_pct(customer, team)
        item_already_added = False
        if not customer_store_order:
            # create new order
            customer_store_order = Order(key=customer_store_order_key)
            customer_store_order.contact_id = contact.key().id()
            customer_store_order.date = now()
            customer_store_order.vat_pct = 0
            customer_store_order.amount = 0
            customer_store_order.vat = 0
            customer_store_order.vat_pct = vat_pct
            customer_store_order.total_amount = 0
            customer_store_order.is_subscription_order = False
            customer_store_order.manager = STORE_MANAGER
            customer_store_order.team_id = None
        else:
            order_items = OrderItem.list_by_order(customer_store_order.key())
            for i in order_items:
                number = i.number if i.number > number else number
                existing_order_items.append(i)
                # Check if this city isn't already in the possible pending order.
                if hasattr(i, 'app_id') and (i.app_id == item.app_id or
                                             item.app_id in customer.app_ids):
                    raise BusinessException(
                        translate(lang, SOLUTION_COMMON,
                                  u'item_already_added'))
                else:
                    # Check if there already is an orderitem with the same product code.
                    # If so, add the count of this new item to the existing item.
                    for it in order_items:
                        if it.product_code == item.code and it.product_code not in (
                                Product.PRODUCT_EXTRA_CITY,
                                Product.PRODUCT_NEWS_PROMOTION):
                            if (
                                    it.count + item.count
                            ) in product.possible_counts or not product.possible_counts:
                                it.count += item.count
                                item_already_added = True
                                to_put.append(it)
                                order_item = it
                            elif len(product.possible_counts) != 0:
                                raise BusinessException(
                                    translate(
                                        lang,
                                        SOLUTION_COMMON,
                                        u'cant_order_more_than_specified',
                                        allowed_items=max(
                                            product.possible_counts)))

        if item.app_id is not MISSING:
            remaining_length, _ = get_subscription_order_remaining_length(
                customer.id, customer.subscription_order_number)
            subscription_order_charge_date = format_date(
                datetime.datetime.utcfromtimestamp(sub_order.next_charge_date),
                locale=lang)
            total = remaining_length * product.price
        else:
            total = product.price * item.count
        vat = total * vat_pct / 100
        total_price = total + vat
        customer_store_order.amount += total
        customer_store_order.vat += vat
        azzert(customer_store_order.total_amount >= 0)
        customer_store_order.total_amount += total_price
        service_visible_in_translation = None
        if not item_already_added:
            order_item = OrderItem(parent=customer_store_order.key())
            order_item.number = number
            order_item.comment = product.default_comment(customer.language)
            order_item.product_code = product.code
            if item.app_id is not MISSING:
                order_item.count = remaining_length
                service_visible_in_translation = translate(
                    lang,
                    SOLUTION_COMMON,
                    'service_visible_in_app',
                    subscription_expiration_date=subscription_order_charge_date,
                    amount_of_months=remaining_length,
                    extra_city_price=product.price_in_euro,
                    app_name=app.name)
            else:
                order_item.count = item.count
            order_item.price = product.price

            if item.app_id is not MISSING:
                order_item.app_id = item.app_id
            to_put.append(order_item)
        to_put.append(customer_store_order)
        db.put(to_put)
        return order_item, service_visible_in_translation
コード例 #36
0
def send_email(app_user_email, stats, dry_run=True):
    # stats: (index, {(sender_user, message_content, broadcast_type, timestamp), ...})
    app_user = users.User(app_user_email)
    app_id = get_app_id_from_app_user(app_user)
    user_profile, app = db.get([get_profile_key(app_user), App.create_key(app_id)])
    if app.type in (App.APP_TYPE_YSAAA, App.APP_TYPE_OSA_LOYALTY):
        logging.debug("App type was %s: %s", app.type_str, app_user.email())
        return

    if not user_profile:
        logging.info("User was deactivated: %s" , app_user.email())
        return

    if user_profile.unsubscribed_from_reminder_email:
        logging.info("User unsubscribed from email reminders: %s" , app_user.email())
        return

    language = convert_web_lang_to_iso_lang(user_profile.language or DEFAULT_LANGUAGE)
    try:
        Locale.parse(language)
    except UnknownLocaleError:
        language = DEFAULT_LANGUAGE

    human_user, app_id = get_app_user_tuple_by_email(app_user_email)
    human_user_email = human_user.email()

    app = get_app_by_id(app_id)
    server_settings = get_server_settings()

    text_params, html_params, avatars = _get_template_params(stats, language, server_settings, user_profile,
                                                             human_user_email, app)

    jinja_template = JINJA_ENVIRONMENT.get_template('generic/unread_messages_notification_email.tmpl')
    body = jinja_template.render(text_params)

    jinja_template = JINJA_ENVIRONMENT.get_template('generic/unread_messages_notification_email_html.tmpl')
    html = jinja_template.render(html_params)

    logging.info("%sSending mail to %s\n%s", 'DRY RUN!\n\n' if dry_run else '', human_user_email, body)

    email_receivers = server_settings.supportWorkers if dry_run else [human_user_email]
    if app.is_default:
        email_sender = server_settings.senderEmail
    else:
        email_sender = ("%s <%s>" % (app.name, app.dashboard_email_address))

    rel_mime = MIMEMultipart('related')
    rel_mime['Subject'] = text_params['title']
    rel_mime['From'] = email_sender
    rel_mime['To'] = ', '.join(email_receivers)

    msg = MIMEMultipart('alternative')
    msg.attach(MIMEText(body.encode('utf-8'), 'plain', 'utf-8'))
    msg.attach(MIMEText(html.encode('utf-8'), 'html', 'utf-8'))
    rel_mime.attach(msg)

    for avatar_id, avatar_data in avatars.iteritems():
        mime_img = MIMEImage(avatar_data, 'png')
        mime_img.add_header('Content-Id', '<%s>' % avatar_id)
        mime_img.add_header("Content-Disposition", "inline", filename="%s.png" % avatar_id)
        rel_mime.attach(mime_img)

    send_mail_via_mime(email_sender, email_receivers, rel_mime)

    if DEBUG and dry_run:
        return html
コード例 #37
0
ファイル: app.py プロジェクト: our-city-app/mobicage-backend
def get_apps(app_types, only_visible=True):
    # type: (list[int], bool) -> list[App]
    qry = App.all().filter('type IN', app_types)
    if only_visible:
        qry.filter("visible =", True)
    return qry
コード例 #38
0
ファイル: demo_apps.py プロジェクト: MarijkeDM/oca-backend
def run():
    apps = list(App.all())
    for app in apps:
        app.demo = 'demo' in app.app_id
    put_and_invalidate_cache(*apps)
コード例 #39
0
ファイル: app.py プロジェクト: our-city-app/mobicage-backend
def get_app_by_id(app_id):
    # type: (unicode) -> App
    return get_cached_model(App.create_key(app_id))
コード例 #40
0
def get_apps_that_use_embedded_app(name):
    app_ids = []
    for k in App.all(keys_only=True).filter('embedded_apps =', name):
        app_ids.append(k.name())
    return app_ids
コード例 #41
0
    def setUp(self, datastore_hr_probability=0):
        from rogerthat.bizz.profile import create_user_profile
        from rogerthat.settings import get_server_settings
        from rogerthat.rpc import users
        from google.appengine.datastore import datastore_stub_util
        from google.appengine.ext import testbed
        from rogerthat_tests import register_tst_mobile
        from rogerthat.to.payment import PaymentProviderTO
        from rogerthat.bizz.payment import create_payment_provider

        os.environ['HTTP_HOST'] = 'rt.dev:8080'

        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.datastore_hr_policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(
            probability=datastore_hr_probability)
        self.testbed.init_datastore_v3_stub(consistency_policy=self.datastore_hr_policy)
        self.testbed.init_taskqueue_stub(root_path=os.path.join(os.path.dirname(__file__), '..', 'src'))
        self.task_queue_stub = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)
        self.testbed.init_channel_stub()
        self.testbed.init_search_stub()
        self.testbed.init_blobstore_stub()

        ss = get_server_settings()
        ss.baseUrl = "http://*****:*****@example.com"
        ss.supportEmail = u"*****@*****.**"
        ss.supportWorkers = ["*****@*****.**"]
        ss.serviceCreators = ["djmatic", "*****@*****.**", "", "*****@*****.**"]
        ss.staticPinCodes = ["0666", "*****@*****.**"]
        ss.userEncryptCipherPart1 = base64.b64encode(u'userEncryptCipherPart1')
        ss.userEncryptCipherPart2 = base64.b64encode(u'userEncryptCipherPart2')

        rogerthat_app = App(key=App.create_key(u"rogerthat"))
        rogerthat_app.name = u"Rogerthat"
        rogerthat_app.type = App.APP_TYPE_ROGERTHAT
        rogerthat_app.core_branding_hash = None
        rogerthat_app.facebook_app_id = 188033791211994
        rogerthat_app.ios_app_id = u"id446796149"
        rogerthat_app.android_app_id = u"com.mobicage.rogerth.at"
        rogerthat_app.secure = True
        rogerthat_app.is_default = True
        rogerthat_app.visible = True
        rogerthat_app.creation_time = now()
        rogerthat_app.admin_services = [u'*****@*****.**']
        rogerthat_app.mdp_client_id = str(uuid.uuid4())
        rogerthat_app.mdp_client_secret = str(uuid.uuid4())

        be_loc_app = App(key=App.create_key(u"be-loc"))
        be_loc_app.name = u"Lochristi"
        be_loc_app.type = App.APP_TYPE_CITY_APP
        be_loc_app.core_branding_hash = None
        be_loc_app.facebook_app_id = 188033791211994
        be_loc_app.ios_app_id = u"com.mobicage.cityapp.lochristi"
        be_loc_app.android_app_id = u"com.mobicage.cityapp.lochristi"
        be_loc_app.creation_time = now()
        be_loc_app.secure = False
        be_loc_app.is_default = False
        be_loc_app.visible = True
        be_loc_app.mdp_client_id = str(uuid.uuid4())
        be_loc_app.mdp_client_secret = str(uuid.uuid4())

        be_berlare_app = App(key=App.create_key(u"be-berlare"))
        be_berlare_app.name = u"Berlare"
        be_berlare_app.type = App.APP_TYPE_CITY_APP
        be_berlare_app.core_branding_hash = None
        be_berlare_app.facebook_app_id = None
        be_berlare_app.ios_app_id = u"com.mobicage.cityapp.berlare"
        be_berlare_app.android_app_id = u"com.mobicage.cityapp.berlare"
        be_berlare_app.creation_time = now()
        be_berlare_app.secure = False
        be_berlare_app.is_default = False
        be_berlare_app.visible = True
        be_berlare_app.mdp_client_id = str(uuid.uuid4())
        be_berlare_app.mdp_client_secret = str(uuid.uuid4())

        osa_loyalty_app = App(key=App.create_key(u"osa-loyalty"))
        osa_loyalty_app.name = u"OSA Loyalty"
        osa_loyalty_app.type = App.APP_TYPE_CONTENT_BRANDING
        osa_loyalty_app.core_branding_hash = None
        osa_loyalty_app.facebook_app_id = 188033791211994
        osa_loyalty_app.ios_app_id = u"com.mobicage.rogerthat.osa.loyalty"
        osa_loyalty_app.android_app_id = u"com.mobicage.rogerthat.osa.loyalty"
        osa_loyalty_app.creation_time = now()
        osa_loyalty_app.is_default = False
        osa_loyalty_app.visible = True

        put_and_invalidate_cache(ss, rogerthat_app, be_loc_app, be_berlare_app, osa_loyalty_app)

        create_payment_provider(PaymentProviderTO(id=u"payconiq",
                                                  name=u"Payconiq",
                                                  logo=None,
                                                  version=1,
                                                  description=u"payconiq descripion is markdown",
                                                  oauth_settings=None,
                                                  background_color=None,
                                                  text_color=None,
                                                  button_color=None,
                                                  black_white_logo=None,
                                                  asset_types=[],
                                                  currencies=[u'EUR'],
                                                  settings=u"{'a': 1}",
                                                  embedded_application=None,
                                                  app_ids=[]))

        self.setup_qr_templates(u"rogerthat")
        self.setup_qr_templates(u"be-loc")
        self.setup_qr_templates(u"be-berlare")

        app.get_default_app = lambda: rogerthat_app

        users.get_current_user = lambda: users.User(u'*****@*****.**')
        user = users.get_current_user()
        create_user_profile(user, u"Geert test", language='nl')
        m = register_tst_mobile(user.email())
        users.get_current_mobile = lambda: m