get orgs and services from user

this endpoint should probably only be used for the choose-service page
also create an OrganisationBrowsableItem to aid rendering of them
in the front-end.
This commit is contained in:
Leo Hemsted
2018-03-07 18:10:14 +00:00
parent 4edd990bc7
commit ee665caa7d
4 changed files with 19 additions and 2 deletions

View File

@@ -68,6 +68,7 @@ class User(UserMixin):
self.max_failed_login_count = max_failed_login_count
self.platform_admin = fields.get('platform_admin')
self.current_session_id = fields.get('current_session_id')
self.services = fields.get('services', [])
self.organisations = fields.get('organisations', [])
def _set_permissions(self, permissions_by_service):

View File

@@ -1,4 +1,7 @@
from flask import url_for
from app.notify_client import NotifyAdminAPIClient, _attach_current_user
from app.notify_client.service_api_client import ServicesBrowsableItem
class OrganisationsClient(NotifyAdminAPIClient):
@@ -51,3 +54,12 @@ class OrganisationsClient(NotifyAdminAPIClient):
url="/organisations/unique",
params={"org_id": org_id, "name": name}
)["result"]
class OrganisationBrowsableItem(ServicesBrowsableItem):
def __init__(self, organisation):
self.services = [ServicesBrowsableItem(x) for x in organisation['services']]
super().__init__(organisation)
@property
def link(self):
return url_for('main.organisation_dashboard', org_id=self._item['id'])

View File

@@ -185,3 +185,7 @@ class UserApiClient(NotifyAdminAPIClient):
endpoint = '/user/{}/change-email-verification'.format(user_id)
data = {'email': new_email}
self.post(endpoint, data)
def get_organisations_and_services_for_user(self, user):
endpoint = '/user/{}/organisations-and-services'.format(user.id)
return self.get(endpoint)

View File

@@ -33,14 +33,14 @@ FAILURE_STATUSES = ['failed', 'temporary-failure', 'permanent-failure', 'technic
REQUESTED_STATUSES = SENDING_STATUSES + DELIVERED_STATUSES + FAILURE_STATUSES
class BrowsableItem(object):
class BrowsableItem:
"""
Maps for the template browse-list.
"""
def __init__(self, item, *args, **kwargs):
print(self, item)
self._item = item
super(BrowsableItem, self).__init__()
@property
def title(self):