コード例 #1
0
    def create_user(self, user):
        # Temporary workaround as JIRA returns 500 error if user already exists
        if self.use_old_api:
            # old API has a bug that causes user active status to be set to False if includeInactive is passed as True
            existing_support_user = self.manager.search_users(user.email)
        else:
            existing_support_user = self.manager.search_users(
                user.email, includeInactive=True)

        if existing_support_user:
            active_user = [u for u in existing_support_user if u.active]
            if not active_user:
                raise SupportUserInactive()

            logger.debug('Skipping user %s creation because it already exists',
                         user.email)
            backend_customer = active_user[0]
        else:
            if self.use_old_api:
                # add_user method returns boolean value therefore we need to fetch user object to find its key
                self.manager.add_user(user.email,
                                      user.email,
                                      fullname=user.full_name,
                                      ignore_existing=True)
                backend_customer = self.manager.search_users(user.email)[0]
            else:
                backend_customer = self.manager.create_customer(
                    user.email, user.full_name)

        try:
            user.supportcustomer
        except ObjectDoesNotExist:
            support_customer = models.SupportCustomer(
                user=user, backend_id=backend_customer.key)
            support_customer.save()
コード例 #2
0
    def create_user(self, user):
        # Temporary workaround as JIRA returns 500 error if user already exists
        if self.use_old_api or self.use_teenage_api:
            # old API has a bug that causes user active status to be set to False if includeInactive is passed as True
            existing_support_user = self.manager.search_users(user.email)
        else:
            # user GDPR-compliant version of user search
            existing_support_user = self.manager.waldur_search_users(
                user.email, includeInactive=True)

        if existing_support_user:
            active_user = [u for u in existing_support_user if u.active]
            if not active_user:
                raise SupportUserInactive(
                    'Issue is not created because caller user is disabled.')

            logger.debug('Skipping user %s creation because it already exists',
                         user.email)
            backend_customer = active_user[0]
        else:
            if self.use_old_api:
                backend_customer = self.manager.waldur_create_customer(
                    user.email, user.full_name)
            else:
                backend_customer = self.manager.create_customer(
                    user.email, user.full_name)
        try:
            user.supportcustomer
        except ObjectDoesNotExist:
            support_customer = models.SupportCustomer(
                user=user, backend_id=self.get_user_id(backend_customer))
            support_customer.save()