def should_run(cls, environment, data): """Should the spoke run?""" if not is_module_available(USERS): return False if FirstbootSpokeMixIn.should_run(environment, data): return True # the user spoke should run always in the anaconda and in firstboot only # when doing reconfig or if no user has been created in the installation users_module = USERS.get_proxy() user_list = get_user_list(users_module) if environment == FIRSTBOOT_ENVIRON and data and not user_list: return True return False
def refresh(self): # user data could have changed in the Users DBus module # since the last visit, so reload it from DBus # # In the case that the user list is empty or # a requested user has been cleared from the list in previous # spoke visit we need to have an empty user instance prepended # to the list. self._user_list = get_user_list(self._users_module, add_default=True, add_if_not_empty=self._requested_user_cleared) self.username = self.user.name self.fullname = self.user.gecos self._admin_checkbox.set_active(self.user.has_admin_priviledges()) # rerun checks so that we have a correct status message, if any self.checker.run_checks()
def should_run(cls, environment, data): # the user spoke should run always in the anaconda and in firstboot only # when doing reconfig or if no user has been created in the installation users_module = USERS.get_proxy() user_list = get_user_list(users_module) if environment == constants.ANACONDA_ENVIRON: return True elif environment == constants.FIRSTBOOT_ENVIRON and data is None: # cannot decide, stay in the game and let another call with data # available (will come) decide return True elif environment == constants.FIRSTBOOT_ENVIRON and data and not user_list: return True else: return False
def refresh(self, args=None): NormalTUISpoke.refresh(self, args) # refresh the user list self._user_list = get_user_list(self._users_module, add_default=True, add_if_not_empty=self._user_cleared) self._is_admin = self.user.has_admin_priviledges() self._groups = ", ".join(self.user.groups) self._container = ListColumnContainer(1) w = CheckboxWidget(title=_("Create user"), completed=self._create_user) self._container.add(w, self._set_create_user) if self._create_user: dialog = Dialog(title=_("Full name"), conditions=[self._check_fullname]) self._container.add(EntryWidget(dialog.title, self.user.gecos), self._set_fullname, dialog) dialog = Dialog(title=_("User name"), conditions=[self._check_username]) self._container.add(EntryWidget(dialog.title, self.user.name), self._set_username, dialog) w = CheckboxWidget(title=_("Use password"), completed=self._use_password) self._container.add(w, self._set_use_password) if self._use_password: password_dialog = PasswordDialog( title=_("Password"), policy_name=PASSWORD_POLICY_USER ) if self.user.password: entry = EntryWidget(password_dialog.title, _(PASSWORD_SET)) else: entry = EntryWidget(password_dialog.title) self._container.add(entry, self._set_password, password_dialog) msg = _("Administrator") w = CheckboxWidget(title=msg, completed=self._is_admin) self._container.add(w, self._set_administrator) dialog = Dialog(title=_("Groups"), conditions=[self._check_groups]) self._container.add(EntryWidget(dialog.title, self._groups), self._set_groups, dialog) self.window.add_with_separator(self._container)
def __init__(self, data, storage, payload): FirstbootSpokeMixIn.__init__(self) NormalTUISpoke.__init__(self, data, storage, payload) self.initialize_start() # connect to the Users DBus module self._users_module = USERS.get_proxy() self.title = N_("User creation") self._container = None # was user creation requested by the Users DBus module # - at the moment this basically means user creation was # requested via kickstart # - note that this does not currently update when user # list is changed via DBus self._user_requested = False self._user_cleared = False # should a user be created ? self._create_user = False self._user_list = get_user_list(self._users_module, add_default=True) # if user has a name, it's an actual user that has been requested, # rather than a default user added by us if self.user.name: self._user_requested = True self._create_user = True self._use_password = self.user.is_crypted or self.user.password self._groups = "" self._is_admin = False self._policy = self.data.anaconda.pwpolicy.get_policy( "user", fallback_to_default=True) self.errors = [] self._users_module = USERS.get_proxy() self.initialize_done()
def completed(self): return bool(get_user_list(self._users_module))
def initialize(self): NormalSpoke.initialize(self) self.initialize_start() # We consider user creation requested if there was at least one user # in the DBus module user list at startup. # We also remember how the user was called so that we can clear it # in a reasonably safe way & if it was cleared. self._user_list = get_user_list(self._users_module, add_default=True) self._user_requested = False self._requested_user_cleared = False # if user has a name, it's an actual user that has been requested, # rather than a default user added by us if self.user.name: self._user_requested = True # gather references to relevant GUI objects # entry fields self._fullname_entry = self.builder.get_object("fullname_entry") self._username_entry = self.builder.get_object("username_entry") self._password_entry = self.builder.get_object("password_entry") self._password_confirmation_entry = self.builder.get_object( "password_confirmation_entry") # check boxes self._admin_checkbox = self.builder.get_object("admin_checkbox") self._password_required_checkbox = self.builder.get_object( "password_required_checkbox") # advanced user configration dialog button self._advanced_button = self.builder.get_object("advanced_button") # password checking status bar & label self._password_bar = self.builder.get_object("password_bar") self._password_label = self.builder.get_object("password_label") # Install the password checks: # - Has a password been specified? # - If a password has been specified and there is data in the confirm box, do they match? # - How strong is the password? # - Does the password contain non-ASCII characters? # Setup the password checker for password checking self._checker = input_checking.PasswordChecker( initial_password_content=self.password, initial_password_confirmation_content=self.password_confirmation, policy=input_checking.get_policy(self.data, "user")) # configure the checker for password checking self.checker.username = self.username self.checker.secret_type = constants.SecretType.PASSWORD # remove any placeholder texts if either password or confirmation field changes content from initial state self.checker.password.changed_from_initial_state.connect( self.remove_placeholder_texts) self.checker.password_confirmation.changed_from_initial_state.connect( self.remove_placeholder_texts) # connect UI updates to check results self.checker.checks_done.connect(self._checks_done) # username and full name checks self._username_check = input_checking.UsernameCheck() self._fullname_check = input_checking.FullnameCheck() # empty username is considered a success so that the user can leave # the spoke without filling it in self._username_check.success_if_username_empty = True # check that the password is not empty self._empty_check = input_checking.PasswordEmptyCheck() # check that the content of the password field & the conformation field are the same self._confirm_check = input_checking.PasswordConfirmationCheck() # check password validity, quality and strength self._validity_check = input_checking.PasswordValidityCheck() # connect UI updates to validity check results self._validity_check.result.password_score_changed.connect( self.set_password_score) self._validity_check.result.status_text_changed.connect( self.set_password_status) # check if the password contains non-ascii characters self._ascii_check = input_checking.PasswordASCIICheck() # register the individual checks with the checker in proper order # 0) is the username and fullname valid ? # 1) is the password non-empty ? # 2) are both entered passwords the same ? # 3) is the password valid according to the current password checking policy ? # 4) is the password free of non-ASCII characters ? self.checker.add_check(self._username_check) self.checker.add_check(self._fullname_check) self.checker.add_check(self._empty_check) self.checker.add_check(self._confirm_check) self.checker.add_check(self._validity_check) self.checker.add_check(self._ascii_check) self.guesser = {self.username_entry: True} # Configure levels for the password bar self.password_bar.add_offset_value("low", 2) self.password_bar.add_offset_value("medium", 3) self.password_bar.add_offset_value("high", 4) # 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. password_set_message = _("The password was set by kickstart.") if self.password_kickstarted: self.password_required = True self.password_entry.set_placeholder_text(password_set_message) self.password_confirmation_entry.set_placeholder_text( password_set_message) elif not self.checker.policy.emptyok: # Policy is that a non-empty password is required self.password_required = True if not self.checker.policy.emptyok: # User isn't allowed to change whether password is required or not self.password_required_checkbox.set_sensitive(False) self._advanced_user_dialog = AdvancedUserDialog(self) self._advanced_user_dialog.initialize() # set the visibility of the password entries set_password_visibility(self.password_entry, False) set_password_visibility(self.password_confirmation_entry, False) # report that we are done self.initialize_done()
def test_get_empty_user_list(self): """Test the shared get_user_list() method with no users.""" users_module_mock = Mock() users_module_mock.Users = [] user_data_list = get_user_list(users_module_mock) assert user_data_list == []
def get_empty_user_list_test(self): """Test the shared get_user_list() method with no users.""" users_module_mock = Mock() users_module_mock.Users = [] user_data_list = get_user_list(users_module_mock) self.assertEqual(user_data_list, [])