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))
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
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