mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-19 14:09:20 -04:00
Merge branch 'master' of github.com:alphagov/notifications-admin into deactivate-services-plat-admin
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from flask import request, render_template, redirect, url_for, flash
|
||||
from flask import request, render_template, redirect, url_for, flash, Markup, abort
|
||||
from flask_login import login_required
|
||||
from app.main import main
|
||||
from app.main.forms import CreateKeyForm, Whitelist
|
||||
@@ -68,13 +68,22 @@ def create_api_key(service_id):
|
||||
key['name'] for key in api_key_api_client.get_api_keys(service_id=service_id)['apiKeys']
|
||||
]
|
||||
form = CreateKeyForm(key_names)
|
||||
form.key_type.choices = filter(None, [
|
||||
(KEY_TYPE_NORMAL, 'Send messages to anyone')
|
||||
if not current_service['restricted'] else None,
|
||||
(KEY_TYPE_TEST, 'Simulate sending messages to anyone'),
|
||||
(KEY_TYPE_TEAM, 'Only send messages to your team or whitelist')
|
||||
])
|
||||
form.key_type.choices = [
|
||||
(KEY_TYPE_NORMAL, 'Send messages to anyone'),
|
||||
(KEY_TYPE_TEAM, 'Send messages to anyone on my whitelist'),
|
||||
(KEY_TYPE_TEST, 'Pretend to send messages to anyone'),
|
||||
]
|
||||
if current_service['restricted']:
|
||||
disabled_options = [KEY_TYPE_NORMAL]
|
||||
option_hints = {KEY_TYPE_NORMAL: Markup(
|
||||
'This option is not available because your service is in '
|
||||
'<a href="{}">trial mode</a>'.format(url_for(".trial_mode"))
|
||||
)}
|
||||
else:
|
||||
disabled_options, option_hints = [], {}
|
||||
if form.validate_on_submit():
|
||||
if form.key_type.data in disabled_options:
|
||||
abort(400)
|
||||
secret = api_key_api_client.create_api_key(
|
||||
service_id=service_id,
|
||||
key_name=form.key_name.data,
|
||||
@@ -88,7 +97,9 @@ def create_api_key(service_id):
|
||||
)
|
||||
return render_template(
|
||||
'views/api/keys/create.html',
|
||||
form=form
|
||||
form=form,
|
||||
disabled_options=disabled_options,
|
||||
option_hints=option_hints
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ from app.utils import user_has_permissions
|
||||
|
||||
@main.route("/services/<service_id>/letters")
|
||||
@login_required
|
||||
@user_has_permissions('manage_templates', 'send_letters', admin_override=True, any_=True)
|
||||
def letters(service_id):
|
||||
if not current_service['can_send_letters']:
|
||||
abort(403)
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import itertools
|
||||
from datetime import datetime
|
||||
|
||||
import pytz
|
||||
from flask import render_template
|
||||
from flask_login import login_required
|
||||
|
||||
@@ -63,13 +61,10 @@ def create_global_stats(services):
|
||||
|
||||
def format_stats_by_service(services):
|
||||
for service in services:
|
||||
stats = service['statistics'].values()
|
||||
yield {
|
||||
'id': service['id'],
|
||||
'name': service['name'],
|
||||
'sending': sum((stat['requested'] - stat['delivered'] - stat['failed']) for stat in stats),
|
||||
'delivered': sum(stat['delivered'] for stat in stats),
|
||||
'failed': sum(stat['failed'] for stat in stats),
|
||||
'stats': service['statistics'],
|
||||
'restricted': service['restricted'],
|
||||
'research_mode': service['research_mode'],
|
||||
'created_at': service['created_at'],
|
||||
|
||||
@@ -21,7 +21,7 @@ from notifications_utils.template import Template
|
||||
from notifications_utils.recipients import RecipientCSV, first_column_heading, validate_and_format_phone_number
|
||||
|
||||
from app.main import main
|
||||
from app.main.forms import CsvUploadForm, ChooseTimeForm
|
||||
from app.main.forms import CsvUploadForm, ChooseTimeForm, get_next_days_until, get_furthest_possible_scheduled_time
|
||||
from app.main.uploader import (
|
||||
s3upload,
|
||||
s3download
|
||||
|
||||
@@ -112,11 +112,13 @@ def service_request_to_go_live(service_id):
|
||||
'subject': 'Request to go live',
|
||||
'message': (
|
||||
'On behalf of {} ({})\n\nExpected usage\n---'
|
||||
'\nMOU in place: {}'
|
||||
'\nChannel: {}\nStart date: {}\nStart volume: {}'
|
||||
'\nPeak volume: {}\nUpload or API: {}'
|
||||
).format(
|
||||
current_service['name'],
|
||||
url_for('main.service_dashboard', service_id=current_service['id'], _external=True),
|
||||
form.mou.data,
|
||||
form.channel.data,
|
||||
form.start_date.data,
|
||||
form.start_volume.data,
|
||||
|
||||
@@ -42,7 +42,8 @@ def view_template(service_id, template_id):
|
||||
'views/templates/template.html',
|
||||
template=Template(
|
||||
service_api_client.get_service_template(service_id, template_id)['data'],
|
||||
prefix=current_service['name']
|
||||
prefix=current_service['name'],
|
||||
sms_sender=current_service['sms_sender']
|
||||
)
|
||||
)
|
||||
|
||||
@@ -63,7 +64,8 @@ def view_template_version(service_id, template_id, version):
|
||||
'views/templates/template_history.html',
|
||||
template=Template(
|
||||
service_api_client.get_service_template(service_id, template_id, version)['data'],
|
||||
prefix=current_service['name']
|
||||
prefix=current_service['name'],
|
||||
sms_sender=current_service['sms_sender']
|
||||
)
|
||||
)
|
||||
|
||||
@@ -231,7 +233,8 @@ def view_template_versions(service_id, template_id):
|
||||
versions=[
|
||||
Template(
|
||||
template,
|
||||
prefix=current_service['name']
|
||||
prefix=current_service['name'],
|
||||
sms_sender=current_service['sms_sender']
|
||||
) for template in service_api_client.get_service_template_versions(service_id, template_id)['data']
|
||||
]
|
||||
)
|
||||
|
||||
@@ -47,8 +47,8 @@ def user_profile_name():
|
||||
form = ChangeNameForm(new_name=current_user.name)
|
||||
|
||||
if form.validate_on_submit():
|
||||
current_user.name = form.new_name.data
|
||||
user_api_client.update_user(current_user)
|
||||
user_api_client.update_user_attribute(current_user.id,
|
||||
name=form.new_name.data)
|
||||
return redirect(url_for('.user_profile'))
|
||||
|
||||
return render_template(
|
||||
@@ -107,7 +107,6 @@ def user_profile_email_authenticate():
|
||||
@main.route("/user-profile/email/confirm/<token>", methods=['GET'])
|
||||
@login_required
|
||||
def user_profile_email_confirm(token):
|
||||
|
||||
token_data = check_token(token,
|
||||
current_app.config['SECRET_KEY'],
|
||||
current_app.config['DANGEROUS_SALT'],
|
||||
@@ -115,9 +114,8 @@ def user_profile_email_confirm(token):
|
||||
token_data = json.loads(token_data)
|
||||
user_id = token_data['user_id']
|
||||
new_email = token_data['email']
|
||||
user = user_api_client.get_user(user_id)
|
||||
user.email_address = new_email
|
||||
user_api_client.update_user(user)
|
||||
user_api_client.update_user_attribute(user_id,
|
||||
email_address=new_email)
|
||||
session.pop(NEW_EMAIL, None)
|
||||
|
||||
return redirect(url_for('.user_profile'))
|
||||
@@ -179,10 +177,11 @@ def user_profile_mobile_number_confirm():
|
||||
form = ConfirmMobileNumberForm(_check_code)
|
||||
|
||||
if form.validate_on_submit():
|
||||
current_user.mobile_number = session[NEW_MOBILE]
|
||||
mobile_number = session[NEW_MOBILE]
|
||||
del session[NEW_MOBILE]
|
||||
del session[NEW_MOBILE_PASSWORD_CONFIRMED]
|
||||
user_api_client.update_user(current_user)
|
||||
user_api_client.update_user_attribute(current_user.id,
|
||||
mobile_number=mobile_number)
|
||||
return redirect(url_for('.user_profile'))
|
||||
|
||||
return render_template(
|
||||
|
||||
Reference in New Issue
Block a user