From f940698b4e5dd963cc9146b128272069863b1702 Mon Sep 17 00:00:00 2001
From: Martin Mares <mj@ucw.cz>
Date: Tue, 16 Nov 2021 21:37:52 +0100
Subject: [PATCH] =?UTF-8?q?Role=20nyn=C3=AD=20logujeme=20pod=20user=5Fid?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Closes #252.
---
bin/add-role | 6 +++---
db/db.ddl | 2 +-
mo/imports.py | 6 +++---
mo/web/org_users.py | 12 ++++++------
4 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/bin/add-role b/bin/add-role
index 046b33c2..465c0e19 100755
--- a/bin/add-role
+++ b/bin/add-role
@@ -61,8 +61,8 @@ ur = db.UserRole(
session.add(ur)
session.flush()
-mo.util.log(db.LogType.user_role, ur.user_role_id, {
- 'action': 'assigned',
- 'new': db.row2dict(ur),
+mo.util.log(db.LogType.user, user.user_id, {
+ 'action': 'new-role',
+ 'role': db.row2dict(ur),
})
session.commit()
diff --git a/db/db.ddl b/db/db.ddl
index 9da44a08..e7fb513d 100644
--- a/db/db.ddl
+++ b/db/db.ddl
@@ -282,7 +282,7 @@ CREATE TYPE log_type AS ENUM (
'contest', -- contests(contest_id)
'participant', -- participants(user_id)
'task', -- tasks(task_id)
- 'user_role' -- user_roles(user_id)
+ 'user_role' -- user_roles(user_id) -- momentálně nepoužíváme, změny rolí logujeme pod user_id
);
CREATE TABLE log (
diff --git a/mo/imports.py b/mo/imports.py
index cbbe2379..79480888 100644
--- a/mo/imports.py
+++ b/mo/imports.py
@@ -278,9 +278,9 @@ class Import:
sess.flush()
logger.info(f'Import: {role.name.title()} user=#{user.user_id} place=#{place.place_id} user_role=#{ur.user_role_id}')
mo.util.log(
- type=db.LogType.user_role,
- what=ur.user_role_id,
- details={'action': 'import', 'new': db.row2dict(ur)},
+ type=db.LogType.user,
+ what=user.user_id,
+ details={'action': 'import-role', 'role': db.row2dict(ur)},
)
self.cnt_new_roles += 1
diff --git a/mo/web/org_users.py b/mo/web/org_users.py
index fbf78033..0f0d217b 100644
--- a/mo/web/org_users.py
+++ b/mo/web/org_users.py
@@ -310,12 +310,12 @@ def org_org(id: int):
sess.add(new_role)
sess.flush()
mo.util.log(
- type=db.LogType.user_role,
+ type=db.LogType.user,
what=id,
- details={'action': 'new', 'role': db.row2dict(new_role)},
+ details={'action': 'new-role', 'role': db.row2dict(new_role)},
)
sess.commit()
- app.logger.info(f"New role for user id {id} added: {db.row2dict(new_role)}")
+ app.logger.info(f"New role for user #{id} added: {db.row2dict(new_role)}")
flash(f'Role "{new_role}" úspěšně přidána', 'success')
return redirect(url_for('org_user', id=id))
@@ -329,12 +329,12 @@ def org_org(id: int):
else:
sess.delete(role)
mo.util.log(
- type=db.LogType.user_role,
+ type=db.LogType.user,
what=id,
- details={'action': 'delete', 'role': db.row2dict(role)},
+ details={'action': 'delete-role', 'role': db.row2dict(role)},
)
sess.commit()
- app.logger.info(f"Role for user {id} removed: {db.row2dict(role)}")
+ app.logger.info(f"Role for user #{id} removed: {db.row2dict(role)}")
flash(f'Role "{role}" úspěšně odebrána', 'success')
return redirect(url_for('org_user', id=id))
--
GitLab