def _test_embargo_details(self): """ If the request is in a closed state, it needs a date to be applied. If the user has permission, apply a permanent embargo. """ self.foia.status = 'rejected' self.foia.save() default_expiration_date = datetime.date.today() + datetime.timedelta(1) embargo_form = FOIAEmbargoForm({ 'permanent_embargo': True, 'date_embargo': default_expiration_date }) assert_true(embargo_form.is_valid(), 'Form should validate.') assert_true(self.foia.has_perm(self.user, 'embargo_perm')) data = {'embargo': 'create'} data.update(embargo_form.data) request = self.request_factory.post(self.url, data) request.user = self.user response = self.get_response(request) self.foia.refresh_from_db() eq_(response.status_code, 302) assert_true(self.foia.embargo, 'An embargo should be set on the request.') eq_(self.foia.date_embargo, default_expiration_date, 'An expiration date should be set on the request.') assert_true(self.foia.permanent_embargo, 'A permanent embargo should be set on the request.')
def fine_tune_embargo(request, foia): """Adds an expiration date or makes permanent if necessary.""" form = FOIAEmbargoForm({ 'permanent_embargo': request.POST.get('permanent_embargo'), 'date_embargo': request.POST.get('date_embargo') }) if form.is_valid(): permanent = form.cleaned_data['permanent_embargo'] expiration = form.cleaned_data['date_embargo'] if foia.has_perm(request.user, 'embargo_perm'): foia.permanent_embargo = permanent if expiration and foia.status in END_STATUS: foia.date_embargo = expiration foia.save(comment='updated embargo')
def fine_tune_embargo(request, foia): """Adds an expiration date or makes permanent if necessary.""" form = FOIAEmbargoForm( { "permanent_embargo": request.POST.get("permanent_embargo"), "date_embargo": request.POST.get("date_embargo"), } ) if form.is_valid(): permanent = form.cleaned_data["permanent_embargo"] expiration = form.cleaned_data["date_embargo"] if foia.has_perm(request.user, "embargo_perm"): foia.permanent_embargo = permanent if expiration and foia.status in END_STATUS: foia.date_embargo = expiration foia.save(comment="updated embargo")
def test_update_embargo(self): """The embargo should be able to be updated.""" self.foia.embargo = True self.foia.embargo_permanent = True self.foia.date_embargo = datetime.date.today() + datetime.timedelta(5) self.foia.status = "rejected" self.foia.save() self.foia.refresh_from_db() assert_true(self.foia.embargo) expiration = datetime.date.today() + datetime.timedelta(15) embargo_form = FOIAEmbargoForm({"date_embargo": expiration}) data = {"embargo": "update"} data.update(embargo_form.data) request = self.request_factory.post(self.url, data) request.user = self.user response = self.get_response(request) eq_(response.status_code, 302) self.foia.refresh_from_db() assert_true( self.foia.embargo, "The embargo should stay applied to the request." ) assert_false( self.foia.permanent_embargo, "The permanent embargo should be repealed." ) eq_( self.foia.date_embargo, expiration, "The embargo expiration date should be updated.", )
def get_context_data(self, **kwargs): """Add extra context data""" context = super(Detail, self).get_context_data(**kwargs) foia = context['foia'] user = self.request.user user_can_edit = foia.has_perm(self.request.user, 'change') user_can_embargo = foia.has_perm(self.request.user, 'embargo') is_past_due = foia.date_due < datetime.now().date() if foia.date_due else False include_draft = user.is_staff or foia.status == 'started' context['all_tags'] = Tag.objects.all() context['past_due'] = is_past_due context['user_can_edit'] = user_can_edit context['user_can_pay'] = user_can_edit and foia.is_payable() context['embargo'] = { 'show': user_can_embargo or foia.embargo, 'edit': user_can_embargo, 'add': user_can_embargo, 'remove': user_can_edit and foia.embargo, } context['embargo_form'] = FOIAEmbargoForm(initial={ 'permanent_embargo': foia.permanent_embargo, 'date_embargo': foia.date_embargo }) context['note_form'] = FOIANoteForm() context['access_form'] = FOIAAccessForm() context['question_form'] = QuestionForm(user=user, initial={'foia': foia}) context['crowdfund_form'] = CrowdfundForm(initial={ 'name': u'Crowdfund Request: %s' % unicode(foia), 'description': 'Help cover the request fees needed to free these docs!', 'payment_required': foia.get_stripe_amount(), 'date_due': datetime.now() + timedelta(30), 'foia': foia }) context['embargo_needs_date'] = foia.status in END_STATUS context['user_actions'] = foia.user_actions(user) context['contextual_request_actions'] = \ foia.contextual_request_actions(user, user_can_edit) context['status_choices'] = STATUS if include_draft else STATUS_NODRAFT context['show_estimated_date'] = foia.status not in ['submitted', 'ack', 'done', 'rejected'] context['change_estimated_date'] = FOIAEstimatedCompletionDateForm(instance=foia) all_tasks = Task.objects.filter_by_foia(foia, user) open_tasks = [task for task in all_tasks if not task.resolved] context['task_count'] = len(all_tasks) context['open_task_count'] = len(open_tasks) context['open_tasks'] = open_tasks context['stripe_pk'] = settings.STRIPE_PUB_KEY context['sidebar_admin_url'] = reverse('admin:foia_foiarequest_change', args=(foia.pk,)) context['is_thankable'] = self.request.user.has_perm( 'foia.thank_foiarequest', foia) context['files'] = foia.files.all()[:50] if foia.sidebar_html: messages.info(self.request, foia.sidebar_html) return context
def test_cannot_permanent_embargo(self): """Users who cannot set permanent embargoes shouldn't be able to.""" user_without_permission = ProfessionalUserFactory() self.foia.composer.user = user_without_permission self.foia.composer.save() assert_true(self.foia.has_perm(user_without_permission, 'embargo')) assert_false( self.foia.has_perm(user_without_permission, 'embargo_perm')) assert_true(self.foia.has_perm(user_without_permission, 'change')) embargo_form = FOIAEmbargoForm({'permanent_embargo': True}) assert_true(embargo_form.is_valid(), 'Form should validate.') data = {'embargo': 'create'} data.update(embargo_form.data) request = self.request_factory.post(self.url, data) request.user = self.foia.composer.user response = self.get_response(request) self.foia.refresh_from_db() eq_(response.status_code, 302) assert_true(self.foia.embargo, 'An embargo should be set on the request.') assert_false(self.foia.permanent_embargo, 'A permanent embargo should not be set on the request.')
def _get_form_context_data(self, context): """Get context data about forms""" context["access_form"] = FOIAAccessForm() context["admin_fix_form"] = self.admin_fix_form context["agency_passcode_form"] = self.agency_passcode_form context["agency_reply_form"] = self.agency_reply_form context["appeal_contact_info_form"] = ContactInfoForm( foia=self.foia, appeal=True, prefix="appeal" ) context["change_estimated_date"] = FOIAEstimatedCompletionDateForm( instance=self.foia ) context["contact_info_form"] = ContactInfoForm( foia=self.foia, prefix="followup" ) context["crowdfund_form"] = CrowdfundForm( initial={ "name": "Crowdfund Request: %s" % str(self.foia), "description": "Help cover the request fees needed to free these docs!", "payment_required": self.foia.get_stripe_amount(), "date_due": timezone.now() + timedelta(30), "foia": self.foia, } ) context["embargo_form"] = FOIAEmbargoForm( initial={ "permanent_embargo": self.foia.permanent_embargo, "date_embargo": self.foia.date_embargo, } ) context["fee_form"] = self.fee_form context["note_form"] = FOIANoteForm() context["portal_form"] = PortalForm(foia=self.foia) context["resend_forms"] = self.resend_forms context["tracking_id_form"] = TrackingNumberForm() # this data used in a form context["status_choices"] = [(k, v) for (k, v) in STATUS if k != "submitted"] context["user_actions"] = self.foia.user_actions( self.request.user, context["is_agency_user"] )
def get_context_data(self, **kwargs): """Add extra context data""" # pylint: disable=too-many-statements context = super(Detail, self).get_context_data(**kwargs) foia = context['foia'] user = self.request.user user_can_edit = foia.has_perm(self.request.user, 'change') user_can_embargo = foia.has_perm(self.request.user, 'embargo') is_past_due = foia.date_due < timezone.now().date( ) if foia.date_due else False context['all_tags'] = Tag.objects.all() context['past_due'] = is_past_due context['user_can_edit'] = user_can_edit context['user_can_pay'] = (foia.has_perm(self.request.user, 'pay') and foia.status == 'payment') context['embargo'] = { 'show': user_can_embargo or foia.embargo, 'edit': user_can_embargo, 'add': user_can_embargo, 'remove': user_can_edit and foia.embargo, } context['embargo_form'] = FOIAEmbargoForm( initial={ 'permanent_embargo': foia.permanent_embargo, 'date_embargo': foia.date_embargo }) context['note_form'] = FOIANoteForm() context['access_form'] = FOIAAccessForm() context['question_form'] = QuestionForm(user=user, initial={'foia': foia}) context['crowdfund_form'] = CrowdfundForm( initial={ 'name': u'Crowdfund Request: %s' % unicode(foia), 'description': 'Help cover the request fees needed to free these docs!', 'payment_required': foia.get_stripe_amount(), 'date_due': timezone.now() + timedelta(30), 'foia': foia }) context['embargo_needs_date'] = foia.status in END_STATUS context['user_actions'] = foia.user_actions(user) context['status_choices'] = STATUS context['show_estimated_date'] = foia.status not in [ 'submitted', 'ack', 'done', 'rejected' ] context['change_estimated_date'] = FOIAEstimatedCompletionDateForm( instance=foia) context['tracking_id_form'] = TrackingNumberForm() context['contact_info_form'] = ContactInfoForm(foia=foia) if user_can_edit or user.is_staff: all_tasks = Task.objects.filter_by_foia(foia, user) open_tasks = [task for task in all_tasks if not task.resolved] context['task_count'] = len(all_tasks) context['open_task_count'] = len(open_tasks) context['open_tasks'] = open_tasks context['asignees'] = User.objects.filter( is_staff=True, ).order_by('last_name') context['stripe_pk'] = settings.STRIPE_PUB_KEY context['sidebar_admin_url'] = reverse('admin:foia_foiarequest_change', args=(foia.pk, )) context['is_thankable'] = self.request.user.has_perm( 'foia.thank_foiarequest', foia) context['files'] = foia.get_files()[:50] if self.request.user.is_authenticated(): context['foia_cache_timeout'] = 0 else: context['foia_cache_timeout'] = settings.DEFAULT_CACHE_TIMEOUT context['settings'] = settings context['agency_status_choices'] = AGENCY_STATUS context['agency_reply_form'] = self.agency_reply_form context['admin_fix_form'] = self.admin_fix_form context['resend_forms'] = self.resend_forms context['cc_emails'] = json.dumps( [unicode(e) for e in foia.cc_emails.all()]) if (foia.composer.status == 'submitted' and foia.composer.datetime_submitted is not None): context['revoke_deadline'] = ( foia.composer.datetime_submitted + timedelta(seconds=COMPOSER_EDIT_DELAY)) context['can_revoke'] = foia.composer.revokable() if foia.sidebar_html: messages.info(self.request, foia.sidebar_html) return context