def _create_image_view(request): if settings.IS_PRODUCTION: referer = request.META.get('HTTP_REFERER', '') if not any(referer.startswith(ap) for ap in ACCEPTABLE_PREFIXES): logging.info('Blocked request with missing referer') return bad_request() try: gae_id = int(request.POST['upload_id']) except (KeyError, ValueError, TypeError): gae_id = None if not gae_id: return bad_request('Please include `upload_id`.') user = None if request.user.is_authenticated(): user = request.user image_result = fn(gae_id, user) if image_result.bad_request: return bad_request('Invalid image provided.') if image_result.server_error: return unavailable_response() image = image_result.image return api_response({ 'image': image.to_dict() })
def screenshot_set_create_bundle_view(request, set_id=None): my_set, shots = screenshots.get_set_and_shots_by_encrypted_id(request.user, set_id, enable_logged_out=False) if not my_set: return not_found() upload_ids = request.POST.getlist('upload_id') or [] try: upload_ids = [long(i) for i in upload_ids] except (ValueError, TypeError): logging.info('invalid upload_ids: %s (set id: %s)', upload_ids, set_id) return bad_request('Invalid `upload_id`, each should be long integer.') if not upload_ids: logging.info('upload ids: %s body: %s %s %s', upload_ids, request.body, request.POST, request.method) return bad_request('Invalid `upload_id`, each should be a GAE upload ID.') upload_names = filter(lambda n: n and n.strip(), request.POST.getlist('upload_name') or []) if len(upload_ids) != len(upload_names): logging.info('invalid upload_names: %s upload_ids: %s (set id: %s)', upload_ids, upload_names, set_id) return bad_request('Invalid `upload_name`, each should be an upload filename corresponding to the `upload_id` provided.') hq = request.POST.get('hq') == '1' bundle = screenshot_bundler.build_screenshot_bundle(my_set, request.user, upload_ids, upload_names, hq=hq) if not bundle: return unavailable_response() return api_response({ 'bundleId': bundle.encrypted_id, })
def connect_twitter_view(request): app_id = request.GET['app_id'] cb_url = None if 'callback_url' in request.GET: cb_url = urllib.unquote(request.GET['callback_url']) twitter_connect_url = twitter.get_auth_redirect(app_id, cb_url) if not twitter_connect_url: return unavailable_response() return api_response({ 'twitterConnectUrl': twitter_connect_url, })
def connect_itunes_view(request): apple_id = request.POST.get('apple_id', '').strip() password = request.POST.get('password', '') if not (apple_id and password): return bad_request('Please provide an Apple ID and password.', errors={'kind': 'auth'}) vendors_response = itunes_connect.associate_user_with_itunes_connect(request.user, apple_id, password) if not vendors_response: # task queue down, etc. return unavailable_response() if vendors_response.auth_error: return bad_request('Could not authenticate with iTunes Connect.', errors={'__all__': vendors_response.auth_error, 'kind': 'auth'}) elif vendors_response.vendors_error: return bad_request('Could not fetch iTunes Connect vendors.', errors={'__all__': vendors_response.vendors_error, 'kind': 'vendors'}) elif vendors_response.connection_error: return bad_request('Could not talk to iTunes Connect.', errors={'__all__': vendors_response.connection_error, 'kind': 'connection'}) elif not vendors_response.vendors: return bad_request('No vendors associated with this account.', errors={'__all__': 'No vendors associated with account', 'kind': 'vendors'}) return ok_response()
def connect_itunes_view(request): apple_id = request.POST.get('apple_id', '').strip() password = request.POST.get('password', '') if not (apple_id and password): return bad_request('Please provide an Apple ID and password.', errors={'kind': 'auth'}) vendors_response = itunes_connect.associate_user_with_itunes_connect( request.user, apple_id, password) if not vendors_response: # task queue down, etc. return unavailable_response() if vendors_response.auth_error: return bad_request('Could not authenticate with iTunes Connect.', errors={ '__all__': vendors_response.auth_error, 'kind': 'auth' }) elif vendors_response.vendors_error: return bad_request('Could not fetch iTunes Connect vendors.', errors={ '__all__': vendors_response.vendors_error, 'kind': 'vendors' }) elif vendors_response.connection_error: return bad_request('Could not talk to iTunes Connect.', errors={ '__all__': vendors_response.connection_error, 'kind': 'connection' }) elif not vendors_response.vendors: return bad_request('No vendors associated with this account.', errors={ '__all__': 'No vendors associated with account', 'kind': 'vendors' }) return ok_response()
def health_check(request): health_check_error = debug.passes_health_check() if not health_check_error: return ok_response() return unavailable_response(message=health_check_error)