Пример #1
0
def connect_shared_settings(service_settings):
    logger.debug('About to connect service settings "%s" to all available customers' % service_settings.name)
    if not service_settings.shared:
        raise ValueError('It is impossible to connect non-shared settings')
    service_model = SupportedServices.get_service_models()[service_settings.type]['service']

    with transaction.atomic():
        for customer in models.Customer.objects.all():
            defaults = {'available_for_all': True}
            try:
                service, _ = service_model.objects.get_or_create(
                    customer=customer, settings=service_settings, defaults=defaults)
            except QuotaValidationError:
                logger.warning('Unable to connect shared service '
                               'settings to customer because quota is exceeded. '
                               'Service settings ID: %s, customer ID: %s',
                               service_settings.id, customer.id)
                continue

            service_project_link_model = service.projects.through
            for project in service.customer.projects.all():
                try:
                    service_project_link_model.objects.get_or_create(project=project, service=service)
                except QuotaValidationError:
                    logger.warning('Unable to connect shared service to project because '
                                   'quota is exceeded. Service ID: %s, project ID: %s',
                                   service.id, project.id)
                    continue
Пример #2
0
 def _find_service(self):
     service_type = self.request.query_params.get('service_type')
     service_uuid = self.request.query_params.get('service_uuid')
     if not service_type or not service_uuid:
         return
     rows = SupportedServices.get_service_models()
     if service_type not in rows:
         return
     service_class = rows.get(service_type)['service']
     try:
         return service_class.objects.get(uuid=service_uuid)
     except ObjectDoesNotExist:
         return None
Пример #3
0
    def execute(self, service_settings):
        logger.debug('About to connect service settings "%s" to all available customers' % service_settings.name)
        if not service_settings.shared:
            raise ValueError('It is impossible to connect non-shared settings')
        service_model = SupportedServices.get_service_models()[service_settings.type]['service']

        with transaction.atomic():
            for customer in models.Customer.objects.all():
                defaults = {'available_for_all': True}
                service, _ = service_model.objects.get_or_create(
                    customer=customer, settings=service_settings, defaults=defaults)

                service_project_link_model = service.projects.through
                for project in service.customer.projects.all():
                    service_project_link_model.objects.get_or_create(project=project, service=service)
        logger.info('Successfully connected service settings "%s" to all available customers' % service_settings.name)
Пример #4
0
def connect_customer_to_shared_service_settings(sender,
                                                instance,
                                                created=False,
                                                **kwargs):
    if not created:
        return
    customer = instance

    for shared_settings in ServiceSettings.objects.filter(shared=True):
        try:
            service_model = SupportedServices.get_service_models()[
                shared_settings.type]['service']
            service_model.objects.create(customer=customer,
                                         settings=shared_settings,
                                         available_for_all=True)
        except KeyError:
            logger.warning("Unregistered service of type %s" %
                           shared_settings.type)
Пример #5
0
 def get_services(self):
     service_model = SupportedServices.get_service_models()[self.type]['service']
     return service_model.objects.filter(settings=self)
Пример #6
0
def get_service_content_types():
    services = [
        service['service']
        for service in SupportedServices.get_service_models().values()
    ]
    return get_content_types_query(services)