mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-03-05 18:02:20 -05:00
Wrap a model around list of all organisations
This commit is contained in:
@@ -31,6 +31,7 @@ from app.main.forms import (
|
||||
SetLetterBranding,
|
||||
)
|
||||
from app.main.views.service_settings import get_branding_as_value_and_label
|
||||
from app.models.organisation import Organisations
|
||||
from app.models.user import InvitedOrgUser, User
|
||||
from app.utils import user_has_permissions, user_is_platform_admin
|
||||
|
||||
@@ -39,11 +40,9 @@ from app.utils import user_has_permissions, user_is_platform_admin
|
||||
@login_required
|
||||
@user_is_platform_admin
|
||||
def organisations():
|
||||
orgs = organisations_client.get_organisations()
|
||||
|
||||
return render_template(
|
||||
'views/organisations/index.html',
|
||||
organisations=orgs,
|
||||
organisations=Organisations(),
|
||||
search_form=SearchByNameForm(),
|
||||
)
|
||||
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from collections.abc import Sequence
|
||||
|
||||
from flask import abort
|
||||
|
||||
|
||||
@@ -33,5 +36,30 @@ class JSONModel():
|
||||
abort(404)
|
||||
|
||||
|
||||
class ModelList(ABC, Sequence):
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def client():
|
||||
pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def model():
|
||||
pass
|
||||
|
||||
def __init__(self):
|
||||
self.items = self.client()
|
||||
|
||||
def __getitem__(self, index):
|
||||
return self.model(self.items[index])
|
||||
|
||||
def __len__(self):
|
||||
return len(self.items)
|
||||
|
||||
def __add__(self, other):
|
||||
return list(self) + list(other)
|
||||
|
||||
|
||||
class InviteTokenError(Exception):
|
||||
pass
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from flask import Markup, abort
|
||||
from werkzeug.utils import cached_property
|
||||
|
||||
from app.models import JSONModel
|
||||
from app.models import JSONModel, ModelList
|
||||
from app.notify_client.organisations_api_client import organisations_client
|
||||
|
||||
|
||||
@@ -155,3 +155,8 @@ class Organisation(JSONModel):
|
||||
self.invited_users + self.active_users,
|
||||
key=lambda user: user.email_address.lower(),
|
||||
)
|
||||
|
||||
|
||||
class Organisations(ModelList):
|
||||
client = organisations_client.get_organisations
|
||||
model = Organisation
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
from collections.abc import Sequence
|
||||
|
||||
from flask import abort, current_app, request, session
|
||||
from flask_login import AnonymousUserMixin, UserMixin, login_user
|
||||
from notifications_python_client.errors import HTTPError
|
||||
from werkzeug.utils import cached_property
|
||||
|
||||
from app.models import JSONModel
|
||||
from app.models import JSONModel, ModelList
|
||||
from app.models.organisation import Organisation
|
||||
from app.models.roles_and_permissions import (
|
||||
all_permissions,
|
||||
@@ -590,22 +588,13 @@ class AnonymousUser(AnonymousUserMixin):
|
||||
return Organisation(None)
|
||||
|
||||
|
||||
class Users(Sequence):
|
||||
class Users(ModelList):
|
||||
|
||||
client = user_api_client.get_users_for_service
|
||||
model = User
|
||||
|
||||
def __init__(self, service_id):
|
||||
self.users = self.client(service_id)
|
||||
|
||||
def __getitem__(self, index):
|
||||
return self.model(self.users[index])
|
||||
|
||||
def __len__(self):
|
||||
return len(self.users)
|
||||
|
||||
def __add__(self, other):
|
||||
return list(self) + list(other)
|
||||
self.items = self.client(service_id)
|
||||
|
||||
|
||||
class OrganisationUsers(Users):
|
||||
@@ -618,7 +607,7 @@ class InvitedUsers(Users):
|
||||
model = InvitedUser
|
||||
|
||||
def __init__(self, service_id):
|
||||
self.users = [
|
||||
self.items = [
|
||||
user for user in self.client(service_id)
|
||||
if user['status'] != 'accepted'
|
||||
]
|
||||
|
||||
@@ -32,8 +32,8 @@
|
||||
<ul>
|
||||
{% for org in organisations %}
|
||||
<li class="browse-list-item">
|
||||
<a href="{{ url_for('main.organisation_dashboard', org_id=org['id']) }}" class="browse-list-link">{{ org['name'] }}</a>
|
||||
{% if not org['active'] %}
|
||||
<a href="{{ url_for('main.organisation_dashboard', org_id=org.id) }}" class="browse-list-link">{{ org.name }}</a>
|
||||
{% if not org.active %}
|
||||
<span class="table-field-status-default heading-medium">- archived</span>
|
||||
{% endif %}
|
||||
</li>
|
||||
|
||||
@@ -26,7 +26,7 @@ def test_organisation_page_shows_all_organisations(
|
||||
]
|
||||
|
||||
mocker.patch(
|
||||
'app.organisations_client.get_organisations', return_value=orgs
|
||||
'app.models.organisation.Organisations.client', return_value=orgs
|
||||
)
|
||||
response = logged_in_platform_admin_client.get(
|
||||
url_for('.organisations')
|
||||
|
||||
Reference in New Issue
Block a user