From 77e869be366d057b008a797ea607571a851acb59 Mon Sep 17 00:00:00 2001
From: Pavel Vomacka <pvomacka@redhat.com>
Date: Mon, 22 Aug 2016 14:45:14 +0200
Subject: [PATCH] Add 'Restore' option to action dropdown menu

Also moving activate_action method several lines up - correcting logical order of methods.

https://fedorahosted.org/freeipa/ticket/5818
---
 install/ui/src/freeipa/stageuser.js | 37 +++++++++++++++++++++++++++++--------
 install/ui/src/freeipa/user.js      |  6 +++++-
 install/ui/test/data/ipa_init.json  |  1 +
 ipaserver/plugins/internal.py       |  1 +
 4 files changed, 36 insertions(+), 9 deletions(-)

diff --git a/install/ui/src/freeipa/stageuser.js b/install/ui/src/freeipa/stageuser.js
index bd56384..bf24491 100644
--- a/install/ui/src/freeipa/stageuser.js
+++ b/install/ui/src/freeipa/stageuser.js
@@ -364,6 +364,26 @@ stageuser.batch_activate_action = function(spec) {
     return IPA.batch_items_action(spec);
 };
 
+stageuser.activate_action = function(spec) {
+    spec = spec || {};
+    spec.name = spec.name || 'activate';
+    spec.method = spec.method || 'activate';
+    spec.needs_confirm = spec.needs_confirm !== undefined ? spec.needs_confirm : true;
+    spec.confirm_msg = spec.confirm_msg || '@i18n:objects.stageuser.activate_one_confirm';
+    spec.label = spec.label || '@i18n:buttons.activate';
+
+    var that = IPA.object_action(spec);
+
+    that.on_success = function(facet, data, text_status, xhr) {
+
+        IPA.notify_success(data.result.summary);
+        facet.on_update.notify();
+        facet.redirect();
+    };
+
+    return that;
+};
+
 stageuser.batch_undel_action = function(spec) {
 
     spec = spec || {};
@@ -379,18 +399,18 @@ stageuser.batch_undel_action = function(spec) {
     return IPA.batch_items_action(spec);
 };
 
-stageuser.activate_action = function(spec) {
+stageuser.undel_action = function(spec) {
     spec = spec || {};
-    spec.name = spec.name || 'activate';
-    spec.method = spec.method || 'activate';
-    spec.needs_confirm = spec.needs_confirm !== undefined ? spec.needs_confirm : true;
-    spec.confirm_msg = spec.confirm_msg || '@i18n:objects.stageuser.activate_one_confirm';
-    spec.label = spec.label || '@i18n:buttons.activate';
+
+    spec.name = spec.name || 'undel';
+    spec.method = spec.method || 'undel';
+    spec.needs_confirm = spec.needs_confirm === undefined ? true : spec.needs_confirm;
+    spec.confirm_msg = spec.confirm_msg || '@i18n:objects.stageuser.undel_one_confirm';
+    spec.label = spec.label || '@i18n:buttons.restore';
 
     var that = IPA.object_action(spec);
 
     that.on_success = function(facet, data, text_status, xhr) {
-
         IPA.notify_success(data.result.summary);
         facet.on_update.notify();
         facet.redirect();
@@ -451,8 +471,9 @@ stageuser.register = function() {
     var e = reg.entity;
     var f = reg.facet;
     a.register('batch_activate', stageuser.batch_activate_action);
-    a.register('batch_undel', stageuser.batch_undel_action);
     a.register('activate', stageuser.activate_action);
+    a.register('batch_undel', stageuser.batch_undel_action);
+    a.register('undel', stageuser.undel_action);
     a.register('batch_stage', stageuser.batch_stage_action);
     a.register('stage', stageuser.stage_action);
     e.register({type: 'stageuser', spec: stageuser.stageuser_spec});
diff --git a/install/ui/src/freeipa/user.js b/install/ui/src/freeipa/user.js
index 0bebf44..e3eda50 100644
--- a/install/ui/src/freeipa/user.js
+++ b/install/ui/src/freeipa/user.js
@@ -373,6 +373,10 @@ return {
                     show_cond: ['preserved-user']
                 },
                 {
+                    $type: 'undel',
+                    show_cond: ['preserved-user']
+                },
+                {
                     $type: 'stage',
                     show_cond: ['preserved-user']
                 },
@@ -401,7 +405,7 @@ return {
                 }
             ],
             header_actions: [
-                'reset_password', 'enable', 'disable', 'stage',
+                'reset_password', 'enable', 'disable', 'stage', 'undel',
                 'delete_active_user', 'delete', 'unlock', 'add_otptoken',
                 'automember_rebuild', 'request_cert'
             ],
diff --git a/install/ui/test/data/ipa_init.json b/install/ui/test/data/ipa_init.json
index efaf6b6..6903f92 100644
--- a/install/ui/test/data/ipa_init.json
+++ b/install/ui/test/data/ipa_init.json
@@ -592,6 +592,7 @@
                             "stage_success": "${count} users(s) staged",
                             "stage_one_confirm": "Are you sure you want to stage ${object}?",
                             "undel_confirm": "Are you sure you want to restore selected users?",
+                            "undel_one_confirm": "Are you sure you want to restore ${object}?",
                             "undel_success": "${count} user(s) restored",
                             "user_categories": "User categories",
                         },
diff --git a/ipaserver/plugins/internal.py b/ipaserver/plugins/internal.py
index 8af0af7..c2819aa 100644
--- a/ipaserver/plugins/internal.py
+++ b/ipaserver/plugins/internal.py
@@ -744,6 +744,7 @@ class i18n_messages(Command):
                 "stage_success": _("${count} users(s) staged"),
                 "stage_one_confirm": _("Are you sure you want to stage ${object}?"),
                 "undel_confirm": _("Are you sure you want to restore selected users?"),
+                "undel_one_confirm": _("Are you sure you want to restore ${object}?"),
                 "undel_success": _("${count} user(s) restored"),
                 "user_categories": _("User categories"),
             },
