diff --git a/teraserver/python/modules/FlaskModule/API/device/DeviceLogin.py b/teraserver/python/modules/FlaskModule/API/device/DeviceLogin.py index f6316493..0b6652c2 100644 --- a/teraserver/python/modules/FlaskModule/API/device/DeviceLogin.py +++ b/teraserver/python/modules/FlaskModule/API/device/DeviceLogin.py @@ -3,7 +3,6 @@ from modules.LoginModule.LoginModule import LoginModule, current_device from modules.DatabaseModule.DBManager import DBManager from modules.FlaskModule.FlaskModule import device_api_ns as api -from opentera.db.models.TeraDevice import TeraDevice from opentera.redis.RedisRPCClient import RedisRPCClient from opentera.modules.BaseModule import ModuleNames from opentera.utils.UserAgentParser import UserAgentParser @@ -30,6 +29,9 @@ def __init__(self, _api, *args, **kwargs): @api.expect(get_parser) @LoginModule.device_token_or_certificate_required def get(self): + """ + Device login + """ # Redis key is handled in LoginModule server_name = self.module.config.server_config['hostname'] port = self.module.config.server_config['port'] diff --git a/teraserver/python/modules/FlaskModule/API/device/DeviceLogout.py b/teraserver/python/modules/FlaskModule/API/device/DeviceLogout.py index 3912707d..052f90e8 100644 --- a/teraserver/python/modules/FlaskModule/API/device/DeviceLogout.py +++ b/teraserver/python/modules/FlaskModule/API/device/DeviceLogout.py @@ -1,4 +1,4 @@ -from flask import jsonify, session +from flask import session from flask_restx import Resource from flask_babel import gettext from modules.LoginModule.LoginModule import LoginModule, current_device @@ -7,7 +7,7 @@ # Parser definition(s) get_parser = api.parser() -get_parser.add_argument('token', type=str, help='Secret Token') +get_parser.add_argument('token', type=str, help='Access Token') class DeviceLogout(Resource): @@ -22,6 +22,9 @@ def __init__(self, _api, *args, **kwargs): @api.expect(get_parser) @LoginModule.device_token_or_certificate_required def get(self): + """ + Device logout + """ if current_device: logout_user() session.clear() diff --git a/teraserver/python/modules/FlaskModule/API/device/DeviceQueryAssets.py b/teraserver/python/modules/FlaskModule/API/device/DeviceQueryAssets.py index c2ebb674..1d1ac831 100644 --- a/teraserver/python/modules/FlaskModule/API/device/DeviceQueryAssets.py +++ b/teraserver/python/modules/FlaskModule/API/device/DeviceQueryAssets.py @@ -15,7 +15,6 @@ get_parser.add_argument('with_urls', type=inputs.boolean, help='Also include assets infos and download-upload url') get_parser.add_argument('with_only_token', type=inputs.boolean, help='Only includes the access token. ' 'Will ignore with_urls if specified.') -get_parser.add_argument('token', type=str, help='Secret Token') class DeviceQueryAssets(Resource): @@ -27,10 +26,14 @@ def __init__(self, _api, *args, **kwargs): @api.doc(description='Get device assets based specified session or asset ID or, if no parameters, get all assets', responses={200: 'Success', - 403: 'Device doesn\'t have access to the specified asset'}) + 403: 'Device doesn\'t have access to the specified asset'}, + params={'token': 'Access token'}) @api.expect(get_parser) @LoginModule.device_token_or_certificate_required def get(self): + """ + Get device assets + """ args = get_parser.parse_args() device_access = DBManager.deviceAccess(current_device) diff --git a/teraserver/python/modules/FlaskModule/API/device/DeviceQueryDevices.py b/teraserver/python/modules/FlaskModule/API/device/DeviceQueryDevices.py index 871b0e11..3609912c 100644 --- a/teraserver/python/modules/FlaskModule/API/device/DeviceQueryDevices.py +++ b/teraserver/python/modules/FlaskModule/API/device/DeviceQueryDevices.py @@ -1,5 +1,5 @@ -from flask import jsonify, session, request -from flask_restx import Resource, reqparse +from flask import request +from flask_restx import Resource from flask_babel import gettext from sqlalchemy import exc @@ -25,11 +25,14 @@ def __init__(self, _api, *args, **kwargs): 500: 'Required parameter is missing', 501: 'Not implemented', 403: 'Logged device doesn\'t have permission to access the requested data'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(get_parser) @LoginModule.device_token_or_certificate_required def get(self): - args = get_parser.parse_args() + """ + Get connected device information + """ + # args = get_parser.parse_args() # Reply device information response = {'device_info': current_device.to_json(minimal=True)} @@ -62,9 +65,12 @@ def get(self): 403: 'Logged device can\'t update the specified device', 400: 'Badly formed JSON or missing fields(id_device) in the JSON body', 500: 'Internal error occurred when saving device'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @LoginModule.device_token_or_certificate_required def post(self): + """ + Update current device information + """ if 'device' not in request.json: return gettext('Missing device schema'), 400 diff --git a/teraserver/python/modules/FlaskModule/API/device/DeviceQueryParticipants.py b/teraserver/python/modules/FlaskModule/API/device/DeviceQueryParticipants.py index 0f925b7e..f5994fdc 100644 --- a/teraserver/python/modules/FlaskModule/API/device/DeviceQueryParticipants.py +++ b/teraserver/python/modules/FlaskModule/API/device/DeviceQueryParticipants.py @@ -1,10 +1,7 @@ -from flask import jsonify, session, request -from flask_restx import Resource, reqparse +from flask_restx import Resource from flask_babel import gettext from modules.LoginModule.LoginModule import LoginModule, current_device -from modules.DatabaseModule.DBManager import DBManager from modules.FlaskModule.FlaskModule import device_api_ns as api -from opentera.db.models.TeraDevice import TeraDevice # Parser definition(s) get_parser = api.parser() @@ -22,11 +19,14 @@ def __init__(self, _api, *args, **kwargs): 500: 'Required parameter is missing', 501: 'Not implemented', 403: 'Logged device doesn\'t have permission to access the requested data'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(get_parser) @LoginModule.device_token_or_certificate_required def get(self): - args = get_parser.parse_args() + """ + Get device associated participants information + """ + # args = get_parser.parse_args() # Device must have device_onlineable flag if current_device and current_device.device_onlineable: diff --git a/teraserver/python/modules/FlaskModule/API/device/DeviceQuerySessionEvents.py b/teraserver/python/modules/FlaskModule/API/device/DeviceQuerySessionEvents.py index 706e5337..02543aaf 100644 --- a/teraserver/python/modules/FlaskModule/API/device/DeviceQuerySessionEvents.py +++ b/teraserver/python/modules/FlaskModule/API/device/DeviceQuerySessionEvents.py @@ -1,12 +1,11 @@ -from flask import jsonify, request, session -from flask_restx import Resource, reqparse +from flask import request +from flask_restx import Resource from flask_babel import gettext from opentera.db.models.TeraSessionEvent import TeraSessionEvent from modules.LoginModule.LoginModule import LoginModule, current_device from modules.DatabaseModule.DBManager import DBManager from sqlalchemy import exc from modules.FlaskModule.FlaskModule import device_api_ns as api -from opentera.db.models.TeraDevice import TeraDevice # Parser definition(s) get_parser = api.parser() @@ -24,10 +23,13 @@ def __init__(self, _api, *args, **kwargs): @api.doc(description='Get session events', responses={403: 'Forbidden for security reasons.'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(get_parser) @LoginModule.device_token_or_certificate_required def get(self): + """ + Get events for a specific session + """ return gettext('Forbidden for security reasons'), 403 @api.doc(description='Update/Create session events', @@ -36,10 +38,13 @@ def get(self): 500: 'Internal server error', 501: 'Not implemented', 403: 'Logged device doesn\'t have permission to access the requested data'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(post_parser) @LoginModule.device_token_or_certificate_required def post(self): + """ + Create / update session events + """ device_access = DBManager.deviceAccess(current_device) # Using request.json instead of parser, since parser messes up the json! @@ -94,4 +99,7 @@ def post(self): @LoginModule.device_token_or_certificate_required def delete(self): + """ + Delete session events + """ return gettext('Forbidden for security reasons'), 403 diff --git a/teraserver/python/modules/FlaskModule/API/device/DeviceQuerySessions.py b/teraserver/python/modules/FlaskModule/API/device/DeviceQuerySessions.py index f36df815..977cd994 100644 --- a/teraserver/python/modules/FlaskModule/API/device/DeviceQuerySessions.py +++ b/teraserver/python/modules/FlaskModule/API/device/DeviceQuerySessions.py @@ -1,4 +1,4 @@ -from flask import jsonify, session, request +from flask import jsonify, request from flask_restx import Resource, inputs from flask_babel import gettext from opentera.db.models.TeraSession import TeraSession @@ -7,7 +7,6 @@ from modules.LoginModule.LoginModule import LoginModule, current_device from sqlalchemy import exc from modules.FlaskModule.FlaskModule import device_api_ns as api -from opentera.db.models.TeraDevice import TeraDevice import datetime # Parser definition(s) @@ -65,10 +64,13 @@ def __init__(self, _api, *args, **kwargs): @api.doc(description='Get session', responses={403: 'Forbidden for security reasons.'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(get_parser) @LoginModule.device_token_or_certificate_required def get(self): + """ + Query device sessions + """ return gettext('Forbidden for security reasons'), 403 @api.doc(description='Update/Create session', @@ -77,10 +79,13 @@ def get(self): 500: 'Internal server error', 501: 'Not implemented', 403: 'Logged device doesn\'t have permission to access the requested data'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(session_schema) @LoginModule.device_token_or_certificate_required def post(self): + """ + Update / create a session + """ # args = post_parser.parse_args() # Using request.json instead of parser, since parser messes up the json! if 'session' not in request.json: @@ -190,4 +195,7 @@ def post(self): @LoginModule.device_token_or_certificate_required def delete(self): + """ + Delete a session + """ return gettext('Forbidden for security reasons'), 403 diff --git a/teraserver/python/modules/FlaskModule/API/device/DeviceQueryStatus.py b/teraserver/python/modules/FlaskModule/API/device/DeviceQueryStatus.py index 4f34c609..fd3d9289 100644 --- a/teraserver/python/modules/FlaskModule/API/device/DeviceQueryStatus.py +++ b/teraserver/python/modules/FlaskModule/API/device/DeviceQueryStatus.py @@ -1,9 +1,8 @@ -from flask import jsonify, session, request -from flask_restx import Resource, reqparse +from flask import request +from flask_restx import Resource from modules.LoginModule.LoginModule import LoginModule, current_device from flask_babel import gettext from modules.FlaskModule.FlaskModule import device_api_ns as api -from opentera.db.models.TeraDevice import TeraDevice from opentera.redis.RedisRPCClient import RedisRPCClient from opentera.modules.BaseModule import ModuleNames import json @@ -38,10 +37,13 @@ def __init__(self, _api, *args, **kwargs): 500: 'Required parameter is missing', 501: 'Not implemented', 403: 'Logged device doesn\'t have permission to access the requested data'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(status_schema) @LoginModule.device_token_or_certificate_required def post(self): + """ + Update current device status + """ # status_schema.validate(request.json) # This should not be required since schema should be validated first. if 'status' not in request.json or 'timestamp' not in request.json: diff --git a/teraserver/python/modules/FlaskModule/API/device/DeviceRegister.py b/teraserver/python/modules/FlaskModule/API/device/DeviceRegister.py index 7b40596c..e8e7f95a 100644 --- a/teraserver/python/modules/FlaskModule/API/device/DeviceRegister.py +++ b/teraserver/python/modules/FlaskModule/API/device/DeviceRegister.py @@ -66,6 +66,9 @@ def __init__(self, _api, *args, **kwargs): 401: 'Unauthorized - provided registration key is invalid'}) @api.expect(api_parser) def get(self): + """ + Register a new device in the server (token based) + """ args = api_parser.parse_args(strict=True) # Check if provided registration key is ok @@ -92,6 +95,9 @@ def get(self): 400: 'Missing or invalid parameter', 401: 'Unauthorized - provided registration key is invalid'}) def post(self): + """ + Register a new device in the server (certificate based) + """ args = api_parser.parse_args(strict=True) # Check if provided registration key is ok diff --git a/teraserver/python/modules/FlaskModule/API/participant/ParticipantLogin.py b/teraserver/python/modules/FlaskModule/API/participant/ParticipantLogin.py index 0902b5b7..28fb4281 100644 --- a/teraserver/python/modules/FlaskModule/API/participant/ParticipantLogin.py +++ b/teraserver/python/modules/FlaskModule/API/participant/ParticipantLogin.py @@ -37,10 +37,13 @@ def __init__(self, _api, *args, **kwargs): 500: 'Required parameter is missing', 501: 'Not implemented.', 403: 'Logged user doesn\'t have permission to access the requested data'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(get_parser) @participant_multi_auth.login_required(role='limited') def get(self): + """ + Login a participant with username / password + """ if current_participant: args = get_parser.parse_args() diff --git a/teraserver/python/modules/FlaskModule/API/participant/ParticipantLogout.py b/teraserver/python/modules/FlaskModule/API/participant/ParticipantLogout.py index cf7a9681..416b7130 100644 --- a/teraserver/python/modules/FlaskModule/API/participant/ParticipantLogout.py +++ b/teraserver/python/modules/FlaskModule/API/participant/ParticipantLogout.py @@ -1,6 +1,6 @@ -from flask import jsonify, session, request +from flask import session, request from flask_login import logout_user -from flask_restx import Resource, reqparse, fields +from flask_restx import Resource from flask_babel import gettext from modules.LoginModule.LoginModule import participant_multi_auth, current_participant, LoginModule from modules.FlaskModule.FlaskModule import participant_api_ns as api @@ -22,10 +22,13 @@ def __init__(self, _api, *args, **kwargs): 500: 'Required parameter is missing', 501: 'Not implemented.', 403: 'Logged user doesn\'t have permission to access the requested data'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(get_parser) @participant_multi_auth.login_required def get(self): + """ + Participant logout + """ if current_participant: logout_user() session.clear() diff --git a/teraserver/python/modules/FlaskModule/API/participant/ParticipantQueryAssets.py b/teraserver/python/modules/FlaskModule/API/participant/ParticipantQueryAssets.py index 16dc80c1..b8144b5b 100644 --- a/teraserver/python/modules/FlaskModule/API/participant/ParticipantQueryAssets.py +++ b/teraserver/python/modules/FlaskModule/API/participant/ParticipantQueryAssets.py @@ -1,10 +1,9 @@ -from flask import session, request +from flask import request from flask_restx import Resource, inputs from flask_babel import gettext from modules.LoginModule.LoginModule import participant_multi_auth, current_participant from modules.DatabaseModule.DBManager import DBManager from modules.FlaskModule.FlaskModule import device_api_ns as api -from opentera.db.models.TeraParticipant import TeraParticipant from opentera.db.models.TeraAsset import TeraAsset from opentera.redis.RedisVars import RedisVars @@ -29,10 +28,13 @@ def __init__(self, _api, *args, **kwargs): @api.doc(description='Get participant assets based on the ID or, if no parameters, get all assets', responses={200: 'Success', 403: 'Participant doesn\'t have access to the specified asset'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(get_parser) @participant_multi_auth.login_required(role='limited') def get(self): + """ + Get participant assets + """ args = get_parser.parse_args() participant_access = DBManager.participantAccess(current_participant) diff --git a/teraserver/python/modules/FlaskModule/API/participant/ParticipantQueryDevices.py b/teraserver/python/modules/FlaskModule/API/participant/ParticipantQueryDevices.py index 8944a818..c41566d3 100644 --- a/teraserver/python/modules/FlaskModule/API/participant/ParticipantQueryDevices.py +++ b/teraserver/python/modules/FlaskModule/API/participant/ParticipantQueryDevices.py @@ -1,9 +1,6 @@ -from flask import session from flask_restx import Resource, inputs -from flask_babel import gettext from modules.LoginModule.LoginModule import participant_multi_auth, current_participant from modules.FlaskModule.FlaskModule import participant_api_ns as api -from opentera.db.models.TeraParticipant import TeraParticipant from modules.DatabaseModule.DBManager import DBManager # Parser definition(s) @@ -26,11 +23,13 @@ def __init__(self, _api, *args, **kwargs): responses={200: 'Success', 500: 'Required parameter is missing', 501: 'Not implemented.', - 403: 'Logged user doesn\'t have permission to access the requested data'}, - params={'token': 'Secret token'}) + 403: 'Logged user doesn\'t have permission to access the requested data'}) @api.expect(get_parser) @participant_multi_auth.login_required(role='full') def get(self): + """ + Get associated participant devices + """ participant_access = DBManager.participantAccess(current_participant) args = get_parser.parse_args(strict=True) diff --git a/teraserver/python/modules/FlaskModule/API/participant/ParticipantQueryParticipants.py b/teraserver/python/modules/FlaskModule/API/participant/ParticipantQueryParticipants.py index 70020880..d7ee630a 100644 --- a/teraserver/python/modules/FlaskModule/API/participant/ParticipantQueryParticipants.py +++ b/teraserver/python/modules/FlaskModule/API/participant/ParticipantQueryParticipants.py @@ -1,9 +1,7 @@ -from flask import session from flask_restx import Resource, inputs from flask_babel import gettext from modules.LoginModule.LoginModule import participant_multi_auth, current_participant from modules.FlaskModule.FlaskModule import participant_api_ns as api -from opentera.db.models.TeraParticipant import TeraParticipant from modules.DatabaseModule.DBManager import DBManager # Parser definition(s) @@ -26,10 +24,13 @@ def __init__(self, _api, *args, **kwargs): 500: 'Required parameter is missing', 501: 'Not implemented.', 403: 'Logged user doesn\'t have permission to access the requested data'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(get_parser) @participant_multi_auth.login_required(role='limited') def get(self): + """ + Get current participant informations + """ participant_access = DBManager.participantAccess(current_participant) args = get_parser.parse_args(strict=True) @@ -47,9 +48,11 @@ def get(self): responses={200: 'Success - To be documented', 500: 'Required parameter is missing', 501: 'Not implemented.', - 403: 'Logged user doesn\'t have permission to access the requested data'}, - params={'token': 'Secret token'}) + 403: 'Logged user doesn\'t have permission to access the requested data'}) @api.expect(post_parser) @participant_multi_auth.login_required(role='full') def post(self): + """ + Update current participant informations + """ return gettext('Not implemented'), 501 diff --git a/teraserver/python/modules/FlaskModule/API/participant/ParticipantQuerySessions.py b/teraserver/python/modules/FlaskModule/API/participant/ParticipantQuerySessions.py index de80ae44..fbf98eb7 100644 --- a/teraserver/python/modules/FlaskModule/API/participant/ParticipantQuerySessions.py +++ b/teraserver/python/modules/FlaskModule/API/participant/ParticipantQuerySessions.py @@ -75,9 +75,11 @@ def __init__(self, _api, *args, **kwargs): 400: 'Bad request', 500: 'Required parameter is missing', 501: 'Not implemented.', - 403: 'Logged user doesn\'t have permission to access the requested data'}, - params={'token': 'Secret token'}) + 403: 'Logged user doesn\'t have permission to access the requested data'}) def get(self): + """ + Get participant sessions + """ participant_access = DBManager.participantAccess(current_participant) args = get_parser.parse_args(strict=True) @@ -105,10 +107,13 @@ def get(self): 500: 'Internal server error', 501: 'Not implemented', 403: 'Logged participant doesn\'t have permission to access the requested data'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(session_schema) @participant_multi_auth.login_required(role='limited') def post(self): + """ + Create / update a session + """ # args = post_parser.parse_args() # Using request.json instead of parser, since parser messes up the json! if 'session' not in request.json: diff --git a/teraserver/python/modules/FlaskModule/API/participant/ParticipantRefreshToken.py b/teraserver/python/modules/FlaskModule/API/participant/ParticipantRefreshToken.py index 79bf760a..bf9f0a2b 100644 --- a/teraserver/python/modules/FlaskModule/API/participant/ParticipantRefreshToken.py +++ b/teraserver/python/modules/FlaskModule/API/participant/ParticipantRefreshToken.py @@ -1,10 +1,9 @@ -from flask import session, request +from flask import request from flask_restx import Resource from modules.LoginModule.LoginModule import participant_token_auth, current_participant from modules.FlaskModule.FlaskModule import participant_api_ns as api from modules.LoginModule.LoginModule import LoginModule from opentera.redis.RedisVars import RedisVars -from opentera.db.models.TeraParticipant import TeraParticipant # Parser definition(s) get_parser = api.parser() @@ -19,11 +18,13 @@ def __init__(self, _api, *args, **kwargs): @api.doc(description='Refresh token, old token needs to be passed in request headers.', responses={200: 'Success', - 500: 'Server error'}, - params={'token': 'Secret token'}) + 500: 'Server error'}) @api.expect(get_parser) @participant_token_auth.login_required(role='full') def get(self): + """ + Refresh participant dynamic token + """ # If we have made it this far, token passed in headers was valid. # Get user token key from redis diff --git a/teraserver/python/modules/FlaskModule/API/service/ServiceQueryAccess.py b/teraserver/python/modules/FlaskModule/API/service/ServiceQueryAccess.py index 16da654f..fb846588 100644 --- a/teraserver/python/modules/FlaskModule/API/service/ServiceQueryAccess.py +++ b/teraserver/python/modules/FlaskModule/API/service/ServiceQueryAccess.py @@ -1,5 +1,4 @@ -from flask import request -from flask_restx import Resource, reqparse, inputs +from flask_restx import Resource, inputs from flask_babel import gettext from modules.LoginModule.LoginModule import LoginModule, current_service from modules.FlaskModule.FlaskModule import service_api_ns as api @@ -41,10 +40,13 @@ def __init__(self, _api, *args, **kwargs): 500: 'Required parameter is missing', 501: 'Not implemented.', 403: 'Service doesn\'t have permission to access the requested data'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(get_parser) @LoginModule.service_token_or_certificate_required def get(self): + """ + Get current service access + """ service_access = DBManager.serviceAccess(current_service) args = get_parser.parse_args() diff --git a/teraserver/python/modules/FlaskModule/API/service/ServiceQueryAssets.py b/teraserver/python/modules/FlaskModule/API/service/ServiceQueryAssets.py index 4d53f379..ea5d4c98 100644 --- a/teraserver/python/modules/FlaskModule/API/service/ServiceQueryAssets.py +++ b/teraserver/python/modules/FlaskModule/API/service/ServiceQueryAssets.py @@ -1,5 +1,5 @@ from flask import request -from flask_restx import Resource, reqparse, inputs +from flask_restx import Resource, inputs from flask_babel import gettext from modules.LoginModule.LoginModule import LoginModule, current_service from modules.FlaskModule.FlaskModule import service_api_ns as api @@ -48,10 +48,13 @@ def __init__(self, _api, *args, **kwargs): 500: 'Required parameter is missing', 501: 'Not implemented.', 403: 'Service doesn\'t have permission to access the requested data'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(get_parser) @LoginModule.service_token_or_certificate_required def get(self): + """ + Get assets + """ service_access = DBManager.serviceAccess(current_service) args = get_parser.parse_args() @@ -151,10 +154,13 @@ def get(self): 400: 'Bad request - wrong or missing parameters in query', 500: 'Required parameter is missing', 403: 'Service doesn\'t have permission to post that asset'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(post_parser) @LoginModule.service_token_or_certificate_required def post(self): + """ + Create / update an asset + """ args = post_parser.parse_args() service_access = DBManager.serviceAccess(current_service) @@ -254,10 +260,13 @@ def post(self): responses={200: 'Success', 403: 'Service can\'t delete asset', 500: 'Database error.'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(delete_parser) @LoginModule.service_token_or_certificate_required def delete(self): + """ + Delete a specific asset + """ service_access = DBManager.serviceAccess(current_service) parser = delete_parser diff --git a/teraserver/python/modules/FlaskModule/API/service/ServiceQueryDevices.py b/teraserver/python/modules/FlaskModule/API/service/ServiceQueryDevices.py index 6e378faf..b1c4d395 100644 --- a/teraserver/python/modules/FlaskModule/API/service/ServiceQueryDevices.py +++ b/teraserver/python/modules/FlaskModule/API/service/ServiceQueryDevices.py @@ -4,11 +4,6 @@ from modules.LoginModule.LoginModule import LoginModule from modules.FlaskModule.FlaskModule import service_api_ns as api from opentera.db.models.TeraDevice import TeraDevice -from opentera.db.models.TeraDeviceType import TeraDeviceType -from opentera.db.models.TeraDeviceSubType import TeraDeviceSubType - -import uuid -from datetime import datetime # Parser definition(s) get_parser = api.parser() @@ -40,10 +35,13 @@ def __init__(self, _api, *args, **kwargs): 500: 'Required parameter is missing', 501: 'Not implemented.', 403: 'Service doesn\'t have permission to access the requested data'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(get_parser) @LoginModule.service_token_or_certificate_required def get(self): + """ + Query device information + """ args = get_parser.parse_args() # args['device_uuid'] Will be None if not specified in args if args['device_uuid']: @@ -77,10 +75,13 @@ def get(self): 500: 'Required parameter is missing', 501: 'Not implemented.', 403: 'Service doesn\'t have permission to access the requested data'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(device_schema, validate=True) @LoginModule.service_token_or_certificate_required def post(self): + """ + Create / update device + """ # args = post_parser.parse_args() # Using request.json instead of parser, since parser messes up the json! if 'device' not in request.json: diff --git a/teraserver/python/modules/FlaskModule/API/service/ServiceQueryDisconnect.py b/teraserver/python/modules/FlaskModule/API/service/ServiceQueryDisconnect.py index 5daab230..763b8947 100644 --- a/teraserver/python/modules/FlaskModule/API/service/ServiceQueryDisconnect.py +++ b/teraserver/python/modules/FlaskModule/API/service/ServiceQueryDisconnect.py @@ -1,5 +1,4 @@ -from flask import request -from flask_restx import Resource, inputs +from flask_restx import Resource from flask_babel import gettext from modules.LoginModule.LoginModule import LoginModule, current_service from modules.FlaskModule.FlaskModule import service_api_ns as api @@ -33,10 +32,13 @@ def __init__(self, _api, *args, **kwargs): 403: 'Forbidden access. Please check that the service has access to' ' the requested id/uuid.', 500: 'Database error'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(get_parser) @LoginModule.service_token_or_certificate_required def get(self): + """ + Forcefully disconnect a user, participant or device + """ args = get_parser.parse_args() service_access: DBManagerTeraServiceAccess = DBManager.serviceAccess(current_service) diff --git a/teraserver/python/modules/FlaskModule/API/service/ServiceQueryParticipantGroups.py b/teraserver/python/modules/FlaskModule/API/service/ServiceQueryParticipantGroups.py index 27b5a4fb..21364dae 100644 --- a/teraserver/python/modules/FlaskModule/API/service/ServiceQueryParticipantGroups.py +++ b/teraserver/python/modules/FlaskModule/API/service/ServiceQueryParticipantGroups.py @@ -35,10 +35,13 @@ def __init__(self, _api, *args, **kwargs): 500: 'Required parameter is missing', 501: 'Not implemented.', 403: 'Service doesn\'t have permission to access the requested data'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(get_parser) @LoginModule.service_token_or_certificate_required def get(self): + """ + Get participant groups + """ # Get service access manager, that allows to check for access service_access = DBManager.serviceAccess(current_service) @@ -80,10 +83,13 @@ def get(self): 500: 'Required parameter is missing', 501: 'Not implemented.', 403: 'Logged user doesn\'t have permission to access the requested data'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(post_schema) @LoginModule.service_token_or_certificate_required def post(self): + """ + Create / update participant group + """ # Parse arguments args = post_parser.parse_args() @@ -163,10 +169,13 @@ def post(self): responses={200: 'Success', 403: 'Logged user doesn\'t have permission to access the requested data', 500: 'Database error.'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(delete_parser) @LoginModule.service_token_or_certificate_required def delete(self): + """ + Delete participant group + """ # Parse arguments args = delete_parser.parse_args() id_todel = args['id'] diff --git a/teraserver/python/modules/FlaskModule/API/service/ServiceQueryParticipants.py b/teraserver/python/modules/FlaskModule/API/service/ServiceQueryParticipants.py index 6b7e8f0f..4f952a8b 100644 --- a/teraserver/python/modules/FlaskModule/API/service/ServiceQueryParticipants.py +++ b/teraserver/python/modules/FlaskModule/API/service/ServiceQueryParticipants.py @@ -58,10 +58,13 @@ def __init__(self, _api, *args, **kwargs): 500: 'Required parameter is missing', 501: 'Not implemented.', 403: 'Service doesn\'t have permission to access the requested data'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(get_parser) @LoginModule.service_token_or_certificate_required def get(self): + """ + Get participant + """ args = get_parser.parse_args() service_access = DBManager.serviceAccess(current_service) @@ -108,10 +111,13 @@ def get(self): 500: 'Required parameter is missing', 501: 'Not implemented.', 403: 'Logged user doesn\'t have permission to access the requested data'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(participant_schema) @LoginModule.service_token_or_certificate_required def post(self): + """ + Create / update a participant + """ args = post_parser.parse_args() # Using request.json instead of parser, since parser messes up the json! diff --git a/teraserver/python/modules/FlaskModule/API/service/ServiceQueryProjects.py b/teraserver/python/modules/FlaskModule/API/service/ServiceQueryProjects.py index 3c51fb3b..72ffd621 100644 --- a/teraserver/python/modules/FlaskModule/API/service/ServiceQueryProjects.py +++ b/teraserver/python/modules/FlaskModule/API/service/ServiceQueryProjects.py @@ -35,10 +35,13 @@ def __init__(self, _api, *args, **kwargs): 500: 'Required parameter is missing', 501: 'Not implemented.', 403: 'Service doesn\'t have permission to access the requested data'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(get_parser) @LoginModule.service_token_or_certificate_required def get(self): + """ + Get projects + """ args = get_parser.parse_args() service_access = DBManager.serviceAccess(current_service) @@ -77,10 +80,13 @@ def get(self): 403: 'Logged service can\'t create/update the specified project', 400: 'Badly formed JSON or missing fields(id_site or id_project) in the JSON body', 500: 'Internal error occured when saving project'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(post_schema) @LoginModule.service_token_or_certificate_required def post(self): + """ + Create / update projects + """ service_access = DBManager.serviceAccess(current_service) # Using request.json instead of parser, since parser messes up the json! if 'project' not in request.json: @@ -145,10 +151,13 @@ def post(self): responses={200: 'Success', 403: 'Logged service can\'t delete project (service not associated to)', 500: 'Database error.'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(delete_parser) @LoginModule.service_token_or_certificate_required def delete(self): + """ + Delete project + """ service_access = DBManager.serviceAccess(current_service) args = delete_parser.parse_args() id_todel = args['id'] diff --git a/teraserver/python/modules/FlaskModule/API/service/ServiceQueryRoles.py b/teraserver/python/modules/FlaskModule/API/service/ServiceQueryRoles.py index a2f38f31..f99bc340 100644 --- a/teraserver/python/modules/FlaskModule/API/service/ServiceQueryRoles.py +++ b/teraserver/python/modules/FlaskModule/API/service/ServiceQueryRoles.py @@ -27,10 +27,13 @@ def __init__(self, _api, *args, **kwargs): @api.doc(description='Get service roles for that service', responses={200: 'Success - returns list of roles', 500: 'Database error'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(get_parser) @LoginModule.service_token_or_certificate_required def get(self): + """ + Get service roles for the current service + """ args = get_parser.parse_args() roles = TeraServiceRole.get_service_roles(service_id=current_service.id_service) roles_list = [] @@ -43,10 +46,13 @@ def get(self): responses={200: 'Success', 400: 'Badly formed JSON or missing fields in the JSON body', 500: 'Internal error when saving roles'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(post_schema) @LoginModule.service_token_or_certificate_required def post(self): + """ + Create / update service roles for the current service + """ # Using request.json instead of parser, since parser messes up the json! if 'service_role' not in request.json: return gettext('Missing service_role field'), 400 @@ -99,10 +105,13 @@ def post(self): responses={200: 'Success', 403: 'Logged service can\'t delete role (not related to that service)', 500: 'Database error.'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(delete_parser) @LoginModule.service_token_or_certificate_required def delete(self): + """ + Delete a specific service role + """ args = delete_parser.parse_args() id_todel = args['id'] diff --git a/teraserver/python/modules/FlaskModule/API/service/ServiceQueryServiceAccess.py b/teraserver/python/modules/FlaskModule/API/service/ServiceQueryServiceAccess.py index bf434ab0..661af342 100644 --- a/teraserver/python/modules/FlaskModule/API/service/ServiceQueryServiceAccess.py +++ b/teraserver/python/modules/FlaskModule/API/service/ServiceQueryServiceAccess.py @@ -36,10 +36,13 @@ def __init__(self, _api, *args, **kwargs): responses={200: 'Success - returns list of access roles', 400: 'Required parameter is missing (must have at least one id)', 500: 'Error when getting association'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(get_parser) @LoginModule.service_token_or_certificate_required def get(self): + """ + Get access roles for a specific item + """ service_access: DBManagerTeraServiceAccess = DBManager.serviceAccess(current_service) args = get_parser.parse_args() @@ -72,10 +75,13 @@ def get(self): 403: 'Logged service can\'t modify association (only self access can be modified)', 400: 'Badly formed JSON or missing fields in the JSON body', 500: 'Internal error occurred when saving association'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(post_schema) @LoginModule.service_token_or_certificate_required def post(self): + """ + Create / update service - access association + """ service_access: DBManagerTeraServiceAccess = DBManager.serviceAccess(current_service) # Using request.json instead of parser, since parser messes up the json! @@ -177,10 +183,13 @@ def post(self): responses={200: 'Success', 403: 'Logged user can\'t delete association (not related to this service)', 500: 'Association not found or database error.'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(delete_parser) @LoginModule.service_token_or_certificate_required def delete(self): + """ + Delete a specific service access + """ service_access: DBManagerTeraServiceAccess = DBManager.serviceAccess(current_service) args = delete_parser.parse_args() id_todel = args['id'] diff --git a/teraserver/python/modules/FlaskModule/API/service/ServiceQueryServices.py b/teraserver/python/modules/FlaskModule/API/service/ServiceQueryServices.py index 50d6b0a0..e453d25a 100644 --- a/teraserver/python/modules/FlaskModule/API/service/ServiceQueryServices.py +++ b/teraserver/python/modules/FlaskModule/API/service/ServiceQueryServices.py @@ -30,6 +30,9 @@ def __init__(self, _api, *args, **kwargs): @api.expect(get_parser) @LoginModule.service_token_or_certificate_required def get(self): + """ + Get service information + """ args = get_parser.parse_args() services = [] diff --git a/teraserver/python/modules/FlaskModule/API/service/ServiceQuerySessionEvents.py b/teraserver/python/modules/FlaskModule/API/service/ServiceQuerySessionEvents.py index afc33a51..38dfa396 100644 --- a/teraserver/python/modules/FlaskModule/API/service/ServiceQuerySessionEvents.py +++ b/teraserver/python/modules/FlaskModule/API/service/ServiceQuerySessionEvents.py @@ -1,9 +1,8 @@ -from flask import jsonify, session, request +from flask import request from flask_restx import Resource, reqparse from flask_babel import gettext from modules.LoginModule.LoginModule import LoginModule, current_service from modules.FlaskModule.FlaskModule import service_api_ns as api -from opentera.db.models.TeraUser import TeraUser from opentera.db.models.TeraSessionEvent import TeraSessionEvent from opentera.db.models.TeraSession import TeraSession from modules.DatabaseModule.DBManager import DBManager @@ -34,10 +33,13 @@ def __init__(self, _api, *args, **kwargs): 400: 'Required parameter is missing (id_session)', 403: 'Service doesn\'t have permission to access the requested data', 500: 'Database error'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(get_parser) @LoginModule.service_token_or_certificate_required def get(self): + """ + Get events for a session + """ args = get_parser.parse_args() sessions_events = [] @@ -67,10 +69,13 @@ def get(self): 403: 'Logged user can\'t create/update the specified event', 400: 'Badly formed JSON or missing fields(id_session_event or id_session) in the JSON body', 500: 'Internal error when saving device'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(post_schema) @LoginModule.service_token_or_certificate_required def post(self): + """ + Create / update session events + """ # Using request.json instead of parser, since parser messes up the json! if 'session_event' not in request.json: return gettext('Missing session_event field'), 400 diff --git a/teraserver/python/modules/FlaskModule/API/service/ServiceQuerySessionTypes.py b/teraserver/python/modules/FlaskModule/API/service/ServiceQuerySessionTypes.py index 07e0034a..82bb3967 100644 --- a/teraserver/python/modules/FlaskModule/API/service/ServiceQuerySessionTypes.py +++ b/teraserver/python/modules/FlaskModule/API/service/ServiceQuerySessionTypes.py @@ -27,10 +27,13 @@ def __init__(self, _api, *args, **kwargs): 500: 'Required parameter is missing', 501: 'Not implemented.', 403: 'Service doesn\'t have permission to access the requested data'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(get_parser) @LoginModule.service_token_or_certificate_required def get(self): + """ + Get session types associated to that service + """ args = get_parser.parse_args() service_access = DBManager.serviceAccess(current_service) diff --git a/teraserver/python/modules/FlaskModule/API/service/ServiceQuerySessions.py b/teraserver/python/modules/FlaskModule/API/service/ServiceQuerySessions.py index 64a9cc58..b45452c0 100644 --- a/teraserver/python/modules/FlaskModule/API/service/ServiceQuerySessions.py +++ b/teraserver/python/modules/FlaskModule/API/service/ServiceQuerySessions.py @@ -1,5 +1,5 @@ from flask import request -from flask_restx import Resource, inputs # , reqparse +from flask_restx import Resource, inputs from flask_babel import gettext from modules.LoginModule.LoginModule import LoginModule, current_service from modules.FlaskModule.FlaskModule import service_api_ns as api @@ -52,10 +52,13 @@ def __init__(self, _api, *args, **kwargs): 500: 'Required parameter is missing', 501: 'Not implemented.', 403: 'Service doesn\'t have permission to access the requested data'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(get_parser) @LoginModule.service_token_or_certificate_required def get(self): + """ + Get sessions + """ args = get_parser.parse_args() service_access = DBManager.serviceAccess(current_service) @@ -128,10 +131,13 @@ def get(self): 400: 'Badly formed JSON or missing fields(session, id_session, session_participants_ids and/or ' 'session_users_ids[for new sessions]) in the JSON body', 500: 'Internal error when saving session'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(post_schema) @LoginModule.service_token_or_certificate_required def post(self): + """ + Create / update session + """ if 'session' not in request.json: return gettext('Missing session'), 400 diff --git a/teraserver/python/modules/FlaskModule/API/service/ServiceQuerySiteProjectAccessRoles.py b/teraserver/python/modules/FlaskModule/API/service/ServiceQuerySiteProjectAccessRoles.py index c7135959..cd688ea6 100644 --- a/teraserver/python/modules/FlaskModule/API/service/ServiceQuerySiteProjectAccessRoles.py +++ b/teraserver/python/modules/FlaskModule/API/service/ServiceQuerySiteProjectAccessRoles.py @@ -24,10 +24,13 @@ def __init__(self, _api, *args, **kwargs): 500: 'Required parameter is missing', 501: 'Not implemented.', 403: 'Service doesn\'t have permission to access the requested data'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(get_parser) @LoginModule.service_token_or_certificate_required def get(self): + """ + Get access roles for a specific user and/or project/site + """ args = get_parser.parse_args(strict=True) service_access = DBManager.serviceAccess(current_service) diff --git a/teraserver/python/modules/FlaskModule/API/service/ServiceQuerySites.py b/teraserver/python/modules/FlaskModule/API/service/ServiceQuerySites.py index 0714bfd4..25a09c3d 100644 --- a/teraserver/python/modules/FlaskModule/API/service/ServiceQuerySites.py +++ b/teraserver/python/modules/FlaskModule/API/service/ServiceQuerySites.py @@ -23,10 +23,13 @@ def __init__(self, _api, *args, **kwargs): 500: 'Required parameter is missing', 501: 'Not implemented.', 403: 'Service doesn\'t have permission to access the requested data'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(get_parser) @LoginModule.service_token_or_certificate_required def get(self): + """ + Get sites + """ args = get_parser.parse_args(strict=True) service_access = DBManager.serviceAccess(current_service) diff --git a/teraserver/python/modules/FlaskModule/API/service/ServiceQueryTestTypeProjects.py b/teraserver/python/modules/FlaskModule/API/service/ServiceQueryTestTypeProjects.py index 9847e29a..7ca1b847 100644 --- a/teraserver/python/modules/FlaskModule/API/service/ServiceQueryTestTypeProjects.py +++ b/teraserver/python/modules/FlaskModule/API/service/ServiceQueryTestTypeProjects.py @@ -42,10 +42,13 @@ def __init__(self, _api, *args, **kwargs): responses={200: 'Success - returns list of test-types - projects association', 400: 'Required parameter is missing (must have at least one id)', 500: 'Error when getting association'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(get_parser) @LoginModule.service_token_or_certificate_required def get(self): + """ + Get test types associated with a project + """ service_access = DBManager.serviceAccess(current_service) args = get_parser.parse_args() @@ -102,10 +105,13 @@ def get(self): 403: 'Logged service can\'t modify association (not associated to project or test type)', 400: 'Badly formed JSON or missing fields in the JSON body', 500: 'Internal error occurred when saving association'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(post_schema) @LoginModule.service_token_or_certificate_required def post(self): + """ + Create / update test types -> project association + """ service_access = DBManager.serviceAccess(current_service) accessible_projects_ids = service_access.get_accessible_projects_ids(admin_only=True) @@ -238,10 +244,13 @@ def post(self): responses={200: 'Success', 403: 'Logged service can\'t delete association (no access to test-type or project)', 400: 'Association not found (invalid id?)'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(delete_parser) @LoginModule.service_token_or_certificate_required def delete(self): + """ + Delete a specific test type -> project association + """ service_access = DBManager.serviceAccess(current_service) args = delete_parser.parse_args() id_todel = args['id'] diff --git a/teraserver/python/modules/FlaskModule/API/service/ServiceQueryTestTypes.py b/teraserver/python/modules/FlaskModule/API/service/ServiceQueryTestTypes.py index ecbeaf6b..55a497c5 100644 --- a/teraserver/python/modules/FlaskModule/API/service/ServiceQueryTestTypes.py +++ b/teraserver/python/modules/FlaskModule/API/service/ServiceQueryTestTypes.py @@ -39,10 +39,13 @@ def __init__(self, _api, *args, **kwargs): 500: 'Required parameter is missing', 501: 'Not implemented.', 403: 'Service doesn\'t have permission to access the requested data'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(get_parser) @LoginModule.service_token_or_certificate_required def get(self): + """ + Get test types + """ args = get_parser.parse_args(strict=True) service_access = DBManager.serviceAccess(current_service) @@ -78,10 +81,13 @@ def get(self): 403: 'Service can\'t create/update the specified test type', 400: 'Badly formed JSON or missing field in the JSON body', 500: 'Internal error when saving test type'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(post_schema) @LoginModule.service_token_or_certificate_required def post(self): + """ + Create / update test types + """ # Using request.json instead of parser, since parser messes up the json! if 'test_type' not in request.json: return gettext('Missing test_type'), 400 @@ -139,10 +145,13 @@ def post(self): responses={200: 'Success', 403: 'Service can\'t delete test type', 500: 'Database error.'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(delete_parser) @LoginModule.service_token_or_certificate_required def delete(self): + """ + Delete a test type + """ args = delete_parser.parse_args() uuid_todel = args['uuid'] diff --git a/teraserver/python/modules/FlaskModule/API/service/ServiceQueryTests.py b/teraserver/python/modules/FlaskModule/API/service/ServiceQueryTests.py index 400e1cb6..7a76e708 100644 --- a/teraserver/python/modules/FlaskModule/API/service/ServiceQueryTests.py +++ b/teraserver/python/modules/FlaskModule/API/service/ServiceQueryTests.py @@ -1,5 +1,5 @@ from flask import request -from flask_restx import Resource, reqparse, inputs +from flask_restx import Resource, inputs from flask_babel import gettext from modules.LoginModule.LoginModule import LoginModule, current_service from modules.FlaskModule.FlaskModule import service_api_ns as api @@ -44,10 +44,13 @@ def __init__(self, _api, *args, **kwargs): 500: 'Required parameter is missing', 501: 'Not implemented.', 403: 'Service doesn\'t have permission to access the requested data'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(get_parser) @LoginModule.service_token_or_certificate_required def get(self): + """ + Get tests + """ service_access = DBManager.serviceAccess(current_service) args = get_parser.parse_args() @@ -120,10 +123,13 @@ def get(self): 400: 'Bad request - wrong or missing parameters in query', 500: 'Required parameter is missing', 403: 'Service doesn\'t have permission to post that test'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(post_parser) @LoginModule.service_token_or_certificate_required def post(self): + """ + Create / update test + """ service_access = DBManager.serviceAccess(current_service) # Using request.json instead of parser, since parser messes up the json! @@ -249,10 +255,13 @@ def post(self): responses={200: 'Success', 403: 'Service can\'t delete test', 500: 'Database error.'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(delete_parser) @LoginModule.service_token_or_certificate_required def delete(self): + """ + Delete specific test + """ service_access = DBManager.serviceAccess(current_service) args = delete_parser.parse_args() uuid_todel = args['uuid'] diff --git a/teraserver/python/modules/FlaskModule/API/service/ServiceQueryUserGroups.py b/teraserver/python/modules/FlaskModule/API/service/ServiceQueryUserGroups.py index faf0455f..d2d67e22 100644 --- a/teraserver/python/modules/FlaskModule/API/service/ServiceQueryUserGroups.py +++ b/teraserver/python/modules/FlaskModule/API/service/ServiceQueryUserGroups.py @@ -8,7 +8,6 @@ from opentera.db.models.TeraUserGroup import TeraUserGroup from flask_babel import gettext from modules.DatabaseModule.DBManager import DBManager, DBManagerTeraServiceAccess -import modules.Globals as Globals # Parser definition(s) get_parser = api.parser() @@ -34,10 +33,13 @@ def __init__(self, _api, *args, **kwargs): @api.doc(description='Get user group information. If no id specified, returns all accessible users groups', responses={200: 'Success', 500: 'Database error'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(get_parser) @LoginModule.service_token_or_certificate_required def get(self): + """ + Get usergroups + """ service_access: DBManagerTeraServiceAccess = DBManager.serviceAccess(current_service) args = get_parser.parse_args() user_groups = [] @@ -71,10 +73,13 @@ def get(self): 403: 'Logged service can\'t create/update the specified user group', 400: 'Badly formed JSON or missing field(id_user_group) in the JSON body', 500: 'Internal error when saving user group'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(post_schema) @LoginModule.service_token_or_certificate_required def post(self): + """ + Create / update usergroup + """ service_access: DBManagerTeraServiceAccess = DBManager.serviceAccess(current_service) if 'user_group' not in request.json: @@ -193,10 +198,13 @@ def post(self): responses={200: 'Success', 403: 'Service can\'t delete user group (no access to it)', 500: 'Database error.'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(delete_parser) @LoginModule.service_token_or_certificate_required def delete(self): + """ + Delete a specific usergroup + """ service_access: DBManagerTeraServiceAccess = DBManager.serviceAccess(current_service) args = delete_parser.parse_args() id_todel = args['id'] diff --git a/teraserver/python/modules/FlaskModule/API/service/ServiceQueryUsers.py b/teraserver/python/modules/FlaskModule/API/service/ServiceQueryUsers.py index 5af700fc..7743ef5b 100644 --- a/teraserver/python/modules/FlaskModule/API/service/ServiceQueryUsers.py +++ b/teraserver/python/modules/FlaskModule/API/service/ServiceQueryUsers.py @@ -23,10 +23,13 @@ def __init__(self, _api, *args, **kwargs): 500: 'Required parameter is missing', 501: 'Not implemented.', 403: 'Service doesn\'t have permission to access the requested data'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(get_parser) @LoginModule.service_token_or_certificate_required def get(self): + """ + Get specific user information + """ args = get_parser.parse_args() # args['user_id'] Will be None if not specified in args diff --git a/teraserver/python/modules/FlaskModule/API/service/ServiceSessionManager.py b/teraserver/python/modules/FlaskModule/API/service/ServiceSessionManager.py index 8acee8dd..89735f4e 100644 --- a/teraserver/python/modules/FlaskModule/API/service/ServiceSessionManager.py +++ b/teraserver/python/modules/FlaskModule/API/service/ServiceSessionManager.py @@ -1,8 +1,7 @@ -from flask import session, request +from flask import request from flask_restx import Resource from modules.LoginModule.LoginModule import LoginModule, current_service from modules.FlaskModule.FlaskModule import user_api_ns as api -from opentera.db.models.TeraUser import TeraUser from opentera.db.models.TeraService import TeraService from opentera.db.models.TeraSession import TeraSession from flask_babel import gettext @@ -99,10 +98,13 @@ def __init__(self, _api, *args, **kwargs): 500: 'Internal server error', 501: 'Not implemented', 403: 'Service doesn\'t have enough permission'}, - params={'token': 'Secret token'}) + params={'token': 'Access token'}) @api.expect(session_manager_schema) @LoginModule.service_token_or_certificate_required def post(self): + """ + Starts / stop a session related to a service + """ args = post_parser.parse_args() service_access = DBManager.serviceAccess(current_service) diff --git a/teraserver/python/modules/FlaskModule/API/user/UserLogout.py b/teraserver/python/modules/FlaskModule/API/user/UserLogout.py index 597953fb..ae2a8279 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserLogout.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserLogout.py @@ -1,5 +1,5 @@ from flask_login import logout_user -from flask_restx import Resource, reqparse +from flask_restx import Resource from flask_babel import gettext from flask import session, request from modules.FlaskModule.FlaskModule import user_api_ns as api @@ -15,10 +15,13 @@ def __init__(self, _api, *args, **kwargs): self.module = kwargs.get('flaskModule', None) self.test = kwargs.get('test', False) - @api.doc(description='Logout from the server', params={'token': 'Secret token'}) + @api.doc(description='Logout from the server') @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Logout the user + """ if current_user: logout_user() session.clear() diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryAssets.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryAssets.py index 8d980e61..d144c2c8 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryAssets.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryAssets.py @@ -1,9 +1,8 @@ -from flask import session, request +from flask import request from flask_restx import Resource, inputs from flask_babel import gettext from modules.LoginModule.LoginModule import user_multi_auth, current_user from modules.FlaskModule.FlaskModule import user_api_ns as api -from opentera.db.models.TeraUser import TeraUser from opentera.db.models.TeraAsset import TeraAsset from opentera.db.models.TeraService import TeraService @@ -46,11 +45,13 @@ def __init__(self, _api, *args, **kwargs): @api.doc(description='Get asset information. Only one of the ID parameter is supported at once', responses={200: 'Success - returns list of assets', 400: 'Required parameter is missing', - 403: 'Logged user doesn\'t have permission to access the requested data'}, - params={'token': 'Secret token'}) + 403: 'Logged user doesn\'t have permission to access the requested data'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get asset information + """ user_access = DBManager.userAccess(current_user) args = get_parser.parse_args() @@ -166,18 +167,22 @@ def get(self): # else: return assets_list - @api.doc(description='Delete asset.', - responses={501: 'Unable to update asset information from here'}, - params={'token': 'Secret token'}) + @api.doc(description='Update asset information', + responses={501: 'Unable to update asset information from here'}) @user_multi_auth.login_required def post(self): + """ + Update asset information + """ return gettext('Asset information update and creation must be done directly into a service (such as ' 'Filetransfer service)'), 501 - @api.doc(description='Delete asset.', - responses={501: 'Unable to delete asset information from here'}, - params={'token': 'Secret token'}) + @api.doc(description='Delete asset information', + responses={501: 'Unable to delete asset information from here'}) @user_multi_auth.login_required def delete(self): + """ + Delete asset information + """ return gettext('Asset information deletion must be done directly into a service (such as ' 'Filetransfer service)'), 501 diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryAssetsArchive.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryAssetsArchive.py index 2997c022..866a27d0 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryAssetsArchive.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryAssetsArchive.py @@ -4,17 +4,14 @@ import json import datetime import threading -import zipfile -from io import BytesIO -from flask import session, request, Response -from flask_restx import Resource, inputs +from flask import request +from flask_restx import Resource from flask_babel import gettext from modules.LoginModule.LoginModule import user_multi_auth, current_user from modules.FlaskModule.FlaskModule import user_api_ns as api from modules.FlaskModule import FlaskModule -from opentera.db.models.TeraUser import TeraUser from opentera.db.models.TeraAsset import TeraAsset from opentera.db.models.TeraService import TeraService from opentera.db.models.TeraProject import TeraProject @@ -46,11 +43,13 @@ def __init__(self, _api, *args, **kwargs): @api.doc(description='Get asset archive. Only one of the ID parameter is supported at once.', responses={200: 'Success - returns list of assets', 400: 'Required parameter is missing', - 403: 'Logged user doesn\'t have permission to access the requested data'}, - params={'token': 'Secret token'}) + 403: 'Logged user doesn\'t have permission to access the requested data'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get asset archive + """ # Get parameters args = get_parser.parse_args() user_access = DBManager.userAccess(current_user) diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryDeviceParticipants.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryDeviceParticipants.py index 92855b9c..12ff9198 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryDeviceParticipants.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryDeviceParticipants.py @@ -1,8 +1,7 @@ -from flask import jsonify, session, request +from flask import jsonify, request from flask_restx import Resource, reqparse, fields, inputs from modules.LoginModule.LoginModule import user_multi_auth, current_user from modules.FlaskModule.FlaskModule import user_api_ns as api -from opentera.db.models.TeraUser import TeraUser from opentera.db.models.TeraDeviceParticipant import TeraDeviceParticipant from opentera.db.models.TeraParticipant import TeraParticipant from opentera.db.models.TeraDeviceProject import TeraDeviceProject @@ -55,11 +54,13 @@ def __init__(self, _api, *args, **kwargs): ' at once.', responses={200: 'Success - returns list of devices - participants association', 400: 'Required parameter is missing (must have at least one id)', - 500: 'Error occurred when loading devices for participant'}, - params={'token': 'Secret token'}) + 500: 'Error occurred when loading devices for participant'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get devices assigned to a participant + """ user_access = DBManager.userAccess(current_user) args = get_parser.parse_args() @@ -107,11 +108,13 @@ def get(self): responses={200: 'Success', 403: 'Logged user can\'t modify device association', 400: 'Badly formed JSON or missing fields(id_participant or id_device) in the JSON body', - 500: 'Internal error occured when saving device association'}, - params={'token': 'Secret token'}) + 500: 'Internal error occured when saving device association'}) @api.expect(post_schema) @user_multi_auth.login_required def post(self): + """ + Assign / remove devices from a participant + """ user_access = DBManager.userAccess(current_user) # Using request.json instead of parser, since parser messes up the json! @@ -187,11 +190,13 @@ def post(self): @api.doc(description='Delete a specific device-participant association.', responses={200: 'Success', 403: 'Logged user can\'t delete device association', - 500: 'Device-participant association not found or database error.'}, - params={'token': 'Secret token'}) + 500: 'Device-participant association not found or database error.'}) @api.expect(delete_parser) @user_multi_auth.login_required def delete(self): + """ + Remove a specific device - participant association + """ user_access = DBManager.userAccess(current_user) args = delete_parser.parse_args() diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryDeviceProjects.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryDeviceProjects.py index 72ca569a..7e88a050 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryDeviceProjects.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryDeviceProjects.py @@ -1,8 +1,7 @@ -from flask import jsonify, session, request -from flask_restx import Resource, reqparse, inputs +from flask import request +from flask_restx import Resource, inputs from modules.LoginModule.LoginModule import user_multi_auth, current_user from modules.FlaskModule.FlaskModule import user_api_ns as api -from opentera.db.models.TeraUser import TeraUser from opentera.db.models.TeraDeviceProject import TeraDeviceProject from opentera.db.models.TeraDeviceSite import TeraDeviceSite from opentera.db.models.TeraDevice import TeraDevice @@ -51,11 +50,13 @@ def __init__(self, _api, *args, **kwargs): 'supported at once.', responses={200: 'Success - returns list of devices - project association', 400: 'Required parameter is missing (must have at least one id)', - 500: 'Error occurred when loading devices for projects'}, - params={'token': 'Secret token'}) + 500: 'Error occurred when loading devices for projects'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get devices associated with a project + """ user_access = DBManager.userAccess(current_user) args = get_parser.parse_args() @@ -127,11 +128,13 @@ def get(self): 403: 'Logged user can\'t modify device association - the user isn\'t admin ' 'of the project or current user can\'t access the device.', 400: 'Badly formed JSON or missing fields(id_project or id_device) in the JSON body', - 500: 'Internal error occured when saving device association'}, - params={'token': 'Secret token'}) + 500: 'Internal error occured when saving device association'}) @api.expect(post_schema) @user_multi_auth.login_required def post(self): + """ + Create/update devices associated with a project + """ user_access = DBManager.userAccess(current_user) # Using request.json instead of parser, since parser messes up the json! @@ -281,11 +284,13 @@ def post(self): responses={200: 'Success', 403: 'Logged user can\'t delete device association (no admin access to project or one of the ' 'device\'s site)', - 500: 'Device-project association not found or database error.'}, - params={'token': 'Secret token'}) + 500: 'Device-project association not found or database error.'}) @api.expect(delete_parser) @user_multi_auth.login_required def delete(self): + """ + Delete a specific device-project association + """ user_access = DBManager.userAccess(current_user) args = delete_parser.parse_args() id_todel = args['id'] diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryDeviceSites.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryDeviceSites.py index 4bb04dfc..7c5b37d9 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryDeviceSites.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryDeviceSites.py @@ -1,8 +1,7 @@ -from flask import jsonify, session, request +from flask import request from flask_restx import Resource, reqparse, inputs from modules.LoginModule.LoginModule import user_multi_auth, current_user from modules.FlaskModule.FlaskModule import user_api_ns as api -from opentera.db.models.TeraUser import TeraUser from opentera.db.models.TeraDevice import TeraDevice from opentera.db.models.TeraSite import TeraSite from opentera.db.models.TeraDeviceSite import TeraDeviceSite @@ -47,11 +46,13 @@ def __init__(self, _api, *args, **kwargs): ' at once.', responses={200: 'Success - returns list of devices - sites association', 400: 'Required parameter is missing (must have at least one id)', - 500: 'Error occurred when loading devices for sites'}, - params={'token': 'Secret token'}) + 500: 'Error occurred when loading devices for sites'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get devices associated to a site + """ user_access = DBManager.userAccess(current_user) args = get_parser.parse_args() @@ -112,11 +113,13 @@ def get(self): responses={200: 'Success', 403: 'Logged user can\'t modify device association', 400: 'Badly formed JSON or missing fields(id_site or id_device) in the JSON body', - 500: 'Internal error occured when saving device association'}, - params={'token': 'Secret token'}) + 500: 'Internal error occured when saving device association'}) @api.expect(post_schema) @user_multi_auth.login_required def post(self): + """ + Create/update devices association with a site + """ # Only super admins can change service - site associations if not current_user.user_superadmin: return gettext('Forbidden'), 403 @@ -236,11 +239,13 @@ def post(self): @api.doc(description='Delete a specific device-site association.', responses={200: 'Success', 403: 'Logged user can\'t delete device association (no admin access to site)', - 500: 'Device-site association not found or database error.'}, - params={'token': 'Secret token'}) + 500: 'Device-site association not found or database error.'}) @api.expect(delete_parser) @user_multi_auth.login_required def delete(self): + """ + Delete a specific device-site association + """ user_access = DBManager.userAccess(current_user) args = delete_parser.parse_args() diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryDeviceSubTypes.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryDeviceSubTypes.py index 03463e12..d77a3115 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryDeviceSubTypes.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryDeviceSubTypes.py @@ -1,9 +1,8 @@ -from flask import session, request +from flask import request from flask_restx import Resource, reqparse, inputs from flask_babel import gettext from modules.LoginModule.LoginModule import user_multi_auth, current_user from modules.FlaskModule.FlaskModule import user_api_ns as api -from opentera.db.models.TeraUser import TeraUser from opentera.db.models.TeraDeviceSubType import TeraDeviceSubType from sqlalchemy.exc import InvalidRequestError from sqlalchemy import exc @@ -36,11 +35,13 @@ def __init__(self, _api, *args, **kwargs): 400: 'No parameters specified at least one id must be used', 403: 'Forbidden access to the device type specified. Please check that the user has access to a' ' session type containing that device type.', - 500: 'Database error'}, - params={'token': 'Secret token'}) + 500: 'Database error'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get devices subtypes + """ user_access = DBManager.userAccess(current_user) args = get_parser.parse_args() has_list = args.pop('list') @@ -92,11 +93,13 @@ def get(self): 403: 'Logged user can\'t create/update the specified device subtype', 400: 'Badly formed JSON or missing fields(id_device_subtype or id_device_type) in the JSON ' 'body', - 500: 'Internal error occured when saving device subtype'}, - params={'token': 'Secret token'}) + 500: 'Internal error occured when saving device subtype'}) @api.expect(post_schema) @user_multi_auth.login_required def post(self): + """ + Create / update devices subtypes + """ user_access = DBManager.userAccess(current_user) if 'device_subtype' not in request.json: return gettext('Missing device_subtype'), 400 @@ -151,11 +154,13 @@ def post(self): @api.doc(description='Delete a specific device subtype', responses={200: 'Success', 403: 'Logged user can\'t delete device subtype (can delete if site admin)', - 500: 'Device subtype not found or database error.'}, - params={'token': 'Secret token'}) + 500: 'Device subtype not found or database error.'}) @api.expect(delete_parser) @user_multi_auth.login_required def delete(self): + """ + Delete a specific device subtype + """ user_access = DBManager.userAccess(current_user) args = delete_parser.parse_args() id_todel = args['id'] diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryDeviceTypes.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryDeviceTypes.py index 6c439a5d..a075bf03 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryDeviceTypes.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryDeviceTypes.py @@ -1,12 +1,10 @@ -from flask import session, request +from flask import request from flask_babel import gettext from flask_restx import Resource, reqparse, inputs from sqlalchemy import exc from sqlalchemy.exc import InvalidRequestError -from opentera.db.models import TeraDeviceType from opentera.db.models.TeraDeviceType import TeraDeviceType -from opentera.db.models.TeraUser import TeraUser from modules.DatabaseModule.DBManager import DBManager from modules.FlaskModule.FlaskModule import user_api_ns as api from modules.LoginModule.LoginModule import user_multi_auth, current_user @@ -40,11 +38,13 @@ def __init__(self, _api, *args, **kwargs): 400: 'No parameters specified at least one id must be used', 403: 'Forbidden access to the device type specified. Please check that the user has access to a' ' session type containing that device type.', - 500: 'Database error'}, - params={'token': 'Secret token'}) + 500: 'Database error'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get devices types + """ user_access = DBManager.userAccess(current_user) args = get_parser.parse_args() device_type = [] @@ -84,12 +84,14 @@ def get(self): 403: 'Logged user can\'t create/update the specified device type', 400: 'Badly formed JSON or missing fields(id_device_name or id_device_type) in the JSON ' 'body', - 500: 'Internal error occured when saving device type'}, - params={'token': 'Secret token'}) + 500: 'Internal error occured when saving device type'}) @api.expect(post_schema) @user_multi_auth.login_required def post(self): - user_access = DBManager.userAccess(current_user) + """ + Create / update devices types + """ + # user_access = DBManager.userAccess(current_user) if 'device_type' not in request.json: return gettext('Missing device type'), 400 @@ -144,11 +146,13 @@ def post(self): responses={200: 'Success', 403: 'Logged user can\'t delete device type (can delete if site admin)', 500: 'Device type not found or database error.', - 501: 'Tried to delete with 2 parameters'}, - params={'token': 'Secret token'}) + 501: 'Tried to delete with 2 parameters'}) @api.expect(delete_parser) @user_multi_auth.login_required def delete(self): + """ + Delete a specific device type + """ user_access = DBManager.userAccess(current_user) args = delete_parser.parse_args() # To accommodate the 'delete_with_http_auth' function which uses id as args, the id_device_type is rename as id diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryDevices.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryDevices.py index 740685e9..d0d4cf58 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryDevices.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryDevices.py @@ -1,8 +1,7 @@ -from flask import jsonify, session, request +from flask import jsonify, request from flask_restx import Resource, reqparse, inputs from modules.LoginModule.LoginModule import user_multi_auth, current_user from modules.FlaskModule.FlaskModule import user_api_ns as api -from opentera.db.models.TeraUser import TeraUser from opentera.db.models.TeraDevice import TeraDevice from opentera.db.models.TeraProject import TeraProject from opentera.db.models.TeraSite import TeraSite @@ -75,11 +74,13 @@ def __init__(self, _api, *args, **kwargs): responses={200: 'Success - returns list of devices', 400: 'User Error : Too Many IDs', 403: 'Forbidden access', - 500: 'Database error'}, - params={'token': 'Secret token'}) + 500: 'Database error'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get device information + """ user_access = DBManager.userAccess(current_user) args = get_parser.parse_args() @@ -242,11 +243,13 @@ def get(self): responses={200: 'Success', 403: 'Logged user can\'t create/update the specified device', 400: 'Badly formed JSON or missing fields(id_device) in the JSON body', - 500: 'Internal error occurred when saving device'}, - params={'token': 'Secret token'}) + 500: 'Internal error occurred when saving device'}) @api.expect(post_schema) @user_multi_auth.login_required def post(self): + """ + Create / update devices + """ user_access = DBManager.userAccess(current_user) # Using request.json instead of parser, since parser messes up the json! if 'device' not in request.json: @@ -395,11 +398,13 @@ def post(self): responses={200: 'Success', 400: 'Wrong ID/ No ID', 403: 'Logged user can\'t delete device (can delete if superadmin)', - 500: 'Device not found or database error.'}, - params={'token': 'Secret token'}) + 500: 'Device not found or database error.'}) @api.expect(delete_parser) @user_multi_auth.login_required def delete(self): + """ + Delete a specific device + """ user_access = DBManager.userAccess(current_user) args = delete_parser.parse_args() id_todel = args['id'] diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryDisconnect.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryDisconnect.py index b3a1e9a7..4a30a210 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryDisconnect.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryDisconnect.py @@ -1,5 +1,4 @@ -from flask import jsonify, session, request -from flask_restx import Resource, reqparse, inputs +from flask_restx import Resource from modules.FlaskModule.FlaskModule import user_api_ns as api from modules.LoginModule.LoginModule import user_multi_auth, current_user from opentera.db.models.TeraUser import TeraUser @@ -33,11 +32,13 @@ def __init__(self, _api, *args, **kwargs): 400: 'No parameters specified, at least one id / uuid must be used', 403: 'Forbidden access. Please check that the user has access to' ' the requested id/uuid.', - 500: 'Database error'}, - params={'token': 'Secret token'}) + 500: 'Database error'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Force disconnect a specific user / participant / device from server + """ args = get_parser.parse_args() user_access: DBManagerTeraUserAccess = DBManager.userAccess(current_user) diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryForms.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryForms.py index 5e21fa09..badbf226 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryForms.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryForms.py @@ -1,5 +1,4 @@ -from flask import jsonify, session -from flask_restx import Resource, reqparse +from flask_restx import Resource from modules.LoginModule.LoginModule import user_multi_auth, current_user from modules.FlaskModule.FlaskModule import user_api_ns as api from modules.DatabaseModule.DBManager import DBManager @@ -66,11 +65,13 @@ def __init__(self, _api, *args, **kwargs): @api.doc(description='Get json description of standard input form for the specified data type.', responses={200: 'Success', 400: 'Missing required parameter', - 500: 'Unknown or unsupported data type'}, - params={'token': 'Secret token'}) + 500: 'Unknown or unsupported data type'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get json description of form to display to edit a specific data type + """ args = get_parser.parse_args() user_access = DBManager.userAccess(current_user) diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryOnlineDevices.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryOnlineDevices.py index ec7ff8eb..a0daefb4 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryOnlineDevices.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryOnlineDevices.py @@ -1,10 +1,8 @@ -from flask import session from flask_restx import Resource from flask_babel import gettext from modules.LoginModule.LoginModule import user_multi_auth, current_user from modules.FlaskModule.FlaskModule import user_api_ns as api from sqlalchemy.exc import InvalidRequestError -from opentera.db.models.TeraUser import TeraUser from opentera.db.models.TeraDevice import TeraDevice from opentera.redis.RedisRPCClient import RedisRPCClient from opentera.modules.BaseModule import ModuleNames @@ -20,12 +18,14 @@ def __init__(self, _api, *args, **kwargs): self.test = kwargs.get('test', False) @api.doc(description='Get online devices uuids.', - responses={200: 'Success'}, - params={'token': 'Secret token'}) + responses={200: 'Success'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): - args = get_parser.parse_args() + """ + Get online devices + """ + # args = get_parser.parse_args() user_access = DBManager.userAccess(current_user) try: diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryOnlineParticipants.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryOnlineParticipants.py index c645852e..9c8bca75 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryOnlineParticipants.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryOnlineParticipants.py @@ -1,10 +1,8 @@ -from flask import session from flask_restx import Resource, inputs from flask_babel import gettext from modules.LoginModule.LoginModule import user_multi_auth, current_user from modules.FlaskModule.FlaskModule import user_api_ns as api from sqlalchemy.exc import InvalidRequestError -from opentera.db.models.TeraUser import TeraUser from opentera.db.models.TeraParticipant import TeraParticipant from opentera.redis.RedisRPCClient import RedisRPCClient from opentera.modules.BaseModule import ModuleNames @@ -27,6 +25,9 @@ def __init__(self, _api, *args, **kwargs): @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get online participants + """ args = get_parser.parse_args() user_access = DBManager.userAccess(current_user) diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryOnlineUsers.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryOnlineUsers.py index e49c9c09..0286a95b 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryOnlineUsers.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryOnlineUsers.py @@ -1,4 +1,3 @@ -from flask import session from flask_restx import Resource from flask_babel import gettext from modules.LoginModule.LoginModule import user_multi_auth, current_user @@ -24,7 +23,10 @@ def __init__(self, _api, *args, **kwargs): @api.expect(get_parser) @user_multi_auth.login_required def get(self): - args = get_parser.parse_args() + """ + Get online users + """ + # args = get_parser.parse_args() user_access = DBManager.userAccess(current_user) try: diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryParticipantGroup.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryParticipantGroup.py index 63909a3f..be3542f6 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryParticipantGroup.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryParticipantGroup.py @@ -1,8 +1,7 @@ -from flask import jsonify, session, request +from flask import jsonify, request from flask_restx import Resource, reqparse, inputs from modules.LoginModule.LoginModule import user_multi_auth, current_user from modules.FlaskModule.FlaskModule import user_api_ns as api -from opentera.db.models.TeraUser import TeraUser from opentera.db.models.TeraParticipantGroup import TeraParticipantGroup from modules.DatabaseModule.DBManager import DBManager from sqlalchemy.exc import InvalidRequestError @@ -36,11 +35,13 @@ def __init__(self, _api, *args, **kwargs): @api.doc(description='Get participant groups information. Only one of the ID parameter is supported at once. ' 'If no ID is specified, returns all accessible groups for the logged user', responses={200: 'Success - returns list of participant groups', - 500: 'Database error'}, - params={'token': 'Secret token'}) + 500: 'Database error'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get participant groups + """ user_access = DBManager.userAccess(current_user) args = get_parser.parse_args() @@ -82,11 +83,13 @@ def get(self): responses={200: 'Success', 403: 'Logged user can\'t create/update the specified device', 400: 'Badly formed JSON or missing fields(id_participant_group or id_project) in the JSON body', - 500: 'Internal error occurred when saving device'}, - params={'token': 'Secret token'}) + 500: 'Internal error occurred when saving device'}) @api.expect(post_schema) @user_multi_auth.login_required def post(self): + """ + Create / update participant groups + """ user_access = DBManager.userAccess(current_user) # Using request.json instead of parser, since parser messes up the json! if 'group' not in request.json and 'participant_group' not in request.json: @@ -141,11 +144,13 @@ def post(self): @api.doc(description='Delete a specific participant group', responses={200: 'Success', 403: 'Logged user can\'t delete participant group (only project admin can delete)', - 500: 'Database error.'}, - params={'token': 'Secret token'}) + 500: 'Database error.'}) @api.expect(delete_parser) @user_multi_auth.login_required def delete(self): + """ + Delete a participant group + """ user_access = DBManager.userAccess(current_user) args = delete_parser.parse_args() diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryParticipants.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryParticipants.py index 04e556b2..683d4938 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryParticipants.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryParticipants.py @@ -57,11 +57,13 @@ def __init__(self, _api, *args, **kwargs): @api.doc(description='Get participants information. Only one of the ID parameter is supported and required at once', responses={200: 'Success - returns list of participants', 400: 'No parameters specified at least one id must be used', - 500: 'Database error'}, - params={'token': 'Secret token'}) + 500: 'Database error'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get participants + """ user_access = DBManager.userAccess(current_user) args = get_parser.parse_args() @@ -208,11 +210,13 @@ def get(self): 403: 'Logged user can\'t create/update the specified participant', 400: 'Badly formed JSON or missing fields(id_participant or id_project/id_group [only one of ' 'them]) in the JSON body, or mismatch between id_project and participant group project', - 500: 'Internal error when saving participant'}, - params={'token': 'Secret token'}) + 500: 'Internal error when saving participant'}) @api.expect(post_schema) @user_multi_auth.login_required def post(self): + """ + Create / update participant + """ user_access = DBManager.userAccess(current_user) # Using request.json instead of parser, since parser messes up the json! if 'participant' not in request.json: @@ -345,11 +349,13 @@ def post(self): @api.doc(description='Delete a specific participant', responses={200: 'Success', 403: 'Logged user can\'t delete participant (only project admin can delete)', - 500: 'Database error.'}, - params={'token': 'Secret token'}) + 500: 'Database error.'}) @api.expect(delete_parser) @user_multi_auth.login_required def delete(self): + """ + Delete a participant + """ user_access = DBManager.userAccess(current_user) args = delete_parser.parse_args() id_todel = args['id'] diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryProjectAccess.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryProjectAccess.py index 9d31ad88..cd42dcb7 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryProjectAccess.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryProjectAccess.py @@ -1,10 +1,9 @@ -from flask import jsonify, session, request +from flask import jsonify, request from flask_restx import Resource, reqparse, inputs from flask_babel import gettext from sqlalchemy import exc from modules.LoginModule.LoginModule import user_multi_auth, current_user from modules.FlaskModule.FlaskModule import user_api_ns as api -from opentera.db.models.TeraUser import TeraUser from opentera.db.models.TeraServiceAccess import TeraServiceAccess from opentera.db.models.TeraServiceRole import TeraServiceRole from opentera.db.models.TeraProject import TeraProject @@ -67,11 +66,13 @@ def __init__(self, _api, *args, **kwargs): @api.doc(description='Get user roles for projects. Only one ID parameter required and supported at once.', responses={200: 'Success - returns list of users roles in projects', 400: 'Required parameter is missing (must have at least one id)', - 500: 'Error occured when loading project roles'}, - params={'token': 'Secret token'}) + 500: 'Error occured when loading project roles'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get roles for users / user groupes in a project + """ user_access = DBManager.userAccess(current_user) args = get_parser.parse_args() @@ -173,15 +174,17 @@ def get(self): # No access, but still fine return [], 200 - @api.doc(description='Create/update project access for an user.', + @api.doc(description='Create/update project access for an user / usergroup.', responses={200: 'Success', 403: 'Logged user can\'t modify this project or user access (project admin access required)', 400: 'Badly formed JSON or missing fields(id_user_group or id_project) in the JSON body', - 500: 'Database error'}, - params={'token': 'Secret token'}) + 500: 'Database error'}) @api.expect(post_schema) @user_multi_auth.login_required def post(self): + """ + Create / update project roles for users / usergroups + """ user_access = DBManager.userAccess(current_user) # Using request.json instead of parser, since parser messes up the json! json_projects = request.json['project_access'] @@ -256,11 +259,13 @@ def post(self): responses={200: 'Success', 403: 'Logged user can\'t delete project access(only user who is admin in that project can ' 'remove it)', - 500: 'Database error.'}, - params={'token': 'Secret token'}) + 500: 'Database error.'}) @api.expect(delete_parser) @user_multi_auth.login_required def delete(self): + """ + Delete specific user / usergroup role in a project + """ user_access = DBManager.userAccess(current_user) args = delete_parser.parse_args() id_todel = args['id'] diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryProjects.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryProjects.py index f1d1670d..a73a4ee4 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryProjects.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryProjects.py @@ -43,11 +43,13 @@ def __init__(self, _api, *args, **kwargs): @api.doc(description='Get projects information. Only one of the ID parameter is supported and required at once', responses={200: 'Success - returns list of participants', - 500: 'Database error'}, - params={'token': 'Secret token'}) + 500: 'Database error'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get projects + """ user_access = DBManager.userAccess(current_user) args = get_parser.parse_args() @@ -121,11 +123,13 @@ def get(self): responses={200: 'Success', 403: 'Logged user can\'t create/update the specified project', 400: 'Badly formed JSON or missing fields(id_site or id_project) in the JSON body', - 500: 'Internal error occured when saving project'}, - params={'token': 'Secret token'}) + 500: 'Internal error occured when saving project'}) @api.expect(post_schema) @user_multi_auth.login_required def post(self): + """ + Create / update project + """ user_access = DBManager.userAccess(current_user) # Using request.json instead of parser, since parser messes up the json! if 'project' not in request.json: @@ -247,11 +251,13 @@ def post(self): @api.doc(description='Delete a specific project', responses={200: 'Success', 403: 'Logged user can\'t delete project (only site admin can delete)', - 500: 'Database error.'}, - params={'token': 'Secret token'}) + 500: 'Database error.'}) @api.expect(delete_parser) @user_multi_auth.login_required def delete(self): + """ + Delete project + """ user_access = DBManager.userAccess(current_user) args = delete_parser.parse_args() id_todel = args['id'] diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryServerSettings.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryServerSettings.py index ac10146c..e35a1108 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryServerSettings.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryServerSettings.py @@ -19,11 +19,13 @@ def __init__(self, _api, *args, **kwargs): @api.doc(description='Get server setting key', responses={200: 'Success - returns setting value', - 401: 'Logged user doesn\'t have permission to access the requested data'}, - params={'token': 'Secret token'}) + 401: 'Logged user doesn\'t have permission to access the requested data'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get server settings + """ # As soon as we are authorized, we can output the server versions args = get_parser.parse_args() diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryServiceAccess.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryServiceAccess.py index 285bfc62..f33cd965 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryServiceAccess.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryServiceAccess.py @@ -1,5 +1,5 @@ -from flask import jsonify, request -from flask_restx import Resource, reqparse, inputs +from flask import request +from flask_restx import Resource, reqparse from modules.LoginModule.LoginModule import user_multi_auth, current_user from modules.FlaskModule.FlaskModule import user_api_ns as api from opentera.db.models.TeraServiceAccess import TeraServiceAccess @@ -39,11 +39,13 @@ def __init__(self, _api, *args, **kwargs): 'supported at once.', responses={200: 'Success - returns list of access roles', 400: 'Required parameter is missing (must have at least one id)', - 500: 'Error when getting association'}, - params={'token': 'Secret token'}) + 500: 'Error when getting association'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get service access roles for a specific item + """ user_access = DBManager.userAccess(current_user) args = get_parser.parse_args() @@ -88,11 +90,13 @@ def get(self): responses={200: 'Success', 403: 'Logged user can\'t modify association (only site admin can modify association)', 400: 'Badly formed JSON or missing fields(id_project or id_service) in the JSON body', - 500: 'Internal error occurred when saving association'}, - params={'token': 'Secret token'}) + 500: 'Internal error occurred when saving association'}) @api.expect(post_schema) @user_multi_auth.login_required def post(self): + """ + Create / update service - access association + """ user_access = DBManager.userAccess(current_user) # Using request.json instead of parser, since parser messes up the json! @@ -194,11 +198,13 @@ def post(self): @api.doc(description='Delete a specific service access.', responses={200: 'Success', 403: 'Logged user can\'t delete association (not admin of the associated elements)', - 500: 'Association not found or database error.'}, - params={'token': 'Secret token'}) + 500: 'Association not found or database error.'}) @api.expect(delete_parser) @user_multi_auth.login_required def delete(self): + """ + Delete a specific service access for an item + """ user_access = DBManager.userAccess(current_user) args = delete_parser.parse_args() id_todel = args['id'] diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryServiceAccessToken.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryServiceAccessToken.py index e38ae3e0..22abc3fa 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryServiceAccessToken.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryServiceAccessToken.py @@ -23,11 +23,13 @@ def __init__(self, _api, *args, **kwargs): @api.doc(description='Get access token for a specific service.', responses={200: 'Success - returns access token', 400: 'Required parameter is missing (must have at least one id)', - 500: 'Error when getting association'}, - params={'token': 'Secret token'}) + 500: 'Error when getting association'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get service access token + """ user_access = DBManager.userAccess(current_user) args = get_parser.parse_args() diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryServiceConfigs.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryServiceConfigs.py index efeeba66..18a06b8c 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryServiceConfigs.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryServiceConfigs.py @@ -1,8 +1,7 @@ -from flask import jsonify, session, request +from flask import session, request from flask_restx import Resource, reqparse, inputs from modules.LoginModule.LoginModule import user_multi_auth, current_user from modules.FlaskModule.FlaskModule import user_api_ns as api -from opentera.db.models.TeraUser import TeraUser from opentera.db.models.TeraServiceConfig import TeraServiceConfig from modules.DatabaseModule.DBManager import DBManager from sqlalchemy.exc import InvalidRequestError @@ -47,11 +46,13 @@ def __init__(self, _api, *args, **kwargs): 'config the current user.', responses={200: 'Success - returns list of configurations', 400: 'No parameters specified - id_service is at least required', - 500: 'Database error'}, - params={'token': 'Secret token'}) + 500: 'Database error'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get specific service configuration for an item + """ user_access = DBManager.userAccess(current_user) args = get_parser.parse_args() @@ -110,11 +111,13 @@ def get(self): 403: 'Logged user can\'t create/update the specified session', 400: 'Badly formed JSON or missing fields(service_config, id_service_config, id_service) in the' ' JSON body', - 500: 'Internal error when saving service config'}, - params={'token': 'Secret token'}) + 500: 'Internal error when saving service config'}) @api.expect(post_schema) @user_multi_auth.login_required def post(self): + """ + Create / update service configuration for an item + """ user_access = DBManager.userAccess(current_user) # Using request.json instead of parser, since parser messes up the json! if 'service_config' not in request.json: @@ -220,15 +223,17 @@ def post(self): else: return [update_config.to_json()] - @api.doc(description='Delete a specific session', + @api.doc(description='Delete a specific service configuration', responses={200: 'Success', 403: 'Logged user can\'t delete config (must have admin access to the related object - user,' 'device or participant, or be its own config)', - 500: 'Database error.'}, - params={'token': 'Secret token'}) + 500: 'Database error.'}) @api.expect(delete_parser) @user_multi_auth.login_required def delete(self): + """ + Delete a specific service configuration for an item + """ user_access = DBManager.userAccess(current_user) args = delete_parser.parse_args() id_todel = args['id'] diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryServiceProjects.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryServiceProjects.py index 512cdc31..3f0456f2 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryServiceProjects.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryServiceProjects.py @@ -49,11 +49,13 @@ def __init__(self, _api, *args, **kwargs): 'supported at once.', responses={200: 'Success - returns list of services - projects association', 400: 'Required parameter is missing (must have at least one id)', - 500: 'Error when getting association'}, - params={'token': 'Secret token'}) + 500: 'Error when getting association'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get services associated with a project + """ user_access = DBManager.userAccess(current_user) args = get_parser.parse_args() @@ -128,11 +130,13 @@ def get(self): responses={200: 'Success', 403: 'Logged user can\'t modify association (only site admin can modify association)', 400: 'Badly formed JSON or missing fields(id_project or id_service) in the JSON body', - 500: 'Internal error occurred when saving association'}, - params={'token': 'Secret token'}) + 500: 'Internal error occurred when saving association'}) @api.expect(post_schema) @user_multi_auth.login_required def post(self): + """ + Create / update service-project association + """ user_access = DBManager.userAccess(current_user) # Using request.json instead of parser, since parser messes up the json! @@ -293,11 +297,13 @@ def post(self): @api.doc(description='Delete a specific service - project association.', responses={200: 'Success', 403: 'Logged user can\'t delete association (not site admin of the associated project)', - 500: 'Association not found or database error.'}, - params={'token': 'Secret token'}) + 500: 'Association not found or database error.'}) @api.expect(delete_parser) @user_multi_auth.login_required def delete(self): + """ + Delete a specific service - project association + """ user_access = DBManager.userAccess(current_user) args = delete_parser.parse_args() id_todel = args['id'] diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryServiceRoles.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryServiceRoles.py index 06724799..7d9fa30e 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryServiceRoles.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryServiceRoles.py @@ -33,11 +33,13 @@ def __init__(self, _api, *args, **kwargs): @api.doc(description='Get service roles for either a specific service or for all available services.', responses={200: 'Success - returns list of service roles', - 500: 'Error when getting roles'}, - params={'token': 'Secret token'}) + 500: 'Error when getting roles'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get service roles + """ user_access = DBManager.userAccess(current_user) args = get_parser.parse_args() @@ -70,11 +72,13 @@ def get(self): responses={200: 'Success', 403: 'Logged user can\'t modify service role (only super admin)', 400: 'Badly formed JSON or missing fields(id_service or id_service_role) in the JSON body', - 500: 'Internal error occurred when saving association'}, - params={'token': 'Secret token'}) + 500: 'Internal error occurred when saving association'}) @api.expect(post_schema) @user_multi_auth.login_required def post(self): + """ + Create / update service roles + """ if not current_user.user_superadmin: return gettext('Forbidden'), 403 @@ -123,11 +127,13 @@ def post(self): @api.doc(description='Delete a specific service role.', responses={200: 'Success', 403: 'Logged user can\'t delete role (not super admin)', - 500: 'Database error.'}, - params={'token': 'Secret token'}) + 500: 'Database error.'}) @api.expect(delete_parser) @user_multi_auth.login_required def delete(self): + """ + Delete service role + """ user_access = DBManager.userAccess(current_user) args = delete_parser.parse_args() id_todel = args['id'] diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryServiceSites.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryServiceSites.py index 55d48709..c0459993 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryServiceSites.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryServiceSites.py @@ -1,4 +1,4 @@ -from flask import jsonify, request +from flask import request from flask_restx import Resource, reqparse, inputs from modules.LoginModule.LoginModule import user_multi_auth, current_user from modules.FlaskModule.FlaskModule import user_api_ns as api @@ -46,11 +46,13 @@ def __init__(self, _api, *args, **kwargs): 'supported at once.', responses={200: 'Success - returns list of services - sites association', 400: 'Required parameter is missing (must have at least one id)', - 500: 'Error when getting association'}, - params={'token': 'Secret token'}) + 500: 'Error when getting association'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get services associated with a site + """ user_access = DBManager.userAccess(current_user) args = get_parser.parse_args() @@ -117,12 +119,14 @@ def get(self): responses={200: 'Success', 403: 'Logged user can\'t modify association (only super admin can modify association)', 400: 'Badly formed JSON or missing fields(id_project or id_service) in the JSON body', - 500: 'Internal error occurred when saving association'}, - params={'token': 'Secret token'}) + 500: 'Internal error occurred when saving association'}) @api.expect(post_schema) @user_multi_auth.login_required def post(self): - user_access = DBManager.userAccess(current_user) + """ + Create / update service-site association + """ + # user_access = DBManager.userAccess(current_user) # Only super admins can change service - site associations if not current_user.user_superadmin: @@ -248,12 +252,14 @@ def post(self): @api.doc(description='Delete a specific service - site association.', responses={200: 'Success', 403: 'Logged user can\'t delete association (only super admins can)', - 500: 'Association not found or database error.'}, - params={'token': 'Secret token'}) + 500: 'Association not found or database error.'}) @api.expect(delete_parser) @user_multi_auth.login_required def delete(self): - user_access = DBManager.userAccess(current_user) + """ + Delete service-site association + """ + # user_access = DBManager.userAccess(current_user) if not current_user.user_superadmin: return gettext('Forbidden'), 403 diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryServices.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryServices.py index 2c830618..dbe85513 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryServices.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryServices.py @@ -1,10 +1,9 @@ -from flask import jsonify, session, request +from flask import jsonify, request from flask_restx import Resource, reqparse, inputs from modules.LoginModule.LoginModule import user_multi_auth, current_user from modules.FlaskModule.FlaskModule import user_api_ns as api from sqlalchemy.exc import InvalidRequestError from sqlalchemy import exc -from opentera.db.models.TeraUser import TeraUser from opentera.db.models.TeraService import TeraService from opentera.db.models.TeraServiceRole import TeraServiceRole from modules.DatabaseModule.DBManager import DBManager @@ -41,11 +40,13 @@ def __init__(self, _api, *args, **kwargs): @api.doc(description='Get services information. Only one of the ID parameter is supported and required at once.', responses={200: 'Success - returns list of services', - 500: 'Database error'}, - params={'token': 'Secret token'}) + 500: 'Database error'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get services + """ user_access = DBManager.userAccess(current_user) args = get_parser.parse_args() @@ -109,11 +110,13 @@ def get(self): responses={200: 'Success', 403: 'Logged user can\'t create/update the specified service', 400: 'Badly formed JSON or missing fields(id_service) in the JSON body', - 500: 'Internal error occured when saving service'}, - params={'token': 'Secret token'}) + 500: 'Internal error occured when saving service'}) @api.expect(post_schema) @user_multi_auth.login_required def post(self): + """ + Create / update services + """ user_access = DBManager.userAccess(current_user) # Check if user is a super admin @@ -217,11 +220,13 @@ def post(self): 400: 'Service doesn\'t exists', 403: 'Logged user can\'t delete service (only super admins can delete) or service is a system ' 'service', - 500: 'Database error.'}, - params={'token': 'Secret token'}) + 500: 'Database error.'}) @api.expect(delete_parser) @user_multi_auth.login_required def delete(self): + """ + Delete service + """ user_access = DBManager.userAccess(current_user) args = delete_parser.parse_args() id_todel = args['id'] diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQuerySessionEvents.py b/teraserver/python/modules/FlaskModule/API/user/UserQuerySessionEvents.py index 76ca8aa2..b2270df8 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQuerySessionEvents.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQuerySessionEvents.py @@ -1,9 +1,8 @@ -from flask import jsonify, session, request +from flask import jsonify, request from flask_restx import Resource, reqparse from flask_babel import gettext from modules.LoginModule.LoginModule import user_multi_auth, current_user from modules.FlaskModule.FlaskModule import user_api_ns as api -from opentera.db.models.TeraUser import TeraUser from opentera.db.models.TeraSessionEvent import TeraSessionEvent from modules.DatabaseModule.DBManager import DBManager from sqlalchemy.exc import InvalidRequestError @@ -32,11 +31,13 @@ def __init__(self, _api, *args, **kwargs): @api.doc(description='Get events for a specific session', responses={200: 'Success - returns list of events', 400: 'Required parameter is missing (id_session)', - 500: 'Database error'}, - params={'token': 'Secret token'}) + 500: 'Database error'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get events for a session + """ user_access = DBManager.userAccess(current_user) args = get_parser.parse_args() @@ -66,11 +67,13 @@ def get(self): responses={200: 'Success', 403: 'Logged user can\'t create/update the specified event', 400: 'Badly formed JSON or missing fields(id_session_event or id_session) in the JSON body', - 500: 'Internal error when saving device'}, - params={'token': 'Secret token'}) + 500: 'Internal error when saving device'}) @api.expect(post_schema) @user_multi_auth.login_required def post(self): + """ + Create / update session events + """ user_access = DBManager.userAccess(current_user) # Using request.json instead of parser, since parser messes up the json! if 'session_event' not in request.json: @@ -126,11 +129,13 @@ def post(self): @api.doc(description='Delete a specific session event', responses={200: 'Success', 403: 'Logged user can\'t delete event (no access to that session)', - 500: 'Database error.'}, - params={'token': 'Secret token'}) + 500: 'Database error.'}) @api.expect(delete_parser) @user_multi_auth.login_required def delete(self): + """ + Delete a session event + """ user_access = DBManager.userAccess(current_user) args = delete_parser.parse_args() id_todel = args['id'] diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQuerySessionTypeProjects.py b/teraserver/python/modules/FlaskModule/API/user/UserQuerySessionTypeProjects.py index 83ec3685..d0427392 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQuerySessionTypeProjects.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQuerySessionTypeProjects.py @@ -44,15 +44,17 @@ def __init__(self, _api, *args, **kwargs): self.module = kwargs.get('flaskModule', None) self.test = kwargs.get('test', False) - @api.doc(description='Get devices types that are associated with a project. Only one "ID" parameter required and ' + @api.doc(description='Get session types that are associated with a project. Only one "ID" parameter required and ' 'supported at once.', responses={200: 'Success - returns list of devices-types - projects association', 400: 'Required parameter is missing (must have at least one id)', - 500: 'Error when getting association'}, - params={'token': 'Secret token'}) + 500: 'Error when getting association'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get session types associated with a project + """ user_access = DBManager.userAccess(current_user) args = get_parser.parse_args() @@ -115,11 +117,13 @@ def get(self): 403: 'Logged user can\'t modify association (session type must be accessible from project ' 'access)', 400: 'Badly formed JSON or missing fields(id_project or id_session_type) in the JSON body', - 500: 'Internal error occurred when saving association'}, - params={'token': 'Secret token'}) + 500: 'Internal error occurred when saving association'}) @api.expect(post_schema) @user_multi_auth.login_required def post(self): + """ + Create / update session types for a project + """ user_access = DBManager.userAccess(current_user) accessible_projects_ids = user_access.get_accessible_projects_ids(admin_only=True) @@ -255,11 +259,13 @@ def post(self): @api.doc(description='Delete a specific session-type - project association.', responses={200: 'Success', 403: 'Logged user can\'t delete association (no access to session-type or project)', - 400: 'Association not found (invalid id?)'}, - params={'token': 'Secret token'}) + 400: 'Association not found (invalid id?)'}) @api.expect(delete_parser) @user_multi_auth.login_required def delete(self): + """ + Delete specific session type - project association + """ user_access = DBManager.userAccess(current_user) args = delete_parser.parse_args() id_todel = args['id'] diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQuerySessionTypeSites.py b/teraserver/python/modules/FlaskModule/API/user/UserQuerySessionTypeSites.py index d43e0b57..49075376 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQuerySessionTypeSites.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQuerySessionTypeSites.py @@ -45,11 +45,13 @@ def __init__(self, _api, *args, **kwargs): ' at once.', responses={200: 'Success - returns list of session types - sites association', 400: 'Required parameter is missing (must have at least one id)', - 500: 'Error occurred when loading devices for sites'}, - params={'token': 'Secret token'}) + 500: 'Error occurred when loading devices for sites'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get session types associated with a site + """ user_access = DBManager.userAccess(current_user) args = get_parser.parse_args() @@ -104,11 +106,13 @@ def get(self): responses={200: 'Success', 403: 'Logged user can\'t modify device association', 400: 'Badly formed JSON or missing fields(id_site or id_device) in the JSON body', - 500: 'Internal error occured when saving device association'}, - params={'token': 'Secret token'}) + 500: 'Internal error occured when saving device association'}) @api.expect(post_schema) @user_multi_auth.login_required def post(self): + """ + Create / update session types associated with a site + """ user_access = DBManager.userAccess(current_user) # Only super admins can change session type - site associations @@ -248,11 +252,13 @@ def post(self): @api.doc(description='Delete a specific session type-site association.', responses={200: 'Success', 403: 'Logged user can\'t delete association (no admin access to site)', - 500: 'Session type - site association not found or database error.'}, - params={'token': 'Secret token'}) + 500: 'Session type - site association not found or database error.'}) @api.expect(delete_parser) @user_multi_auth.login_required def delete(self): + """ + Delete a specific session type - site association + """ user_access = DBManager.userAccess(current_user) args = delete_parser.parse_args() id_todel = args['id'] diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQuerySessionTypes.py b/teraserver/python/modules/FlaskModule/API/user/UserQuerySessionTypes.py index df9c1b2e..80ddf24b 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQuerySessionTypes.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQuerySessionTypes.py @@ -1,4 +1,4 @@ -from flask import session, request +from flask import request from flask_restx import Resource, reqparse, inputs from modules.LoginModule.LoginModule import user_multi_auth, current_user from modules.FlaskModule.FlaskModule import user_api_ns as api @@ -37,11 +37,13 @@ def __init__(self, _api, *args, **kwargs): @api.doc(description='Get session type information. If no id_session_type specified, returns all available ' 'session types', responses={200: 'Success - returns list of session types', - 500: 'Database error'}, - params={'token': 'Secret token'}) + 500: 'Database error'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get session type + """ user_access = DBManager.userAccess(current_user) args = get_parser.parse_args() @@ -84,11 +86,13 @@ def get(self): responses={200: 'Success', 403: 'Logged user can\'t create/update the specified session type', 400: 'Badly formed JSON or missing field(id_session_type) in the JSON body', - 500: 'Internal error when saving session type'}, - params={'token': 'Secret token'}) + 500: 'Internal error when saving session type'}) @api.expect(post_schema) @user_multi_auth.login_required def post(self): + """ + Create / update session type + """ user_access = DBManager.userAccess(current_user) # Using request.json instead of parser, since parser messes up the json! if 'session_type' not in request.json: @@ -302,6 +306,9 @@ def post(self): @api.expect(delete_parser) @user_multi_auth.login_required def delete(self): + """ + Delete session type + """ user_access = DBManager.userAccess(current_user) args = delete_parser.parse_args() id_todel = args['id'] diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQuerySessions.py b/teraserver/python/modules/FlaskModule/API/user/UserQuerySessions.py index f6c4d6aa..dea61725 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQuerySessions.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQuerySessions.py @@ -1,4 +1,4 @@ -from flask import jsonify, session, request +from flask import jsonify, request from flask_restx import Resource, reqparse, inputs from modules.LoginModule.LoginModule import user_multi_auth, current_user from modules.FlaskModule.FlaskModule import user_api_ns as api @@ -45,11 +45,13 @@ def __init__(self, _api, *args, **kwargs): @api.doc(description='Get sessions information. Only one of the ID parameter is supported and required at once', responses={200: 'Success - returns list of sessions', 400: 'No parameters specified at least one id must be used', - 500: 'Database error'}, - params={'token': 'Secret token'}) + 500: 'Database error'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get session + """ user_access = DBManager.userAccess(current_user) args = get_parser.parse_args() @@ -109,11 +111,13 @@ def get(self): 403: 'Logged user can\'t create/update the specified session', 400: 'Badly formed JSON or missing fields(session, id_session, session_participants_ids and/or ' 'session_users_ids[for new sessions]) in the JSON body', - 500: 'Internal error when saving session'}, - params={'token': 'Secret token'}) + 500: 'Internal error when saving session'}) @api.expect(post_schema) @user_multi_auth.login_required def post(self): + """ + Create / update session + """ user_access = DBManager.userAccess(current_user) # Using request.json instead of parser, since parser messes up the json! if 'session' not in request.json: @@ -225,11 +229,13 @@ def post(self): responses={200: 'Success', 403: 'Logged user can\'t delete session (must have access to all participants and users in the ' 'session to delete)', - 500: 'Database error.'}, - params={'token': 'Secret token'}) + 500: 'Database error.'}) @api.expect(delete_parser) @user_multi_auth.login_required def delete(self): + """ + Delete session + """ user_access = DBManager.userAccess(current_user) args = delete_parser.parse_args() id_todel = args['id'] diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQuerySiteAccess.py b/teraserver/python/modules/FlaskModule/API/user/UserQuerySiteAccess.py index 45d21a8e..c8890c63 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQuerySiteAccess.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQuerySiteAccess.py @@ -1,10 +1,9 @@ -from flask import jsonify, session, request +from flask import request from flask_restx import Resource, reqparse, inputs from flask_babel import gettext from sqlalchemy import exc from modules.LoginModule.LoginModule import user_multi_auth, current_user from modules.FlaskModule.FlaskModule import user_api_ns as api -from opentera.db.models.TeraUser import TeraUser from opentera.db.models.TeraServiceAccess import TeraServiceAccess from opentera.db.models.TeraSite import TeraSite from opentera.db.models.TeraServiceRole import TeraServiceRole @@ -66,11 +65,13 @@ def __init__(self, _api, *args, **kwargs): @api.doc(description='Get user roles for sites. Only one parameter required and supported at once.', responses={200: 'Success - returns list of users roles in sites', 400: 'Required parameter is missing (must have at least one id)', - 500: 'Error occurred when loading sites roles'}, - params={'token': 'Secret token'}) + 500: 'Error occurred when loading sites roles'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get access role to site for user / usergroup + """ user_access = DBManager.userAccess(current_user) args = get_parser.parse_args() @@ -160,11 +161,13 @@ def get(self): responses={200: 'Success', 403: 'Logged user can\'t modify this site or user access (site admin access required)', 400: 'Badly formed JSON or missing fields(id_user or id_site) in the JSON body', - 500: 'Database error'}, - params={'token': 'Secret token'}) + 500: 'Database error'}) @api.expect(post_schema) @user_multi_auth.login_required def post(self): + """ + Create / update site access for an user / usergroup + """ user_access = DBManager.userAccess(current_user) # Using request.json instead of parser, since parser messes up the json! json_sites = request.json['site_access'] @@ -257,11 +260,13 @@ def post(self): @api.doc(description='Delete a specific site access', responses={200: 'Success', 403: 'Logged user can\'t delete site access(only user who is admin in that site can remove it)', - 500: 'Database error.'}, - params={'token': 'Secret token'}) + 500: 'Database error.'}) @api.expect(delete_parser) @user_multi_auth.login_required def delete(self): + """ + Delete a specific site access + """ user_access = DBManager.userAccess(current_user) args = delete_parser.parse_args() id_todel = args['id'] diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQuerySites.py b/teraserver/python/modules/FlaskModule/API/user/UserQuerySites.py index 2f430fe3..7d48f485 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQuerySites.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQuerySites.py @@ -1,7 +1,7 @@ from flask import jsonify, request from flask_restx import Resource, reqparse from sqlalchemy import exc -from modules.LoginModule.LoginModule import user_multi_auth, current_user, user_token_auth +from modules.LoginModule.LoginModule import user_multi_auth, current_user from modules.FlaskModule.FlaskModule import user_api_ns as api from sqlalchemy.exc import InvalidRequestError from opentera.db.models.TeraUser import TeraUser @@ -39,6 +39,9 @@ def __init__(self, _api, *args, **kwargs): @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get site + """ user_access = DBManager.userAccess(current_user) args = get_parser.parse_args() @@ -105,6 +108,9 @@ def get(self): @api.expect(post_schema) @user_multi_auth.login_required def post(self): + """ + Create / update site + """ user_access = DBManager.userAccess(current_user) if 'site' not in request.json: return gettext('Missing site'), 400 @@ -165,6 +171,9 @@ def post(self): @api.expect(delete_parser) @user_multi_auth.login_required def delete(self): + """ + Delete a site + """ args = delete_parser.parse_args() id_todel = args['id'] diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryStats.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryStats.py index b51f3b71..8da3e5f6 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryStats.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryStats.py @@ -39,11 +39,13 @@ def __init__(self, _api, *args, **kwargs): @api.doc(description='Get stats for the specified item.', responses={200: 'Success', 400: 'Missing parameter - one id must be specified.', - 500: 'Database error'}, - params={'token': 'Secret token'}) + 500: 'Database error'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get stats for the specified item + """ args = get_parser.parse_args() user_access = DBManager.userAccess(current_user) @@ -238,7 +240,6 @@ def get_site_stats(user_access: DBManagerTeraUserAccess, item_id: int, with_part @staticmethod def get_project_stats(user_access: DBManagerTeraUserAccess, item_id: int, with_parts: bool) -> dict: - from opentera.db.models.TeraSessionParticipants import TeraSessionParticipants from opentera.db.models.TeraProject import TeraProject project_users = user_access.query_users_for_project(project_id=item_id) project_users_enabled = user_access.query_users_for_project(project_id=item_id, enabled_only=True) diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryTestType.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryTestType.py index fe4e96f9..2d7f8dab 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryTestType.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryTestType.py @@ -1,4 +1,4 @@ -from flask import session, request +from flask import request from flask_restx import Resource, reqparse, inputs from modules.LoginModule.LoginModule import user_multi_auth, current_user from modules.FlaskModule.FlaskModule import user_api_ns as api @@ -41,11 +41,13 @@ def __init__(self, _api, *args, **kwargs): @api.doc(description='Get test type information. If no id_test_type specified, returns all available test types', responses={200: 'Success - returns list of test types', - 500: 'Database error'}, - params={'token': 'Secret token'}) + 500: 'Database error'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get test types + """ user_access = DBManager.userAccess(current_user) args = get_parser.parse_args() @@ -117,11 +119,13 @@ def get(self): responses={200: 'Success', 403: 'Logged user can\'t create/update the specified test type', 400: 'Badly formed JSON or missing field in the JSON body', - 500: 'Internal error when saving test type'}, - params={'token': 'Secret token'}) + 500: 'Internal error when saving test type'}) @api.expect(post_schema) @user_multi_auth.login_required def post(self): + """ + Create / update test types + """ user_access = DBManager.userAccess(current_user) # Using request.json instead of parser, since parser messes up the json! if 'test_type' not in request.json: @@ -311,11 +315,13 @@ def post(self): responses={200: 'Success', 403: 'Logged user can\'t delete test type (no admin access to project related to that type ' 'or tests of that type exists in the system somewhere)', - 500: 'Database error.'}, - params={'token': 'Secret token'}) + 500: 'Database error.'}) @api.expect(delete_parser) @user_multi_auth.login_required def delete(self): + """ + Delete test type + """ user_access = DBManager.userAccess(current_user) args = delete_parser.parse_args() id_todel = args['id'] diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryTestTypeProjects.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryTestTypeProjects.py index ccb64505..7181f2ce 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryTestTypeProjects.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryTestTypeProjects.py @@ -48,11 +48,13 @@ def __init__(self, _api, *args, **kwargs): 'supported at once.', responses={200: 'Success - returns list of test-types - projects association', 400: 'Required parameter is missing (must have at least one id)', - 500: 'Error when getting association'}, - params={'token': 'Secret token'}) + 500: 'Error when getting association'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get test types - project association + """ user_access = DBManager.userAccess(current_user) args = get_parser.parse_args() @@ -113,11 +115,13 @@ def get(self): responses={200: 'Success', 403: 'Logged user can\'t modify association (project admin access required)', 400: 'Badly formed JSON or missing fields in the JSON body', - 500: 'Internal error occurred when saving association'}, - params={'token': 'Secret token'}) + 500: 'Internal error occurred when saving association'}) @api.expect(post_schema) @user_multi_auth.login_required def post(self): + """ + Create / update test-type -> project association + """ user_access = DBManager.userAccess(current_user) accessible_projects_ids = user_access.get_accessible_projects_ids(admin_only=True) @@ -256,11 +260,13 @@ def post(self): @api.doc(description='Delete a specific test-type - project association.', responses={200: 'Success', 403: 'Logged user can\'t delete association (no access to test-type or project)', - 400: 'Association not found (invalid id?)'}, - params={'token': 'Secret token'}) + 400: 'Association not found (invalid id?)'}) @api.expect(delete_parser) @user_multi_auth.login_required def delete(self): + """ + Delete a specific test type - project association + """ user_access = DBManager.userAccess(current_user) args = delete_parser.parse_args() id_todel = args['id'] diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryTestTypeSites.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryTestTypeSites.py index 2339a5dc..f39521fa 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryTestTypeSites.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryTestTypeSites.py @@ -42,15 +42,17 @@ def __init__(self, _api, *args, **kwargs): self.module = kwargs.get('flaskModule', None) self.test = kwargs.get('test', False) - @api.doc(description='Get session types that are related to a site. Only one "ID" parameter required and supported' + @api.doc(description='Get test types that are related to a site. Only one "ID" parameter required and supported' ' at once.', responses={200: 'Success - returns list of session types - sites association', 400: 'Required parameter is missing (must have at least one id)', - 500: 'Error occured when loading devices for sites'}, - params={'token': 'Secret token'}) + 500: 'Error occured when loading devices for sites'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get test types associated to a site + """ user_access = DBManager.userAccess(current_user) args = get_parser.parse_args() @@ -102,11 +104,13 @@ def get(self): responses={200: 'Success', 403: 'Logged user can\'t modify association', 400: 'Badly formed JSON or missing fields(id_site or id_test_type) in the JSON body', - 500: 'Internal error occurred when saving device association'}, - params={'token': 'Secret token'}) + 500: 'Internal error occurred when saving device association'}) @api.expect(post_schema) @user_multi_auth.login_required def post(self): + """ + Create / update test types associated to a site + """ user_access = DBManager.userAccess(current_user) # Only super admins can change session type - site associations @@ -237,11 +241,13 @@ def post(self): @api.doc(description='Delete a specific test type-site association.', responses={200: 'Success', 403: 'Logged user can\'t delete association (no admin access to site)', - 500: 'Session type - site association not found or database error.'}, - params={'token': 'Secret token'}) + 500: 'Session type - site association not found or database error.'}) @api.expect(delete_parser) @user_multi_auth.login_required def delete(self): + """ + Delete specific test type - site association + """ user_access = DBManager.userAccess(current_user) args = delete_parser.parse_args() id_todel = args['id'] diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryTests.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryTests.py index dc4a0d3b..4edbf3c8 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryTests.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryTests.py @@ -1,4 +1,4 @@ -from flask import session, request +from flask import request from flask_restx import Resource, inputs from flask_babel import gettext from modules.LoginModule.LoginModule import user_multi_auth, current_user @@ -41,11 +41,13 @@ def __init__(self, _api, *args, **kwargs): @api.doc(description='Get test information. Only one of the ID parameter is supported at once', responses={200: 'Success - returns list of assets', 400: 'Required parameter is missing', - 403: 'Logged user doesn\'t have permission to access the requested data'}, - params={'token': 'Secret token'}) + 403: 'Logged user doesn\'t have permission to access the requested data'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get test information + """ user_access = DBManager.userAccess(current_user) args = get_parser.parse_args() @@ -115,11 +117,13 @@ def get(self): return tests_list @api.doc(description='Delete test.', - responses={501: 'Unable to update test from here - use service!'}, - params={'token': 'Secret token'}) + responses={501: 'Unable to update test from here - use service!'}) @api.expect(post_parser) @user_multi_auth.login_required def post(self): + """ + Create / update test + """ return gettext('Test information update and creation must be done directly into a service (such as ' 'Test service)'), 501 @@ -131,6 +135,9 @@ def post(self): @api.expect(delete_parser) @user_multi_auth.login_required def delete(self): + """ + Delete test + """ user_access = DBManager.userAccess(current_user) args = delete_parser.parse_args(strict=True) id_todel = args['id'] diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryUndelete.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryUndelete.py index a28fd6e2..fbe09992 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryUndelete.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryUndelete.py @@ -21,11 +21,13 @@ def __init__(self, _api, *args, **kwargs): 400: 'Required parameter is missing', 401: 'Requested item not found or is undeletable', 403: 'Access level insufficient to access that API or the item to undelete', - 500: 'Database error'}, - params={'token': 'Secret token'}) + 500: 'Database error'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Undelete an item + """ if not current_user.user_superadmin: return gettext('No access to this API'), 403 diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryUserGroups.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryUserGroups.py index 500f4dfd..0a0e85bd 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryUserGroups.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryUserGroups.py @@ -1,9 +1,8 @@ -from flask import jsonify, session, request +from flask import jsonify, request from flask_restx import Resource, reqparse, inputs from sqlalchemy import exc from modules.LoginModule.LoginModule import user_multi_auth, current_user from modules.FlaskModule.FlaskModule import user_api_ns as api -from opentera.db.models.TeraUser import TeraUser from opentera.db.models.TeraServiceAccess import TeraServiceAccess from opentera.db.models.TeraServiceRole import TeraServiceRole from opentera.db.models.TeraUserGroup import TeraUserGroup @@ -72,11 +71,13 @@ def get_sites_roles_json(user_access, user_group_id: int): @api.doc(description='Get user group information. If no id specified, returns all accessible users groups', responses={200: 'Success', - 500: 'Database error'}, - params={'token': 'Secret token'}) + 500: 'Database error'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get usergroup + """ args = get_parser.parse_args() user_access = DBManager.userAccess(current_user) @@ -121,11 +122,13 @@ def get(self): responses={200: 'Success', 403: 'Logged user can\'t create/update the specified user group', 400: 'Badly formed JSON or missing field(id_user_group) in the JSON body', - 500: 'Internal error when saving user group'}, - params={'token': 'Secret token'}) + 500: 'Internal error when saving user group'}) @api.expect(post_schema) @user_multi_auth.login_required def post(self): + """ + Create / update usergroup + """ user_access = DBManager.userAccess(current_user) if 'user_group' not in request.json: @@ -274,11 +277,13 @@ def post(self): responses={200: 'Success', 403: 'Logged user can\'t delete user group (only a site admin that includes that user group in ' 'their site can delete)', - 500: 'Database error.'}, - params={'token': 'Secret token'}) + 500: 'Database error.'}) @api.expect(delete_parser) @user_multi_auth.login_required def delete(self): + """ + Delete an usergroup + """ user_access = DBManager.userAccess(current_user) args = delete_parser.parse_args() id_todel = args['id'] diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryUserPreferences.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryUserPreferences.py index b8fec30a..b1da1ff6 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryUserPreferences.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryUserPreferences.py @@ -1,9 +1,8 @@ -from flask import session, request -from flask_restx import Resource, reqparse, inputs +from flask import request +from flask_restx import Resource from flask_babel import gettext from modules.LoginModule.LoginModule import user_multi_auth, current_user from modules.FlaskModule.FlaskModule import user_api_ns as api -from opentera.db.models.TeraUser import TeraUser from opentera.db.models.TeraUserPreference import TeraUserPreference from sqlalchemy.exc import InvalidRequestError from sqlalchemy import exc @@ -31,11 +30,13 @@ def __init__(self, _api, *args, **kwargs): responses={200: 'Success - returns list of user preferences', 400: 'Missing parameter or bad app_tag', 403: 'Forbidden access to that user.', - 500: 'Database error'}, - params={'token': 'Secret token'}) + 500: 'Database error'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get user preferences (for a specific app) + """ user_access = DBManager.userAccess(current_user) args = get_parser.parse_args() @@ -72,11 +73,13 @@ def get(self): responses={200: 'Success', 403: 'Logged user can\'t create/update the user linked to that preference', 400: 'Badly formed JSON or missing fields(app_tag) in the JSON body', - 500: 'Internal error occurred when saving user preference'}, - params={'token': 'Secret token'}) + 500: 'Internal error occurred when saving user preference'}) @api.expect(post_schema) @user_multi_auth.login_required def post(self): + """ + Create / update user preferences + """ user_access = DBManager.userAccess(current_user) # Using request.json instead of parser, since parser messes up the json! json_user_pref = request.json['user_preference'] diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryUserUserGroups.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryUserUserGroups.py index 1f866078..cb17256f 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryUserUserGroups.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryUserUserGroups.py @@ -1,4 +1,4 @@ -from flask import jsonify, session, request +from flask import request from flask_restx import Resource, reqparse, inputs from sqlalchemy import exc from modules.LoginModule.LoginModule import user_multi_auth, current_user @@ -35,11 +35,13 @@ def __init__(self, _api, *args, **kwargs): @api.doc(description='Get user - user group information. At least one "id" field must be specified', responses={200: 'Success', - 500: 'Database error'}, - params={'token': 'Secret token'}) + 500: 'Database error'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get user usergroups + """ args = get_parser.parse_args() user_access = DBManager.userAccess(current_user) @@ -78,11 +80,13 @@ def get(self): responses={200: 'Success', 403: 'Logged user can\'t create/update the specified user group', 400: 'Badly formed JSON or missing field(id_user_group) in the JSON body', - 500: 'Internal error when saving user group'}, - params={'token': 'Secret token'}) + 500: 'Internal error when saving user group'}) @api.expect(post_schema) @user_multi_auth.login_required def post(self): + """ + Create / update user's usergroups + """ user_access = DBManager.userAccess(current_user) if not 'user_user_group' in request.json: @@ -143,11 +147,13 @@ def post(self): responses={200: 'Success', 403: 'Logged user can\'t delete user group (only a site admin that includes that user group in ' 'their site can delete)', - 500: 'Database error.'}, - params={'token': 'Secret token'}) + 500: 'Database error.'}) @api.expect(delete_parser) @user_multi_auth.login_required def delete(self): + """ + Delete a specific user-usergroup assocation + """ user_access = DBManager.userAccess(current_user) args = delete_parser.parse_args() id_todel = args['id'] diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryUsers.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryUsers.py index 93ccf307..fa8a3c3b 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryUsers.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryUsers.py @@ -45,11 +45,13 @@ def __init__(self, _api, *args, **kwargs): @api.doc(description='Get user information. If no id specified, returns all accessible users', responses={200: 'Success', - 500: 'Database error'}, - params={'token': 'Secret token'}) + 500: 'Database error'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get users + """ args = get_parser.parse_args() user_access = DBManager.userAccess(current_user) @@ -147,14 +149,6 @@ def get(self): return jsonify(users_list) return [], 200 - # try: - # users = TeraUser.query_data(my_args) - # users_list = [] - # for user in users: - # users_list.append(user.to_json()) - # return jsonify(users_list) - # except InvalidRequestError: - # return '', 500 @api.doc(description='Create / update user. id_user must be set to "0" to create a new user. User can be modified ' 'if: current user is super admin or user is part of a project which the current user is admin.' @@ -165,11 +159,13 @@ def get(self): 400: 'Badly formed JSON or missing field(id_user or missing password when new user) in the ' 'JSON body', 409: 'Username is already taken', - 500: 'Internal error when saving user'}, - params={'token': 'Secret token'}) + 500: 'Internal error when saving user'}) @api.expect(post_schema) @user_multi_auth.login_required def post(self): + """ + Create / update an user + """ user_access = DBManager.userAccess(current_user) if 'user' not in request.json: @@ -299,34 +295,18 @@ def post(self): update_user.commit() - # Check if there's some user groups for the updated user that we need to delete - # id_groups_to_delete = set([group.id_user_group for group in update_user.user_user_groups])\ - # .difference(user_user_groups_ids) - # - # for id_to_del in id_groups_to_delete: - # uug_to_del = TeraUserUserGroup.query_user_user_group_for_user_user_group(user_id=update_user.id_user, - # user_group_id=id_to_del) - # TeraUserUserGroup.delete(id_todel=uug_to_del.id_user_user_group) - # - # # Update / insert user groups - # for user_group in user_user_groups: - # if not TeraUserUserGroup.query_user_user_group_for_user_user_group(user_id=update_user.id_user, - # user_group_id= - # user_group['id_user_group']): - # # Group not already associated - associates! - # TeraUserUserGroup.insert_user_user_group(id_user_group=user_group['id_user_group'], - # id_user=update_user.id_user) - return [update_user.to_json()] @api.doc(description='Delete a specific user', responses={200: 'Success', 403: 'Logged user can\'t delete user (only super admin can delete)', - 500: 'Database error.'}, - params={'token': 'Secret token'}) + 500: 'Database error.'}) @api.expect(delete_parser) @user_multi_auth.login_required def delete(self): + """ + Delete an user + """ user_access = DBManager.userAccess(current_user) args = delete_parser.parse_args() id_todel = args['id'] diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryVersions.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryVersions.py index 12152247..cf88672f 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryVersions.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryVersions.py @@ -27,13 +27,15 @@ def __init__(self, _api, *args, **kwargs): @api.doc(description='Get server versions', responses={200: 'Success - returns versions information', 400: 'Required parameter is missing', - 403: 'Logged user doesn\'t have permission to access the requested data'}, - params={'token': 'Secret token'}) + 403: 'Logged user doesn\'t have permission to access the requested data'}) @api.expect(get_parser) @user_multi_auth.login_required def get(self): + """ + Get server versions + """ # As soon as we are authorized, we can output the server versions - args = get_parser.parse_args() + # args = get_parser.parse_args() current_settings = TeraServerSettings.get_server_setting_value(TeraServerSettings.ServerVersions) if not current_settings: @@ -45,11 +47,13 @@ def get(self): responses={200: 'Success - asset posted', 500: 'Database error occurred', 403: 'Logged user doesn\'t have permission to delete the requested asset (must be an user of' - 'the related project)'}, - params={'token': 'Secret token'}) + 'the related project)'}) @api.expect(post_schema) @user_multi_auth.login_required def post(self): + """ + Update server versions + """ # Only superuser can change the versions settings # Only some fields can be changed. if current_user.user_superadmin: diff --git a/teraserver/python/modules/FlaskModule/API/user/UserRefreshToken.py b/teraserver/python/modules/FlaskModule/API/user/UserRefreshToken.py index 6edf0e94..e699365f 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserRefreshToken.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserRefreshToken.py @@ -1,6 +1,5 @@ from flask import session, request -from flask_restx import Resource, reqparse, inputs -from flask_babel import gettext +from flask_restx import Resource, inputs from modules.LoginModule.LoginModule import user_token_auth, current_user from modules.FlaskModule.FlaskModule import user_api_ns as api from modules.LoginModule.LoginModule import LoginModule @@ -23,11 +22,13 @@ def __init__(self, _api, *args, **kwargs): @api.doc(description='Refresh token, old token needs to be passed in request headers.', responses={200: 'Success', - 500: 'Server error'}, - params={'token': 'Secret token'}) + 500: 'Server error'}) @api.expect(get_parser) @user_token_auth.login_required def get(self): + """ + Refresh token for current user + """ # If we have made it this far, token passed in headers was valid. # Get user token key from redis token_key = self.module.redisGet(RedisVars.RedisVar_UserTokenAPIKey) diff --git a/teraserver/python/modules/FlaskModule/API/user/UserSessionManager.py b/teraserver/python/modules/FlaskModule/API/user/UserSessionManager.py index ad9c498a..3f98bb4e 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserSessionManager.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserSessionManager.py @@ -1,8 +1,7 @@ -from flask import session, request +from flask import request from flask_restx import Resource from modules.LoginModule.LoginModule import user_multi_auth, current_user from modules.FlaskModule.FlaskModule import user_api_ns as api -from opentera.db.models.TeraUser import TeraUser from opentera.db.models.TeraService import TeraService from opentera.db.models.TeraSession import TeraSession from flask_babel import gettext @@ -89,11 +88,13 @@ def __init__(self, _api, *args, **kwargs): 400: 'Required parameter is missing', 500: 'Internal server error', 501: 'Not implemented', - 403: 'Logged user doesn\'t have enough permission'}, - params={'token': 'Secret token'}) + 403: 'Logged user doesn\'t have enough permission'}) @api.expect(session_manager_schema) @user_multi_auth.login_required def post(self): + """ + Starts / stop a session related to a service + """ args = post_parser.parse_args() user_access = DBManager.userAccess(current_user)