mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-05-28 18:10:11 -04:00
Rename all_services property on user
For consistency with `.organisations`/`.organisation_ids`. `.services` returns a list of semi-rich dictionaries for each service. `.service_ids` returns service IDs only.
This commit is contained in:
@@ -31,17 +31,17 @@ def show_accounts_or_dashboard():
|
||||
return redirect(url_for('.index'))
|
||||
|
||||
service_id = session.get('service_id')
|
||||
if service_id and (service_id in current_user.services or current_user.platform_admin):
|
||||
if service_id and (service_id in current_user.service_ids or current_user.platform_admin):
|
||||
return redirect(url_for('.service_dashboard', service_id=service_id))
|
||||
|
||||
organisation_id = session.get('organisation_id')
|
||||
if organisation_id and (organisation_id in current_user.organisation_ids or current_user.platform_admin):
|
||||
return redirect(url_for('.organisation_dashboard', org_id=organisation_id))
|
||||
|
||||
if len(current_user.services) == 1 and not current_user.organisation_ids:
|
||||
return redirect(url_for('.service_dashboard', service_id=current_user.services[0]))
|
||||
if len(current_user.service_ids) == 1 and not current_user.organisation_ids:
|
||||
return redirect(url_for('.service_dashboard', service_id=current_user.service_ids[0]))
|
||||
|
||||
if len(current_user.organisation_ids) == 1 and not current_user.services:
|
||||
if len(current_user.organisation_ids) == 1 and not current_user.service_ids:
|
||||
return redirect(url_for('.organisation_dashboard', org_id=current_user.organisation_ids[0]))
|
||||
|
||||
return redirect(url_for('.choose_account'))
|
||||
|
||||
@@ -126,7 +126,7 @@ def choose_template(service_id, template_type='all', template_folder_id=None):
|
||||
template_type=template_type,
|
||||
allow_adding_letter_template=current_service.has_permission('letter'),
|
||||
allow_adding_copy_of_template=(
|
||||
current_service.all_templates or len(current_user.services) > 1
|
||||
current_service.all_templates or len(current_user.service_ids) > 1
|
||||
),
|
||||
)
|
||||
option_hints = {template_folder_id: 'current folder'}
|
||||
@@ -369,7 +369,7 @@ def choose_template_to_copy(
|
||||
'views/templates/copy.html',
|
||||
services_templates_and_folders=TemplateLists([
|
||||
Service(service) for service in
|
||||
current_user.all_services
|
||||
current_user.services
|
||||
], user=current_user),
|
||||
search_form=SearchByNameForm(),
|
||||
)
|
||||
@@ -401,7 +401,7 @@ def copy_template(service_id, template_id):
|
||||
form=form,
|
||||
template=template,
|
||||
heading_action='Add',
|
||||
services=current_user.all_service_ids,
|
||||
services=current_user.service_ids,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -42,7 +42,6 @@ class User(JSONModel, UserMixin):
|
||||
'password_changed_at',
|
||||
'permissions',
|
||||
'platform_admin',
|
||||
'services',
|
||||
'state',
|
||||
}
|
||||
|
||||
@@ -195,7 +194,7 @@ class User(JSONModel, UserMixin):
|
||||
if org_id:
|
||||
return org_id in self.organisation_ids
|
||||
if not permissions:
|
||||
return service_id in self.services
|
||||
return service_id in self.service_ids
|
||||
if service_id:
|
||||
return any(x in self._permissions.get(service_id, []) for x in permissions)
|
||||
|
||||
@@ -223,7 +222,7 @@ class User(JSONModel, UserMixin):
|
||||
]
|
||||
|
||||
def belongs_to_service(self, service_id):
|
||||
return str(service_id) in self.services
|
||||
return str(service_id) in self.service_ids
|
||||
|
||||
def belongs_to_service_or_403(self, service_id):
|
||||
if not self.belongs_to_service(service_id):
|
||||
@@ -242,29 +241,27 @@ class User(JSONModel, UserMixin):
|
||||
return user_api_client.get_organisations_and_services_for_user(self.id)
|
||||
|
||||
@property
|
||||
def all_services(self):
|
||||
def services(self):
|
||||
all_services = self.orgs_and_services['services_without_organisations'] + next(chain(
|
||||
org['services'] for org in self.orgs_and_services['organisations']
|
||||
), [])
|
||||
return sorted(all_services, key=lambda service: service['name'].lower())
|
||||
|
||||
@property
|
||||
def all_service_ids(self):
|
||||
return {
|
||||
service['id'] for service in self.all_services
|
||||
}
|
||||
def service_ids(self):
|
||||
return self._dict['services']
|
||||
|
||||
@property
|
||||
def trial_mode_services(self):
|
||||
return [
|
||||
service for service in self.all_services
|
||||
service for service in self.services
|
||||
if service['restricted']
|
||||
]
|
||||
|
||||
@property
|
||||
def live_services(self):
|
||||
return [
|
||||
service for service in self.all_services
|
||||
service for service in self.services
|
||||
if not service['restricted']
|
||||
]
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
<h2 class="heading-medium">Services</h2>
|
||||
<nav class="browse-list">
|
||||
<ul>
|
||||
{% for service in user.all_services %}
|
||||
{% for service in user.services %}
|
||||
<li class="browse-list-item">
|
||||
<a class="browse-list-hint" href={{url_for('.service_dashboard', service_id=service.id)}}>{{ service.name }}</a>
|
||||
</li>
|
||||
|
||||
Reference in New Issue
Block a user