- Add API for returning the user’s used private repos and available private repos

- Fix the same API for orgs
- Change the chosen plan in the create repo view to use the API
- Add an account indicator if the user is over their plan
This commit is contained in:
Joseph Schorr 2013-12-18 23:03:19 -05:00
parent 95a8915546
commit ed82d65dd1
5 changed files with 74 additions and 14 deletions

View file

@ -118,6 +118,26 @@ def get_logged_in_user():
return jsonify(user_view(user))
@app.route('/api/user/private', methods=['GET'])
@api_login_required
def get_user_private_count():
user = current_user.db_user()
private_repos = model.get_private_repo_count(user.username)
repos_allowed = 0
if user.stripe_id:
cus = stripe.Customer.retrieve(user.stripe_id)
if cus.subscription:
plan = get_plan(cus.subscription.plan.id)
if plan:
repos_allowed = plan['privateRepos']
return jsonify({
'privateCount': private_repos,
'reposAllowed': repos_allowed
})
@app.route('/api/user/convert', methods=['POST'])
@api_login_required
def convert_user_to_organization():
@ -485,7 +505,11 @@ def get_organization_private_allowed(orgname):
if organization.stripe_id:
cus = stripe.Customer.retrieve(organization.stripe_id)
if cus.subscription:
repos_allowed = get_plan(cus.subscription.plan.id)
repos_allowed = 0
plan = get_plan(cus.subscription.plan.id)
if plan:
repos_allowed = plan['privateRepos']
return jsonify({
'privateAllowed': (private_repos < repos_allowed)
})