Example #1
0
    def get(self, orgname):
        """
        Return whether or not this org is allowed to create new private repositories.
        """
        permission = CreateRepositoryPermission(orgname)
        if permission.can():
            organization = model.organization.get_organization(orgname)
            private_repos = model.user.get_private_repo_count(
                organization.username)
            data = {"privateAllowed": False}

            if organization.stripe_id:
                cus = stripe.Customer.retrieve(organization.stripe_id)
                if cus.subscription:
                    repos_allowed = 0
                    plan = get_plan(cus.subscription.plan.id)
                    if plan:
                        repos_allowed = plan["privateRepos"]

                    data["privateAllowed"] = private_repos < repos_allowed

            if AdministerOrganizationPermission(orgname).can():
                data["privateCount"] = private_repos

            return data

        raise Unauthorized()
Example #2
0
    def get(self):
        """ Get the number of private repos this user has, and whether they are allowed to create more.
    """
        user = get_authenticated_user()
        private_repos = model.user.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 {"privateCount": private_repos, "privateAllowed": (private_repos < repos_allowed)}
Example #3
0
def get_namespace_plan(namespace):
    """ Returns the plan of the given namespace. """
    namespace_user = model.user.get_namespace_user(namespace)
    if namespace_user is None:
        return None

    if not namespace_user.stripe_id:
        return None

    # Ask Stripe for the subscribed plan.
    # TODO: Can we cache this or make it faster somehow?
    try:
        cus = billing.Customer.retrieve(namespace_user.stripe_id)
    except stripe.error.APIConnectionError:
        abort(503, message='Cannot contact Stripe')

    if not cus.subscription:
        return None

    return get_plan(cus.subscription.plan.id)