users: add column to store is_active (#42428)

This commit is contained in:
Benjamin Dauvergne 2020-07-07 11:59:34 +02:00 committed by Frédéric Péters
parent 4c8d63eaab
commit b145351e2d
2 changed files with 14 additions and 5 deletions

View File

@ -641,6 +641,7 @@ def do_user_table():
ascii_name varchar,
email varchar,
roles text[],
is_active bool,
is_admin bool,
anonymous bool,
verified_fields text[],
@ -657,7 +658,7 @@ def do_user_table():
needed_fields = set(['id', 'name', 'email', 'roles', 'is_admin',
'anonymous', 'name_identifiers', 'verified_fields',
'lasso_dump', 'last_seen', 'fts', 'ascii_name',
'deleted_timestamp'])
'deleted_timestamp', 'is_active'])
from wcs.admin.settings import UserFieldsFormDef
formdef = UserFieldsFormDef()
@ -699,6 +700,10 @@ def do_user_table():
if 'deleted_timestamp' not in existing_fields:
cur.execute('ALTER TABLE %s ADD COLUMN deleted_timestamp timestamp' % table_name)
if 'is_active' not in existing_fields:
cur.execute('ALTER TABLE %s ADD COLUMN is_active bool DEFAULT TRUE' % table_name)
cur.execute('UPDATE %s SET is_active = FALSE WHERE deleted_timestamp IS NOT NULL' % table_name)
# delete obsolete fields
for field in (existing_fields - needed_fields):
cur.execute('''ALTER TABLE %s DROP COLUMN %s''' % (table_name, field))
@ -1888,6 +1893,7 @@ class SqlUser(SqlMixin, wcs.users.User):
('last_seen', 'timestamp'),
('ascii_name', 'varchar'),
('deleted_timestamp', 'timestamp'),
('is_active', 'bool'),
]
id = None
@ -1913,6 +1919,7 @@ class SqlUser(SqlMixin, wcs.users.User):
'lasso_dump': self.lasso_dump,
'last_seen': None,
'deleted_timestamp': self.deleted_timestamp,
'is_active': self.is_active,
}
if self.last_seen:
sql_dict['last_seen'] = datetime.datetime.fromtimestamp(self.last_seen),
@ -1980,8 +1987,8 @@ class SqlUser(SqlMixin, wcs.users.User):
o = cls()
(o.id, o.name, o.email, o.roles, o.is_admin, o.anonymous,
o.name_identifiers, o.verified_fields, o.lasso_dump,
o.last_seen, ascii_name, o.deleted_timestamp) = [
str_encode(x) for x in tuple(row[:12])]
o.last_seen, ascii_name, o.deleted_timestamp, o.is_active) = [
str_encode(x) for x in tuple(row[:13])]
if o.last_seen:
o.last_seen = time.mktime(o.last_seen.timetuple())
if o.roles:
@ -2544,7 +2551,7 @@ def get_yearly_totals(period_start=None, period_end=None, criterias=None):
return result
SQL_LEVEL = 39
SQL_LEVEL = 40
def migrate_global_views(conn, cur):
@ -2638,13 +2645,14 @@ def migrate():
# 33: add anonymised field to global view
# 38: extract submission_agent_id to its own column
migrate_views(conn, cur)
if sql_level < 39:
if sql_level < 40:
# 3: introduction of _structured for user fields
# 4: removal of identification_token
# 12: (first part) add fts to users
# 16: add verified_fields to users
# 21: (first part) add ascii_name to users
# 39: add deleted_timestamp
# 40: add is_active to users
do_user_table()
if sql_level < 6:
# 6: add actions_roles_array to tables and views

View File

@ -31,6 +31,7 @@ class User(StorableObject):
name = None
email = None
roles = None
is_active = True
is_admin = False
anonymous = False
form_data = None # dumping ground for custom fields