Skip to content

Commit

Permalink
Deprecate spacecmd function to delete user and call deactivate instead
Browse files Browse the repository at this point in the history
Signed-off-by: Pascal Arlt <parlt@suse.com>
  • Loading branch information
parlt91 committed Sep 15, 2023
1 parent a1b4845 commit ae0d792
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 31 deletions.
1 change: 1 addition & 0 deletions spacecmd/spacecmd.changes.parlt.user-soft-deletion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Remove functionality to delete users. Disable should be used instead.
15 changes: 10 additions & 5 deletions spacecmd/src/spacecmd/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ def do_user_create(self, args):


def help_user_delete(self):
print(_('This method is deprecated and will be removed in a future API version. '
'Please use user_disable instead.'))
logging.warning(_("This method is deprecated and will be removed in a future API version"))
print(_('user_delete: Delete an user'))
print(_('usage: user_delete NAME'))

Expand All @@ -145,6 +148,10 @@ def complete_user_delete(self, text, line, beg, end):


def do_user_delete(self, args):
print(_('This method is deprecated and will be removed in a future API version. '
'Please use user_disable instead.'))
logging.warning(_("This method is deprecated and will be removed in a future API version"))

arg_parser = get_argument_parser()

(args, _options) = parse_command_arguments(args, arg_parser)
Expand All @@ -155,11 +162,9 @@ def do_user_delete(self, args):

name = args[0]

if self.options.yes or self.user_confirm('Delete this user [y/N]:'):
self.client.user.delete(self.session, name)
return 0
else:
return 1
self.client.user.disable(self.session, name)

return 0

####################

Expand Down
29 changes: 3 additions & 26 deletions spacecmd/tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,49 +212,26 @@ def test_user_delete_noargs(self, shell):
"""
shell.client.user.delete = MagicMock()
shell.help_user_delete = MagicMock()
shell.user_confirm = MagicMock()

spacecmd.user.do_user_delete(shell, "")

assert not shell.client.user.delete.called
assert not shell.user_confirm.called
assert shell.help_user_delete.called

def test_user_delete_non_interactive(self, shell):
def test_user_delete(self, shell):
"""
Test do_user_delete, non-interactive mode.
Test do_user_delete, username
:param shell:
:return:
"""
shell.client.user.delete = MagicMock()
shell.help_user_delete = MagicMock()
shell.options.yes = True
shell.user_confirm = MagicMock(return_value=False)

spacecmd.user.do_user_delete(shell, "pointyhaired")

assert not shell.help_user_delete.called
assert not shell.user_confirm.called
assert shell.client.user.delete.called

def test_user_delete_interactive(self, shell):
"""
Test do_user_delete, interactive mode.
:param shell:
:return:
"""
shell.client.user.delete = MagicMock()
shell.help_user_delete = MagicMock()
shell.options.yes = False
shell.user_confirm = MagicMock(return_value=True)

spacecmd.user.do_user_delete(shell, "pointyhaired")

assert not shell.help_user_delete.called
assert shell.user_confirm.called
assert shell.client.user.delete.called
assert shell.client.user.disable.called

def test_user_disable_noargs(self, shell):
"""
Expand Down

0 comments on commit ae0d792

Please sign in to comment.