Skip to content

Commit

Permalink
[admin] nonprofit applications
Browse files Browse the repository at this point in the history
  • Loading branch information
gregv committed Aug 31, 2024
1 parent f2345ec commit 9f9c6d0
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
47 changes: 47 additions & 0 deletions api/messages/messages_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,53 @@ def unjoin_team(propel_user_id, json):
return Message(
"Removed from Team")

@limits(calls=100, period=ONE_MINUTE)
def update_npo_application( application_id, json, propel_id):
send_slack_audit(action="update_npo_application", message="Updating", payload=json)
db = get_db()
logger.info("NPO Application Update")
doc = db.collection('project_applications').document(application_id)
if doc:
doc_dict = doc.get().to_dict()
send_slack_audit(action="update_npo_application",
message="Updating", payload=doc_dict)
doc.update(json)

# Clear cache for get_npo_applications
logger.info(f"Clearing cache for application_id={application_id}")

clear_cache()

return Message(
"Updated NPO Application"
)


@limits(calls=100, period=ONE_MINUTE)
def get_npo_applications():
logger.info("get_npo_applications Start")
db = get_db()

# Use a transaction to ensure consistency
@firestore.transactional
def get_latest_docs(transaction):
docs = db.collection('project_applications').get(transaction=transaction)
return [doc_to_json(docid=doc.id, doc=doc) for doc in docs]


# Use a transaction to get the latest data
transaction = db.transaction()
results = get_latest_docs(transaction)

if not results:
return {"applications": []}

logger.info(results)
logger.info("get_npo_applications End")

return {"applications": results}


@limits(calls=100, period=ONE_MINUTE)
def save_npo_application(json):
send_slack_audit(action="save_npo_application", message="Saving", payload=json)
Expand Down
16 changes: 15 additions & 1 deletion api/messages/messages_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
save_lead_async,
get_news,
get_all_profiles,
save_npo_application
save_npo_application,
get_npo_applications,
update_npo_application
)


Expand Down Expand Up @@ -108,6 +110,18 @@ def get_npo(npo_id):
def submit_npo_application():
return vars(save_npo_application(request.get_json()))

@bp.route("/npo/applications", methods=["GET"])
@auth.require_user
@auth.require_org_member_with_permission("volunteer.admin", req_to_org_id=getOrgId)
def get_npo_applications_api():
return get_npo_applications()

@bp.route("/npo/applications/<application_id>", methods=["PATCH"])
@auth.require_user
@auth.require_org_member_with_permission("volunteer.admin", req_to_org_id=getOrgId)
def update_npo_application_api(application_id):
if auth_user and auth_user.user_id:
return vars(update_npo_application(application_id, request.get_json(), auth_user.user_id))

#
# Hackathon Related Endpoints
Expand Down

0 comments on commit 9f9c6d0

Please sign in to comment.