Skip to content

Commit

Permalink
Merge pull request #585 from CityOfNewYork/johnyu95-close-requests-cli
Browse files Browse the repository at this point in the history
Added CLI command to close requests
  • Loading branch information
johnyu95 authored Nov 6, 2024
2 parents 1f9826d + c1c718f commit d041a98
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 11 deletions.
10 changes: 7 additions & 3 deletions app/agency/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,16 @@ def update_agency_active_status(agency_ein, is_active):
)
# remove requests from index
for request in agency.requests:
request.es_delete()
try:
request.es_delete()
except Exception as e:
# exception for document not found
print(e)
# deactivate agency users
for user in agency.active_users:
update_object(
{"is_agency_active": "False",
"is_agency_admin": "False"},
{"is_agency_active": False,
"is_agency_admin": False},
AgencyUsers,
(user.guid, agency_ein)
)
Expand Down
7 changes: 4 additions & 3 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1303,11 +1303,11 @@ class Responses(db.Model):

# TODO: overwrite filter to automatically check if deleted=False

def __init__(self, request_id, privacy, date_modified=None, is_editable=False, is_dataset=False, dataset_description=None):
def __init__(self, request_id, privacy, date_modified=None, release_date=None, is_editable=False, is_dataset=False, dataset_description=None):
self.request_id = request_id
self.privacy = privacy
self.date_modified = date_modified or datetime.utcnow()
self.release_date = (
self.release_date = release_date or (
calendar.addbusdays(datetime.utcnow(), RELEASE_PUBLIC_DAYS)
if privacy == response_privacy.RELEASE_AND_PUBLIC
else None
Expand Down Expand Up @@ -1955,10 +1955,11 @@ def __init__(
reason,
date=None,
date_modified=None,
release_date=None,
is_editable=False,
):
super(Determinations, self).__init__(
request_id, privacy, date_modified, is_editable
request_id, privacy, date_modified, release_date, is_editable
)
self.dtype = dtype

Expand Down
63 changes: 63 additions & 0 deletions app/response/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,69 @@ def add_closing(request_id, reason_ids, content, method, letter_template_id):
request_id=request_id,
reason="Request is already closed or has not been acknowledged")

def add_closing_cli(request_id, reason_text):
"""
Create and store a closing-determination response for the specified request and update the request accordingly.
Meant to be used with the CLI command close_requests
:param request_id: FOIL request ID
:param reason_text: reason text for closing
"""
request = Requests.query.filter_by(id=request_id).one()
if request.status != request_status.CLOSED:
previous_status = request.status
previous_date_closed = request.date_closed.isoformat() if request.date_closed else None
update_vals = {'status': request_status.CLOSED}
if not calendar.isbusday(datetime.utcnow()) or datetime.utcnow().date() < request.date_submitted.date():
update_vals['date_closed'] = get_next_business_day()
else:
update_vals['date_closed'] = datetime.utcnow()
if not request.privacy['agency_request_summary'] and request.agency_request_summary is not None:
update_vals['agency_request_summary_release_date'] = calendar.addbusdays(datetime.utcnow(),
RELEASE_PUBLIC_DAYS)
update_object(
update_vals,
Requests,
request_id,
es_update=False
)
else:
update_object(
update_vals,
Requests,
request_id,
es_update=False
)
create_request_info_event(
request_id,
type_=event_type.REQ_STATUS_CHANGED,
previous_value={'status': previous_status, 'date_closed': previous_date_closed},
new_value={'status': request.status, 'date_closed': request.date_closed.isoformat()}
)

if not calendar.isbusday(datetime.utcnow()) or datetime.utcnow().date() < request.date_submitted.date():
# push the closing date to the next business day if it is a weekend/holiday
# or if it is before the date submitted
response = Determinations(
request_id,
RELEASE_AND_PUBLIC,
determination_type.CLOSING,
reason_text,
date_modified=get_next_business_day(),
release_date=datetime.utcnow()
)
else:
response = Determinations(
request_id,
RELEASE_AND_PUBLIC,
determination_type.CLOSING,
reason_text,
release_date=datetime.utcnow()
)
create_object(response)
create_response_event(event_type.REQ_CLOSED, response)
request.es_update()


def add_quick_closing(request_id, days, date, tz_name, content):
"""Create and store an acknowledgement-determination response followed by a closing-determination response for
Expand Down
4 changes: 2 additions & 2 deletions app/templates/response/add_acknowledgment.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<option value="40">40 Business Days</option>
<option value="60">60 Business Days</option>
<option value="90">90 Business Days</option>
<option value="120">120 Business Days (Not Recommended)</option>
<option value="120">120 Business Days</option>
<option value="-1">Custom Due Date</option>
</select>
<br>
Expand Down Expand Up @@ -72,7 +72,7 @@
<option value="30">30 Business Days</option>
<option value="60">60 Business Days</option>
<option value="90">90 Business Days</option>
<option value="120">120 Business Days (Not Recommended)</option>
<option value="120">120 Business Days</option>
<option value="-1">Custom Due Date</option>
</select>
<br>
Expand Down
2 changes: 1 addition & 1 deletion data/agencies.json
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,7 @@
"text": "<p>For information or assistance with services for older adults, including caregiver services, please call <strong>Aging Connect</strong>, NYC Department for the Aging’s information and referral contact center, at <strong>212-244-6469</strong>. You may also submit an inquiry online at: <a target='_blank' rel='noopener noreferrer' href='https://www.nyc.gov/site/dfta/about/contact-aging-connect.page' >https://www.nyc.gov/site/dfta/about/contact-aging-connect.page</a>.</p><br><p>Requests for employment records of current and/or former NYC Department for the Aging employees should be directed to the NYC Department for the Aging’s Office of Human Resources at: <a href='mailto:[email protected]'>[email protected]</a>.</p><br><p>Requests related to police reports, arrest records, criminal complaints, or other criminal records should be directed to the <strong>New York City Police Department (NYPD)</strong> by selecting “NYPD” in the Agency drop-down menu above.</p>"
}
},
"acronym": "DFTA"
"acronym": "NYC Aging"
},
{
"ein": "0003",
Expand Down
33 changes: 31 additions & 2 deletions openrecords.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
from werkzeug.contrib.profiler import ProfilerMiddleware

from app import create_app, db
from app.constants import OPENRECORDS_DL_EMAIL
from app.constants import OPENRECORDS_DL_EMAIL, request_status
from app.jobs import _update_request_statuses
from app.lib.date_utils import process_due_date, local_to_utc
from app.lib.email_utils import send_email
Expand All @@ -82,7 +82,7 @@
)
from app.report.utils import generate_request_closing_user_report, generate_monthly_metrics_report
from app.request.utils import generate_guid
from app.response.utils import add_extension
from app.response.utils import add_extension, add_closing_cli
from app.search.utils import recreate
from app.user.utils import make_user_admin

Expand Down Expand Up @@ -275,6 +275,35 @@ def extend_requests(agency_ein: str, agency_name: str, user_guid: str, extension
print(request.id, 'failed')


@app.cli.command()
@click.option("--agency_ein", prompt="Agency EIN (e.g. 0056)")
@click.option("--user_guid", prompt="User GUID")
@click.option("--reason_text", prompt="Reason text")
def close_requests(agency_ein: str, user_guid: str, reason_text: str):
# Create request context
ctx = app.test_request_context()
ctx.push()
app.preprocess_request()

# Select user to perform the extensions
user = Users.query.filter_by(guid=user_guid).first()
login_user(user)

# Close open requests
open_requests = Requests.query.filter(Requests.agency_ein==agency_ein, Requests.status!=request_status.CLOSED).order_by(Requests.id).all()
for request in open_requests:
try:
# Close request
add_closing_cli(
request.id,
reason_text,
)
print(request.id, 'closed')
except Exception as e:
print(request.id, 'failed')
print(e)


@app.cli.command()
def update_request_statuses():
_update_request_statuses()
Expand Down

0 comments on commit d041a98

Please sign in to comment.