Skip to content

Commit

Permalink
fix admin school selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Belissimo-T authored and OfficialFreak committed Dec 4, 2024
1 parent 7c5eb23 commit 6dd6738
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
4 changes: 4 additions & 0 deletions endpoints/authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from discord_webhook import DiscordEmbed

import utils
from user_settings import DEFAULT_SETTINGS
from utils import User, users
from utils import send_error, send_success
Expand Down Expand Up @@ -121,6 +122,9 @@ def settings() -> Response:
@authorization.route(f'{AUTH_PATH}/authorized_schools', methods=['GET'])
@login_required
def authorized_schools() -> Response:
if current_user.get_field("admin"):
return send_success([elem["school_number"] for elem in utils.get_all_schools(only_shown=False)])

return send_success(current_user.get_authorized_schools())


Expand Down
39 changes: 20 additions & 19 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ def get_school_by_id(school_num: str):
# doesn't get the passwords
def get_all_schools(only_shown: bool = True, include_ids: list[str] = None):
if only_shown:
assert include_ids is not None
pipeline = [
{
"$match": {
Expand All @@ -276,33 +277,33 @@ def get_all_schools(only_shown: bool = True, include_ids: list[str] = None):
pipeline = []

pipeline += [
{
"$match": {
"is_shown": True
}
},
{
"$sort": {"count": pymongo.DESCENDING}
},
{
"$project": {
# "_id": False,
"count": False,
# "hosting": False,
"comment": False,
"display_name": 1,
"school_number": 1,
"icon": 1,
"hosting": 1,
}
}
},
{
"$set": {
"creds_needed": {
"$gt": [
"$hosting.creds",
{}
]
}
}
},
{
"$unset": ["hosting"]
},
]

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
del schools_list[ind]["hosting"]
return schools_list


def get_all_schools_by_number():
return {elem["_id"]: elem for elem in get_all_schools()}
return list(creds.aggregate(pipeline))


def add_database_icons():
Expand Down

0 comments on commit 6dd6738

Please sign in to comment.