mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-05-29 18:40:10 -04:00
Refactor government user check onto model
This commit is contained in:
@@ -75,7 +75,7 @@ def add_service():
|
||||
service_id = _add_invited_user_to_service(invited_user)
|
||||
return redirect(url_for('main.service_dashboard', service_id=service_id))
|
||||
|
||||
if not is_gov_user(current_user.email_address):
|
||||
if not current_user.is_gov_user:
|
||||
abort(403)
|
||||
|
||||
form = CreateServiceForm()
|
||||
|
||||
@@ -26,7 +26,7 @@ def choose_account():
|
||||
'views/choose-account.html',
|
||||
organisations=orgs_and_services['organisations'],
|
||||
services_without_organisations=orgs_and_services['services_without_organisations'],
|
||||
can_add_service=is_gov_user(current_user.email_address)
|
||||
can_add_service=current_user.is_gov_user,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ NEW_MOBILE_PASSWORD_CONFIRMED = 'new-mob-password-confirmed'
|
||||
def user_profile():
|
||||
return render_template(
|
||||
'views/user-profile.html',
|
||||
can_see_edit=is_gov_user(current_user.email_address)
|
||||
can_see_edit=current_user.is_gov_user,
|
||||
)
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ def user_profile_name():
|
||||
@login_required
|
||||
def user_profile_email():
|
||||
|
||||
if not is_gov_user(current_user.email_address):
|
||||
if not current_user.is_gov_user:
|
||||
abort(403)
|
||||
|
||||
def _is_email_already_in_use(email):
|
||||
|
||||
@@ -3,6 +3,9 @@ from itertools import chain
|
||||
from flask import request, session
|
||||
from flask_login import AnonymousUserMixin, UserMixin
|
||||
|
||||
from app.utils import is_gov_user
|
||||
|
||||
|
||||
roles = {
|
||||
'send_messages': ['send_texts', 'send_emails', 'send_letters'],
|
||||
'manage_templates': ['manage_templates'],
|
||||
@@ -102,6 +105,10 @@ class User(UserMixin):
|
||||
def is_active(self):
|
||||
return self.state == 'active'
|
||||
|
||||
@property
|
||||
def is_gov_user(self):
|
||||
return is_gov_user(self.email_address)
|
||||
|
||||
@property
|
||||
def is_authenticated(self):
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user