def _delete_aux_tag(self) -> ActionResult: del_id = request.get_item_input("_del_aux", dict(self._tag_config.aux_tag_list.get_choices()))[1] # Make sure that this aux tag is not begin used by any tag group for group in self._tag_config.tag_groups: for grouped_tag in group.tags: if del_id in grouped_tag.aux_tag_ids: raise MKUserError( None, _("You cannot delete this auxiliary tag. " "It is being used in the tag group <b>%s</b>.") % group.title) message = _rename_tags_after_confirmation(self.breadcrumb(), OperationRemoveAuxTag(del_id)) if message is False: return FinalizeRequest(code=200) if message: self._tag_config.aux_tag_list.remove(del_id) try: self._tag_config.validate_config() except MKGeneralException as e: raise MKUserError(None, "%s" % e) self._save_tags_and_update_hosts(self._tag_config.get_dict_format()) add_change("edit-tags", _("Removed auxiliary tag %s (%s)") % (message, del_id)) if isinstance(message, str): flash(message) return redirect(mode_url("tags"))
def _show_aux_tag_row(self, table: Table, aux_tag: cmk.utils.tags.AuxTag) -> None: table.row() table.cell(_("Actions"), css="buttons") self._show_aux_tag_icons(aux_tag) table.cell(_("Tag"), _u(aux_tag.choice_title)) table.cell(_("Used by tags")) _show_aux_tag_used_by_tags(self._get_tags_using_aux_tag(aux_tag)) # TODO: This check shouldn't be necessary if we get our types right. if aux_tag.id is None: raise Exception("uninitialized tag") operation = OperationRemoveAuxTag(aux_tag.id) affected_folders, affected_hosts, affected_rulesets = \ change_host_tags_in_folders(operation, TagCleanupMode.CHECK, watolib.Folder.root_folder()) table.cell(_("Explicitly set on folders")) if affected_folders: _show_affected_folders(affected_folders) table.cell(_("Explicitly set on hosts")) if affected_hosts: _show_affected_hosts(affected_hosts) table.cell(_("Used in rulesets")) if affected_rulesets: _show_affected_rulesets(affected_rulesets)
def _delete_aux_tag(self): del_id = html.get_item_input( "_del_aux", dict(self._tag_config.aux_tag_list.get_choices()))[1] # Make sure that this aux tag is not begin used by any tag group for group in self._tag_config.tag_groups: for grouped_tag in group.tags: if del_id in grouped_tag.aux_tag_ids: raise MKUserError( None, _("You cannot delete this auxiliary tag. " "It is being used in the tag group <b>%s</b>.") % group.title) message = _rename_tags_after_confirmation( self.breadcrumb(), OperationRemoveAuxTag(del_id)) if message is True: # no confirmation yet c = wato_confirm( _("Confirm deletion of the auxiliary tag '%s'") % del_id, _("Do you really want to delete the auxiliary tag '%s'?") % del_id) if c is False: return "" if c is None: return None if message: self._tag_config.aux_tag_list.remove(del_id) try: self._tag_config.validate_config() except MKGeneralException as e: raise MKUserError(None, "%s" % e) self._save_tags_and_update_hosts( self._tag_config.get_dict_format()) add_change("edit-tags", _("Removed auxiliary tag %s (%s)") % (message, del_id)) return "tags", message if message is not True else None