mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-18 05:29:38 -04:00
Able to get services by user id
This commit is contained in:
@@ -26,8 +26,11 @@ def get_service_by_id(id_):
|
||||
return notifications_api_client.get_service(id_)
|
||||
|
||||
|
||||
def get_services():
|
||||
return notifications_api_client.get_services()
|
||||
def get_services(user_id=None):
|
||||
if user_id:
|
||||
return notifications_api_client.get_services({'user_id': str(user_id)})
|
||||
else:
|
||||
return notifications_api_client.get_services()
|
||||
|
||||
|
||||
def unrestrict_service(service_id):
|
||||
@@ -55,8 +58,8 @@ def activate_service(service_id):
|
||||
|
||||
|
||||
# TODO Fix when functionality is added to the api.
|
||||
def find_service_by_service_name(service_name):
|
||||
resp = notifications_api_client.get_services()
|
||||
def find_service_by_service_name(service_name, user_id=None):
|
||||
resp = notifications_api_client.get_services(user_id)
|
||||
retval = None
|
||||
for srv_json in resp['data']:
|
||||
if srv_json['name'] == service_name:
|
||||
@@ -69,8 +72,8 @@ def delete_service(id_):
|
||||
return notifications_api_client.delete_service(id_)
|
||||
|
||||
|
||||
def find_all_service_names():
|
||||
resp = notifications_api_client.get_services()
|
||||
def find_all_service_names(user_id=None):
|
||||
resp = notifications_api_client.get_services(user_id)
|
||||
return [x['name'] for x in resp['data']]
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from flask import request, render_template, jsonify, redirect, session, url_for, abort
|
||||
from flask_login import login_required
|
||||
from flask import render_template, redirect, session, url_for
|
||||
from flask_login import login_required, current_user
|
||||
from app.main import main
|
||||
from app.main.dao import services_dao, users_dao
|
||||
from app.main.forms import AddServiceForm
|
||||
@@ -9,7 +9,7 @@ from app.main.forms import AddServiceForm
|
||||
@login_required
|
||||
def add_service():
|
||||
form = AddServiceForm(services_dao.find_all_service_names)
|
||||
services = services_dao.get_services()
|
||||
services = services_dao.get_services(current_user.id)
|
||||
if len(services) > 0:
|
||||
heading = 'Set up notifications for your service'
|
||||
else:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from flask import (render_template, redirect, url_for)
|
||||
from flask_login import login_required
|
||||
from flask_login import login_required, current_user
|
||||
from app.main.dao import services_dao
|
||||
from app.main import main
|
||||
|
||||
@@ -7,7 +7,7 @@ from app.main import main
|
||||
@main.route("/services")
|
||||
@login_required
|
||||
def choose_service():
|
||||
services = services_dao.get_services()
|
||||
services = services_dao.get_services(current_user.id)
|
||||
# If there is only one service redirect
|
||||
# to the service dashboard.
|
||||
if len(services['data']) == 1:
|
||||
|
||||
Reference in New Issue
Block a user