diff options
author | Timotej Lazar <timotej.lazar@fri.uni-lj.si> | 2016-02-28 15:52:09 +0100 |
---|---|---|
committer | Timotej Lazar <timotej.lazar@fri.uni-lj.si> | 2016-02-28 16:01:00 +0100 |
commit | 441bca2319f66a7fd79f350e45fdc5f018e9f2e7 (patch) | |
tree | c4369deb2d68bc2684e64515a7026f49c0b14191 | |
parent | 3072efb05b460f8edcf1d9187a92e98e513ca421 (diff) |
Add experiments column to codeq_user
This JSON column holds an array of experiment objects, for example:
[{'id': 'prolog_hints', 'group': 'manual_hints'}].
To include users in an experiment, just add appropriate objects to their
records. Not the cleanest design from the DB point of view, but enough
for the single current use case.
-rw-r--r-- | db/create.sql | 1 | ||||
-rw-r--r-- | scripts/db_update-20160228.sql | 1 | ||||
-rw-r--r-- | server/user_session.py | 7 |
3 files changed, 8 insertions, 1 deletions
diff --git a/db/create.sql b/db/create.sql index 5d2af79..43d275e 100644 --- a/db/create.sql +++ b/db/create.sql @@ -52,6 +52,7 @@ create table codeq_user ( gui_lang varchar(2), robot_address varchar(30), gui_layout varchar(30), + experiments jsonb, constraint codeq_user_pk primary key (id), constraint codeq_user_uq1 unique (username) ); diff --git a/scripts/db_update-20160228.sql b/scripts/db_update-20160228.sql new file mode 100644 index 0000000..73b045c --- /dev/null +++ b/scripts/db_update-20160228.sql @@ -0,0 +1 @@ +alter table codeq_user add column experiments jsonb; diff --git a/server/user_session.py b/server/user_session.py index af28046..7860022 100644 --- a/server/user_session.py +++ b/server/user_session.py @@ -86,7 +86,7 @@ class UserSession(object): try: cur = conn.cursor() try: - cur.execute('select id, password, name, email, is_admin, date_joined, gui_lang, robot_address, gui_layout from codeq_user where username = %s', (username,)) + cur.execute('select id, password, name, email, is_admin, date_joined, gui_lang, robot_address, gui_layout, experiments from codeq_user where username = %s', (username,)) row = cur.fetchone() if row is None: raise AuthenticationFailed('No such user: {}'.format(username)) @@ -96,6 +96,7 @@ class UserSession(object): self.username = username self.is_admin = row[4] self.settings = {'gui_lang': row[6], 'robot_address': row[7], 'gui_layout': row[8]} + self.experiments = row[9] if row[9] else [] return row[2], row[3], row[4], row[5], now else: raise AuthenticationFailed('Password mismatch') @@ -253,6 +254,10 @@ class UserSession(object): with self._access_lock: # settings are mutable, so we need a locked access return self.settings + def get_experiments(self): + with self._access_lock: + return self.experiments + def update_settings(self, new_settings): with self._access_lock: self.settings.update(new_settings) |