def get_yearly_holidays(year): """ Retrieve a list of dates that are holidays in the specified year :param year: 4-digit year. :return: List of strings ["YYYY-MM-DD"] """ if year: return jsonify(holidays=sorted(get_holidays_date_list(year))) else: return jsonify(holidays=sorted(get_holidays_date_list(int(datetime.now().year))))
def get_yearly_holidays(year): """ Retrieve a list of dates that are holidays in the specified year :param year: 4-digit year. :return: List of strings ["YYYY-MM-DD"] """ if year: return jsonify(holidays=sorted(get_holidays_date_list(year))) else: return jsonify(holidays=sorted(get_holidays_date_list(int(datetime.now().year))))
def view_all(): return render_template( 'request/all.html', form=SearchRequestsForm(), holidays=sorted(get_holidays_date_list( datetime.utcnow().year, (datetime.utcnow() + rd(years=DEFAULT_YEARS_HOLIDAY_LIST)).year) ) )
def view_all(): user_agencies = current_user.get_agencies if current_user.is_agency else '' return render_template( 'request/all.html', form=SearchRequestsForm(), holidays=sorted(get_holidays_date_list( datetime.utcnow().year, (datetime.utcnow() + rd(years=DEFAULT_YEARS_HOLIDAY_LIST)).year) ), user_agencies=user_agencies )
def view_all(): user_agencies = current_user.get_agencies if current_user.is_agency else '' return render_template( 'request/all.html', form=SearchRequestsForm(), holidays=sorted( get_holidays_date_list( datetime.utcnow().year, (datetime.utcnow() + rd(years=DEFAULT_YEARS_HOLIDAY_LIST)).year)), user_agencies=user_agencies)
def test_view_all_anon(self, render_template_patch, search_requests_form_patch): """ Test render_template in request.views.view_all is called once for anonymous user. """ with self.client: self.client.get('/request/view_all') render_template_patch.assert_called_once_with( 'request/all.html', form=search_requests_form_patch(), holidays=sorted(get_holidays_date_list( datetime.utcnow().year, (datetime.utcnow() + rd(years=DEFAULT_YEARS_HOLIDAY_LIST)).year) ) )
def test_view_all_agency(self, render_template_patch, search_requests_form_patch): """ Test render_template in request.views.view_all is called once for logged in agency user. """ # login agency_user with self.client as client: login_user_with_client(client, self.agency_admin.get_id()) self.client.get('/request/view_all') render_template_patch.assert_called_once_with( 'request/all.html', form=search_requests_form_patch(), holidays=sorted(get_holidays_date_list( datetime.utcnow().year, (datetime.utcnow() + rd(years=DEFAULT_YEARS_HOLIDAY_LIST)).year) ) )
def view(request_id): """ This function is for testing purposes of the view a request back until backend functionality is implemented. :return: redirect to view request page """ try: current_request = Requests.query.filter_by(id=request_id).one() assert current_request.agency.is_active except NoResultFound: print("Request with id '{}' does not exist.".format(request_id)) sentry.captureException() return abort(404) except AssertionError: print("Request belongs to inactive agency.") sentry.captureException() return abort(404) holidays = sorted(get_holidays_date_list( datetime.utcnow().year, (datetime.utcnow() + rd(years=DEFAULT_YEARS_HOLIDAY_LIST)).year) ) active_users = [] assigned_users = [] if current_user.is_agency: for agency_user in current_request.agency.active_users: if not agency_user in current_request.agency.administrators and (agency_user != current_user): # populate list of assigned users that can be removed from a request if agency_user in current_request.agency_users: assigned_users.append(agency_user) # append to list of active users that can be added to a request else: active_users.append(agency_user) permissions = { 'acknowledge': permission.ACKNOWLEDGE, 'deny': permission.DENY, 'extend': permission.EXTEND, 'close': permission.CLOSE, 're_open': permission.RE_OPEN, 'add_file': permission.ADD_FILE, 'edit_file_privacy': permission.EDIT_FILE_PRIVACY, 'delete_file': permission.DELETE_FILE, 'add_note': permission.ADD_NOTE, 'edit_note_privacy': permission.EDIT_NOTE_PRIVACY, 'delete_note': permission.DELETE_NOTE, 'add_link': permission.ADD_LINK, 'edit_link_privacy': permission.EDIT_LINK_PRIVACY, 'delete_link': permission.DELETE_LINK, 'add_instructions': permission.ADD_OFFLINE_INSTRUCTIONS, 'edit_instructions_privacy': permission.EDIT_OFFLINE_INSTRUCTIONS_PRIVACY, 'delete_instructions': permission.DELETE_OFFLINE_INSTRUCTIONS, 'generate_letter': permission.GENERATE_LETTER, 'add_user': permission.ADD_USER_TO_REQUEST, 'edit_user': permission.EDIT_USER_REQUEST_PERMISSIONS, 'remove_user': permission.REMOVE_USER_FROM_REQUEST, 'edit_title': permission.EDIT_TITLE, 'edit_title_privacy': permission.CHANGE_PRIVACY_TITLE, 'edit_agency_request_summary': permission.EDIT_AGENCY_REQUEST_SUMMARY, 'edit_agency_request_summary_privacy': permission.CHANGE_PRIVACY_AGENCY_REQUEST_SUMMARY, 'edit_requester_info': permission.EDIT_REQUESTER_INFO } # Build permissions dictionary for checking on the front-end. for key, val in permissions.items(): if current_user.is_anonymous or not current_request.user_requests.filter_by( user_guid=current_user.guid).first(): permissions[key] = False else: permissions[key] = is_allowed(current_user, request_id, val) if not current_user.is_anonymous else False # Build dictionary of current permissions for all assigned users. assigned_user_permissions = {} for u in assigned_users: assigned_user_permissions[u.guid] = UserRequests.query.filter_by( request_id=request_id, user_guid=u.guid).one().get_permission_choice_indices() point_of_contact = get_current_point_of_contact(request_id) if point_of_contact: current_point_of_contact = {'user_guid': point_of_contact.user_guid} else: current_point_of_contact = {'user_guid': ''} # Determine if the Agency Request Summary should be shown. show_agency_request_summary = False if current_user in current_request.agency_users \ or current_request.agency_request_summary \ and (current_request.requester == current_user and current_request.status == request_status.CLOSED and not current_request.privacy['agency_request_summary'] or current_request.status == request_status.CLOSED and current_request.agency_request_summary_release_date and current_request.agency_request_summary_release_date < datetime.utcnow() and not current_request.privacy['agency_request_summary']): show_agency_request_summary = True # Determine if the title should be shown. show_title = (current_user in current_request.agency_users or current_request.requester == current_user or not current_request.privacy['title']) # Determine if "Generate Letter" functionality is enabled for the agency. if 'letters' in current_request.agency.agency_features: generate_letters_enabled = current_request.agency.agency_features['letters']['generate_letters'] else: generate_letters_enabled = False # Determine if custom request forms are enabled if 'enabled' in current_request.agency.agency_features['custom_request_forms']: custom_request_forms_enabled = current_request.agency.agency_features['custom_request_forms']['enabled'] else: custom_request_forms_enabled = False # Determine if custom request form panels should be expanded by default if 'expand_by_default' in current_request.agency.agency_features['custom_request_forms']: expand_by_default = current_request.agency.agency_features['custom_request_forms']['expand_by_default'] else: expand_by_default = False # Determine if request description should be hidden when custom forms are enabled if 'description_hidden_by_default' in current_request.agency.agency_features['custom_request_forms']: description_hidden_by_default = current_request.agency.agency_features['custom_request_forms']['description_hidden_by_default'] else: description_hidden_by_default = False return render_template( 'request/view_request.html', request=current_request, status=request_status, agency_users=current_request.agency_users, edit_requester_form=EditRequesterForm(current_request.requester), contact_agency_form=ContactAgencyForm(current_request), deny_request_form=DenyRequestForm(current_request.agency.ein), close_request_form=CloseRequestForm(current_request.agency.ein), reopen_request_form=ReopenRequestForm(current_request.agency.ein), remove_user_request_form=RemoveUserRequestForm(assigned_users), add_user_request_form=AddUserRequestForm(active_users), edit_user_request_form=EditUserRequestForm(assigned_users), generate_acknowledgment_letter_form=GenerateAcknowledgmentLetterForm(current_request.agency.ein), generate_denial_letter_form=GenerateDenialLetterForm(current_request.agency.ein), generate_closing_letter_form=GenerateClosingLetterForm(current_request.agency.ein), generate_extension_letter_form=GenerateExtensionLetterForm(current_request.agency.ein), generate_envelope_form=GenerateEnvelopeForm(current_request.agency_ein, current_request.requester), generate_response_letter_form=GenerateResponseLetterForm(current_request.agency.ein), assigned_user_permissions=assigned_user_permissions, current_point_of_contact=current_point_of_contact, holidays=holidays, assigned_users=assigned_users, active_users=active_users, permissions=permissions, show_agency_request_summary=show_agency_request_summary, show_title=show_title, is_requester=(current_request.requester == current_user), permissions_length=len(permission.ALL), generate_letters_enabled=generate_letters_enabled, custom_request_forms_enabled = custom_request_forms_enabled, expand_by_default=expand_by_default, description_hidden_by_default=description_hidden_by_default )
def view(request_id): """ This function is for testing purposes of the view a request back until backend functionality is implemented. :return: redirect to view request page """ try: current_request = Requests.query.filter_by(id=request_id).one() assert current_request.agency.is_active except NoResultFound: print("Request with id '{}' does not exist.".format(request_id)) sentry.captureException() return abort(404) except AssertionError: print("Request belongs to inactive agency.") sentry.captureException() return abort(404) holidays = sorted( get_holidays_date_list( datetime.utcnow().year, (datetime.utcnow() + rd(years=DEFAULT_YEARS_HOLIDAY_LIST)).year, )) active_users = [] assigned_users = [] if current_user.is_agency: for agency_user in current_request.agency.active_users: if not agency_user in current_request.agency.administrators and ( agency_user != current_user): # populate list of assigned users that can be removed from a request if agency_user in current_request.agency_users: assigned_users.append(agency_user) # append to list of active users that can be added to a request else: active_users.append(agency_user) permissions = { "acknowledge": permission.ACKNOWLEDGE, "deny": permission.DENY, "extend": permission.EXTEND, "close": permission.CLOSE, "re_open": permission.RE_OPEN, "add_file": permission.ADD_FILE, "edit_file_privacy": permission.EDIT_FILE_PRIVACY, "delete_file": permission.DELETE_FILE, "add_note": permission.ADD_NOTE, "edit_note_privacy": permission.EDIT_NOTE_PRIVACY, "delete_note": permission.DELETE_NOTE, "add_link": permission.ADD_LINK, "edit_link_privacy": permission.EDIT_LINK_PRIVACY, "delete_link": permission.DELETE_LINK, "add_instructions": permission.ADD_OFFLINE_INSTRUCTIONS, "edit_instructions_privacy": permission.EDIT_OFFLINE_INSTRUCTIONS_PRIVACY, "delete_instructions": permission.DELETE_OFFLINE_INSTRUCTIONS, "generate_letter": permission.GENERATE_LETTER, "add_user": permission.ADD_USER_TO_REQUEST, "edit_user": permission.EDIT_USER_REQUEST_PERMISSIONS, "remove_user": permission.REMOVE_USER_FROM_REQUEST, "edit_title": permission.EDIT_TITLE, "edit_title_privacy": permission.CHANGE_PRIVACY_TITLE, "edit_agency_request_summary": permission.EDIT_AGENCY_REQUEST_SUMMARY, "edit_agency_request_summary_privacy": permission.CHANGE_PRIVACY_AGENCY_REQUEST_SUMMARY, "edit_requester_info": permission.EDIT_REQUESTER_INFO, } # Build permissions dictionary for checking on the front-end. for key, val in permissions.items(): if (current_user.is_anonymous or not current_request.user_requests.filter_by( user_guid=current_user.guid).first()): permissions[key] = False else: permissions[key] = (is_allowed(current_user, request_id, val) if not current_user.is_anonymous else False) # Build dictionary of current permissions for all assigned users. assigned_user_permissions = {} for u in assigned_users: assigned_user_permissions[u.guid] = (UserRequests.query.filter_by( request_id=request_id, user_guid=u.guid).one().get_permission_choice_indices()) point_of_contact = get_current_point_of_contact(request_id) if point_of_contact: current_point_of_contact = {"user_guid": point_of_contact.user_guid} else: current_point_of_contact = {"user_guid": ""} # Determine if the Agency Request Summary should be shown. show_agency_request_summary = False if (current_user in current_request.agency_users or current_request.agency_request_summary and (current_request.requester == current_user and current_request.status == request_status.CLOSED and not current_request.privacy["agency_request_summary"] or current_request.status == request_status.CLOSED and current_request.agency_request_summary_release_date and current_request.agency_request_summary_release_date < datetime.utcnow() and not current_request.privacy["agency_request_summary"])): show_agency_request_summary = True # Determine if "Generate Letter" functionality is enabled for the agency. if "letters" in current_request.agency.agency_features: generate_letters_enabled = current_request.agency.agency_features[ "letters"]["generate_letters"] else: generate_letters_enabled = False # Determine if custom request forms are enabled if "enabled" in current_request.agency.agency_features[ "custom_request_forms"]: custom_request_forms_enabled = current_request.agency.agency_features[ "custom_request_forms"]["enabled"] else: custom_request_forms_enabled = False # Determine if custom request form panels should be expanded by default if ("expand_by_default" in current_request.agency.agency_features["custom_request_forms"]): expand_by_default = current_request.agency.agency_features[ "custom_request_forms"]["expand_by_default"] else: expand_by_default = False # Determine if request description should be hidden when custom forms are enabled if ("description_hidden_by_default" in current_request.agency.agency_features["custom_request_forms"]): description_hidden_by_default = current_request.agency.agency_features[ "custom_request_forms"]["description_hidden_by_default"] else: description_hidden_by_default = False return render_template( "request/view_request.html", request=current_request, status=request_status, agency_users=current_request.agency_users, edit_requester_form=EditRequesterForm(current_request.requester), contact_agency_form=ContactAgencyForm(current_request), deny_request_form=DenyRequestForm(current_request.agency.ein), close_request_form=CloseRequestForm(current_request.agency.ein), reopen_request_form=ReopenRequestForm(current_request.agency.ein), remove_user_request_form=RemoveUserRequestForm(assigned_users), add_user_request_form=AddUserRequestForm(active_users), edit_user_request_form=EditUserRequestForm(assigned_users), generate_acknowledgment_letter_form=GenerateAcknowledgmentLetterForm( current_request.agency.ein), generate_denial_letter_form=GenerateDenialLetterForm( current_request.agency.ein), generate_closing_letter_form=GenerateClosingLetterForm( current_request.agency.ein), generate_extension_letter_form=GenerateExtensionLetterForm( current_request.agency.ein), generate_envelope_form=GenerateEnvelopeForm(current_request.agency_ein, current_request.requester), generate_response_letter_form=GenerateResponseLetterForm( current_request.agency.ein), assigned_user_permissions=assigned_user_permissions, current_point_of_contact=current_point_of_contact, holidays=holidays, assigned_users=assigned_users, active_users=active_users, permissions=permissions, show_agency_request_summary=show_agency_request_summary, is_requester=(current_request.requester == current_user), permissions_length=len(permission.ALL), generate_letters_enabled=generate_letters_enabled, custom_request_forms_enabled=custom_request_forms_enabled, expand_by_default=expand_by_default, description_hidden_by_default=description_hidden_by_default, )
def view(request_id): """ This function is for testing purposes of the view a request back until backend functionality is implemented. :return: redirect to view request page """ try: current_request = Requests.query.filter_by(id=request_id).one() assert current_request.agency.is_active except NoResultFound: print("Request with id '{}' does not exist.".format(request_id)) return abort(404) except AssertionError: print("Request belongs to inactive agency.") return abort(404) holidays = sorted(get_holidays_date_list( datetime.utcnow().year, (datetime.utcnow() + rd(years=DEFAULT_YEARS_HOLIDAY_LIST)).year) ) active_users = [] assigned_users = [] if current_user.is_agency: for agency_user in current_request.agency.active_users: if not agency_user in current_request.agency.administrators and (agency_user != current_user): # populate list of assigned users that can be removed from a request if agency_user in current_request.agency_users: assigned_users.append(agency_user) # append to list of active users that can be added to a request else: active_users.append(agency_user) permissions = { 'acknowledge': permission.ACKNOWLEDGE, 'deny': permission.DENY, 'extend': permission.EXTEND, 'close': permission.CLOSE, 're_open': permission.RE_OPEN, 'add_file': permission.ADD_FILE, 'edit_file_privacy': permission.EDIT_FILE_PRIVACY, 'delete_file': permission.DELETE_FILE, 'add_note': permission.ADD_NOTE, 'edit_note_privacy': permission.EDIT_NOTE_PRIVACY, 'delete_note': permission.DELETE_NOTE, 'add_link': permission.ADD_LINK, 'edit_link_privacy': permission.EDIT_LINK_PRIVACY, 'delete_link': permission.DELETE_LINK, 'add_instructions': permission.ADD_OFFLINE_INSTRUCTIONS, 'edit_instructions_privacy': permission.EDIT_OFFLINE_INSTRUCTIONS_PRIVACY, 'delete_instructions': permission.DELETE_OFFLINE_INSTRUCTIONS, 'add_user': permission.ADD_USER_TO_REQUEST, 'edit_user': permission.EDIT_USER_REQUEST_PERMISSIONS, 'remove_user': permission.REMOVE_USER_FROM_REQUEST, 'edit_title': permission.EDIT_TITLE, 'edit_title_privacy': permission.CHANGE_PRIVACY_TITLE, 'edit_agency_request_summary': permission.EDIT_AGENCY_REQUEST_SUMMARY, 'edit_agency_request_summary_privacy': permission.CHANGE_PRIVACY_AGENCY_REQUEST_SUMMARY, 'edit_requester_info': permission.EDIT_REQUESTER_INFO } for key, val in permissions.items(): if current_user.is_anonymous or not current_request.user_requests.filter_by( user_guid=current_user.guid, auth_user_type=current_user.auth_user_type).first(): permissions[key] = False else: permissions[key] = is_allowed(current_user, request_id, val) if not current_user.is_anonymous else False assigned_user_permissions = {} for u in assigned_users: assigned_user_permissions[u.guid] = UserRequests.query.filter_by( request_id=request_id, user_guid=u.guid).one().get_permission_choice_indices() show_agency_request_summary = False if ( current_user in current_request.agency_users or (current_request.agency_request_summary and (( current_request.requester == current_user and current_request.status == request_status.CLOSED and not current_request.privacy['agency_request_summary'] ) or ( current_request.status == request_status.CLOSED and current_request.agency_request_summary_release_date and current_request.agency_request_summary_release_date < datetime.utcnow() and not current_request.privacy['agency_request_summary'] ))) ): show_agency_request_summary = True show_title = (current_user in current_request.agency_users or current_request.requester == current_user or not current_request.privacy['title']) return render_template( 'request/view_request.html', request=current_request, status=request_status, agency_users=current_request.agency_users, edit_requester_form=EditRequesterForm(current_request.requester), contact_agency_form=ContactAgencyForm(current_request), deny_request_form=DenyRequestForm(current_request.agency.ein), close_request_form=CloseRequestForm(current_request.agency.ein), remove_user_request_form=RemoveUserRequestForm(assigned_users), add_user_request_form=AddUserRequestForm(active_users), edit_user_request_form=EditUserRequestForm(assigned_users), assigned_user_permissions=assigned_user_permissions, holidays=holidays, assigned_users=assigned_users, active_users=active_users, permissions=permissions, show_agency_request_summary=show_agency_request_summary, show_title=show_title, is_requester=(current_request.requester == current_user), permissions_length=len(permission.ALL) )