Skip to content

Commit

Permalink
[Profile] Add linkedin and IG URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
gregv committed Sep 17, 2024
1 parent 18fff92 commit 29546d5
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 3 deletions.
71 changes: 70 additions & 1 deletion api/messages/messages_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -1847,6 +1847,8 @@ def get_history_old(db_id):
"expertise": res["expertise"] if "expertise" in res else "",
"education": res["education"] if "education" in res else "",
"shirt_size": res["shirt_size"] if "shirt_size" in res else "",
"linkedin_url": res["linkedin_url"] if "linkedin_url" in res else "",
"instagram_url": res["instagram_url"] if "instagram_url" in res else "",
"github": res["github"] if "github" in res else "",
"why": res["why"] if "why" in res else "",
"role": res["role"] if "role" in res else "",
Expand Down Expand Up @@ -1938,7 +1940,7 @@ def save_profile_metadata_old(propel_id, json):
logger.info(f"User exists: {user.id}")

# Only update metadata that is in the json
metadataList = ["role", "expertise", "education", "company", "why", "shirt_size", "github"]
metadataList = ["role", "expertise", "education", "company", "why", "shirt_size", "github", "linkedin_url", "instagram_url"]

d = {}

Expand Down Expand Up @@ -1975,3 +1977,70 @@ def get_user_by_id_old(id):
logger.debug(f"Get User By ID Result: {res}")
return res


@limits(calls=50, period=ONE_MINUTE)
def save_feedback(propel_user_id, json):
db = get_db()
logger.info("Saving Feedback")
send_slack_audit(action="save_feedback", message="Saving", payload=json)

slack_user = get_slack_user_from_propel_user_id(propel_user_id)
user_db_id = get_user_from_slack_id(slack_user["sub"]).id
feedback_giver_id = slack_user["sub"]

doc_id = uuid.uuid1().hex
feedback_receiver_id = json.get("feedback_receiver_id")
relationship = json.get("relationship")
duration = json.get("duration")
confidence_level = json.get("confidence_level")
is_anonymous = json.get("is_anonymous", False)
feedback_data = json.get("feedback", {})

collection = db.collection('feedback')

insert_res = collection.document(doc_id).set({
"feedback_giver_slack_id": feedback_giver_id,
"feedback_giver_id": user_db_id,
"feedback_receiver_id": feedback_receiver_id,
"relationship": relationship,
"duration": duration,
"confidence_level": confidence_level,
"is_anonymous": is_anonymous,
"feedback": feedback_data,
"timestamp": datetime.now().isoformat()
})

logger.info(f"Insert Result: {insert_res}")

# Notify the feedback receiver
notify_feedback_receiver(feedback_receiver_id)

# Clear cache
get_user_feedback.cache_clear()

return Message("Feedback saved successfully")

def notify_feedback_receiver(feedback_receiver_id):
# Implement notification logic here
# This could be sending an email, a Slack message, or updating a notification field in the user's document
pass

@cached(cache=TTLCache(maxsize=100, ttl=600))
@limits(calls=100, period=ONE_MINUTE)
def get_user_feedback(propel_user_id):
logger.info(f"Getting feedback for propel_user_id: {propel_user_id}")
db = get_db()

slack_user = get_slack_user_from_propel_user_id(propel_user_id)
db_user_id = get_user_from_slack_id(slack_user["sub"]).id

feedback_docs = db.collection('feedback').where("feedback_receiver_id", "==", db_user_id).stream()

feedback_list = []
for doc in feedback_docs:
feedback = doc.to_dict()
if feedback.get("is_anonymous", False):
feedback.pop("feedback_giver_id", None)
feedback_list.append(feedback)

return {"feedback": feedback_list}
22 changes: 21 additions & 1 deletion api/messages/messages_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
get_npo_applications,
update_npo_application,
get_github_profile,
save_praise
save_praise,
save_feedback,
get_user_feedback
)

logger = logging.getLogger("myapp")
Expand Down Expand Up @@ -358,3 +360,21 @@ def all_profiles():
return get_all_profiles()


@bp.route("/feedback", methods=["POST"])
@auth.require_user
def submit_feedback():
if auth_user and auth_user.user_id:
return vars(save_feedback(auth_user.user_id, request.get_json()))
else:
return {"error": "Unauthorized"}, 401

@bp.route("/feedback", methods=["GET"])
@auth.require_user
def get_feedback():
"""
Get feedback for a user - note that you can only get this for the current logged in user
"""
if auth_user and auth_user.user_id:
return get_user_feedback(auth_user.user_id)
else:
return {"error": "Unauthorized"}, 401
4 changes: 3 additions & 1 deletion model/user.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
metadata_list = ["role", "expertise", "education", "company", "why", "shirt_size", "github", "volunteering"]
metadata_list = ["role", "expertise", "education", "company", "why", "shirt_size", "github", "volunteering", "linkedin_url", "instagram_url"]

class User:
id = None
Expand Down Expand Up @@ -34,6 +34,8 @@ def deserialize(cls, d):
u.expertise = d['expertise'] if 'expertise' in d else ''
u.education = d['education'] if 'education' in d else ''
u.shirt_size = d['shirt_size'] if 'shirt_size' in d else ''
u.linkedin_url = d['linkedin_url'] if 'linkedin_url' in d else ''
u.instagram_url = d['instagram_url'] if 'instagram_url' in d else ''
u.github = d['github'] if 'github' in d else ''
u.role = d['role'] if 'role' in d else ''
u.company = d['company'] if 'company' in d else ''
Expand Down

0 comments on commit 29546d5

Please sign in to comment.