Merge branch 'orgs' of ssh://bitbucket.org/yackob03/quay into orgs
Conflicts: data/model.py
This commit is contained in:
commit
1aaefe6053
7 changed files with 299 additions and 104 deletions
|
@ -16,6 +16,7 @@ import storage
|
|||
from data import model
|
||||
from data.userfiles import UserRequestFiles
|
||||
from data.queue import dockerfile_build_queue
|
||||
from data.plans import USER_PLANS, getPlan, isPlanActive
|
||||
from app import app
|
||||
from util.email import send_confirmation_email, send_recovery_email
|
||||
from util.names import parse_repository_name
|
||||
|
@ -45,11 +46,13 @@ def api_login_required(f):
|
|||
def handle_dme(ex):
|
||||
return make_response(ex.message, 400)
|
||||
|
||||
|
||||
@app.route('/api/')
|
||||
def welcome():
|
||||
return make_response('welcome', 200)
|
||||
|
||||
@app.route('/api/plans/')
|
||||
def plans_list():
|
||||
return jsonify({ 'plans': USER_PLANS })
|
||||
|
||||
@app.route('/api/user/', methods=['GET'])
|
||||
def get_logged_in_user():
|
||||
|
@ -216,18 +219,45 @@ def get_organization(orgname):
|
|||
return jsonify(org_view(organization, teams))
|
||||
|
||||
|
||||
@app.route('/api/organization/<orgname>/private', methods=['GET'])
|
||||
def get_organization_private_allowed(orgname):
|
||||
if current_user.is_anonymous():
|
||||
abort(404)
|
||||
|
||||
user = current_user.db_user()
|
||||
organization = model.lookup_organization(orgname, username = user.username)
|
||||
if not organization:
|
||||
abort(404)
|
||||
|
||||
private_repos = model.get_private_repo_count(organization.username)
|
||||
if organization.stripe_id:
|
||||
cus = stripe.Customer.retrieve(organization.stripe_id)
|
||||
|
||||
if cus.subscription and isPlanActive(cus.subscription):
|
||||
repos_allowed = getPlan(cus.subscription.plan.id)
|
||||
return jsonify({
|
||||
'privateAllowed': (private_repos < repos_allowed)
|
||||
})
|
||||
|
||||
return jsonify({
|
||||
'privateAllowed': False
|
||||
})
|
||||
|
||||
|
||||
@app.route('/api/repository', methods=['POST'])
|
||||
@api_login_required
|
||||
def create_repo_api():
|
||||
owner = current_user.db_user()
|
||||
|
||||
namespace_name = owner.username
|
||||
repository_name = request.get_json()['repository']
|
||||
visibility = request.get_json()['visibility']
|
||||
# TODO(jake): Verify that the user can create a repo in this namespace.
|
||||
json = request.get_json()
|
||||
namespace_name = json['namespace'] if 'namespace' in json else owner.username
|
||||
repository_name = json['repository']
|
||||
visibility = json['visibility']
|
||||
|
||||
repo = model.create_repository(namespace_name, repository_name, owner,
|
||||
visibility)
|
||||
repo.description = request.get_json()['description']
|
||||
repo.description = json['description']
|
||||
repo.save()
|
||||
|
||||
return jsonify({
|
||||
|
@ -784,7 +814,7 @@ def get_subscription():
|
|||
if user.stripe_id:
|
||||
cus = stripe.Customer.retrieve(user.stripe_id)
|
||||
|
||||
if cus.subscription:
|
||||
if cus.subscription:
|
||||
return jsonify(subscription_view(cus.subscription, private_repos))
|
||||
|
||||
return jsonify({
|
||||
|
|
Reference in a new issue