mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-22 08:56:17 +00:00
CLI: fixed foreign key errors on user deletion
This commit is contained in:
parent
d3271e7174
commit
0a47ef89a5
@ -224,13 +224,11 @@ class SupysonicCLI(cmd.Cmd):
|
||||
self.write_error_line(UserManager.error_str(status))
|
||||
|
||||
def user_delete(self, name):
|
||||
user = self.__store.find(User, User.name == name).one()
|
||||
if not user:
|
||||
self.write_error_line('No such user')
|
||||
ret = UserManager.delete_by_name(self.__store, name)
|
||||
if ret != UserManager.SUCCESS:
|
||||
self.write_error_line(UserManager.error_str(ret))
|
||||
else:
|
||||
self.__store.remove(user)
|
||||
self.__store.commit()
|
||||
self.write_line("User '{}' deleted".format(name))
|
||||
self.write_line("Deleted user '{}'".format(name))
|
||||
|
||||
def user_setadmin(self, name, off):
|
||||
user = self.__store.find(User, User.name == name).one()
|
||||
|
@ -83,6 +83,13 @@ class UserManager:
|
||||
|
||||
return UserManager.SUCCESS
|
||||
|
||||
@staticmethod
|
||||
def delete_by_name(store, name):
|
||||
user = store.find(User, User.name == name).one()
|
||||
if not user:
|
||||
return UserManager.NO_SUCH_USER
|
||||
return UserManager.delete(store, user.id)
|
||||
|
||||
@staticmethod
|
||||
def try_auth(store, name, password):
|
||||
user = store.find(User, User.name == name).one()
|
||||
|
@ -112,6 +112,15 @@ class UserManagerTestCase(unittest.TestCase):
|
||||
self.assertIsNone(self.store.get(db.User, user.id))
|
||||
self.assertEqual(self.store.find(db.User).count(), 0)
|
||||
|
||||
def test_delete_by_name(self):
|
||||
# Delete existing users
|
||||
for name in ['alice', 'bob', 'charlie']:
|
||||
self.assertEqual(UserManager.delete_by_name(self.store, name), UserManager.SUCCESS)
|
||||
self.assertEqual(self.store.find(db.User, db.User.name == name).count(), 0)
|
||||
|
||||
# Delete non-existent user
|
||||
self.assertEqual(UserManager.delete_by_name(self.store, 'null'), UserManager.NO_SUCH_USER)
|
||||
|
||||
def test_try_auth(self):
|
||||
# Test authentication
|
||||
for name in ['alice', 'bob', 'charlie']:
|
||||
|
Loading…
Reference in New Issue
Block a user