Fix restrictions for unknown users

This commit is contained in:
Kovid Goyal 2017-04-18 15:54:48 +05:30
parent c6cd432d92
commit 8e1b718060
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 4 additions and 2 deletions

View File

@ -184,7 +184,9 @@ def manage_users(path=None):
m.set_readonly(username, not readonly) m.set_readonly(username, not readonly)
def change_restriction(username): def change_restriction(username):
r = m.restrictions(username) or {} r = m.restrictions(username)
if r is None:
raise SystemExit('The user {} does not exist'.format(username))
if r['allowed_library_names']: if r['allowed_library_names']:
prints(_('{} is currently only allowed to access the libraries named: {}').format( prints(_('{} is currently only allowed to access the libraries named: {}').format(
username, ', '.join(r['allowed_library_names']))) username, ', '.join(r['allowed_library_names'])))

View File

@ -153,6 +153,7 @@ class TestAuth(BaseTest):
self.assertEqual(library_info('a')[0], {'l%d'%i:'l%d'%i for i in range(1, 4) if i == 3}) self.assertEqual(library_info('a')[0], {'l%d'%i:'l%d'%i for i in range(1, 4) if i == 3})
self.assertEqual(library_info('a')[1], 'l3') self.assertEqual(library_info('a')[1], 'l3')
self.assertRaises(HTTPForbidden, get_library, 'a', 'l1') self.assertRaises(HTTPForbidden, get_library, 'a', 'l1')
self.assertRaises(HTTPForbidden, get_library, 'xxx')
# }}} # }}}

View File

@ -197,7 +197,6 @@ class UserManager(object):
with self.lock: with self.lock:
r = self._restrictions.get(username) r = self._restrictions.get(username)
if r is None: if r is None:
r = self._restrictions[username] = parse_restriction('{}')
for restriction, in self.conn.cursor().execute( for restriction, in self.conn.cursor().execute(
'SELECT restriction FROM users WHERE name=?', (username,)): 'SELECT restriction FROM users WHERE name=?', (username,)):
self._restrictions[username] = r = parse_restriction(restriction) self._restrictions[username] = r = parse_restriction(restriction)