diff --git a/endpoints/api.py b/endpoints/api.py index edd1a9b87..5c86e8710 100644 --- a/endpoints/api.py +++ b/endpoints/api.py @@ -28,7 +28,7 @@ from auth.permissions import (ReadRepositoryPermission, ViewTeamPermission, UserPermission) from endpoints.common import (common_login, get_route_data, truthy_param, - start_build, add_notification) + start_build, check_repository_usage) from endpoints.trigger import (BuildTrigger, TriggerActivationException, TriggerDeactivationException, EmptyRepositoryException) @@ -2197,6 +2197,7 @@ def subscribe(user, plan, token, require_business_plan): cus = stripe.Customer.create(email=user.email, plan=plan, card=card) user.stripe_id = cus.id user.save() + check_repository_usage(user, plan_found) log_action('account_change_plan', user.username, {'plan': plan}) except stripe.CardError as e: return carderror_response(e) @@ -2213,6 +2214,7 @@ def subscribe(user, plan, token, require_business_plan): # We only have to cancel the subscription if they actually have one cus.cancel_subscription() cus.save() + check_repository_usage(user, plan_found) log_action('account_change_plan', user.username, {'plan': plan}) else: @@ -2228,6 +2230,7 @@ def subscribe(user, plan, token, require_business_plan): return carderror_response(e) response_json = subscription_view(cus.subscription, private_repos) + check_repository_usage(user, plan_found) log_action('account_change_plan', user.username, {'plan': plan}) resp = jsonify(response_json) diff --git a/endpoints/common.py b/endpoints/common.py index 0f0e68df7..064d29461 100644 --- a/endpoints/common.py +++ b/endpoints/common.py @@ -126,11 +126,14 @@ def render_page_template(name, **kwargs): return resp -def add_notification(kind, metadata=None, user=None): - if not user and current_user: - user = current_user.db_user() +def check_repository_usage(user_or_org, plan_found): + private_repos = model.get_private_repo_count(user_or_org.username) + repos_allowed = plan_found['privateRepos'] - return model.create_notification(kind, user, metadata or {}) + if private_repos > repos_allowed: + model.create_notification('over_private_usage', user_or_org, {'namespace': user_or_org.username}) + else: + model.delete_notifications_by_kind(user_or_org, 'over_private_usage') def start_build(repository, dockerfile_id, tags, build_name, subdir, manual, diff --git a/static/directives/header-bar.html b/static/directives/header-bar.html index 688eb8411..6d31cf951 100644 --- a/static/directives/header-bar.html +++ b/static/directives/header-bar.html @@ -43,8 +43,7 @@ ng-show="notificationService.notifications.length" ng-class="notificationService.notificationClasses" bs-tooltip="" - title="{{ notificationService.notificationSummaries }}" - data-html="true" + title="User Notifications" data-placement="left" data-container="body"> {{ notificationService.notifications.length }} diff --git a/static/directives/notification-view.html b/static/directives/notification-view.html index 5adb81261..6327a5df8 100644 --- a/static/directives/notification-view.html +++ b/static/directives/notification-view.html @@ -1,7 +1,7 @@