Skip to content

Commit

Permalink
Merge pull request #152 from CityOfNewYork/hotfix/agency_description_…
Browse files Browse the repository at this point in the history
…release_date_on_closing

HotFix: Agency Description Release Date Fix
  • Loading branch information
joelbcastillo authored May 4, 2017
2 parents a842798 + ab3c217 commit 16310df
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 33 deletions.
1 change: 1 addition & 0 deletions app/constants/event_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
REQ_AGENCY_DESC_EDITED = "request_agency_description_edited"
REQ_TITLE_PRIVACY_EDITED = "request_title_privacy_edited"
REQ_AGENCY_DESC_PRIVACY_EDITED = "request_agency_description_privacy_edited"
REQ_AGENCY_DESC_DATE_SET = "request_agency_description_date_set"
EMAIL_NOTIFICATION_SENT = "email_notification_sent"
FILE_ADDED = "file_added"
FILE_EDITED = "file_edited"
Expand Down
4 changes: 2 additions & 2 deletions app/request/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from app.models import Events


def create_edit_event(request_id, type_, previous_value, new_value):
def create_request_info_event(request_id, type_, previous_value, new_value):
"""
Create and store events object for editing request information into database.
Create and store events object for updating the request information into database.
:param request_id: request ID
:param type_: event type
Expand Down
36 changes: 10 additions & 26 deletions app/request/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from flask_login import current_user
from app.lib.date_utils import calendar
from app.request.api import request_api_blueprint
from app.request.api.utils import create_edit_event
from app.request.api.utils import create_request_info_event
from app.lib.db_utils import update_object
from app.lib.utils import eval_request_bool
from app.lib.permission_utils import (
Expand Down Expand Up @@ -58,34 +58,18 @@ def edit_privacy():
previous_value['privacy'] = current_request.privacy['agency_description']
new_value['privacy'] = agency_desc
type_ = event_type.REQ_AGENCY_DESC_PRIVACY_EDITED
if not privacy['agency_description']:
# if current_request.agency_description_release_date:
previous_value['release_date'] = None
release_date = calendar.addbusdays(datetime.utcnow(), offset=20)
update_object({'privacy': privacy,
'agency_description_release_date': release_date},
Requests,
current_request.id)
new_value['release_date'] = release_date.isoformat()
else:
previous_value['release_date'] = current_request.agency_description_release_date.isoformat()
update_object({'privacy': privacy,
'agency_description_release_date': None},
Requests,
current_request.id)
new_value['release_date'] = None
create_edit_event(request_id,
type_,
previous_value,
new_value)
create_request_info_event(request_id,
type_,
previous_value,
new_value)
return jsonify(privacy), 200
update_object({'privacy': privacy},
Requests,
current_request.id)
create_edit_event(request_id,
type_,
previous_value,
new_value)
create_request_info_event(request_id,
type_,
previous_value,
new_value)
return jsonify(privacy), 200


Expand Down Expand Up @@ -115,7 +99,7 @@ def edit_request_info():
update_object({edit_request['name']: val if val else None},
Requests,
current_request.id)
create_edit_event(request_id,
create_request_info_event(request_id,
type_,
previous_value,
new_value)
Expand Down
21 changes: 16 additions & 5 deletions app/response/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
ResponseTokens,
Users,
)
from app.request.api.utils import create_request_info_event


# TODO: class ResponseProducer()
Expand Down Expand Up @@ -252,11 +253,21 @@ def add_closing(request_id, reason_ids, email_content):
)
create_object(response)
create_response_event(event_type.REQ_CLOSED, response)
update_object(
{'agency_description_release_date': calendar.addbusdays(datetime.utcnow(), RELEASE_PUBLIC_DAYS)},
Requests,
request_id
)
if current_request.agency_description and not current_request.privacy['agency_description']:
date_now_local = utc_to_local(datetime.utcnow(), current_app.config['APP_TIMEZONE'])
release_date = local_to_utc(calendar.addbusdays(date_now_local, RELEASE_PUBLIC_DAYS),
current_app.config['APP_TIMEZONE'])
update_object(
{'agency_description_release_date': release_date},
Requests,
request_id
)
create_request_info_event(
request_id,
event_type.REQ_AGENCY_DESC_DATE_SET,
None,
{"release_date": release_date.isoformat()}
)
_send_response_email(request_id,
privacy,
email_content,
Expand Down

0 comments on commit 16310df

Please sign in to comment.