mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-06 17:58:24 -04:00
add new endpoint to get organisations and services for a user
contains orgs, and unmapped services. the orgs contain nested services - services the user is a part of that belong to that org. the unmapped services are any services that the user is a part of that either don't have an org or have one that the user doesn't know about
This commit is contained in:
@@ -120,7 +120,7 @@ class User(db.Model):
|
|||||||
organisations = db.relationship(
|
organisations = db.relationship(
|
||||||
'Organisation',
|
'Organisation',
|
||||||
secondary='user_to_organisation',
|
secondary='user_to_organisation',
|
||||||
backref=db.backref('user_to_organisation', lazy='dynamic'))
|
backref=db.backref('users', lazy='dynamic'))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def password(self):
|
def password(self):
|
||||||
|
|||||||
@@ -395,6 +395,45 @@ def update_password(user_id):
|
|||||||
return jsonify(data=user.serialize()), 200
|
return jsonify(data=user.serialize()), 200
|
||||||
|
|
||||||
|
|
||||||
|
@user_blueprint.route('/<uuid:user_id>/organisations-and-services', methods=['GET'])
|
||||||
|
def get_organisations_and_services_for_user(user_id):
|
||||||
|
user = get_user_by_id(user_id=user_id)
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'organisations': [
|
||||||
|
{
|
||||||
|
'name': org.name,
|
||||||
|
'id': org.id,
|
||||||
|
'services': [
|
||||||
|
{
|
||||||
|
'id': service.id,
|
||||||
|
'name': service.name
|
||||||
|
}
|
||||||
|
for service in org.services
|
||||||
|
if service.active and user in service.users
|
||||||
|
]
|
||||||
|
}
|
||||||
|
for org in user.organisations
|
||||||
|
],
|
||||||
|
'services_without_organisations': [
|
||||||
|
{
|
||||||
|
'id': service.id,
|
||||||
|
'name': service.name
|
||||||
|
} for service in user.services
|
||||||
|
if (
|
||||||
|
service.active and
|
||||||
|
# include services that either aren't in an organisation, or are in an organisation,
|
||||||
|
# but not one that the user can see.
|
||||||
|
(
|
||||||
|
not service.organisation or
|
||||||
|
user not in service.organisation.users
|
||||||
|
)
|
||||||
|
)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
return jsonify(data)
|
||||||
|
|
||||||
|
|
||||||
def _create_reset_password_url(email):
|
def _create_reset_password_url(email):
|
||||||
data = json.dumps({'email': email, 'created_at': str(datetime.utcnow())})
|
data = json.dumps({'email': email, 'created_at': str(datetime.utcnow())})
|
||||||
url = '/new-password/'
|
url = '/new-password/'
|
||||||
|
|||||||
Reference in New Issue
Block a user