mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-18 21:49:37 -04:00
Merge branch 'main' of https://github.com/GSA/notifications-admin into 1484-dashboard-visualizations
This commit is contained in:
@@ -312,7 +312,7 @@ def get_status_filters(service, message_type, statistics):
|
||||
filters = [
|
||||
# key, label, option
|
||||
("requested", "total", "sending,delivered,failed"),
|
||||
("pending", "pending", "pending"),
|
||||
("pending", "pending", "sending,pending"),
|
||||
("delivered", "delivered", "delivered"),
|
||||
("failed", "failed", "failed"),
|
||||
]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
from flask import current_app, redirect, url_for
|
||||
from flask import current_app, redirect, session, url_for
|
||||
from flask_login import current_user
|
||||
|
||||
from app.main import main
|
||||
@@ -25,12 +25,16 @@ def _sign_out_at_login_dot_gov():
|
||||
|
||||
@main.route("/sign-out", methods=(["GET", "POST"]))
|
||||
def sign_out():
|
||||
# An AnonymousUser does not have an id
|
||||
current_app.logger.info("HIT THE REGULAR SIGN OUT")
|
||||
|
||||
if current_user.is_authenticated:
|
||||
# TODO This doesn't work yet, due to problems above.
|
||||
current_user.deactivate()
|
||||
session.clear()
|
||||
current_user.sign_out()
|
||||
|
||||
session.permanent = False
|
||||
|
||||
login_dot_gov_logout_url = os.getenv("LOGIN_DOT_GOV_LOGOUT_URL")
|
||||
if login_dot_gov_logout_url:
|
||||
current_app.config["SESSION_PERMANENT"] = False
|
||||
return redirect(login_dot_gov_logout_url)
|
||||
return redirect(url_for("main.index"))
|
||||
|
||||
@@ -79,5 +79,4 @@ def activate_user(user_id):
|
||||
else:
|
||||
activated_user = user.activate()
|
||||
activated_user.login()
|
||||
|
||||
return redirect(url_for("main.add_service", first="first"))
|
||||
|
||||
@@ -147,6 +147,13 @@ class User(JSONModel, UserMixin):
|
||||
else:
|
||||
return self
|
||||
|
||||
def deactivate(self):
|
||||
if self.is_active:
|
||||
user_data = user_api_client.deactivate_user(self.id)
|
||||
return self.__class__(user_data["data"])
|
||||
else:
|
||||
return self
|
||||
|
||||
def login(self):
|
||||
login_user(self)
|
||||
session["user_id"] = self.id
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import os
|
||||
|
||||
from flask import abort, has_request_context, request
|
||||
from flask_login import current_user
|
||||
from notifications_python_client import __version__
|
||||
@@ -54,16 +56,44 @@ class NotifyAdminAPIClient(BaseAPIClient):
|
||||
):
|
||||
abort(403)
|
||||
|
||||
def check_inactive_user(self, *args):
|
||||
still_signing_in = False
|
||||
for arg in args:
|
||||
arg = str(arg)
|
||||
if (
|
||||
"get-login-gov-user" in arg
|
||||
or "user/email" in arg
|
||||
or "/activate" in arg
|
||||
or "/email-code" in arg
|
||||
):
|
||||
still_signing_in = True
|
||||
|
||||
# This seems to be a weird edge case that happens intermittently with invites
|
||||
if str(arg) == "()":
|
||||
still_signing_in = True
|
||||
# TODO: Update this once E2E tests are managed by a feature flag or some other main config option.
|
||||
if os.getenv("NOTIFY_E2E_TEST_EMAIL"):
|
||||
# allow end-to-end tests to skip check
|
||||
pass
|
||||
elif still_signing_in is True:
|
||||
# we are not full signed in yet
|
||||
pass
|
||||
elif not current_user or not current_user.is_active:
|
||||
abort(403)
|
||||
|
||||
def post(self, *args, **kwargs):
|
||||
self.check_inactive_service()
|
||||
self.check_inactive_user(args)
|
||||
return super().post(*args, **kwargs)
|
||||
|
||||
def put(self, *args, **kwargs):
|
||||
self.check_inactive_service()
|
||||
self.check_inactive_user()
|
||||
return super().put(*args, **kwargs)
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
self.check_inactive_service()
|
||||
self.check_inactive_user()
|
||||
return super().delete(*args, **kwargs)
|
||||
|
||||
|
||||
|
||||
@@ -217,6 +217,10 @@ class UserApiClient(NotifyAdminAPIClient):
|
||||
def activate_user(self, user_id):
|
||||
return self.post("/user/{}/activate".format(user_id), data=None)
|
||||
|
||||
@cache.delete("user-{user_id}")
|
||||
def deactivate_user(self, user_id):
|
||||
return self.post("/user/{}/deactivate".format(user_id), data=None)
|
||||
|
||||
def send_change_email_verification(self, user_id, new_email):
|
||||
endpoint = "/user/{}/change-email-verification".format(user_id)
|
||||
data = {"email": new_email}
|
||||
|
||||
Reference in New Issue
Block a user