def revoke_partner(request, partnership_id): if request.user.crm_type != 'named' or not request.user.is_company_admin: return HttpResponseRedirect(reverse('home')) try: partnership = Partnership.objects.get(id=partnership_id) if request.user.company_association == partnership.client: partnership.is_deleted = True partnership.save() utils.send_partnership_revoked_notification( partner=partnership.partner, client=partnership.client, company_admin=request.user) # crm_interface.remove_partnership(partnership) messages.success(request, _('Company has been removed from Partners.')) else: log_error( 'Error Revoking Partnership Access: Partnership {}, User {}'. format(partnership.id, request.user.email)) except ObjectDoesNotExist: log_error('Error Revoking Access of Named Account: User not found') return HttpResponseRedirect( reverse('profile:dashboard', kwargs={'page_type': 'company-partners'}))
def latest_tweet(): try: tweets = cache.get('tweets') if tweets: return {'tweets': tweets} api = twitter.Api(consumer_key=settings.CONSUMER_KEY, consumer_secret=settings.CONSUMER_SECRET, access_token_key=settings.ACCESS_TOKEN, access_token_secret=settings.ACCESS_TOKEN_SECRET) tweets = api.GetUserTimeline(screen_name=settings.TWITTER_USER) if len(tweets) == 0: return {'tweets': ''} cache.set('tweets', tweets[:2], settings.TWITTER_TIMEOUT) return {'tweets': tweets[:2]} except Exception as e: log_error('Error when retrieving Tweets: {}'.format(e)) return {'tweets': ''}
def handle(self, *args, **options): categories = [c[0] for c in TICKET_CATEGORY] tickets = Ticket.objects.filter(is_deleted=False) for ticket in tickets: if ticket.ticket_category not in categories: log_error('{} {} {}'.format(ticket.id, ticket.ticket_category, generate_ticket_link(ticket))) ticket.ticket_category = ticket.ticket_category.upper() ticket.save()
def last_updated(self): last_answer = self.ticket_answers.last() if last_answer: return last_answer.created_by last_update = self.ticket_history.last() if last_update: try: return last_update.created_by except ObjectDoesNotExist: log_error('Last Update Created By not found: {}, {}'.format(last_update.id, self.id)) return self.created_by
def revoke_access(request, user_id): if request.user.crm_type != 'named' or not request.user.is_company_admin: return HttpResponseRedirect(reverse('home')) try: user = UserProfile.objects.get(id=user_id) if user.company_association == request.user.company_association: user.crm_type = 'user' user.is_company_admin = False company = user.company_association user.company_association = None if request.GET.get('deactivate', '') == 'true': user.is_active = False # utils.send_deactivation_email(user) utils.send_role_change_notification(user, 'named', True) else: # utils.send_revoke_access_email(user, company) utils.send_role_change_notification(user, 'named') crm_interface.downgrade_named_user(user) user.save() else: log_error( 'Error Revoking Access of Named Account: User does not belong to same company' ) except ObjectDoesNotExist: log_error('Error Revoking Access of Named Account: User not found') return HttpResponseRedirect( reverse('profile:dashboard', kwargs={'page_type': 'company-users'}))
def latest_press_releases(): press_releases = cache.get('press_releases') if press_releases: return {'press_releases': press_releases} try: press_content = requests.get(settings.PRESS_RELEASES_URL) tree = html.fromstring(press_content.content) press_releases = tree.xpath('//div[@class="year-box"][1]//a')[:2] cache_press = [] for p in press_releases: cache_press.append({'title': p.text, 'link': p.attrib['href']}) except Exception as ex: log_error(ex) return {'press_releases': ''} cache.set('press_releases', cache_press, settings.PRESS_RELEASES_TIMEOUT) return {'press_releases': cache_press}
def logout_view(request): if request.user: try: user_social = UserSocialAuth.objects.get(uid=request.user.email) try: id_token_hint = user_social.extra_data['id_token'] except TypeError: id_token_hint = json.loads(user_social.extra_data)['id_token'] ox_auth_end_session_url = settings.SOCIAL_AUTH_END_SESSION_ENDPOINT post_logout_redirect_uri = settings.SOCIAL_AUTH_POST_LOGOUT_REDIRECT_URL logout_url = '{}/?id_token_hint={}&post_logout_redirect_uri={}'.format( ox_auth_end_session_url, id_token_hint, post_logout_redirect_uri) logout(request) return HttpResponseRedirect(logout_url) except ObjectDoesNotExist: log_error( 'Logout Failed: Social Auth Credentials for {} could not be found' .format(request.user.email)) except Exception as e: log_error('Logout Failed, Message {}'.format(e.message)) logout(request) return HttpResponseRedirect(reverse('home'))
def handle(self, *args, **options): tickets = Ticket.objects.filter(is_deleted=False) count = 0 for ticket in tickets: if ticket.ticket_category.strip().upper() == 'INTEGRATIONS': if 'SCIM' in ticket.title.upper(): count = count + 1 log_error('Ticket {} got category IDNTY assigned'.format( ticket.id)) ticket.ticket_category = 'IDNTY' ticket.save() elif 'UMA' in ticket.title.upper(): count = count + 1 log_error('Ticket {} got category ACCESS assigned'.format( ticket.id)) ticket.ticket_category = 'ACCESS' ticket.save() elif 'SAML' in ticket.title.upper(): count = count + 1 log_error('Ticket {} got category SSO assigned'.format( ticket.id)) ticket.ticket_category = 'SSO' ticket.save() elif 'OPENID' in ticket.title.upper(): count = count + 1 log_error('Ticket {} got category SSO assigned'.format( ticket.id)) ticket.ticket_category = 'SSO' ticket.save() elif 'SSO' in ticket.title.upper(): count = count + 1 log_error('Ticket {} got category SSO assigned'.format( ticket.id)) ticket.ticket_category = 'SSO' ticket.save() elif 'LDAP' in ticket.title.upper(): count = count + 1 log_error('Ticket {} got category IDNTY assigned'.format( ticket.id)) ticket.ticket_category = 'IDNTY' ticket.save() elif 'SHIBBOLETH' in ticket.title.upper(): count = count + 1 log_error('Ticket {} got category SSO assigned'.format( ticket.id)) ticket.ticket_category = 'SSO' ticket.save() elif 'ASIMBA' in ticket.title.upper(): count = count + 1 log_error('Ticket {} got category SSO assigned'.format( ticket.id)) ticket.ticket_category = 'SSO' ticket.save() log_error('Assigned {} tickets'.format(count))
def __unicode__(self): try: return self.ticket.title except ObjectDoesNotExist: log_error('Answer without a ticket: {}'.format(self.id)) return '{}'.format(self.id)