Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[admin] nonprofit applications #82

Merged
merged 1 commit into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading