Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #313 from FIRST-Tech-Challenge/2023.05.19-site-dow…
Browse files Browse the repository at this point in the history
…n-cleanup

A tad cleaner site status check plus check for site status prior to throwing NoRoles.
  • Loading branch information
cmacfarl authored May 19, 2023
2 parents a6c02a3 + 181bbf5 commit 17138ab
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 13 deletions.
37 changes: 25 additions & 12 deletions server/app_engine/app_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import dataset_zipper
import exceptions
from exceptions import NoRoles
from exceptions import DownForMaintenance
from exceptions import ClosedForOffseason
import frame_extractor
import model_trainer
import oidc
Expand Down Expand Up @@ -432,6 +434,8 @@ def login_via_oidc():

team_roles = oidc.user_getfield('team_roles')

check_site_status()

#
# There are a couple reasons that a user might have no team roles, lack
# of YPP screening or a global admin or custom role that is not also
Expand Down Expand Up @@ -532,10 +536,7 @@ def login():
@handle_exceptions
@redirect_to_login_if_needed
def index():
if config.config[KEY_SITE_DOWN_FOR_MAINTENANCE]:
return 'This site is temporarily down for maintenance.'
elif config.config[KEY_SITE_CLOSED_FOR_OFFSEASON]:
return flask.render_template('offseason.html')
check_site_status()

roles.can_login(flask.session['user_roles'], flask.session['team_number'])

Expand All @@ -552,10 +553,7 @@ def index():
@handle_exceptions
@redirect_to_login_if_needed
def label_video():
if config.config[KEY_SITE_DOWN_FOR_MAINTENANCE]:
return 'This site is temporarily down for maintenance.'
elif config.config[KEY_SITE_CLOSED_FOR_OFFSEASON]:
return flask.render_template('offseason.html')
check_site_status()

team_uuid = team_info.retrieve_team_uuid(flask.session, flask.request)
data = validate_keys(flask.request.args.to_dict(flat=True),
Expand All @@ -582,10 +580,7 @@ def label_video():
@handle_exceptions
@redirect_to_login_if_needed
def monitor_training():
if config.config[KEY_SITE_DOWN_FOR_MAINTENANCE]:
return 'This site is temporarily down for maintenance.'
elif config.config[KEY_SITE_CLOSED_FOR_OFFSEASON]:
return flask.render_template('offseason.html')
check_site_status()

team_uuid = team_info.retrieve_team_uuid(flask.session, flask.request)
data = validate_keys(flask.request.args.to_dict(flat=True),
Expand Down Expand Up @@ -1650,6 +1645,13 @@ def perform_action_gcf():
return 'OK'


def check_site_status():
if config.config[KEY_SITE_DOWN_FOR_MAINTENANCE]:
raise DownForMaintenance()
elif config.config[KEY_SITE_CLOSED_FOR_OFFSEASON]:
raise ClosedForOffseason()


# errors
def add_userinfo_breadcrumb():
if sentry_dsn is not None:
Expand Down Expand Up @@ -1708,6 +1710,17 @@ def forbidden_handler(e):
error_message="You do not have the required permissions to access this page"), 403


@app.errorhandler(ClosedForOffseason)
def closed_handler(e):
return flask.render_template('offseason.html')


@app.errorhandler(DownForMaintenance)
def maintenance_handler(e):
return flask.render_template('maintenance.html')



# For running locally:
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
Expand Down
11 changes: 10 additions & 1 deletion server/app_engine/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,13 @@ def __init__(self, message, status_code=500):


class NoRoles(Exception):
pass
pass


class DownForMaintenance(Exception):
pass


class ClosedForOffseason(Exception):
pass

27 changes: 27 additions & 0 deletions server/app_engine/templates/maintenance.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!--
Copyright 2020 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
{% extends 'layout.html' %}

{% block content %}
<main class="flex-shrink-0">
<div class="row justify-content-center">
<h3 class="text-center">The Machine Learning Toolchain is currently down for maintenance.</h3>
</div>
<div class="row justify-content-center">
<img src="https://info.firstinspires.org/hubfs/first_in_show/centerstage.svg">
</div>
</main>
{% endblock %}

0 comments on commit 17138ab

Please sign in to comment.