Example #1
0
 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.')
Example #2
0
 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')
Example #3
0
 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")
Example #4
0
 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.')