def test_user_renewal_notice_future_date(self): """ If we have multiple authorizations to send emails for, let's make sure we send distinct emails to the right places. """ editor2 = EditorFactory(user__email='*****@*****.**') authorization2 = Authorization() authorization2.authorized_user = editor2.user authorization2.authorizer = self.coordinator authorization2.partner = self.partner authorization2.date_expires = datetime.today() + timedelta(weeks=1) authorization2.save() call_command('user_renewal_notice') self.assertEqual(len(mail.outbox), 2) # Make sure that the two emails went to the two expected # email addresses. # This looks a little complicated because mail.outbox[0].to is a # (one element) list, and we need to compare sets to ensure we've # got 1 of each email. self.assertEqual(set([mail.outbox[0].to[0],mail.outbox[1].to[0]]), set(['*****@*****.**', '*****@*****.**']))
def post_revision_commit(sender, instance, **kwargs): if reversion.is_active() and (instance.status == 2 or instance.status == 4) and not instance.imported: authorized_user = instance.user authorizer = reversion.get_user() authorization = Authorization() if instance.specific_stream: authorization.stream = instance.specific_stream authorization.authorized_user = authorized_user authorization.authorizer = authorizer authorization.partner = instance.partner authorization.save()
def post_revision_commit(sender, instance, **kwargs): # For some authorization methods, we can skip the manual Approved->Sent # step and just immediately take an Approved application and give it # a finalised status. skip_approved = (instance.status == Application.APPROVED and instance.is_instantly_finalized()) if skip_approved: instance.status = Application.SENT instance.save() # Authorize editor to access resource after an application is saved as sent. if instance.status == Application.SENT and not instance.imported: # Check if an authorization already exists. if instance.specific_stream: existing_authorization = Authorization.objects.filter( authorized_user=instance.user, partner=instance.partner, stream=instance.specific_stream) else: existing_authorization = Authorization.objects.filter( authorized_user=instance.user, partner=instance.partner) authorized_user = instance.user authorizer = instance.sent_by # In the case that there is no existing authorization, create a new one if existing_authorization.count() == 0: authorization = Authorization() # If an authorization already existed (such as in the case of a # renewal), we'll simply update that one. elif existing_authorization.count() == 1: authorization = existing_authorization[0] else: logger.error("Found more than one authorization object for " "{user} - {partner}".format(user=instance.user, partner=instance.partner)) return if instance.specific_stream: authorization.stream = instance.specific_stream authorization.authorized_user = authorized_user authorization.authorizer = authorizer authorization.partner = instance.partner # If this is a proxy partner, and the requested_access_duration # field is set to false, set (or reset) the expiry date # to one year from now if instance.partner.authorization_method == Partner.PROXY and instance.requested_access_duration is None: one_year_from_now = date.today() + timedelta(days=365) authorization.date_expires = one_year_from_now # If this is a proxy partner, and the requested_access_duration # field is set to true, set (or reset) the expiry date # to 1, 3, 6 or 12 months from today based on user input elif instance.partner.authorization_method == Partner.PROXY and instance.partner.requested_access_duration is True: custom_expiry_date = date.today() + relativedelta( months=+instance.requested_access_duration) authorization.date_expires = custom_expiry_date # Alternatively, if this partner has a specified account_length, # we'll use that to set the expiry. elif instance.partner.account_length: # account_length should be a timedelta authorization.date_expires = date.today( ) + instance.partner.account_length authorization.save()