aboutsummaryrefslogtreecommitdiff
path: root/gn3
diff options
context:
space:
mode:
Diffstat (limited to 'gn3')
-rw-r--r--gn3/auth/authorisation/groups.py1
-rw-r--r--gn3/auth/db.py18
2 files changed, 14 insertions, 5 deletions
diff --git a/gn3/auth/authorisation/groups.py b/gn3/auth/authorisation/groups.py
index ad30763..5290196 100644
--- a/gn3/auth/authorisation/groups.py
+++ b/gn3/auth/authorisation/groups.py
@@ -8,6 +8,7 @@ from . import authorised_p
("create-group",), success_message="Successfully created group.",
error_message="Failed to create group.")
def create_group(conn, group_name):
+ """Create a group"""
with db.cursor(conn) as cursor:
group_id = uuid.uuid4()
cursor.execute(
diff --git a/gn3/auth/db.py b/gn3/auth/db.py
index c0d0415..e732a03 100644
--- a/gn3/auth/db.py
+++ b/gn3/auth/db.py
@@ -4,16 +4,24 @@ import contextlib
@contextlib.contextmanager
def connection(db_path: str):
- connection = sqlite3.connect(db_path)
+ """Create the connection to the auth database."""
+ conn = sqlite3.connect(db_path)
try:
- yield connection
+ yield conn
+ except: # pylint: disable=bare-except
+ conn.rollback()
finally:
- connection.close()
+ conn.commit()
+ conn.close()
@contextlib.contextmanager
-def cursor(connection):
- cur = connection.cursor()
+def cursor(conn):
+ """Get a cursor from the given connection to the auth database."""
+ cur = conn.cursor()
try:
yield cur
+ except: # pylint: disable=bare-except
+ conn.rollback()
finally:
+ conn.commit()
cur.close()