mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-22 17:06: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))
|
self.write_error_line(UserManager.error_str(status))
|
||||||
|
|
||||||
def user_delete(self, name):
|
def user_delete(self, name):
|
||||||
user = self.__store.find(User, User.name == name).one()
|
ret = UserManager.delete_by_name(self.__store, name)
|
||||||
if not user:
|
if ret != UserManager.SUCCESS:
|
||||||
self.write_error_line('No such user')
|
self.write_error_line(UserManager.error_str(ret))
|
||||||
else:
|
else:
|
||||||
self.__store.remove(user)
|
self.write_line("Deleted user '{}'".format(name))
|
||||||
self.__store.commit()
|
|
||||||
self.write_line("User '{}' deleted".format(name))
|
|
||||||
|
|
||||||
def user_setadmin(self, name, off):
|
def user_setadmin(self, name, off):
|
||||||
user = self.__store.find(User, User.name == name).one()
|
user = self.__store.find(User, User.name == name).one()
|
||||||
|
@ -83,6 +83,13 @@ class UserManager:
|
|||||||
|
|
||||||
return UserManager.SUCCESS
|
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
|
@staticmethod
|
||||||
def try_auth(store, name, password):
|
def try_auth(store, name, password):
|
||||||
user = store.find(User, User.name == name).one()
|
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.assertIsNone(self.store.get(db.User, user.id))
|
||||||
self.assertEqual(self.store.find(db.User).count(), 0)
|
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):
|
def test_try_auth(self):
|
||||||
# Test authentication
|
# Test authentication
|
||||||
for name in ['alice', 'bob', 'charlie']:
|
for name in ['alice', 'bob', 'charlie']:
|
||||||
|
Loading…
Reference in New Issue
Block a user