mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-19 14:09:20 -04:00
servicepermission enum part 5
This commit is contained in:
@@ -8,6 +8,7 @@ from app import (
|
||||
notification_api_client,
|
||||
service_api_client,
|
||||
)
|
||||
from app.enums import ServicePermission
|
||||
from app.formatters import email_safe
|
||||
from app.main import main
|
||||
from app.main.forms import CallbackForm, CreateKeyForm, GuestList
|
||||
@@ -26,7 +27,7 @@ dummy_bearer_token = "bearer_token_set" # nosec B105 - this is not a real token
|
||||
def api_integration(service_id):
|
||||
callbacks_link = (
|
||||
".api_callbacks"
|
||||
if current_service.has_permission("inbound_sms")
|
||||
if current_service.has_permission(ServicePermission.INBOUND_SMS)
|
||||
else ".delivery_status_callback"
|
||||
)
|
||||
return render_template(
|
||||
@@ -162,7 +163,7 @@ def check_token_against_dummy_bearer(token):
|
||||
@main.route("/services/<uuid:service_id>/api/callbacks", methods=["GET"])
|
||||
@user_has_permissions("manage_api_keys")
|
||||
def api_callbacks(service_id):
|
||||
if not current_service.has_permission("inbound_sms"):
|
||||
if not current_service.has_permission(ServicePermission.INBOUND_SMS):
|
||||
return redirect(url_for(".delivery_status_callback", service_id=service_id))
|
||||
|
||||
delivery_status_callback, received_text_messages_callback = get_apis()
|
||||
@@ -196,7 +197,7 @@ def delivery_status_callback(service_id):
|
||||
delivery_status_callback = get_delivery_status_callback_details()
|
||||
back_link = (
|
||||
".api_callbacks"
|
||||
if current_service.has_permission("inbound_sms")
|
||||
if current_service.has_permission(ServicePermission.INBOUND_SMS)
|
||||
else ".api_integration"
|
||||
)
|
||||
|
||||
@@ -260,7 +261,7 @@ def get_received_text_messages_callback():
|
||||
)
|
||||
@user_has_permissions("manage_api_keys")
|
||||
def received_text_messages_callback(service_id):
|
||||
if not current_service.has_permission("inbound_sms"):
|
||||
if not current_service.has_permission(ServicePermission.INBOUND_SMS):
|
||||
return redirect(url_for(".api_integration", service_id=service_id))
|
||||
|
||||
received_text_messages_callback = get_received_text_messages_callback()
|
||||
|
||||
@@ -2,6 +2,7 @@ from flask import flash, redirect, render_template, request, url_for
|
||||
from flask_login import current_user
|
||||
|
||||
from app import user_api_client
|
||||
from app.enums import ServicePermission
|
||||
from app.event_handlers import create_archive_user_event
|
||||
from app.main import main
|
||||
from app.main.forms import AdminSearchUsersByEmailForm, AuthTypeForm
|
||||
@@ -40,7 +41,7 @@ def archive_user(user_id):
|
||||
try:
|
||||
user_api_client.archive_user(user_id)
|
||||
except HTTPError as e:
|
||||
if e.status_code == 400 and "manage_settings" in e.message:
|
||||
if e.status_code == 400 and ServicePermission.MANAGE_SETTINGS in e.message:
|
||||
flash(
|
||||
"User can’t be removed from a service - "
|
||||
"check all services have another team member with manage_settings"
|
||||
|
||||
@@ -2,7 +2,7 @@ from flask import abort, flash, redirect, render_template, session, url_for
|
||||
from flask_login import current_user
|
||||
from markupsafe import Markup
|
||||
|
||||
from app.enums import InvitedOrgUserStatus, InvitedUserStatus
|
||||
from app.enums import InvitedOrgUserStatus, InvitedUserStatus, ServicePermission, AuthType
|
||||
from app.main import main
|
||||
from app.models.organization import Organization
|
||||
from app.models.service import Service
|
||||
@@ -61,10 +61,10 @@ def accept_invite(token):
|
||||
# if the user is a Platform Admin, we silently leave this unchanged to prevent a security
|
||||
# issue where someone could switch their auth type to something less secure
|
||||
if (
|
||||
service.has_permission("email_auth")
|
||||
service.has_permission(ServicePermission.EMAIL_AUTH)
|
||||
and not existing_user.platform_admin
|
||||
):
|
||||
if invited_user.auth_type == "email_auth" or (
|
||||
if invited_user.auth_type == AuthType.EMAIL_AUTH or (
|
||||
# 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
|
||||
|
||||
@@ -73,7 +73,7 @@ def invite_user(service_id, user_id=None):
|
||||
else:
|
||||
user_to_invite = None
|
||||
|
||||
service_has_email_auth = current_service.has_permission("email_auth")
|
||||
service_has_email_auth = current_service.has_permission(ServicePermission.EMAIL_AUTH)
|
||||
if not service_has_email_auth:
|
||||
form.login_authentication.data = "sms_auth"
|
||||
|
||||
@@ -116,7 +116,7 @@ def invite_user(service_id, user_id=None):
|
||||
@main.route("/services/<uuid:service_id>/users/<uuid:user_id>", methods=["GET", "POST"])
|
||||
@user_has_permissions(ServicePermission.MANAGE_SERVICE)
|
||||
def edit_user_permissions(service_id, user_id):
|
||||
service_has_email_auth = current_service.has_permission("email_auth")
|
||||
service_has_email_auth = current_service.has_permission(ServicePermission.EMAIL_AUTH)
|
||||
user = current_service.get_team_member(user_id)
|
||||
|
||||
mobile_number = None
|
||||
|
||||
@@ -94,7 +94,7 @@ def view_notification(service_id, notification_id, error_message=None):
|
||||
updated_at=notification["sent_at"],
|
||||
help=get_help_argument(),
|
||||
notification_id=notification["id"],
|
||||
can_receive_inbound=(current_service.has_permission("inbound_sms")),
|
||||
can_receive_inbound=(current_service.has_permission(ServicePermission.INBOUND_SMS)),
|
||||
sent_with_test_key=(notification.get("key_type") == KEY_TYPE_TEST),
|
||||
back_link=back_link,
|
||||
)
|
||||
|
||||
@@ -57,14 +57,14 @@ from notifications_python_client.errors import HTTPError
|
||||
PLATFORM_ADMIN_SERVICE_PERMISSIONS = OrderedDict(
|
||||
[
|
||||
(
|
||||
"inbound_sms",
|
||||
ServicePermission.INBOUND_SMS,
|
||||
{
|
||||
"title": "Receive inbound SMS",
|
||||
"requires": "sms",
|
||||
"endpoint": ".service_set_inbound_number",
|
||||
},
|
||||
),
|
||||
("email_auth", {"title": "Email authentication"}),
|
||||
(ServicePermission.EMAIL_AUTH, {"title": "Email authentication"}),
|
||||
]
|
||||
)
|
||||
|
||||
@@ -558,7 +558,7 @@ def service_set_inbound_number(service_id):
|
||||
is_default=True,
|
||||
inbound_number_id=form.inbound_number.data,
|
||||
)
|
||||
current_service.force_permission("inbound_sms", on=True)
|
||||
current_service.force_permission(ServicePermission.INBOUND_SMS, on=True)
|
||||
return redirect(url_for(".service_settings", service_id=service_id))
|
||||
|
||||
return render_template(
|
||||
|
||||
@@ -13,6 +13,7 @@ from flask import (
|
||||
from flask_login import current_user
|
||||
|
||||
from app import user_api_client
|
||||
from app.enums import AuthType
|
||||
from app.event_handlers import (
|
||||
create_email_change_event,
|
||||
create_mobile_number_change_event,
|
||||
@@ -179,7 +180,7 @@ def user_profile_mobile_number():
|
||||
@main.route("/user-profile/mobile-number/delete", methods=["POST"])
|
||||
@user_is_logged_in
|
||||
def user_profile_mobile_number_delete():
|
||||
if current_user.auth_type != "email_auth":
|
||||
if current_user.auth_type != AuthType.EMAIL_AUTH:
|
||||
abort(403)
|
||||
|
||||
current_user.update(mobile_number=None)
|
||||
|
||||
Reference in New Issue
Block a user