Skip to content

Commit

Permalink
Admin mode now has a system panel to set system wide messages for all…
Browse files Browse the repository at this point in the history
… users
  • Loading branch information
dhakim87 committed Jun 13, 2020
1 parent 318bae3 commit 9dd5ed7
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 38 deletions.
46 changes: 18 additions & 28 deletions microsetta_private_api/example/client.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -534,14 +534,27 @@ paths:
type: string
post:
operationId: microsetta_private_api.example.client_impl.post_system_message
parameters:
- $ref: '#/components/parameters/system_msg'
- $ref: '#/components/parameters/msg_style'
tags:
- Admin
requestBody:
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
system_msg:
type: string
nullable: true
msg_style:
type: string
enum: [null, "primary", "secondary", "success", "danger", "warning", "info", "light", "dark"]
responses:
'204':
description: Successfully set system message
'200':
description: System Message Builder Webpage
content:
text/html:
schema:
type: string

components:
parameters:
Expand Down Expand Up @@ -601,19 +614,6 @@ components:
description: Error message provided by front-end
schema:
$ref: '#/components/schemas/error_msg'
system_msg:
name: system_msg
in: query
description: System wide message set by administrator
schema:
$ref: '#/components/schemas/system_msg'
msg_style:
name: msg_style
in: query
description: Styling of system_msg
schema:
$ref: '#/components/schemas/msg_style'


schemas:
# account section
Expand All @@ -635,16 +635,6 @@ components:
error_msg:
type: string
example: "%7B%0A%20%20%22detail%22%3A%20%22The%20browser%20(or%20proxy)%20sent%20a%20request%20that%20this%20server%20could%20not%20understand.%22%2C%0A%20%20%22status%22%3A%20400%2C%0A%20%20%22title%22%3A%20%22Bad%20Request%22%2C%0A%20%20%22type%22%3A%20%22about%3Ablank%22%0A%7D%0A"
system_msg:
type: string
nullable: true
example: "%7B%0A%20%20%22detail%22%3A%20%22The%20browser%20(or%20proxy)%20sent%20a%20request%20that%20this%20server%20could%20not%20understand.%22%2C%0A%20%20%22status%22%3A%20400%2C%0A%20%20%22title%22%3A%20%22Bad%20Request%22%2C%0A%20%20%22type%22%3A%20%22about%3Ablank%22%0A%7D%0A"
msg_style:
type: string
nullable: true
enum: [null, "primary", "secondary", "success", "danger", "warning", "info", "light", "dark"]
example: "warning"

kit_name:
type: string
example: "aaaaa"
Expand Down
55 changes: 51 additions & 4 deletions microsetta_private_api/example/client_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# config somewhere and reload

# Python is dumb, don't put spaces anywhere in this string.
from werkzeug.exceptions import BadRequest
from werkzeug.exceptions import BadRequest, Unauthorized

from microsetta_private_api.config_manager import SERVER_CONFIG
from microsetta_private_api.model.source import Source
Expand Down Expand Up @@ -339,6 +339,8 @@ def get_show_error_page(error_msg):

output = render_template('error.jinja2',
admin_mode=session.get(ADMIN_MODE_KEY, False),
system_msg_text=SYSTEM_MSG,
system_msg_style=SYSTEM_MSG_STYLE,
mailto_url=mailto_url,
error_msg=error_msg,
endpoint=SERVER_CONFIG["endpoint"],
Expand All @@ -351,6 +353,8 @@ def get_show_error_page(error_msg):
def get_show_faq():
output = render_template('faq.jinja2',
admin_mode=session.get(ADMIN_MODE_KEY, False),
system_msg_text=SYSTEM_MSG,
system_msg_style=SYSTEM_MSG_STYLE,
authrocket_url=SERVER_CONFIG["authrocket_url"],
endpoint=SERVER_CONFIG["endpoint"])
return output
Expand Down Expand Up @@ -384,6 +388,8 @@ def get_home():
if session.get(ADMIN_MODE_KEY, False):
return render_template('admin_home.jinja2',
admin_mode=session.get(ADMIN_MODE_KEY, False),
system_msg_text=SYSTEM_MSG,
system_msg_style=SYSTEM_MSG_STYLE,
accounts=[],
endpoint=SERVER_CONFIG["endpoint"],
authrocket_url=SERVER_CONFIG["authrocket_url"])
Expand All @@ -392,6 +398,8 @@ def get_home():
# login if they aren't logged in yet.
return render_template('home.jinja2',
admin_mode=session.get(ADMIN_MODE_KEY, False),
system_msg_text=SYSTEM_MSG,
system_msg_style=SYSTEM_MSG_STYLE,
user=user,
email_verified=email_verified,
accounts=accts_output,
Expand Down Expand Up @@ -454,6 +462,8 @@ def get_create_account():
return render_template('account_details.jinja2',
CREATE_ACCT=True,
admin_mode=session.get(ADMIN_MODE_KEY, False),
system_msg_text=SYSTEM_MSG,
system_msg_style=SYSTEM_MSG_STYLE,
authorized_email=email,
account=default_account_values)

Expand Down Expand Up @@ -496,6 +506,8 @@ def get_update_email(account_id):

return render_template("update_email.jinja2",
admin_mode=session.get(ADMIN_MODE_KEY, False),
system_msg_text=SYSTEM_MSG,
system_msg_style=SYSTEM_MSG_STYLE,
account_id=account_id)


Expand Down Expand Up @@ -544,6 +556,8 @@ def get_account(account_id):

return render_template('account_overview.jinja2',
admin_mode=session.get(ADMIN_MODE_KEY, False),
system_msg_text=SYSTEM_MSG,
system_msg_style=SYSTEM_MSG_STYLE,
account=account,
sources=sources)

Expand All @@ -560,6 +574,8 @@ def get_account_details(account_id):
return render_template('account_details.jinja2',
CREATE_ACCT=False,
admin_mode=session.get(ADMIN_MODE_KEY, False),
system_msg_text=SYSTEM_MSG,
system_msg_style=SYSTEM_MSG_STYLE,
account=account)


Expand Down Expand Up @@ -659,6 +675,8 @@ def get_fill_local_source_survey(account_id, source_id, survey_template_id):

return render_template("survey.jinja2",
admin_mode=session.get(ADMIN_MODE_KEY, False),
system_msg_text=SYSTEM_MSG,
system_msg_style=SYSTEM_MSG_STYLE,
endpoint=SERVER_CONFIG["endpoint"],
account_id=account_id,
source_id=source_id,
Expand Down Expand Up @@ -841,6 +859,8 @@ def get_source(account_id, source_id):
is_human = source_output['source_type'] == Source.SOURCE_TYPE_HUMAN
return render_template('source.jinja2',
admin_mode=session.get(ADMIN_MODE_KEY, False),
system_msg_text=SYSTEM_MSG,
system_msg_style=SYSTEM_MSG_STYLE,
account_id=account_id,
source_id=source_id,
is_human=is_human,
Expand Down Expand Up @@ -897,6 +917,8 @@ def get_update_sample(account_id, source_id, sample_id):

return render_template('sample.jinja2',
admin_mode=session.get(ADMIN_MODE_KEY, False),
system_msg_text=SYSTEM_MSG,
system_msg_style=SYSTEM_MSG_STYLE,
account_id=account_id,
source_id=source_id,
source_name=source_output['source_name'],
Expand Down Expand Up @@ -996,6 +1018,9 @@ def post_claim_samples(account_id, source_id, body):

# Administrator Mode Functionality
def get_interactive_account_search(email_query):
if not session.get(ADMIN_MODE_KEY, False):
raise Unauthorized()

do_return, email_diagnostics, _ = ApiRequest.get(
'/admin/search/account/%s' % (email_query,))
if do_return:
Expand All @@ -1005,18 +1030,40 @@ def get_interactive_account_search(email_query):
for acct in email_diagnostics['accounts']]
return render_template('admin_home.jinja2',
admin_mode=session.get(ADMIN_MODE_KEY, False),
system_msg_text=SYSTEM_MSG,
system_msg_style=SYSTEM_MSG_STYLE,
accounts=accounts,
endpoint=SERVER_CONFIG["endpoint"],
authrocket_url=SERVER_CONFIG["authrocket_url"])


def get_system_message():
if not session.get(ADMIN_MODE_KEY, False):
raise Unauthorized()

return render_template('admin_system_panel.jinja2',
admin_mode=session.get(ADMIN_MODE_KEY, False))
admin_mode=session.get(ADMIN_MODE_KEY, False),
system_msg=SYSTEM_MSG,
msg_style=SYSTEM_MSG_STYLE)


def post_system_message(body):
if not session.get(ADMIN_MODE_KEY, False):
raise Unauthorized()

def post_system_message():
pass
global SYSTEM_MSG
global SYSTEM_MSG_STYLE
SYSTEM_MSG = body.get("system_msg")
SYSTEM_MSG_STYLE = body.get("msg_style")

if not SYSTEM_MSG or len(SYSTEM_MSG) == 0:
SYSTEM_MSG = None
SYSTEM_MSG_STYLE = None

return render_template('admin_system_panel.jinja2',
admin_mode=session.get(ADMIN_MODE_KEY, False),
system_msg=SYSTEM_MSG,
msg_style=SYSTEM_MSG_STYLE)


class BearerAuth(AuthBase):
Expand Down
21 changes: 21 additions & 0 deletions microsetta_private_api/static/input_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,24 @@ function preclude_whitespace(selector)
});
});
}

function replicate_text(input_selector, destination_selector)
{
$(input_selector).bind('input', function(){
$(this).val(function(_, v){
$(destination_selector).html(v)
return v
});
});
}

function select_class(input_selector, destination_selector, input_to_class)
{
$(input_selector).change(function(){
$(this).val(function(_, v){
$(destination_selector).removeClass()
$(destination_selector).addClass(input_to_class(v))
return v
});
});
}
29 changes: 23 additions & 6 deletions microsetta_private_api/templates/admin_system_panel.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,37 @@
{% set show_breadcrumbs = False %}
{% set show_logout = True %}
{% block head %}

<script>
$(function(){
to_class = function(choice){ return ["alert", "alert-"+choice]; }
replicate_text("#system_msg", "#test_msg");
select_class("#msg_style", "#test_msg", to_class);
});
</script>
{% endblock %}
{% block content %}
<h4> Set System Message </h4>
<div id="test_msg" class="alert alert-primary" role="alert">
A simple primary alert—check it out!
<div id="test_msg" class="alert alert-{{msg_style|e}}" role="alert">
{{system_msg}}
</div>

<form method="post" id="sample_form" name="sample_form">
<form method="post" id="system_msg_form" name="system_msg_form">
<div class="form-group row">
<label for="system_msg" name="system_msg_label" class="col-sm-2 col-form-label">System Message:</label>
<div class="col-sm-4">
<textarea class="form-control" id="system_msg" name="system_msg" rows="3">The system is entering scheduled downtime.</textarea>
<div class="col-sm-8">
<textarea class="form-control" id="system_msg" name="system_msg" rows="5">{{system_msg |e}}</textarea>
<select id="msg_style" name="msg_style" class="form-control" required>
<option value="primary" {% if msg_style == "primary" %} selected {% endif %}>primary</option>
<option value="secondary" {% if msg_style == "secondary" %} selected {% endif %}>secondary</option>
<option value="success" {% if msg_style == "success" %} selected {% endif %}>success</option>
<option value="danger" {% if msg_style == "danger" %} selected {% endif %}>danger</option>
<option value="warning" {% if msg_style == "warning" %} selected {% endif %}>warning</option>
<option value="info" {% if msg_style == "info" %} selected {% endif %}>info</option>
<option value="light" {% if msg_style == "light" %} selected {% endif %}>light</option>
<option value="dark" {% if msg_style == "dark" %} selected {% endif %}>dark</option>
</select>
</div>
</div>
<button type="submit" class="btn btn-primary">Set System Message</button>
</form>
{% endblock %}
6 changes: 6 additions & 0 deletions microsetta_private_api/templates/sitebase.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
<br />
{% endif %}

{% if system_msg_text and not admin_mode %}
<div id="system_message" class="alert alert-{{system_msg_style|e}}" role="alert">
{{system_msg_text}}
</div>
{% endif %}

<div class="content">

{% if show_breadcrumbs %}
Expand Down

0 comments on commit 9dd5ed7

Please sign in to comment.