From 435daaceed01b1867b9feb23530b24d8926b5722 Mon Sep 17 00:00:00 2001 From: Thomas Piccirello Date: Mon, 23 Jul 2018 01:48:35 -0400 Subject: [PATCH] Require torrent category creation to be explicit --- src/base/bittorrent/torrenthandle.cpp | 6 ++---- src/webui/api/torrentscontroller.cpp | 4 ++++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/base/bittorrent/torrenthandle.cpp b/src/base/bittorrent/torrenthandle.cpp index c61e52f41..3db1d301e 100644 --- a/src/base/bittorrent/torrenthandle.cpp +++ b/src/base/bittorrent/torrenthandle.cpp @@ -1211,10 +1211,8 @@ bool TorrentHandle::setCategory(const QString &category) { if (m_category != category) { if (!category.isEmpty()) { - if (!Session::isValidCategoryName(category)) return false; - if (!m_session->categories().contains(category)) - if (!m_session->addCategory(category)) - return false; + if (!Session::isValidCategoryName(category) || !m_session->categories().contains(category)) + return false; } QString oldCategory = m_category; diff --git a/src/webui/api/torrentscontroller.cpp b/src/webui/api/torrentscontroller.cpp index cdb5fd004..9eb3d1b65 100644 --- a/src/webui/api/torrentscontroller.cpp +++ b/src/webui/api/torrentscontroller.cpp @@ -811,6 +811,10 @@ void TorrentsController::setCategoryAction() const QString category {params()["category"].trimmed()}; applyToTorrents(hashes, [category](BitTorrent::TorrentHandle *torrent) { + auto *session = BitTorrent::Session::instance(); + const QStringList categories = session->categories().keys(); + if (!categories.contains(category) && !session->addCategory(category)) + throw APIError(APIErrorType::Conflict, tr("Unable to create category")); if (!torrent->setCategory(category)) throw APIError(APIErrorType::Conflict, tr("Incorrect category name")); });