Skip to content

Commit

Permalink
only show schools with is_shown==True
Browse files Browse the repository at this point in the history
  • Loading branch information
Belissimo-T committed Jun 19, 2024
1 parent e070513 commit 73bb22e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
7 changes: 5 additions & 2 deletions endpoints/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
@api.route(f"/api/v69.420/schools", methods=["GET"])
@login_required
def schools() -> Response:
# school_data = get_all_schools_by_number()
school_data = get_all_schools()
if current_user.get_field("admin"):
school_data = get_all_schools(only_shown=False)
else:
school_data = get_all_schools(only_shown=True, include_ids=current_user.get_authorized_schools())

return send_success(school_data)


Expand Down
19 changes: 17 additions & 2 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,22 @@ def get_school_by_id(school_num: str):


# doesn't get the passwords
def get_all_schools():
pipeline = [
def get_all_schools(only_shown: bool = True, include_ids: list[str] = None):
if only_shown:
pipeline = [
{
"$match": {
"$or": [
{"is_shown": True},
{"_id": {"$in": include_ids}}
]
}
}
]
else:
pipeline = []

pipeline += [
{
"$match": {
"is_shown": True
Expand All @@ -246,6 +260,7 @@ def get_all_schools():
}
}
]

schools_list = list(creds.aggregate(pipeline))
for ind, elem in enumerate(schools_list):
schools_list[ind]["creds_needed"] = True if elem["hosting"]["creds"] else False
Expand Down

0 comments on commit 73bb22e

Please sign in to comment.