示例#1
0
    def _delete_tag_group(self):
        del_id = html.get_item_input(
            "_delete", dict(self._tag_config.get_tag_group_choices()))[1]

        if not html.request.has_var(
                "_repair") and self._is_cleaning_up_user_tag_group_to_builtin(
                    del_id):
            message = _("Transformed the user tag group \"%s\" to builtin."
                        ) % del_id  # type: Union[bool, str]
        else:
            message = _rename_tags_after_confirmation(
                OperationRemoveTagGroup(del_id))
            if message is True:  # no confirmation yet
                c = wato_confirm(
                    _("Confirm deletion of the tag group '%s'") % del_id,
                    _("Do you really want to delete the tag group '%s'?") %
                    del_id)
                if c is False:
                    return ""
                if c is None:
                    return None

        if message:
            self._tag_config.remove_tag_group(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 tag group %s (%s)") % (message, del_id))
            return "tags", message is not True and message or None
示例#2
0
文件: tags.py 项目: ogaida/checkmk
    def _delete_tag_group(self) -> ActionResult:
        del_id = html.get_item_input(
            "_delete", dict(self._tag_config.get_tag_group_choices()))[1]

        if not html.request.has_var(
                "_repair") and self._is_cleaning_up_user_tag_group_to_builtin(
                    del_id):
            message: Union[bool, str] = _(
                "Transformed the user tag group \"%s\" to builtin.") % del_id
        else:
            message = _rename_tags_after_confirmation(
                self.breadcrumb(), OperationRemoveTagGroup(del_id))
            if message is False:
                return FinalizeRequest(code=200)

        if message:
            self._tag_config.remove_tag_group(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 tag group %s (%s)") % (message, del_id))
            if isinstance(message, str):
                flash(message)
        return redirect(mode_url("tags"))
示例#3
0
文件: tags.py 项目: ogaida/checkmk
    def _delete_aux_tag(self) -> ActionResult:
        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 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"))
示例#4
0
    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)

        operations = {del_id: False}
        message = _rename_tags_after_confirmation(None, operations)
        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 ""
            elif c is None:
                return None

        if message:
            self._tag_config.aux_tag_list.remove(del_id)
            self._tag_config.validate_config()
            self._tag_config_file.save(self._tag_config.get_dict_format())
            watolib.Folder.invalidate_caches()
            watolib.Folder.root_folder().rewrite_hosts_files()
            add_change("edit-tags", _("Removed auxiliary tag %s (%s)") % (message, del_id))
            return "tags", message != True and message or None
示例#5
0
    def _delete_tag_group(self):
        del_id = html.get_item_input("_delete", dict(self._tag_config.get_tag_group_choices()))[1]

        tag_group = self._tag_config.get_tag_group(del_id)
        if tag_group:
            operations = list(tag_group.get_tag_ids())
        else:
            operations = None

        message = _rename_tags_after_confirmation(del_id, operations)
        if message is True:  # no confirmation yet
            c = wato_confirm(
                _("Confirm deletion of the tag group '%s'") % del_id,
                _("Do you really want to delete the tag group '%s'?") % del_id)
            if c is False:
                return ""
            elif c is None:
                return None

        if message:
            self._tag_config.remove_tag_group(del_id)
            self._tag_config.validate_config()
            self._tag_config_file.save(self._tag_config.get_dict_format())
            watolib.Folder.invalidate_caches()
            watolib.Folder.root_folder().rewrite_hosts_files()
            add_change("edit-tags", _("Removed tag group %s (%s)") % (message, del_id))
            return "tags", message != True and message or None
示例#6
0
    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(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 ""
            elif 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
示例#7
0
    def _delete_tag_group(self):
        del_id = html.get_item_input(
            "_delete", dict(self._tag_config.get_tag_group_choices()))[1]

        message = _rename_tags_after_confirmation(
            OperationRemoveTagGroup(del_id))
        if message is True:  # no confirmation yet
            c = wato_confirm(
                _("Confirm deletion of the tag group '%s'") % del_id,
                _("Do you really want to delete the tag group '%s'?") % del_id)
            if c is False:
                return ""
            elif c is None:
                return None

        if message:
            self._tag_config.remove_tag_group(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 tag group %s (%s)") % (message, del_id))
            return "tags", message != True and message or None
示例#8
0
    def _get_id(self):
        if not html.request.has_var("edit"):
            return None

        return html.get_item_input(
            "edit",
            dict(
                self._untainted_hosttags_config.aux_tag_list.get_choices()))[1]