Exemplo n.º 1
0
 def sender(self):
     if self.user:
         if (self.user.is_staff or self.user.is_superuser) and \
                         self.channel.type in [CHANNEL_TYPE_SUPPORT, CHANNEL_TYPE_DEVELOPER]:
             support_name = '%s from Tunga' % self.user.short_name
             user = GenericObject(
                 **dict(id=self.user_id,
                        name=support_name,
                        display_name=support_name,
                        short_name=support_name,
                        email=self.user.email,
                        avatar_url=self.user.avatar_url
                        or 'https://tunga.io/icons/Tunga_squarex150.png'))
             return user
         return self.user
     alt_user = self.get_alt_user()
     if alt_user:
         return alt_user
     inquirer = self.inquirer
     if inquirer:
         return GenericObject(
             **dict(id='inquirer#{}'.format(inquirer.id),
                    name=inquirer.name,
                    display_name=(inquirer.name or '').title(),
                    short_name=(inquirer.name or '').title(),
                    email=inquirer.email,
                    inquirer=True))
     return GenericObject(**dict(id='visitor#{}'.format(self.channel.id),
                                 name='Guest',
                                 display_name='Guest',
                                 short_name='Guest',
                                 inquirer=True))
Exemplo n.º 2
0
 def get_alt_user(self):
     if not self.alt_user:
         return None
     try:
         user = GenericObject(**json.loads(self.alt_user))
         if self.source == APP_INTEGRATION_PROVIDER_SLACK:
             user.name = '%s from Tunga' % user.name.title()
             user.avatar_url = 'https://tunga.io/icons/Tunga_squarex150.png'
         user.display_name = user.name
         user.short_name = user.name
         return user
     except:
         return None
Exemplo n.º 3
0
def get_integration_token(user, provider, task=None):
    if task:
        task_integration = get_task_integration(task, provider)
        if task_integration and task_integration.token:
            return GenericObject(
                **dict(token=task_integration.token,
                       token_secret=task_integration.token_secret,
                       extra=task_integration.token_extra))

    if provider == GitHubProvider.id:
        return get_social_token(user=user, provider=provider)
    else:
        return get_app_integration(user=user, provider=provider)
Exemplo n.º 4
0
 def get_alt_user(self):
     if not self.alt_user:
         return None
     try:
         user = GenericObject(**json.loads(self.alt_user))
         if self.source == APP_INTEGRATION_PROVIDER_SLACK:
             user.name = '%s from Tunga' % user.name.title()
             user.avatar_url = 'https://tunga.io/icons/Tunga_squarex150.png'
         user.display_name = user.name
         user.short_name = user.name
         return user
     except:
         return None