3413ae
From ff4152539b96d309dcceaf854a3e0a49f435acff Mon Sep 17 00:00:00 2001
3413ae
From: Florence Blanc-Renaud <flo@redhat.com>
3413ae
Date: Mon, 20 Jun 2022 09:09:11 +0200
3413ae
Subject: [PATCH] Preserve user: fix the confusing summary
3413ae
3413ae
When ipa user-del --preserve is called, the command output
3413ae
prints a summary with:
3413ae
    Deleted user: user1
3413ae
although the user was preserved.
3413ae
Replace the summary with
3413ae
    Preserved user: user1
3413ae
to reflect what was actually done.
3413ae
3413ae
Fixes: https://pagure.io/freeipa/issue/9187
3413ae
Signed-off-by: Florence Blanc-Renaud <flo@redhat.com>
3413ae
Reviewed-By: Michal Polovka <mpolovka@redhat.com>
3413ae
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
3413ae
---
3413ae
 ipaserver/plugins/user.py | 4 ++++
3413ae
 1 file changed, 4 insertions(+)
3413ae
3413ae
diff --git a/ipaserver/plugins/user.py b/ipaserver/plugins/user.py
3413ae
index 25d2bb6aa..fa8a67d3d 100644
3413ae
--- a/ipaserver/plugins/user.py
3413ae
+++ b/ipaserver/plugins/user.py
3413ae
@@ -56,6 +56,7 @@ from .idviews import remove_ipaobject_overrides
3413ae
 from ipalib.plugable import Registry
3413ae
 from .baseldap import (
3413ae
     LDAPObject,
3413ae
+    pkey_to_unicode,
3413ae
     pkey_to_value,
3413ae
     LDAPCreate,
3413ae
     LDAPSearch,
3413ae
@@ -701,6 +702,7 @@ class user_del(baseuser_del):
3413ae
     __doc__ = _('Delete a user.')
3413ae
 
3413ae
     msg_summary = _('Deleted user "%(value)s"')
3413ae
+    msg_summary_preserved = _('Preserved user "%(value)s"')
3413ae
 
3413ae
     takes_options = baseuser_del.takes_options + (
3413ae
         Bool('preserve?',
3413ae
@@ -831,6 +833,8 @@ class user_del(baseuser_del):
3413ae
                     failed.append(pkey_to_value(pkey, options))
3413ae
 
3413ae
             val = dict(result=dict(failed=failed), value=preserved)
3413ae
+            val['summary'] = self.msg_summary_preserved % dict(
3413ae
+                value=pkey_to_unicode(preserved))
3413ae
             return val
3413ae
         else:
3413ae
             return super(user_del, self).execute(*keys, **options)
3413ae
-- 
3413ae
2.36.1
3413ae
3413ae
From 4984ff210a169129e4e56b10e54e9c795520855c Mon Sep 17 00:00:00 2001
3413ae
From: Florence Blanc-Renaud <flo@redhat.com>
3413ae
Date: Mon, 20 Jun 2022 09:12:14 +0200
3413ae
Subject: [PATCH] xmlrpc tests: updated expected output for preserved user
3413ae
3413ae
Update the expected summary for the command
3413ae
ipa user-del --preserve
3413ae
3413ae
The command now displays: Preserved user: user1
3413ae
instead of                Deleted user: user1
3413ae
3413ae
Related: https://pagure.io/freeipa/issue/9187
3413ae
3413ae
Signed-off-by: Florence Blanc-Renaud <flo@redhat.com>
3413ae
Reviewed-By: Michal Polovka <mpolovka@redhat.com>
3413ae
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
3413ae
---
3413ae
 ipatests/test_xmlrpc/test_stageuser_plugin.py | 5 ++++-
3413ae
 ipatests/test_xmlrpc/tracker/user_plugin.py   | 7 ++++++-
3413ae
 2 files changed, 10 insertions(+), 2 deletions(-)
3413ae
3413ae
diff --git a/ipatests/test_xmlrpc/test_stageuser_plugin.py b/ipatests/test_xmlrpc/test_stageuser_plugin.py
3413ae
index bc606b093..fd146876c 100644
3413ae
--- a/ipatests/test_xmlrpc/test_stageuser_plugin.py
3413ae
+++ b/ipatests/test_xmlrpc/test_stageuser_plugin.py
3413ae
@@ -479,11 +479,12 @@ class TestActive(XMLRPC_test):
3413ae
 
3413ae
     def test_delete_preserve(self, user):
3413ae
         user.ensure_exists()
3413ae
-        user.track_delete()
3413ae
+        user.track_delete(preserve=True)
3413ae
         command = user.make_delete_command(no_preserve=False, preserve=True)
3413ae
         result = command()
3413ae
         user.check_delete(result)
3413ae
 
3413ae
+        user.track_delete(preserve=False)
3413ae
         command = user.make_delete_command()
3413ae
         result = command()
3413ae
         user.check_delete(result)
3413ae
@@ -622,6 +623,7 @@ class TestCustomAttr(XMLRPC_test):
3413ae
         assert 'BusinessCat' in result['result'][u'businesscategory']
3413ae
 
3413ae
         # delete the user with --preserve
3413ae
+        user_customattr.track_delete(preserve=True)
3413ae
         command = user_customattr.make_delete_command(no_preserve=False,
3413ae
                                                       preserve=True)
3413ae
         result = command()
3413ae
@@ -763,6 +765,7 @@ class TestGroups(XMLRPC_test):
3413ae
         result = command()
3413ae
         group.check_retrieve(result)
3413ae
 
3413ae
+        user.track_delete(preserve=True)
3413ae
         command = user.make_delete_command(no_preserve=False, preserve=True)
3413ae
         result = command()
3413ae
         user.check_delete(result)
3413ae
diff --git a/ipatests/test_xmlrpc/tracker/user_plugin.py b/ipatests/test_xmlrpc/tracker/user_plugin.py
3413ae
index 03c106250..b04be4c19 100644
3413ae
--- a/ipatests/test_xmlrpc/tracker/user_plugin.py
3413ae
+++ b/ipatests/test_xmlrpc/tracker/user_plugin.py
3413ae
@@ -273,9 +273,14 @@ class UserTracker(CertmapdataMixin, KerberosAliasMixin, Tracker):
3413ae
 
3413ae
     def check_delete(self, result):
3413ae
         """ Check 'user-del' command result """
3413ae
+        if u'preserved' in self.attrs and self.attrs[u'preserved']:
3413ae
+            summary = u'Preserved user "%s"' % self.uid
3413ae
+        else:
3413ae
+            summary = u'Deleted user "%s"' % self.uid
3413ae
+
3413ae
         assert_deepequal(dict(
3413ae
             value=[self.uid],
3413ae
-            summary=u'Deleted user "%s"' % self.uid,
3413ae
+            summary=summary,
3413ae
             result=dict(failed=[]),
3413ae
             ), result)
3413ae
 
3413ae
-- 
3413ae
2.36.1
3413ae