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