403b09
From f5efedd4c4f25e423e83c45efdc779fa567eb451 Mon Sep 17 00:00:00 2001
403b09
From: Pavel Vomacka <pvomacka@redhat.com>
403b09
Date: Fri, 26 Aug 2016 13:11:22 +0200
403b09
Subject: [PATCH] WebUI add support for sub-CAs while revoking certificates
403b09
403b09
Also the same for removing certificate hold.
403b09
403b09
https://fedorahosted.org/freeipa/ticket/6216
403b09
403b09
Reviewed-By: Petr Vobornik <pvoborni@redhat.com>
403b09
Reviewed-By: Stanislav Laznicka <slaznick@redhat.com>
403b09
---
403b09
 install/ui/src/freeipa/certificate.js | 129 ++++++++++++++++++++++++++--------
403b09
 install/ui/src/freeipa/widget.js      |   1 +
403b09
 2 files changed, 100 insertions(+), 30 deletions(-)
403b09
403b09
diff --git a/install/ui/src/freeipa/certificate.js b/install/ui/src/freeipa/certificate.js
403b09
index e67c348b7edbd2e273f18ed1df40ef8b5b5e59c3..9ab40027817cdcc242762399a0b4d9f41afec0b7 100755
403b09
--- a/install/ui/src/freeipa/certificate.js
403b09
+++ b/install/ui/src/freeipa/certificate.js
403b09
@@ -244,44 +244,104 @@ IPA.cert.download_dialog = function(spec) {
403b09
     return that;
403b09
 };
403b09
 
403b09
-IPA.cert.revoke_dialog = function(spec) {
403b09
+IPA.cert.revocation_reason_select_widget = function(spec) {
403b09
+    spec = spec || {};
403b09
+
403b09
+    var that = IPA.select_widget(spec);
403b09
+
403b09
+    that.create_options = function() {
403b09
+        for (var i=0; i
403b09
+            var reason = IPA.cert.CRL_REASON[i];
403b09
+            if (!reason) continue;
403b09
+            var label = text.get('@i18n:objects.cert.'+reason);
403b09
+            that.options.push({ label: label, value: i});
403b09
+        }
403b09
+
403b09
+        that.select_create_options();
403b09
+    };
403b09
+
403b09
+    return that;
403b09
+};
403b09
+
403b09
+IPA.cert.revoke_dialog = function(spec, no_init) {
403b09
 
403b09
     spec = spec || {};
403b09
+
403b09
     spec.width = spec.width || 500;
403b09
     spec.ok_label = spec.ok_label || '@i18n:buttons.revoke';
403b09
+    spec.sections = [
403b09
+        {
403b09
+            name: 'note',
403b09
+            show_header: false,
403b09
+            fields: [
403b09
+                {
403b09
+                    field: false,
403b09
+                    $type: 'html',
403b09
+                    name: 'note',
403b09
+                    html: ''
403b09
+                }
403b09
+            ],
403b09
+            layout:
403b09
+            {
403b09
+                $factory: widget_mod.fluid_layout,
403b09
+                widget_cls: "col-sm-12 controls",
403b09
+                label_cls: "hide"
403b09
+            }
403b09
+        },
403b09
+        {
403b09
+            name: 'revocation',
403b09
+            show_header: false,
403b09
+            fields: [
403b09
+                {
403b09
+                    $type: 'revocation_reason_select',
403b09
+                    name: 'revocation_reason',
403b09
+                    label: '@i18n:objects.cert.find_revocation_reason'
403b09
+                },
403b09
+                {
403b09
+                    $type: 'entity_select',
403b09
+                    label: '@i18n:objects.cert.ca',
403b09
+                    name: 'cacn',
403b09
+                    empty_option: false,
403b09
+                    other_entity: 'ca',
403b09
+                    other_field: 'cn'
403b09
+                }
403b09
+            ]
403b09
+        }
403b09
+    ];
403b09
 
403b09
     var that = IPA.confirm_dialog(spec);
403b09
-    IPA.table_mixin().apply(that);
403b09
+
403b09
+    that.open = function() {
403b09
+
403b09
+        that.confirmed = false;
403b09
+        that.dialog_open();
403b09
+        that.set_cacn(that.facet.state.cacn);
403b09
+    };
403b09
 
403b09
     that.get_reason = function() {
403b09
-        return that.select.val();
403b09
+        return that.get_field('revocation_reason').value[0];
403b09
     };
403b09
 
403b09
-    that.create_content = function() {
403b09
+    that.set_cacn = function(cacn) {
403b09
+        that.get_field('cacn').set_value([cacn]);
403b09
+    };
403b09
 
403b09
-        var table = that.create_layout().appendTo(that.container);
403b09
+    that.get_cacn = function() {
403b09
+        return that.get_field('cacn').value[0];
403b09
+    };
403b09
 
403b09
-        var tr = that.create_row().appendTo(table);
403b09
-        var td = that.create_cell('@i18n:objects.cert.note', ':').appendTo(tr);
403b09
-        td = that.create_cell('@i18n:objects.cert.revoke_confirmation')
403b09
-            .appendTo(tr);
403b09
+    that.create_content = function() {
403b09
+        that.dialog_create_content();
403b09
 
403b09
-        tr = that.create_row().appendTo(table);
403b09
-        td = that.create_header_cell('@i18n:objects.cert.reason', ':')
403b09
-            .appendTo(tr);
403b09
-        td = that.create_cell().appendTo(tr);
403b09
+    };
403b09
 
403b09
-        that.select = $('<select/>').appendTo(td);
403b09
-        for (var i=0; i
403b09
-            var reason = IPA.cert.CRL_REASON[i];
403b09
-            if (!reason) continue;
403b09
-            $('<option/>', {
403b09
-                'value': i,
403b09
-                'html': text.get('@i18n:objects.cert.'+reason)
403b09
-            }).appendTo(that.select);
403b09
-        }
403b09
+    that.init = function() {
403b09
+        var note = text.get('@i18n:objects.cert.revoke_confirmation');
403b09
+        that.widgets.get_widget('note.note').html = note;
403b09
     };
403b09
 
403b09
+    if (!no_init) that.init();
403b09
+
403b09
     return that;
403b09
 };
403b09
 
403b09
@@ -718,7 +778,7 @@ IPA.cert.request_action = function(spec) {
403b09
     return that;
403b09
 };
403b09
 
403b09
-IPA.cert.perform_revoke = function(spec, sn, revocation_reason) {
403b09
+IPA.cert.perform_revoke = function(spec, sn, revocation_reason, cacn) {
403b09
 
403b09
     spec.hide_activity_icon = spec.hide_activity_icon || false;
403b09
 
403b09
@@ -728,7 +788,8 @@ IPA.cert.perform_revoke = function(spec, sn, revocation_reason) {
403b09
         hide_activity_icon: spec.hide_activity_icon,
403b09
         args: [ sn ],
403b09
         options: {
403b09
-            'revocation_reason': revocation_reason
403b09
+            revocation_reason: revocation_reason,
403b09
+            cacn: cacn
403b09
         },
403b09
         notify_activity_start: spec.notify_activity_start,
403b09
         notify_activity_end: spec.notify_activity_end,
403b09
@@ -782,7 +843,8 @@ IPA.cert.revoke_action = function(spec) {
403b09
 
403b09
         var sn = facet.certificate.serial_number;
403b09
         var revocation_reason = that.dialog.get_reason();
403b09
-        IPA.cert.perform_revoke(spec, sn, revocation_reason);
403b09
+        var cacn = that.dialog.get_cacn();
403b09
+        IPA.cert.perform_revoke(spec, sn, revocation_reason, cacn);
403b09
     };
403b09
 
403b09
     return that;
403b09
@@ -835,19 +897,22 @@ IPA.cert.remove_hold_action = function(spec) {
403b09
             }
403b09
         };
403b09
 
403b09
-        IPA.cert.perform_remove_hold(spec, facet.certificate.serial_number);
403b09
-
403b09
+        IPA.cert.perform_remove_hold(spec, facet.certificate.serial_number,
403b09
+                            facet.state.cacn);
403b09
     };
403b09
 
403b09
     return that;
403b09
 };
403b09
 
403b09
-IPA.cert.perform_remove_hold = function(spec, sn) {
403b09
+IPA.cert.perform_remove_hold = function(spec, sn, cacn) {
403b09
 
403b09
     rpc.command({
403b09
         entity: 'cert',
403b09
         method: 'remove_hold',
403b09
         args: [sn],
403b09
+        options: {
403b09
+            cacn: cacn
403b09
+        },
403b09
         on_success: spec.on_success
403b09
     }).execute();
403b09
 };
403b09
@@ -1360,13 +1425,15 @@ IPA.cert.cert_widget = function(spec) {
403b09
                 };
403b09
 
403b09
                 var sn = that.certificate.serial_number;
403b09
+                var cacn = dialog.get_cacn();
403b09
                 var revocation_reason = dialog.get_reason();
403b09
-                IPA.cert.perform_revoke(command_spec, sn, revocation_reason);
403b09
+                IPA.cert.perform_revoke(command_spec, sn, revocation_reason, cacn);
403b09
             }
403b09
         };
403b09
 
403b09
         var dialog = IPA.cert.revoke_dialog(spec);
403b09
         dialog.open();
403b09
+        dialog.set_cacn(that.certificate.cacn);
403b09
     };
403b09
 
403b09
     that.perform_remove_hold = function() {
403b09
@@ -1392,7 +1459,8 @@ IPA.cert.cert_widget = function(spec) {
403b09
                 };
403b09
 
403b09
                 var sn =  that.certificate.serial_number;
403b09
-                IPA.cert.perform_remove_hold(command_spec, sn);
403b09
+                var cacn = that.certificate.cacn;
403b09
+                IPA.cert.perform_remove_hold(command_spec, sn, cacn);
403b09
             }
403b09
         };
403b09
 
403b09
@@ -1834,6 +1902,7 @@ exp.register = function() {
403b09
     f.register('certificate_status', IPA.cert.status_field);
403b09
     f.register('revocation_reason', IPA.revocation_reason_field);
403b09
     w.register('revocation_reason', IPA.text_widget);
403b09
+    w.register('revocation_reason_select', IPA.cert.revocation_reason_select_widget);
403b09
 
403b09
     a.register('cert_request', IPA.cert.request_action);
403b09
     a.register('download_cert', IPA.cert.download_action);
403b09
diff --git a/install/ui/src/freeipa/widget.js b/install/ui/src/freeipa/widget.js
403b09
index 9151ebac9438e9e674f81bfb1ccfe7a63872b1ae..4769ca616e4337e8f10339048f9851252e6dfd2e 100644
403b09
--- a/install/ui/src/freeipa/widget.js
403b09
+++ b/install/ui/src/freeipa/widget.js
403b09
@@ -2878,6 +2878,7 @@ IPA.select_widget = function(spec) {
403b09
     // methods that should be invoked by subclasses
403b09
     that.select_save = that.save;
403b09
     that.select_update = that.update;
403b09
+    that.select_create_options = that.create_options;
403b09
 
403b09
     return that;
403b09
 };
403b09
-- 
403b09
2.7.4
403b09