mirror of
https://github.com/quay/quay.git
synced 2026-01-29 08:42:15 +03:00
* Adds handling for when a subscription returned from the subscription watch api has a quantity greater than 1. Number of private repos should be correctly calculated using the quantity. * Updates ui so that subscriptions can only be added to an org as a group, i.e. a subscription with quantity = 2 cannot be split across organizations.
57 lines
1.8 KiB
Python
57 lines
1.8 KiB
Python
import logging
|
|
|
|
import peewee
|
|
|
|
from data import model
|
|
from data.database import OrganizationRhSkus, db_transaction
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def get_org_subscriptions(org_id):
|
|
try:
|
|
query = OrganizationRhSkus.select().where(OrganizationRhSkus.org_id == org_id)
|
|
return query
|
|
except OrganizationRhSkus.DoesNotExist:
|
|
return None
|
|
|
|
|
|
def bind_subscription_to_org(subscription_id, org_id, user_id, quantity=1):
|
|
try:
|
|
return OrganizationRhSkus.create(
|
|
subscription_id=subscription_id, org_id=org_id, user_id=user_id, quantity=quantity
|
|
)
|
|
except model.DataModelException as ex:
|
|
logger.error("Problem binding subscription to org %s: %s", org_id, ex)
|
|
except peewee.IntegrityError:
|
|
raise model.OrgSubscriptionBindingAlreadyExists()
|
|
|
|
|
|
def subscription_bound_to_org(subscription_id):
|
|
# lookup row in table matching subscription_id, if there is no row return false, otherwise return true
|
|
# this function is used to check if a subscription is bound to an org or
|
|
try:
|
|
binding = OrganizationRhSkus.get(OrganizationRhSkus.subscription_id == subscription_id)
|
|
return True, binding.org_id
|
|
except OrganizationRhSkus.DoesNotExist:
|
|
return False, None
|
|
|
|
|
|
def remove_subscription_from_org(org_id, subscription_id):
|
|
query = OrganizationRhSkus.delete().where(
|
|
OrganizationRhSkus.org_id == org_id,
|
|
OrganizationRhSkus.subscription_id == subscription_id,
|
|
)
|
|
query.execute()
|
|
|
|
|
|
def remove_all_owner_subscriptions_from_org(user_id, org_id):
|
|
try:
|
|
query = OrganizationRhSkus.delete().where(
|
|
OrganizationRhSkus.user_id == user_id,
|
|
OrganizationRhSkus.org_id == org_id,
|
|
)
|
|
query.execute()
|
|
except model.DataModelException as ex:
|
|
raise model.DataModelException(ex)
|