2013-09-25 16:46:28 -04:00
|
|
|
import logging
|
2013-11-18 14:49:54 -05:00
|
|
|
import stripe
|
2014-02-28 16:23:36 -05:00
|
|
|
import os
|
2013-09-25 16:46:28 -04:00
|
|
|
|
2014-02-18 15:50:15 -05:00
|
|
|
from flask import (abort, redirect, request, url_for, make_response, Response,
|
|
|
|
Blueprint)
|
|
|
|
from flask.ext.login import current_user
|
2013-11-18 19:17:58 -05:00
|
|
|
from urlparse import urlparse
|
2013-09-25 12:45:12 -04:00
|
|
|
|
|
|
|
from data import model
|
2014-02-18 15:50:15 -05:00
|
|
|
from app import app
|
2013-12-27 18:01:44 -05:00
|
|
|
from auth.permissions import AdministerOrganizationPermission
|
2013-11-18 14:49:54 -05:00
|
|
|
from util.invoice import renderInvoiceToPdf
|
2013-11-18 18:42:27 -05:00
|
|
|
from util.seo import render_snapshot
|
2014-01-02 18:01:34 -05:00
|
|
|
from util.cache import no_cache
|
2014-02-18 15:50:15 -05:00
|
|
|
from endpoints.common import common_login, render_page_template
|
2014-02-28 16:23:36 -05:00
|
|
|
from util.names import parse_repository_name
|
2013-11-18 19:17:58 -05:00
|
|
|
|
2013-09-25 16:46:28 -04:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2013-12-30 17:05:27 -05:00
|
|
|
web = Blueprint('web', __name__)
|
|
|
|
|
2014-03-05 14:35:11 -05:00
|
|
|
STATUS_TAGS = app.config['STATUS_TAGS']
|
2013-09-25 16:46:28 -04:00
|
|
|
|
2014-03-10 17:01:36 -04:00
|
|
|
|
2013-12-30 17:05:27 -05:00
|
|
|
@web.route('/', methods=['GET'], defaults={'path': ''})
|
|
|
|
@web.route('/organization/<path:path>', methods=['GET'])
|
2014-01-02 18:01:34 -05:00
|
|
|
@no_cache
|
2013-10-10 19:06:04 -04:00
|
|
|
def index(path):
|
2013-12-27 17:19:14 -05:00
|
|
|
return render_page_template('index.html')
|
2013-09-25 12:45:12 -04:00
|
|
|
|
|
|
|
|
2014-03-10 17:01:36 -04:00
|
|
|
@web.route('/500', methods=['GET'])
|
|
|
|
def internal_error_display():
|
|
|
|
return render_page_template('500.html')
|
|
|
|
|
|
|
|
|
2013-12-30 17:05:27 -05:00
|
|
|
@web.route('/snapshot', methods=['GET'])
|
|
|
|
@web.route('/snapshot/', methods=['GET'])
|
|
|
|
@web.route('/snapshot/<path:path>', methods=['GET'])
|
2013-11-18 17:11:06 -05:00
|
|
|
def snapshot(path = ''):
|
2013-11-18 19:17:58 -05:00
|
|
|
parsed = urlparse(request.url)
|
|
|
|
final_url = '%s://%s/%s' % (parsed.scheme, 'localhost', path)
|
|
|
|
result = render_snapshot(final_url)
|
2013-11-18 17:11:06 -05:00
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
|
|
|
|
abort(404)
|
|
|
|
|
|
|
|
|
2013-12-30 17:05:27 -05:00
|
|
|
@web.route('/plans/')
|
2014-01-02 18:01:34 -05:00
|
|
|
@no_cache
|
2013-10-13 22:06:31 -04:00
|
|
|
def plans():
|
|
|
|
return index('')
|
|
|
|
|
|
|
|
|
2013-12-30 17:05:27 -05:00
|
|
|
@web.route('/guide/')
|
2014-01-02 18:01:34 -05:00
|
|
|
@no_cache
|
2013-10-13 22:06:31 -04:00
|
|
|
def guide():
|
|
|
|
return index('')
|
|
|
|
|
|
|
|
|
2014-02-05 21:00:04 -05:00
|
|
|
@web.route('/tutorial/')
|
|
|
|
@no_cache
|
|
|
|
def tutorial():
|
|
|
|
return index('')
|
|
|
|
|
|
|
|
|
2013-12-30 17:05:27 -05:00
|
|
|
@web.route('/organizations/')
|
|
|
|
@web.route('/organizations/new/')
|
2014-01-02 18:01:34 -05:00
|
|
|
@no_cache
|
2013-11-07 01:48:58 -05:00
|
|
|
def organizations():
|
|
|
|
return index('')
|
|
|
|
|
2013-12-27 18:01:44 -05:00
|
|
|
|
2013-12-30 17:05:27 -05:00
|
|
|
@web.route('/user/')
|
2014-01-02 18:01:34 -05:00
|
|
|
@no_cache
|
2013-10-13 22:06:31 -04:00
|
|
|
def user():
|
|
|
|
return index('')
|
|
|
|
|
|
|
|
|
2013-12-30 17:05:27 -05:00
|
|
|
@web.route('/signin/')
|
2014-01-02 18:01:34 -05:00
|
|
|
@no_cache
|
2013-10-14 17:50:07 -04:00
|
|
|
def signin():
|
|
|
|
return index('')
|
|
|
|
|
|
|
|
|
2014-01-23 14:51:43 -05:00
|
|
|
@web.route('/contact/')
|
|
|
|
@no_cache
|
2013-12-17 17:02:37 -05:00
|
|
|
def contact():
|
|
|
|
return index('')
|
|
|
|
|
|
|
|
|
2014-02-06 19:20:19 -05:00
|
|
|
@web.route('/about/')
|
|
|
|
@no_cache
|
|
|
|
def about():
|
|
|
|
return index('')
|
|
|
|
|
|
|
|
|
2013-12-30 17:05:27 -05:00
|
|
|
@web.route('/new/')
|
2014-01-02 18:01:34 -05:00
|
|
|
@no_cache
|
2013-10-24 17:41:55 -04:00
|
|
|
def new():
|
|
|
|
return index('')
|
|
|
|
|
|
|
|
|
2014-02-18 15:50:15 -05:00
|
|
|
@web.route('/repository/', defaults={'path': ''})
|
|
|
|
@web.route('/repository/<path:path>', methods=['GET'])
|
2014-01-02 18:01:34 -05:00
|
|
|
@no_cache
|
2014-02-18 15:50:15 -05:00
|
|
|
def repository(path):
|
2013-10-15 21:50:14 -04:00
|
|
|
return index('')
|
|
|
|
|
2013-11-22 15:54:23 -05:00
|
|
|
|
2013-12-30 17:05:27 -05:00
|
|
|
@web.route('/security/')
|
2014-01-02 18:01:34 -05:00
|
|
|
@no_cache
|
2013-11-22 15:54:23 -05:00
|
|
|
def security():
|
|
|
|
return index('')
|
|
|
|
|
|
|
|
|
2013-12-30 17:05:27 -05:00
|
|
|
@web.route('/v1')
|
|
|
|
@web.route('/v1/')
|
2014-01-02 18:01:34 -05:00
|
|
|
@no_cache
|
2013-10-17 17:45:08 -04:00
|
|
|
def v1():
|
|
|
|
return index('')
|
2013-10-15 21:50:14 -04:00
|
|
|
|
2013-11-22 15:54:23 -05:00
|
|
|
|
2013-12-30 17:05:27 -05:00
|
|
|
@web.route('/status', methods=['GET'])
|
2014-01-02 18:01:34 -05:00
|
|
|
@no_cache
|
2013-10-02 14:35:21 -04:00
|
|
|
def status():
|
|
|
|
return make_response('Healthy')
|
|
|
|
|
|
|
|
|
2013-12-30 17:05:27 -05:00
|
|
|
@web.route('/tos', methods=['GET'])
|
2014-01-02 18:01:34 -05:00
|
|
|
@no_cache
|
2013-10-01 17:44:13 -04:00
|
|
|
def tos():
|
2013-12-27 17:19:14 -05:00
|
|
|
return render_page_template('tos.html')
|
2013-10-01 17:44:13 -04:00
|
|
|
|
|
|
|
|
2013-12-30 17:05:27 -05:00
|
|
|
@web.route('/disclaimer', methods=['GET'])
|
2014-01-02 18:01:34 -05:00
|
|
|
@no_cache
|
2013-11-22 12:32:05 -05:00
|
|
|
def disclaimer():
|
2013-12-27 17:19:14 -05:00
|
|
|
return render_page_template('disclaimer.html')
|
2013-11-22 12:32:05 -05:00
|
|
|
|
|
|
|
|
2013-12-30 17:05:27 -05:00
|
|
|
@web.route('/privacy', methods=['GET'])
|
2014-01-02 18:01:34 -05:00
|
|
|
@no_cache
|
2013-10-01 17:44:13 -04:00
|
|
|
def privacy():
|
2013-12-27 17:19:14 -05:00
|
|
|
return render_page_template('privacy.html')
|
2013-10-01 17:44:13 -04:00
|
|
|
|
|
|
|
|
2013-12-30 17:05:27 -05:00
|
|
|
@web.route('/receipt', methods=['GET'])
|
2013-11-18 14:49:54 -05:00
|
|
|
def receipt():
|
2013-12-20 22:38:53 -05:00
|
|
|
if not current_user.is_authenticated():
|
|
|
|
abort(401)
|
|
|
|
return
|
|
|
|
|
2013-11-18 14:49:54 -05:00
|
|
|
id = request.args.get('id')
|
|
|
|
if id:
|
|
|
|
invoice = stripe.Invoice.retrieve(id)
|
|
|
|
if invoice:
|
2013-12-20 22:38:53 -05:00
|
|
|
user_or_org = model.get_user_or_org_by_customer_id(invoice.customer)
|
|
|
|
|
|
|
|
if user_or_org:
|
|
|
|
if user_or_org.organization:
|
|
|
|
admin_org = AdministerOrganizationPermission(user_or_org.username)
|
|
|
|
if not admin_org.can():
|
|
|
|
abort(404)
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
if not user_or_org.username == current_user.db_user().username:
|
|
|
|
abort(404)
|
|
|
|
return
|
|
|
|
|
|
|
|
file_data = renderInvoiceToPdf(invoice, user_or_org)
|
|
|
|
return Response(file_data,
|
|
|
|
mimetype="application/pdf",
|
|
|
|
headers={"Content-Disposition": "attachment;filename=receipt.pdf"})
|
2013-11-18 14:49:54 -05:00
|
|
|
abort(404)
|
|
|
|
|
2013-09-27 19:55:04 -04:00
|
|
|
|
2013-12-30 17:05:27 -05:00
|
|
|
@web.route('/confirm', methods=['GET'])
|
2013-09-27 19:29:01 -04:00
|
|
|
def confirm_email():
|
2013-09-27 19:55:04 -04:00
|
|
|
code = request.values['code']
|
2014-01-17 17:23:52 -05:00
|
|
|
user = None
|
|
|
|
new_email = None
|
2013-12-18 19:47:42 -05:00
|
|
|
|
|
|
|
try:
|
2014-01-17 17:23:52 -05:00
|
|
|
user, new_email = model.confirm_user_email(code)
|
2013-12-18 19:47:42 -05:00
|
|
|
except model.DataModelException as ex:
|
2014-01-17 17:23:52 -05:00
|
|
|
return render_page_template('confirmerror.html', error_message=ex.message)
|
2014-01-17 17:20:51 -05:00
|
|
|
|
2014-01-17 17:23:52 -05:00
|
|
|
common_login(user)
|
2013-09-27 19:55:04 -04:00
|
|
|
|
2014-01-30 17:23:14 -05:00
|
|
|
return redirect(url_for('web.user', tab='email')
|
|
|
|
if new_email else url_for('web.index'))
|
2013-09-27 19:29:01 -04:00
|
|
|
|
|
|
|
|
2013-12-30 17:05:27 -05:00
|
|
|
@web.route('/recovery', methods=['GET'])
|
2013-10-14 17:50:07 -04:00
|
|
|
def confirm_recovery():
|
|
|
|
code = request.values['code']
|
|
|
|
user = model.validate_reset_code(code)
|
2013-09-27 19:29:01 -04:00
|
|
|
|
2013-10-14 17:50:07 -04:00
|
|
|
if user:
|
|
|
|
common_login(user)
|
2014-01-30 17:23:14 -05:00
|
|
|
return redirect(url_for('web.user'))
|
2013-10-14 17:50:07 -04:00
|
|
|
else:
|
|
|
|
abort(403)
|
2014-02-28 16:23:36 -05:00
|
|
|
|
|
|
|
|
|
|
|
@web.route('/repository/<path:repository>/status', methods=['GET'])
|
|
|
|
@parse_repository_name
|
|
|
|
@no_cache
|
|
|
|
def build_status_badge(namespace, repository):
|
|
|
|
token = request.args.get('token', None)
|
|
|
|
is_public = model.repository_is_public(namespace, repository)
|
|
|
|
if not is_public:
|
|
|
|
repo = model.get_repository(namespace, repository)
|
|
|
|
if not repo or token != repo.badge_token:
|
|
|
|
abort(404)
|
|
|
|
|
|
|
|
# Lookup the tags for the repository.
|
2014-03-05 14:57:14 -05:00
|
|
|
tags = model.list_repository_tags(namespace, repository)
|
|
|
|
is_empty = len(list(tags)) == 0
|
2014-02-28 16:23:36 -05:00
|
|
|
build = model.get_recent_repository_build(namespace, repository)
|
2014-03-05 14:57:14 -05:00
|
|
|
|
|
|
|
if not is_empty and (not build or build.phase == 'complete'):
|
|
|
|
status_name = 'ready'
|
|
|
|
elif build and build.phase == 'error':
|
|
|
|
status_name = 'failed'
|
2014-03-05 15:14:12 -05:00
|
|
|
elif build and build.phase != 'complete':
|
2014-03-05 14:57:14 -05:00
|
|
|
status_name = 'building'
|
2014-02-28 16:23:36 -05:00
|
|
|
else:
|
2014-03-05 14:57:14 -05:00
|
|
|
status_name = 'none'
|
2014-02-28 16:23:36 -05:00
|
|
|
|
2014-03-05 14:57:14 -05:00
|
|
|
response = make_response(STATUS_TAGS[status_name])
|
2014-02-28 16:23:36 -05:00
|
|
|
response.content_type = 'image/svg+xml'
|
|
|
|
return response
|