mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-23 01:19:27 -04:00
Merge branch 'master' into add_proxy_header_check
This commit is contained in:
@@ -7,7 +7,6 @@ import itertools
|
||||
import ago
|
||||
from itsdangerous import BadSignature
|
||||
from flask import (
|
||||
Flask,
|
||||
session,
|
||||
render_template,
|
||||
make_response,
|
||||
@@ -37,6 +36,7 @@ from werkzeug.exceptions import abort
|
||||
from werkzeug.local import LocalProxy
|
||||
|
||||
from app import proxy_fix
|
||||
from app.config import configs
|
||||
from app.asset_fingerprinter import AssetFingerprinter
|
||||
from app.its_dangerous_session import ItsdangerousSessionInterface
|
||||
from app.notify_client.service_api_client import ServiceAPIClient
|
||||
@@ -54,8 +54,8 @@ from app.notify_client.models import AnonymousUser
|
||||
from app.notify_client.letter_jobs_client import LetterJobsClient
|
||||
from app.notify_client.inbound_number_client import InboundNumberClient
|
||||
from app.notify_client.billing_api_client import BillingAPIClient
|
||||
from app.commands import setup_commands
|
||||
from app.utils import get_cdn_domain
|
||||
|
||||
from app.utils import gmt_timezones
|
||||
|
||||
login_manager = LoginManager()
|
||||
@@ -82,10 +82,8 @@ billing_api_client = BillingAPIClient()
|
||||
current_service = LocalProxy(partial(_lookup_req_object, 'service'))
|
||||
|
||||
|
||||
def create_app():
|
||||
from app.config import configs
|
||||
|
||||
application = Flask(__name__)
|
||||
def create_app(application):
|
||||
setup_commands(application)
|
||||
|
||||
notify_environment = os.environ['NOTIFY_ENVIRONMENT']
|
||||
|
||||
@@ -128,40 +126,12 @@ def create_app():
|
||||
|
||||
application.session_interface = ItsdangerousSessionInterface()
|
||||
|
||||
application.add_template_filter(format_datetime)
|
||||
application.add_template_filter(format_datetime_24h)
|
||||
application.add_template_filter(format_datetime_normal)
|
||||
application.add_template_filter(format_datetime_short)
|
||||
application.add_template_filter(format_time)
|
||||
application.add_template_filter(valid_phone_number)
|
||||
application.add_template_filter(linkable_name)
|
||||
application.add_template_filter(format_date)
|
||||
application.add_template_filter(format_date_normal)
|
||||
application.add_template_filter(format_date_short)
|
||||
application.add_template_filter(format_datetime_relative)
|
||||
application.add_template_filter(format_delta)
|
||||
application.add_template_filter(format_notification_status)
|
||||
application.add_template_filter(format_notification_status_as_time)
|
||||
application.add_template_filter(format_notification_status_as_field_status)
|
||||
application.add_template_filter(format_notification_status_as_url)
|
||||
application.add_template_filter(formatted_list)
|
||||
application.add_template_filter(nl2br)
|
||||
application.add_template_filter(format_phone_number_human_readable)
|
||||
|
||||
application.after_request(useful_headers_after_request)
|
||||
application.after_request(save_service_after_request)
|
||||
application.before_request(load_service_before_request)
|
||||
|
||||
@application.context_processor
|
||||
def _attach_current_service():
|
||||
return {'current_service': current_service}
|
||||
add_template_filters(application)
|
||||
|
||||
register_errorhandlers(application)
|
||||
|
||||
setup_event_handlers()
|
||||
|
||||
return application
|
||||
|
||||
|
||||
def init_csrf(application):
|
||||
csrf.init_app(application)
|
||||
@@ -185,6 +155,13 @@ def init_csrf(application):
|
||||
|
||||
|
||||
def init_app(application):
|
||||
application.after_request(useful_headers_after_request)
|
||||
application.after_request(save_service_after_request)
|
||||
application.before_request(load_service_before_request)
|
||||
|
||||
@application.context_processor
|
||||
def _attach_current_service():
|
||||
return {'current_service': current_service}
|
||||
|
||||
application.before_request(request_helper.check_proxy_header_before_request)
|
||||
|
||||
@@ -522,3 +499,28 @@ def setup_event_handlers():
|
||||
from app.event_handlers import on_user_logged_in
|
||||
|
||||
user_logged_in.connect(on_user_logged_in)
|
||||
|
||||
|
||||
def add_template_filters(application):
|
||||
for fn in [
|
||||
format_datetime,
|
||||
format_datetime_24h,
|
||||
format_datetime_normal,
|
||||
format_datetime_short,
|
||||
format_time,
|
||||
valid_phone_number,
|
||||
linkable_name,
|
||||
format_date,
|
||||
format_date_normal,
|
||||
format_date_short,
|
||||
format_datetime_relative,
|
||||
format_delta,
|
||||
format_notification_status,
|
||||
format_notification_status_as_time,
|
||||
format_notification_status_as_field_status,
|
||||
format_notification_status_as_url,
|
||||
formatted_list,
|
||||
nl2br,
|
||||
format_phone_number_human_readable,
|
||||
]:
|
||||
application.add_template_filter(fn)
|
||||
|
||||
11
app/commands.py
Normal file
11
app/commands.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from flask import current_app
|
||||
|
||||
|
||||
def list_routes():
|
||||
"""List URLs of all application routes."""
|
||||
for rule in sorted(current_app.url_map.iter_rules(), key=lambda r: r.rule):
|
||||
print("{:10} {}".format(", ".join(rule.methods - set(['OPTIONS', 'HEAD'])), rule.rule))
|
||||
|
||||
|
||||
def setup_commands(application):
|
||||
application.cli.command('list-routes')(list_routes)
|
||||
@@ -72,6 +72,16 @@ def accept_invite(token):
|
||||
if existing_user in service_users:
|
||||
return redirect(url_for('main.service_dashboard', service_id=invited_user.service))
|
||||
else:
|
||||
service = service_api_client.get_service(invited_user.service)['data']
|
||||
# if the service you're being added to can modify auth type, then check if this is relevant
|
||||
if 'email_auth' in service['permissions'] and (
|
||||
# they have a phone number, we want them to start using it. if they dont have a mobile we just
|
||||
# ignore that option of the invite
|
||||
(existing_user.mobile_number and invited_user.auth_type == 'sms_auth') or
|
||||
# we want them to start sending emails. it's always valid, so lets always update
|
||||
invited_user.auth_type == 'email_auth'
|
||||
):
|
||||
user_api_client.update_user_attribute(existing_user.id, auth_type=invited_user.auth_type)
|
||||
user_api_client.add_user_to_service(invited_user.service,
|
||||
existing_user.id,
|
||||
invited_user.permissions)
|
||||
|
||||
@@ -102,10 +102,7 @@ def edit_user_permissions(service_id, user_id):
|
||||
permissions=set(get_permissions_from_form(form)),
|
||||
)
|
||||
if service_has_email_auth:
|
||||
user_api_client.update_user_attribute(
|
||||
user_id,
|
||||
auth_type=form.login_authentication.data
|
||||
)
|
||||
user_api_client.update_user_attribute(user_id, auth_type=form.login_authentication.data)
|
||||
return redirect(url_for('.manage_users', service_id=service_id))
|
||||
|
||||
return render_template(
|
||||
|
||||
@@ -4,7 +4,6 @@ from flask import (
|
||||
jsonify,
|
||||
request,
|
||||
url_for,
|
||||
current_app
|
||||
)
|
||||
from flask_login import login_required
|
||||
|
||||
@@ -21,27 +20,11 @@ from app.utils import (
|
||||
get_template,
|
||||
get_time_left,
|
||||
get_letter_timings,
|
||||
REQUESTED_STATUSES,
|
||||
FAILURE_STATUSES,
|
||||
SENDING_STATUSES,
|
||||
DELIVERED_STATUSES,
|
||||
)
|
||||
|
||||
|
||||
def get_status_arg(filter_args):
|
||||
if 'status' not in filter_args or not filter_args['status']:
|
||||
return REQUESTED_STATUSES
|
||||
elif filter_args['status'] == 'sending':
|
||||
return SENDING_STATUSES
|
||||
elif filter_args['status'] == 'delivered':
|
||||
return DELIVERED_STATUSES
|
||||
elif filter_args['status'] == 'failed':
|
||||
return FAILURE_STATUSES
|
||||
else:
|
||||
current_app.logger.info('Unrecognised status filter: {}'.format(filter_args['status']))
|
||||
return REQUESTED_STATUSES
|
||||
|
||||
|
||||
@main.route("/services/<service_id>/notification/<uuid:notification_id>")
|
||||
@login_required
|
||||
@user_has_permissions('view_activity', admin_override=True)
|
||||
|
||||
@@ -47,8 +47,7 @@ def user_profile_name():
|
||||
form = ChangeNameForm(new_name=current_user.name)
|
||||
|
||||
if form.validate_on_submit():
|
||||
user_api_client.update_user_attribute(current_user.id,
|
||||
name=form.new_name.data)
|
||||
user_api_client.update_user_attribute(current_user.id, name=form.new_name.data)
|
||||
return redirect(url_for('.user_profile'))
|
||||
|
||||
return render_template(
|
||||
@@ -114,8 +113,7 @@ def user_profile_email_confirm(token):
|
||||
token_data = json.loads(token_data)
|
||||
user_id = token_data['user_id']
|
||||
new_email = token_data['email']
|
||||
user_api_client.update_user_attribute(user_id,
|
||||
email_address=new_email)
|
||||
user_api_client.update_user_attribute(user_id, email_address=new_email)
|
||||
session.pop(NEW_EMAIL, None)
|
||||
|
||||
return redirect(url_for('.user_profile'))
|
||||
@@ -183,8 +181,7 @@ def user_profile_mobile_number_confirm():
|
||||
mobile_number = session[NEW_MOBILE]
|
||||
del session[NEW_MOBILE]
|
||||
del session[NEW_MOBILE_PASSWORD_CONFIRMED]
|
||||
user_api_client.update_user_attribute(current_user.id,
|
||||
mobile_number=mobile_number)
|
||||
user_api_client.update_user_attribute(current_user.id, mobile_number=mobile_number)
|
||||
return redirect(url_for('.user_profile'))
|
||||
|
||||
return render_template(
|
||||
|
||||
@@ -23,5 +23,13 @@
|
||||
</div>
|
||||
|
||||
{% if service_has_email_auth %}
|
||||
{{ radios(form.login_authentication, disable=['sms_auth' if user_has_no_mobile_number]) }}
|
||||
{% endif %}
|
||||
{% if user_has_no_mobile_number %}
|
||||
{{ radios(
|
||||
form.login_authentication,
|
||||
disable=['sms_auth'],
|
||||
option_hints={'sms_auth': 'Not available because this team member hasn’t added a phone number to their profile'|safe}
|
||||
) }}
|
||||
{% else %}
|
||||
{{ radios(form.login_authentication) }}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
@@ -262,7 +262,7 @@
|
||||
{% endif %}
|
||||
<li class="bottom-gutter">
|
||||
<a href="{{ url_for('.service_switch_email_auth', service_id=current_service.id) }}" class="button">
|
||||
{{ 'Stop email auth' if 'email_auth' in current_service.permissions else 'Allow email auth' }}
|
||||
{{ 'Stop editing user auth' if 'email_auth' in current_service.permissions else 'Allow editing user auth' }}
|
||||
</a>
|
||||
</li>
|
||||
{% if current_service.active %}
|
||||
|
||||
Reference in New Issue
Block a user