More work on GUI for user management

This commit is contained in:
Kovid Goyal 2017-04-21 10:13:10 +05:30
parent 1b3d29e7f8
commit 6907bb3d50
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 9 additions and 4 deletions

View File

@ -303,6 +303,7 @@ class NewUser(QDialog):
self.bb = bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
l.addRow(bb)
bb.accepted.connect(self.accept), bb.rejected.connect(self.reject)
(self.uw if not username else self.p1).setFocus(Qt.OtherFocusReason)
def show_password(self):
for p in self.p1, self.p2:
@ -317,7 +318,7 @@ class NewUser(QDialog):
return self.p1.text()
def accept(self):
if self.uw.isEditable():
if not self.uw.isReadOnly():
un = self.username
if not un:
return error_dialog(self, _('Empty username'), _('You must enter a username'), show=True)

View File

@ -168,14 +168,18 @@ class UserManager(object):
def user_data(self, users):
with self.lock, self.conn:
c = self.conn.cursor()
remove = self.all_user_names - set(users)
if remove:
c.executemany('DELETE FROM users WHERE name=?', (remove,))
for name, data in users.iteritems():
res = serialize_restriction(data['restriction'])
r = 'y' if data['readonly'] else 'n'
c.execute('UPDATE users SET (pw, restriction, readonly) VALUES (?,?,?) WHERE name=?',
data['pw'], res, r, name)
c.execute('UPDATE users SET pw=?, restriction=?, readonly=? WHERE name=?',
(data['pw'], res, r, name))
if self.conn.changes() > 0:
continue
c.execute('INSERT INTO USERS (name, pw, restriction, readonly)', name, data['pw'], res, r)
c.execute('INSERT INTO USERS (name, pw, restriction, readonly) VALUES (?, ?, ?, ?)',
(name, data['pw'], res, r))
self.refresh()
def refresh(self):