mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-09 12:59:48 -04:00
notify-api-412 use black to enforce python coding style
This commit is contained in:
@@ -12,31 +12,40 @@ from app.models.user import InvitedOrgUser, InvitedUser, OrganizationUsers, User
|
||||
def accept_invite(token):
|
||||
invited_user = InvitedUser.from_token(token)
|
||||
|
||||
if not current_user.is_anonymous and current_user.email_address.lower() != invited_user.email_address.lower():
|
||||
message = Markup("""
|
||||
if (
|
||||
not current_user.is_anonymous
|
||||
and current_user.email_address.lower() != invited_user.email_address.lower()
|
||||
):
|
||||
message = Markup(
|
||||
"""
|
||||
You’re signed in as {}.
|
||||
This invite is for another email address.
|
||||
<a href={} class="usa-link">Sign out</a>
|
||||
and click the link again to accept this invite.
|
||||
""".format(
|
||||
current_user.email_address,
|
||||
url_for("main.sign_out")))
|
||||
current_user.email_address, url_for("main.sign_out")
|
||||
)
|
||||
)
|
||||
|
||||
flash(message=message)
|
||||
|
||||
abort(403)
|
||||
|
||||
if invited_user.status == 'cancelled':
|
||||
if invited_user.status == "cancelled":
|
||||
service = Service.from_id(invited_user.service)
|
||||
return render_template('views/cancelled-invitation.html',
|
||||
from_user=invited_user.from_user.name,
|
||||
service_name=service.name)
|
||||
if invited_user.status == 'accepted':
|
||||
session.pop('invited_user_id', None)
|
||||
return render_template(
|
||||
"views/cancelled-invitation.html",
|
||||
from_user=invited_user.from_user.name,
|
||||
service_name=service.name,
|
||||
)
|
||||
if invited_user.status == "accepted":
|
||||
session.pop("invited_user_id", None)
|
||||
service = Service.from_id(invited_user.service)
|
||||
return redirect(url_for('main.service_dashboard', service_id=invited_user.service))
|
||||
return redirect(
|
||||
url_for("main.service_dashboard", service_id=invited_user.service)
|
||||
)
|
||||
|
||||
session['invited_user_id'] = invited_user.id
|
||||
session["invited_user_id"] = invited_user.id
|
||||
|
||||
existing_user = User.from_email_address_or_none(invited_user.email_address)
|
||||
|
||||
@@ -44,17 +53,23 @@ def accept_invite(token):
|
||||
existing_user.update_email_access_validated_at()
|
||||
invited_user.accept_invite()
|
||||
if existing_user in Users(invited_user.service):
|
||||
return redirect(url_for('main.service_dashboard', service_id=invited_user.service))
|
||||
return redirect(
|
||||
url_for("main.service_dashboard", service_id=invited_user.service)
|
||||
)
|
||||
else:
|
||||
service = Service.from_id(invited_user.service)
|
||||
# if the service you're being added to can modify auth type, then check if we can do this;
|
||||
# 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') and not existing_user.platform_admin:
|
||||
if invited_user.auth_type == 'email_auth' or (
|
||||
if (
|
||||
service.has_permission("email_auth")
|
||||
and not existing_user.platform_admin
|
||||
):
|
||||
if invited_user.auth_type == "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 and invited_user.auth_type == 'sms_auth'
|
||||
existing_user.mobile_number
|
||||
and invited_user.auth_type == "sms_auth"
|
||||
):
|
||||
existing_user.update(auth_type=invited_user.auth_type)
|
||||
existing_user.add_to_service(
|
||||
@@ -63,40 +78,49 @@ def accept_invite(token):
|
||||
folder_permissions=invited_user.folder_permissions,
|
||||
invited_by_id=invited_user.from_user.id,
|
||||
)
|
||||
return redirect(url_for('main.service_dashboard', service_id=service.id))
|
||||
return redirect(url_for("main.service_dashboard", service_id=service.id))
|
||||
else:
|
||||
return redirect(url_for('main.register_from_invite'))
|
||||
return redirect(url_for("main.register_from_invite"))
|
||||
|
||||
|
||||
@main.route("/organization-invitation/<token>")
|
||||
def accept_org_invite(token):
|
||||
invited_org_user = InvitedOrgUser.from_token(token)
|
||||
|
||||
if not current_user.is_anonymous and current_user.email_address.lower() != invited_org_user.email_address.lower():
|
||||
message = Markup("""
|
||||
if (
|
||||
not current_user.is_anonymous
|
||||
and current_user.email_address.lower() != invited_org_user.email_address.lower()
|
||||
):
|
||||
message = Markup(
|
||||
"""
|
||||
You’re signed in as {}.
|
||||
This invite is for another email address.
|
||||
<a class="usa-link" href={}>Sign out</a>
|
||||
and click the link again to accept this invite.
|
||||
""".format(
|
||||
current_user.email_address,
|
||||
url_for("main.sign_out")))
|
||||
current_user.email_address, url_for("main.sign_out")
|
||||
)
|
||||
)
|
||||
|
||||
flash(message=message)
|
||||
|
||||
abort(403)
|
||||
|
||||
if invited_org_user.status == 'cancelled':
|
||||
if invited_org_user.status == "cancelled":
|
||||
organization = Organization.from_id(invited_org_user.organization)
|
||||
return render_template('views/cancelled-invitation.html',
|
||||
from_user=invited_org_user.invited_by.name,
|
||||
organization_name=organization.name)
|
||||
return render_template(
|
||||
"views/cancelled-invitation.html",
|
||||
from_user=invited_org_user.invited_by.name,
|
||||
organization_name=organization.name,
|
||||
)
|
||||
|
||||
if invited_org_user.status == 'accepted':
|
||||
session.pop('invited_org_user_id', None)
|
||||
return redirect(url_for('main.organization_dashboard', org_id=invited_org_user.organization))
|
||||
if invited_org_user.status == "accepted":
|
||||
session.pop("invited_org_user_id", None)
|
||||
return redirect(
|
||||
url_for("main.organization_dashboard", org_id=invited_org_user.organization)
|
||||
)
|
||||
|
||||
session['invited_org_user_id'] = invited_org_user.id
|
||||
session["invited_org_user_id"] = invited_org_user.id
|
||||
|
||||
existing_user = User.from_email_address_or_none(invited_org_user.email_address)
|
||||
organization_users = OrganizationUsers(invited_org_user.organization)
|
||||
@@ -105,7 +129,11 @@ def accept_org_invite(token):
|
||||
existing_user.update_email_access_validated_at()
|
||||
invited_org_user.accept_invite()
|
||||
if existing_user not in organization_users:
|
||||
existing_user.add_to_organization(organization_id=invited_org_user.organization)
|
||||
return redirect(url_for('main.organization_dashboard', org_id=invited_org_user.organization))
|
||||
existing_user.add_to_organization(
|
||||
organization_id=invited_org_user.organization
|
||||
)
|
||||
return redirect(
|
||||
url_for("main.organization_dashboard", org_id=invited_org_user.organization)
|
||||
)
|
||||
else:
|
||||
return redirect(url_for('main.register_from_org_invite'))
|
||||
return redirect(url_for("main.register_from_org_invite"))
|
||||
|
||||
Reference in New Issue
Block a user