From cd70689b0642d41dcbdb826df4fc9f79b1ef899e Mon Sep 17 00:00:00 2001
From: "M. Vefa Bicakci" <m.v.b@runbox.com>
Date: Fri, 19 Oct 2018 08:02:12 +0200
Subject: [PATCH] anaconda: Modify user configuration spoke for QubesOS
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Frédéric Pierret <frederic.epitre@orange.fr>
---
 pyanaconda/ui/gui/spokes/user.glade | 96 +++++++------------------------------
 pyanaconda/ui/gui/spokes/user.py    | 57 +++-------------------
 pyanaconda/ui/tui/spokes/user.py    | 21 ++------
 3 files changed, 28 insertions(+), 146 deletions(-)

diff --git a/pyanaconda/ui/gui/spokes/user.glade b/pyanaconda/ui/gui/spokes/user.glade
index 2873ff2d9..e6700657d 100644
--- a/pyanaconda/ui/gui/spokes/user.glade
+++ b/pyanaconda/ui/gui/spokes/user.glade
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.18.3 -->
+<!-- Generated with glade 3.20.0 -->
 <interface>
   <requires lib="gtk+" version="3.6"/>
   <requires lib="AnacondaWidgets" version="1.0"/>
@@ -53,33 +53,15 @@
                     <property name="can_focus">False</property>
                     <property name="row_spacing">8</property>
                     <property name="column_spacing">9</property>
-                    <child>
-                      <object class="GtkLabel" id="label1">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="xalign">1</property>
-                        <property name="xpad">10</property>
-                        <property name="label" translatable="yes" context="GUI|User">_Full name</property>
-                        <property name="use_underline">True</property>
-                        <property name="mnemonic_widget">t_fullname</property>
-                        <attributes>
-                          <attribute name="weight" value="bold"/>
-                        </attributes>
-                      </object>
-                      <packing>
-                        <property name="left_attach">0</property>
-                        <property name="top_attach">0</property>
-                      </packing>
-                    </child>
                     <child>
                       <object class="GtkLabel" id="label2">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
-                        <property name="xalign">1</property>
                         <property name="xpad">10</property>
                         <property name="label" translatable="yes" context="GUI|User">_User name</property>
                         <property name="use_underline">True</property>
                         <property name="mnemonic_widget">t_username</property>
+                        <property name="xalign">1</property>
                         <attributes>
                           <attribute name="weight" value="bold"/>
                         </attributes>
@@ -89,29 +71,12 @@
                         <property name="top_attach">1</property>
                       </packing>
                     </child>
-                    <child>
-                      <object class="GtkEntry" id="t_fullname">
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="caps_lock_warning">False</property>
-                        <signal name="changed" handler="full_name_changed" swapped="no"/>
-                        <child internal-child="accessible">
-                          <object class="AtkObject" id="t_fullname-atkobject">
-                            <property name="AtkObject::accessible-name" translatable="yes">Full Name</property>
-                          </object>
-                        </child>
-                      </object>
-                      <packing>
-                        <property name="left_attach">1</property>
-                        <property name="top_attach">0</property>
-                      </packing>
-                    </child>
                     <child>
                       <object class="GtkEntry" id="t_username">
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
-                        <signal name="changed" handler="username_changed" swapped="no"/>
                         <signal name="changed" handler="on_username_set_by_user" swapped="no"/>
+                        <signal name="changed" handler="username_changed" swapped="no"/>
                         <child internal-child="accessible">
                           <object class="AtkObject" id="t_username-atkobject">
                             <property name="AtkObject::accessible-name" translatable="yes">User Name</property>
@@ -127,11 +92,11 @@
                       <object class="GtkLabel" id="label3">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
-                        <property name="xalign">1</property>
                         <property name="xpad">10</property>
                         <property name="label" translatable="yes" context="GUI|User">_Password</property>
                         <property name="use_underline">True</property>
                         <property name="mnemonic_widget">t_password</property>
+                        <property name="xalign">1</property>
                         <attributes>
                           <attribute name="weight" value="bold"/>
                         </attributes>
@@ -145,11 +110,11 @@
                       <object class="GtkLabel" id="label4">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
-                        <property name="xalign">1</property>
                         <property name="xpad">10</property>
                         <property name="label" translatable="yes" context="GUI|User">_Confirm password</property>
                         <property name="use_underline">True</property>
                         <property name="mnemonic_widget">t_verifypassword</property>
+                        <property name="xalign">1</property>
                         <attributes>
                           <attribute name="weight" value="bold"/>
                         </attributes>
@@ -166,7 +131,7 @@
                         <property name="visibility">False</property>
                         <property name="invisible_char">●</property>
                         <signal name="changed" handler="password_changed" swapped="no"/>
-                        <signal name="icon_release" handler="on_password_icon_clicked" swapped="no"/>
+                        <signal name="icon-release" handler="on_password_icon_clicked" swapped="no"/>
                         <child internal-child="accessible">
                           <object class="AtkObject" id="t_password-atkobject">
                             <property name="AtkObject::accessible-name" translatable="yes">Password</property>
@@ -184,7 +149,7 @@
                         <property name="can_focus">True</property>
                         <property name="visibility">False</property>
                         <property name="invisible_char">●</property>
-                        <signal name="icon_release" handler="on_password_icon_clicked" swapped="no"/>
+                        <signal name="icon-release" handler="on_password_icon_clicked" swapped="no"/>
                         <child internal-child="accessible">
                           <object class="AtkObject" id="t_verifypassword-atkobject">
                             <property name="AtkObject::accessible-name" translatable="yes">Confirm Password</property>
@@ -200,9 +165,9 @@
                       <object class="GtkLabel" id="label6">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
-                        <property name="xalign">0</property>
                         <property name="label" translatable="yes">&lt;b&gt;Tip:&lt;/b&gt; Keep your user name shorter than 32 characters and do not use spaces.</property>
                         <property name="use_markup">True</property>
+                        <property name="xalign">0</property>
                       </object>
                       <packing>
                         <property name="left_attach">1</property>
@@ -268,45 +233,16 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkCheckButton" id="c_admin">
-                        <property name="label" translatable="yes" context="GUI|User">_Make this user administrator</property>
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="receives_default">False</property>
-                        <property name="use_underline">True</property>
-                        <property name="xalign">0</property>
-                        <property name="draw_indicator">True</property>
-                        <signal name="toggled" handler="on_admin_toggled" swapped="no"/>
-                      </object>
-                      <packing>
-                        <property name="left_attach">1</property>
-                        <property name="top_attach">3</property>
-                      </packing>
+                      <placeholder/>
                     </child>
                     <child>
-                      <object class="GtkGrid" id="grid2">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <child>
-                          <object class="GtkButton" id="b_advanced">
-                            <property name="label" translatable="yes" context="GUI|User">_Advanced...</property>
-                            <property name="visible">True</property>
-                            <property name="sensitive">False</property>
-                            <property name="can_focus">True</property>
-                            <property name="receives_default">True</property>
-                            <property name="use_underline">True</property>
-                            <signal name="clicked" handler="on_advanced_clicked" swapped="no"/>
-                          </object>
-                          <packing>
-                            <property name="left_attach">0</property>
-                            <property name="top_attach">0</property>
-                          </packing>
-                        </child>
-                      </object>
-                      <packing>
-                        <property name="left_attach">1</property>
-                        <property name="top_attach">8</property>
-                      </packing>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
                     </child>
                     <child>
                       <placeholder/>
diff --git a/pyanaconda/ui/gui/spokes/user.py b/pyanaconda/ui/gui/spokes/user.py
index e954292c7..dac6ba3e5 100644
--- a/pyanaconda/ui/gui/spokes/user.py
+++ b/pyanaconda/ui/gui/spokes/user.py
@@ -38,7 +38,7 @@ from pyanaconda.constants import ANACONDA_ENVIRON, FIRSTBOOT_ENVIRON,\
         PW_ASCII_CHARS, PASSWORD_ASCII
 from pyanaconda.regexes import GECOS_VALID, GROUPNAME_VALID, GROUPLIST_FANCY_PARSE
 
-__all__ = ["UserSpoke", "AdvancedUserDialog"]
+__all__ = ["UserSpoke"]
 
 class AdvancedUserDialog(GUIObject, GUIDialogInputCheckHandler):
     """
@@ -214,7 +214,7 @@ class UserSpoke(FirstbootSpokeMixIn, NormalSpoke, GUISpokeInputCheckHandler):
     builderObjects = ["userCreationWindow"]
 
     mainWidgetName = "userCreationWindow"
-    focusWidgetName = "t_fullname"
+    focusWidgetName = "t_username"
     uiFile = "spokes/user.glade"
     helpFile = "UserSpoke.xml"
 
@@ -252,14 +252,16 @@ class UserSpoke(FirstbootSpokeMixIn, NormalSpoke, GUISpokeInputCheckHandler):
         else:
             self._user = self.data.UserData()
 
+        self._wheel = self.data.GroupData(name="wheel")
+        self._qubes = self.data.GroupData(name="qubes")
+
+        self._groupDict = {"wheel": self._wheel, "qubes": self._qubes}
+
         # placeholders for the text boxes
-        self.fullname = self.builder.get_object("t_fullname")
         self.username = self.builder.get_object("t_username")
         self.pw = self.builder.get_object("t_password")
         self.confirm = self.builder.get_object("t_verifypassword")
-        self.admin = self.builder.get_object("c_admin")
         self.usepassword = self.builder.get_object("c_usepassword")
-        self.b_advanced = self.builder.get_object("b_advanced")
 
         # Counters for checks that ask the user to click Done to confirm
         self._waiveStrengthClicks = 0
@@ -306,8 +308,6 @@ class UserSpoke(FirstbootSpokeMixIn, NormalSpoke, GUISpokeInputCheckHandler):
 
         self.add_check(self.username, self._checkUsername)
 
-        self.add_re_check(self.fullname, GECOS_VALID, _("Full name cannot contain colon characters"))
-
         # Modify the GUI based on the kickstart and policy information
         # This needs to happen after the input checks have been created, since
         # the Gtk signal handlers use the input check variables.
@@ -323,9 +323,6 @@ class UserSpoke(FirstbootSpokeMixIn, NormalSpoke, GUISpokeInputCheckHandler):
             # User isn't allowed to change whether password is required or not
             self.usepassword.set_sensitive(False)
 
-        self._advanced = AdvancedUserDialog(self._user, self.data)
-        self._advanced.initialize()
-
         # set the visibility of the password entries
         set_password_visibility(self.pw, False)
         set_password_visibility(self.confirm, False)
@@ -336,8 +333,6 @@ class UserSpoke(FirstbootSpokeMixIn, NormalSpoke, GUISpokeInputCheckHandler):
             check.enabled = True
 
         self.username.set_text(self._user.name)
-        self.fullname.set_text(self._user.gecos)
-        self.admin.set_active("wheel" in self._user.groups)
 
         self.pw.emit("changed")
         self.confirm.emit("changed")
@@ -378,7 +373,6 @@ class UserSpoke(FirstbootSpokeMixIn, NormalSpoke, GUISpokeInputCheckHandler):
             self._password_kickstarted = False
 
         self._user.name = self.username.get_text()
-        self._user.gecos = self.fullname.get_text()
 
         if "wheel" not in self._user.groups:
             self._user.groups.append("wheel")
@@ -469,34 +463,10 @@ class UserSpoke(FirstbootSpokeMixIn, NormalSpoke, GUISpokeInputCheckHandler):
     def username_changed(self, editable, data=None):
         """Called by Gtk on all username changes."""
 
-        # Disable the advanced user dialog button when no username is set
-        if editable.get_text():
-            self.b_advanced.set_sensitive(True)
-        else:
-            self.b_advanced.set_sensitive(False)
-
         # Re-run the password checks against the new username
         self.pw.emit("changed")
         self.confirm.emit("changed")
 
-    def full_name_changed(self, editable, data=None):
-        """Called by Gtk callback when the full name field changes."""
-
-        if self.guesser:
-            fullname = editable.get_text()
-            username = guess_username(fullname)
-
-            with blockedHandler(self.username, self.on_username_set_by_user):
-                self.username.set_text(username)
-
-    def on_admin_toggled(self, togglebutton, data=None):
-        # Add or remove "wheel" from the grouplist on changes to the admin checkbox
-        if togglebutton.get_active():
-            if "wheel" not in self._user.groups:
-                self._user.groups.append("wheel")
-        elif "wheel" in self._user.groups:
-            self._user.groups.remove("wheel")
-
     def _checkPasswordEmpty(self, inputcheck):
         """Check whether a password has been specified at all.
 
@@ -612,19 +582,6 @@ class UserSpoke(FirstbootSpokeMixIn, NormalSpoke, GUISpokeInputCheckHandler):
         else:
             return msg or _("Invalid user name")
 
-    def on_advanced_clicked(self, _button, data=None):
-        """Handler for the Advanced.. button. It starts the Advanced dialog
-        for setting homedit, uid, gid and groups.
-        """
-
-        self._user.name = self.username.get_text()
-
-        self._advanced.refresh()
-        with self.main_window.enlightbox(self._advanced.window):
-            self._advanced.run()
-
-        self.admin.set_active("wheel" in self._user.groups)
-
     def on_back_clicked(self, button):
         # If the failed check is for non-ASCII characters,
         # add a click to the counter and check again
diff --git a/pyanaconda/ui/tui/spokes/user.py b/pyanaconda/ui/tui/spokes/user.py
index 1005852db..834b82cbf 100644
--- a/pyanaconda/ui/tui/spokes/user.py
+++ b/pyanaconda/ui/tui/spokes/user.py
@@ -40,11 +40,9 @@ class UserSpoke(FirstbootSpokeMixIn, EditTUISpoke):
 
     edit_fields = [
         Entry("Create user", "_create", EditTUISpoke.CHECK, True),
-        Entry("Fullname", "gecos", GECOS_VALID, lambda self, args: args._create),
         Entry("Username", "name", check_username, lambda self, args: args._create),
         Entry("Use password", "_use_password", EditTUISpoke.CHECK, lambda self, args: args._create),
         Entry("Password", "_password", EditTUISpoke.PASSWORD, lambda self, args: args._use_password and args._create),
-        Entry("Administrator", "_admin", EditTUISpoke.CHECK, lambda self, args: args._create),
         Entry("Groups", "_groups", GROUPLIST_SIMPLE_VALID, lambda self, args: args._create)
         ]
 
@@ -84,7 +82,6 @@ class UserSpoke(FirstbootSpokeMixIn, EditTUISpoke):
         self.errors = []
 
     def refresh(self, args=None):
-        self.args._admin = "wheel" in self.args.groups
         self.args._groups = ", ".join(self.args.groups)
 
         # if we have any errors, display them
@@ -146,22 +143,14 @@ class UserSpoke(FirstbootSpokeMixIn, EditTUISpoke):
         return EditTUISpoke.input(self, args, key)
 
     def apply(self):
-        if self.args.gecos and not self.args.name:
-            username = guess_username(self.args.gecos)
-            valid, msg = check_username(username)
-            if not valid:
-                self.errors.append(_("Invalid user name: %(name)s.\n%(error_message)s")
-                        % {"name": username, "error_message": msg})
-            else:
-                self.args.name = guess_username(self.args.gecos)
-
         self.args.groups = [g.strip() for g in self.args._groups.split(",") if g]
 
-        # Add or remove the user from wheel group
-        if self.args._admin and "wheel" not in self.args.groups:
+        # Add the user to the wheel and qubes groups
+        if "wheel" not in self.args.groups:
             self.args.groups.append("wheel")
-        elif not self.args._admin and "wheel" in self.args.groups:
-            self.args.groups.remove("wheel")
+
+        if "qubes" not in self.args.groups:
+            self.args.groups.append("qubes")
 
         # Add or remove the user from userlist as needed
         if self.args._create and (self.args not in self.data.user.userList and self.args.name):
-- 
2.14.4