def super_clients(): if not is_staff(app.remote, MASTER_COURSE): return "" with connect_db() as db: ret = db("SELECT client_name, creator, unused FROM super_auth_keys" ).fetchall() super_client_names = [ make_row( f'{client_name}, created by {creator} {"(unused)" if unused else ""} ', url_for("revoke_super_key", client_name=client_name), ) for client_name, creator, unused in ret ] return f""" <h3>Super-Clients</h3> <p> Warning - the API keys for these clients are extremely sensitive, as they can access <i>any</i> course's data. Only use them for 61A-hosted apps, and reset them whenever a head TA leaves course staff. </p> Create new super-client and obtain secret key: <form action="{url_for("create_super_key")}" method="post"> <input name="client_name" type="text" placeholder="client_name"> <input type="submit"> </form> """ + "<p>".join(super_client_names)
def slack_help(course): with connect_db() as db: workspace = db( "SELECT workspace FROM slack_config WHERE course=(%s)", [course]).fetchone() workspace = workspace[0] if workspace else "" registered_channels = db( "SELECT purpose, channel, channel_id FROM slack_channels WHERE course=(%s)", [course], ) channel_request = requests.post( f"https://slack.apps.cs61a.org/api/{course}/list_channels", json={"secret": getenv("SLACK_API_SECRET")}, ) if channel_request.status_code != 200: registration = """ To register Slack channels, first go to <a href="https://slack.apps.cs61a.org">slack.apps.cs61a.org</a> to add the bot to your workspace """ else: channels = [ f"<option value=\"{channel['name']}\">{channel['name']}</option>" for channel in channel_request.json() ] registration = f""" Register a new Slack channel. <form action="/slack/{course}/register_channel" method="post"> <input name="purpose" type="text" placeholder="Purpose"> <select name="channel"> {channels} </select> <input type="submit"> </form> """ registered_channels_list = "<p>".join( make_row( f"{purpose} associated with #{channel} (id: {channel_id})", url_for("remove_channel", course=course, purpose=purpose), ) for purpose, channel, channel_id in registered_channels) return f"""
def domains_help(course): with connect_db() as db: ret = db( "SELECT domain FROM domains_config WHERE course=(%s)", [course], ).fetchall() client_names = [ make_row(domain, url_for("remove_domain", domain=domain, course=course)) for domain, in ret ] register_domain = f""" Register new domain: <form action="/domains/{course}/register_domain" method="post"> <input name="domain_name" type="text" placeholder="seating.cs61a.org"> <input type="submit"> </form> """ return "<h3>Domains</h3>" + register_domain + "<p>".join(client_names)
def client_data(course): with connect_db() as db: ret = db( "SELECT email, name, course, creator FROM course_admins WHERE course=(%s)", [course], ).fetchall() admin_names = [ make_row( f'{name} (<a href="mailto:{email}">{email}</a>), added by {creator} ', url_for("remove_admin", course=course, email=email), ) for email, name, course, creator in ret ] create_client = f""" Add new course administrator: <form action="{url_for("add_admin", course=course)}" method="post"> <input name="email" type="email" placeholder="Email address"> <input type="submit"> </form> """ return "<h3>Admins</h3>" + create_client + "<p>".join(admin_names)
def client_data(course): with connect_db() as db: ret = db( "SELECT client_name, creator, unused FROM auth_keys WHERE course=(%s)", [course], ).fetchall() client_names = [ make_row( f'{client_name}, created by {creator} {"(unused)" if unused else ""} ', url_for("revoke_key", course=course, client_name=client_name), ) for client_name, creator, unused in ret ] create_client = f""" Create new client and obtain secret key: <form action="{url_for("create_key", course=course)}" method="post"> <input name="client_name" type="text" placeholder="client_name"> <input type="submit"> </form> """ return "<h3>Clients</h3>" + create_client + "<p>".join(client_names)
def add_course(): if not is_staff(app.remote, MASTER_COURSE): return "" with connect_db() as db: courses = db("SELECT course, endpoint FROM courses").fetchall() courses = [ make_row( "{} ({}), at endpoint {}".format(prettify(course), course, endpoint), url_for("remove_course", course=course), ) for course, endpoint in courses ] return """ <h2>Admin</h2> <h3>Courses</h3> Activate Auth for a new course (method only available to 61A admins): <form action="/api/add_course" method="post"> <input name="course" type="text" placeholder="course name"> <input name="endpoint" type="text" placeholder="OKPy endpoint"> <input type="submit"> </form> """ + "<p>".join(courses)