def delete_group(self, menu_item = None): """Delete the group selected in the group_treeview""" if not self.__check_connection(): return None group, t_iter = self.__get_selected_group() # If nothing is selected we can return and do nothing. # We should only notify the user that what he would like # to do can not be done now. if t_iter is None: show_info_dialog(_("Select a group before asking for its deletion.")) return # Users tend to delete many things they do not want to delete if len(self.__connection.get_members(group)) == 0: question = _("Really delete group <b>%s</b>?") % group else: question = _("Really delete the non empty group <b>%s</b>?" + " This will lead to integrity problems.") % group if not ask_question(question): return # Finally we delete the group try: self.__connection.delete_group(group) except LumInsufficientPermissionsError: show_error_dialog(_("Insufficient permissions to delete group")) return None # and delete the group from the treeview self.__group_store.remove(t_iter) # Finally show the successful operation in the statusbar self.statusbar_update(_("Group %s successfully deleted.") % group)
def __check_connection(self): if self.__connection is None: if ask_question(_("Not connected to any LDAP server, connect now?")): self.connect () else: return False if self.__connection is not None: return True else: show_error_dialog(_("Error while connecting to LDAP server, aborting operation.")) return False
def missing_ou_cb(self, widget, missing_ou): """Callback to ask user if he/she wants to add missing ous before continue""" text = "\n".join(map(lambda x : "- <b>" + x + "</b>", missing_ou)) if ask_question(_("The following organizational units are missing in the database, add them?\n%s" % text)): for ou in missing_ou: self.__connection.add_ou(ou, True) else: show_info_dialog(_("You will not be able to perform any operation without these OUs")) self.disconnect()
def run(self): """Run dialog""" # Check if the user says "save"... if self.__window.run() == 1: # And then retrieve data username = self.__builder.get_object("username_entry").get_text() givenName = self.__builder.get_object("givenName_entry").get_text() sn = self.__builder.get_object("sn_entry").get_text() home = self.__builder.get_object("home_entry").get_text() shell = self.__builder.get_object("shell_entry").get_text() email = self.__builder.get_object("email_entry").get_text() # Set uid to 0 so ldap_protocol will autodetermine the first free uid # when creating the user uid = 0 group = self.__builder.get_object("group_entry").get_text() gid = self.__connection.gid_from_group(group) # Check if this is an existent user if self.__connection.is_present("uid=%s" % username): show_error_dialog(_("User %s is present, not overwriting it!") % username) self.__window.destroy() return None # Ask the user if he intended to create the group and destroy window # before the call to the ldap module, that could raise an exception # catched by our parent (i.e. lumApp) if gid is None: if ask_question(_("The group %s doesn't exists, create it now?") % group): self.__window.destroy() self.__connection.add_group(group) gid = self.__connection.gid_from_group(group) else: self.__window.destroy() return None else: self.__window.destroy() # Fill UserModel self.usermodel = UserModel() self.usermodel.set_username(username) self.usermodel.set_gid(gid) self.usermodel.set_surname(sn) self.usermodel.set_given_name(givenName) self.usermodel.set_home(home) self.usermodel.set_shell(shell) self.usermodel.set_email(email) else: self.__window.destroy()
def delete_user(self, menu_item = None): """Delete the selected user""" usermodel, t_iter = self.__get_selected_user() if t_iter is None: show_info_dialog(_("Select a user to delete!")) return # Users tend to delete many things they do not want # to delete if not ask_question(_("Really delete user <b>%s</b>?") % usermodel.get_username()): return # Delete user from ldap first try: self.__connection.delete_user(usermodel.get_dn()) except LumInsufficientPermissionsError: show_error_dialog(_("Insufficient permissions to delete user")) return None # Delete user from internal dictionary self.__user_store.remove(t_iter) self.statusbar_update(_("User %s deleted.") % usermodel.get_username())