refactored endpoints.api.subscribe to use abstracted data interface
This commit is contained in:
parent
0cbe3bdf73
commit
791bd5aefc
4 changed files with 99 additions and 11 deletions
|
@ -1,32 +1,28 @@
|
|||
""" Subscribe to plans. """
|
||||
|
||||
import logging
|
||||
import stripe
|
||||
|
||||
import features
|
||||
from app import billing
|
||||
from endpoints.api import request_error, log_action
|
||||
from endpoints.exception import NotFound
|
||||
from data import model
|
||||
from data.billing import PLANS
|
||||
|
||||
import features
|
||||
from endpoints.api.subscribe_models_pre_oci import data_model as model
|
||||
from endpoints.exception import NotFound
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def check_repository_usage(user_or_org, plan_found):
|
||||
private_repos = model.user.get_private_repo_count(user_or_org.username)
|
||||
private_repos = model.get_private_repo_count(user_or_org.username)
|
||||
if plan_found is None:
|
||||
repos_allowed = 0
|
||||
else:
|
||||
repos_allowed = plan_found['privateRepos']
|
||||
|
||||
if private_repos > repos_allowed:
|
||||
model.notification.create_unique_notification('over_private_usage', user_or_org,
|
||||
{'namespace': user_or_org.username})
|
||||
model.create_unique_notification('over_private_usage', user_or_org.username, {'namespace': user_or_org.username})
|
||||
else:
|
||||
model.notification.delete_notifications_by_kind(user_or_org, 'over_private_usage')
|
||||
model.delete_notifications_by_kind(user_or_org.username, 'over_private_usage')
|
||||
|
||||
|
||||
def carderror_response(exc):
|
||||
|
@ -70,7 +66,7 @@ def subscribe(user, plan, token, require_business_plan):
|
|||
user.username)
|
||||
raise request_error(message='No matching plan found')
|
||||
|
||||
private_repos = model.user.get_private_repo_count(user.username)
|
||||
private_repos = model.get_private_repo_count(user.username)
|
||||
|
||||
# This is the default response
|
||||
response_json = {
|
||||
|
|
Reference in a new issue