Ensure you can only view/edit http functions created by the currently logged in user

This commit is contained in:
Peter Stockings
2023-12-20 22:57:39 +11:00
parent 30e16277df
commit 8d38c39604
6 changed files with 48 additions and 37 deletions

24
db.py
View File

@@ -47,31 +47,31 @@ class DataBase():
return (rv[0] if rv else None) if one else rv
def get_http_functions(self):
def get_http_functions_for_user(self, user_id):
http_functions = self.execute(
'SELECT id, NAME, script_content, invoked_count, environment_info FROM http_functions ORDER by id DESC', [])
'SELECT id, user_id, NAME, script_content, invoked_count, environment_info FROM http_functions WHERE user_id=%s ORDER by id DESC', [user_id])
return http_functions
def get_http_function(self, name):
def get_http_function(self, user_id, name):
http_function = self.execute(
'SELECT id, NAME, script_content, invoked_count, environment_info FROM http_functions WHERE NAME=%s', [name], one=True)
'SELECT id, user_id, NAME, script_content, invoked_count, environment_info FROM http_functions WHERE user_id=%s AND NAME=%s', [user_id, name], one=True)
return http_function
def create_new_http_function(self, name, script_content, environment_info):
def create_new_http_function(self, user_id, name, script_content, environment_info):
self.execute(
'INSERT INTO http_functions (NAME, script_content, environment_info) VALUES (%s, %s, %s)', [name, script_content, environment_info], commit=True)
'INSERT INTO http_functions (user_id, NAME, script_content, environment_info) VALUES (%s, %s, %s, %s)', [user_id, name, script_content, environment_info], commit=True)
def edit_http_function(self, name, script_content, environment_info):
def edit_http_function(self, user_id, name, script_content, environment_info):
self.execute(
'UPDATE http_functions SET script_content=%s, environment_info=%s WHERE NAME=%s', [script_content, environment_info, name], commit=True)
'UPDATE http_functions SET script_content=%s, environment_info=%s WHERE user_id=%s AND NAME=%s', [script_content, environment_info, user_id, name], commit=True)
def update_http_function_environment_info_and_invoked_count(self, name, environment_info):
def update_http_function_environment_info_and_invoked_count(self, user_id, name, environment_info):
self.execute(
'UPDATE http_functions SET environment_info=%s, invoked_count = invoked_count + 1 WHERE NAME=%s', [json.dumps(environment_info), name], commit=True)
'UPDATE http_functions SET environment_info=%s, invoked_count = invoked_count + 1 WHERE user_id=%s AND NAME=%s', [json.dumps(environment_info), user_id, name], commit=True)
def delete_http_function(self, name):
def delete_http_function(self, user_id, name):
self.execute(
'DELETE FROM http_functions WHERE NAME=%s', [name], commit=True)
'DELETE FROM http_functions WHERE user_id=%s AND NAME=%s', [user_id, name], commit=True)
def add_http_function_invocation(self, http_function_id, status, request_data, response_data, logs):
self.execute(