From ed82d65dd1f4ee4abb3cfb3cd73df895c347a2ed Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Wed, 18 Dec 2013 23:03:19 -0500 Subject: [PATCH] =?UTF-8?q?-=20Add=20API=20for=20returning=20the=20user?= =?UTF-8?q?=E2=80=99s=20used=20private=20repos=20and=20available=20private?= =?UTF-8?q?=20repos=20-=20Fix=20the=20same=20API=20for=20orgs=20-=20Change?= =?UTF-8?q?=20the=20chosen=20plan=20in=20the=20create=20repo=20view=20to?= =?UTF-8?q?=20use=20the=20API=20-=20Add=20an=20account=20indicator=20if=20?= =?UTF-8?q?the=20user=20is=20over=20their=20plan?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- endpoints/api.py | 26 +++++++++++++++++++++++++- static/directives/header-bar.html | 8 ++++++-- static/js/app.js | 26 +++++++++++++++++++++----- static/js/controllers.js | 19 +++++++++++++++---- static/partials/new-repo.html | 9 +++++++-- 5 files changed, 74 insertions(+), 14 deletions(-) diff --git a/endpoints/api.py b/endpoints/api.py index 2a18edf4c..95912b570 100644 --- a/endpoints/api.py +++ b/endpoints/api.py @@ -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) }) diff --git a/static/directives/header-bar.html b/static/directives/header-bar.html index 169c9bf06..6df3e1fe8 100644 --- a/static/directives/header-bar.html +++ b/static/directives/header-bar.html @@ -38,14 +38,18 @@ {{ user.username }} - 1 + + {{ (user.askForPassword ? 1 : 0) + (overPlan ? 1 : 0) }} +