mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-27 20:16:44 +00:00
feat(GODT-2791): Parse the Bug Report Flow description file and ensure forward compatibility (GODT-2789).
This commit is contained in:
committed by
Romain Le Jeune
parent
1a2783a63b
commit
86e115b2f3
@ -37,6 +37,15 @@
|
||||
using namespace bridgepp;
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
|
||||
QString const bugReportFile = ":qml/Resources/bug_report_flow.json";
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
//
|
||||
//****************************************************************************************************************************************************
|
||||
@ -89,7 +98,8 @@ void QMLBackend::init(GRPCConfig const &serviceConfig) {
|
||||
this->setUseSSLForIMAP(sslForIMAP);
|
||||
this->setUseSSLForSMTP(sslForSMTP);
|
||||
this->retrieveUserList();
|
||||
this->retrieveBugReportFlow();
|
||||
if (!reportFlow_.parse(bugReportFile))
|
||||
app().log().error(QString("Cannot parse BugReportFlow description file: %1").arg(bugReportFile));
|
||||
}
|
||||
|
||||
|
||||
@ -216,7 +226,10 @@ bool QMLBackend::areSameFileOrFolder(QUrl const &lhs, QUrl const &rhs) const {
|
||||
/// \return Set of question for this category.
|
||||
//****************************************************************************************************************************************************
|
||||
QVariantList QMLBackend::getQuestionSet(quint8 categoryId) const {
|
||||
return questionsSet_[categoryId];
|
||||
QVariantList list = reportFlow_.questionSet(categoryId);
|
||||
if (list.count() == 0)
|
||||
app().log().error(QString("Bug category not found (id: %1)").arg(categoryId));
|
||||
return list;
|
||||
};
|
||||
|
||||
|
||||
@ -225,7 +238,8 @@ QVariantList QMLBackend::getQuestionSet(quint8 categoryId) const {
|
||||
/// \param[in] answer The answer to that question.
|
||||
//****************************************************************************************************************************************************
|
||||
void QMLBackend::setQuestionAnswer(quint8 questionId, QString const &answer) {
|
||||
this->answers_[questionId] = answer;
|
||||
if (!reportFlow_.setAnswer(questionId, answer))
|
||||
app().log().error(QString("Bug Report Question not found (id: %1)").arg(questionId));
|
||||
}
|
||||
|
||||
|
||||
@ -234,16 +248,7 @@ void QMLBackend::setQuestionAnswer(quint8 questionId, QString const &answer) {
|
||||
/// \return concatenate answers for set of questions.
|
||||
//****************************************************************************************************************************************************
|
||||
QString QMLBackend::collectAnswer(quint8 categoryId) const {
|
||||
QString answers;
|
||||
QVariantList sets = this->getQuestionSet(categoryId);
|
||||
foreach(const QVariant& var, sets) {
|
||||
answers += " - ";
|
||||
answers += questions_[var.toInt()].toMap()["text"].toString();
|
||||
answers += " ";
|
||||
answers += answers_[var.toInt()];
|
||||
answers += "\n\r";
|
||||
}
|
||||
return answers;
|
||||
return reportFlow_.collectAnswers(categoryId);
|
||||
}
|
||||
|
||||
|
||||
@ -622,14 +627,14 @@ QStringList QMLBackend::availableKeychain() const {
|
||||
/// \return The value for the 'bugCategories' property.
|
||||
//****************************************************************************************************************************************************
|
||||
QStringList QMLBackend::bugCategories() const {
|
||||
return categories_;
|
||||
return reportFlow_.categories();
|
||||
}
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The value for the 'bugQuestions' property.
|
||||
//****************************************************************************************************************************************************
|
||||
QVariantList QMLBackend::bugQuestions() const {
|
||||
return questions_;
|
||||
return reportFlow_.questions();
|
||||
}
|
||||
|
||||
|
||||
@ -1221,31 +1226,6 @@ void QMLBackend::retrieveUserList() {
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
//
|
||||
//****************************************************************************************************************************************************
|
||||
void QMLBackend::retrieveBugReportFlow() {
|
||||
categories_.clear();
|
||||
questions_.clear();
|
||||
questionsSet_.clear();
|
||||
QString val;
|
||||
QFile file;
|
||||
file.setFileName(":qml/Resources/bug_report_flow.json");
|
||||
file.open(QIODevice::ReadOnly | QIODevice::Text);
|
||||
val = file.readAll();
|
||||
file.close();
|
||||
QJsonDocument d = QJsonDocument::fromJson(val.toUtf8());
|
||||
QJsonObject root = d.object();
|
||||
QJsonObject data = root.value(QString("data_v1.0.0")).toObject();
|
||||
QJsonArray categoriesJson = data.value(QString("categories")).toArray();
|
||||
foreach (const QJsonValue & v, categoriesJson) {
|
||||
categories_.append(v.toObject()["name"].toString());
|
||||
questionsSet_.append(v.toObject()["questions"].toArray().toVariantList());
|
||||
}
|
||||
questions_ = data.value(QString("questions")).toArray().toVariantList();
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
//
|
||||
//****************************************************************************************************************************************************
|
||||
|
||||
@ -24,6 +24,7 @@
|
||||
#include "BuildConfig.h"
|
||||
#include "TrayIcon.h"
|
||||
#include "UserList.h"
|
||||
#include <bridgepp/BugReportFlow/BugReportFlow.h>
|
||||
#include <bridgepp/GRPC/GRPCClient.h>
|
||||
#include <bridgepp/GRPC/GRPCUtils.h>
|
||||
#include <bridgepp/Worker/Overseer.h>
|
||||
@ -278,7 +279,6 @@ private: // member functions
|
||||
void retrieveUserList(); ///< Retrieve the list of users via gRPC.
|
||||
void connectGrpcEvents(); ///< Connect gRPC that need to be forwarded to QML via backend signals
|
||||
void displayBadEventDialog(QString const& userID); ///< Displays the bad event dialog for a user.
|
||||
void retrieveBugReportFlow(); ///< Get the bug report flow description file and parse it.
|
||||
|
||||
private: // data members
|
||||
UserList *users_ { nullptr }; ///< The user list. Owned by backend.
|
||||
@ -294,10 +294,7 @@ private: // data members
|
||||
bool isInternetOn_ { true }; ///< Does bridge consider internet as on?
|
||||
QList<QString> badEventDisplayQueue_; ///< THe queue for displaying 'bad event feedback request dialog'.
|
||||
std::unique_ptr<TrayIcon> trayIcon_; ///< The tray icon for the application.
|
||||
QStringList categories_; ///< The list of Bug Category parsed from the description file.
|
||||
QVariantList questions_; ///< The list of Questions parsed from the description file.
|
||||
QList<QVariantList> questionsSet_; ///< Sets of questions per bug category.
|
||||
QMap<quint8, QString> answers_; ///< Map of QuestionId/Answer for the bug form.
|
||||
BugReportFlow reportFlow_; ///< The bug report flow.
|
||||
friend class AppController;
|
||||
};
|
||||
|
||||
|
||||
@ -48,7 +48,7 @@ SettingsView {
|
||||
Label {
|
||||
Layout.fillWidth: true
|
||||
colorScheme: root.colorScheme
|
||||
text: qsTr("Give us more details")
|
||||
text: qsTr("Describe the issue")
|
||||
type: Label.Heading
|
||||
}
|
||||
|
||||
|
||||
@ -33,13 +33,13 @@
|
||||
"questions": [
|
||||
{
|
||||
"id": 0,
|
||||
"text": "What did you expect to happen?",
|
||||
"text": "What happened?",
|
||||
"tips": "Expected behavior",
|
||||
"type": 1
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"text": "What happened instead?",
|
||||
"text": "What did you want or expect to happen?",
|
||||
"tips": "Result",
|
||||
"type": 1
|
||||
},
|
||||
@ -51,15 +51,15 @@
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"text": "Can you reproduce your issue?",
|
||||
"text": "Can you reproduce this issue? (If you repeat the actions, the same thing happens.)",
|
||||
"type": 2,
|
||||
"answerList": ["yes", "no", "I don't know"]
|
||||
"answerList": ["Yes", "No", "I don't know"]
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"text": "Do you have such software running?",
|
||||
"text": "Are you running any of these software?",
|
||||
"type": 3,
|
||||
"answerList": ["VPN", "anti-virus", "firewall", "cache cleaner", "None of this"]
|
||||
"answerList": ["VPN", "Antivirus", "Firewall", "Cache cleaner", "None of the above"]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user