def response_closing(request_id):
    """
    Endpoint for closing a request that takes in form data from the front end.
    Required form data include:
        -reasons: a list of closing reasons
        -email-summary: string email body from the confirmation page

    :param request_id: FOIL request ID

    :return: redirect to view request page
    """
    if flask_request.form.get('method') == EMAIL:
        required_fields = ['reasons',
                           'method',
                           'summary']
    else:
        required_fields = ['letter_templates',
                           'method',
                           'summary']
    for field in required_fields:
        if not flask_request.form.get(field, ''):
            flash('Uh Oh, it looks like the closing {} is missing! '
                  'This is probably NOT your fault.'.format(field), category='danger')
            return redirect(url_for('request.view', request_id=request_id))
    try:
        add_closing(request_id,
                    flask_request.form.getlist('reasons'),
                    flask_request.form['summary'],
                    flask_request.form['method'],
                    flask_request.form.get('letter_templates'))
    except UserRequestException as e:
        sentry.captureException()
        flash(str(e), category='danger')
    return redirect(url_for('request.view', request_id=request_id))
Exemple #2
0
 def test_add_closing_file_release_public(self, send_response_email_patch):
     request_title_public = self.rf_agency_860.create_request_as_public_user(title_privacy=False)
     with flask_login_user(self.admin_860):
         request_title_public.acknowledge(days=30)
         request_title_public.add_file(privacy=response_privacy.RELEASE_AND_PUBLIC)
         add_closing(request_title_public.id, self.closing_reasons, self.email_content)
         send_response_email_patch.assert_called_once_with(
             request_title_public.id,
             response_privacy.RELEASE_AND_PUBLIC,
             self.email_content,
             'Request {} Closed'.format(request_title_public.id)
         )
     response = request_title_public.responses.join(Determinations).filter(
         Determinations.dtype == determination_type.CLOSING).one()
     self.assertEqual(
         [
             response.request_id,
             response.privacy,
             response.dtype,
             response.reason
         ],
         [
             request_title_public.id,
             response_privacy.RELEASE_AND_PUBLIC,
             determination_type.CLOSING,
             format_determination_reasons(self.closing_reasons)
         ]
     )
     self.assert_response_event(request_title_public.id, event_type.REQ_CLOSED, response, self.admin_860)
Exemple #3
0
 def test_add_closing(self, send_response_email_patch):
     with flask_login_user(self.admin_860):
         self.request.acknowledge(days=30)
         self.request.set_agency_request_summary('blah')
         self.request.set_agency_request_summary_privacy(False)
         add_closing(self.request.id, self.closing_reasons, self.email_content)
         send_response_email_patch.assert_called_once_with(
             self.request.id,
             response_privacy.RELEASE_AND_PUBLIC,
             self.email_content,
             'Request {} Closed'.format(self.request.id)
         )
     response = self.request.responses.join(Determinations).filter(
         Determinations.dtype == determination_type.CLOSING).one()
     self.assertEqual(
         [
             response.request_id,
             response.privacy,
             response.dtype,
             response.reason
         ],
         [
             self.request.id,
             response_privacy.RELEASE_AND_PUBLIC,
             determination_type.CLOSING,
             format_determination_reasons(self.closing_reasons)
         ]
     )
     self.assert_response_event(self.request.id, event_type.REQ_CLOSED, response, self.admin_860)
def response_closing(request_id):
    """
    Endpoint for closing a request that takes in form data from the front end.
    Required form data include:
        -reasons: a list of closing reasons
        -email-summary: string email body from the confirmation page

    :param request_id: FOIL request ID

    :return: redirect to view request page
    """
    if flask_request.form.get('method') == EMAIL:
        required_fields = ['reasons',
                           'method',
                           'summary']
    else:
        required_fields = ['letter_templates',
                           'method',
                           'summary']
    for field in required_fields:
        if flask_request.form.get(field) is None:
            flash('Uh Oh, it looks like the closing {} is missing! '
                  'This is probably NOT your fault.'.format(field), category='danger')
            return redirect(url_for('request.view', request_id=request_id))
    try:
        add_closing(request_id,
                    flask_request.form.getlist('reasons'),
                    flask_request.form['summary'],
                    flask_request.form['method'],
                    flask_request.form.get('letter_templates'))
    except UserRequestException as e:
        sentry.captureException()
        flash(str(e), category='danger')
    return redirect(url_for('request.view', request_id=request_id))
Exemple #5
0
 def test_add_closing_file_private(self):
     with flask_login_user(self.admin_860):
         self.request.acknowledge(days=30)
         self.request.add_file()
         with self.assertRaises(UserRequestException):
             add_closing(self.request.id, self.closing_reasons, self.email_content)
Exemple #6
0
 def test_add_closing_no_agency_request_summary(self):
     with flask_login_user(self.admin_860):
         self.request.acknowledge(days=30)
         with self.assertRaises(UserRequestException):
             add_closing(self.request.id, self.closing_reasons, self.email_content)
Exemple #7
0
 def test_add_closing_already_closed(self):
     with flask_login_user(self.admin_860):
         self.request.close()
         with self.assertRaises(UserRequestException):
             add_closing(self.request.id, self.closing_reasons, self.email_content)
Exemple #8
0
 def test_add_closing_invalid_request(self):
     with flask_login_user(self.admin_860):
         with self.assertRaises(NoResultFound):
             add_closing('FOIL-2017-002-00001', self.closing_reasons, self.email_content)