dbhub: Allow pushing to other user accounts to which you have access

This adds a new row to the Push dialog in which you can set the user
name in case you want to push to a different account.
This commit is contained in:
Martin Kleusberg
2020-08-30 21:32:11 +02:00
parent 8c12ee01ae
commit dfc7645079
6 changed files with 91 additions and 23 deletions

View File

@@ -379,7 +379,7 @@ void RemoteDock::pushDatabase(const QString& path, const QString& branch)
// Build push URL
QString url = host;
url.append(RemoteNetwork::get().getInfoFromClientCert(remoteModel->currentClientCertificate(), RemoteNetwork::CertInfoUser));
url.append(pushDialog.user());
url.append("/");
url.append(pushDialog.name());

View File

@@ -382,7 +382,7 @@ void RemoteNetwork::prepareProgressDialog(QNetworkReply* reply, bool upload, con
}
void RemoteNetwork::fetch(const QUrl& url, RequestType type, const QString& clientCert,
std::function<void(QByteArray)> when_finished, bool synchronous)
std::function<void(QByteArray)> when_finished, bool synchronous, bool ignore_errors)
{
// Check if network is accessible. If not, abort right here
if(m_manager->networkAccessible() == QNetworkAccessManager::NotAccessible)
@@ -416,6 +416,7 @@ void RemoteNetwork::fetch(const QUrl& url, RequestType type, const QString& clie
QNetworkReply* reply = m_manager->get(request);
reply->setProperty("type", type);
reply->setProperty("certfile", clientCert);
reply->setProperty("ignore_errors", ignore_errors);
// Hook up custom handler when there is one and global handler otherwise
if(when_finished)
@@ -556,7 +557,7 @@ bool RemoteNetwork::handleReply(QNetworkReply* reply)
if(reply->error() != QNetworkReply::NoError)
{
// Do not show error message when operation was cancelled on purpose
if(reply->error() != QNetworkReply::OperationCanceledError)
if(reply->error() != QNetworkReply::OperationCanceledError && !reply->property("ignore_errors").toBool())
{
QMessageBox::warning(nullptr, qApp->applicationName(),
reply->errorString() + "\n" + reply->readAll());

View File

@@ -46,7 +46,8 @@ public:
RequestTypeDownload,
};
void fetch(const QUrl& url, RequestType type, const QString& clientCert = QString(), std::function<void(QByteArray)> when_finished = {}, bool synchronous = false);
void fetch(const QUrl& url, RequestType type, const QString& clientCert = QString(),
std::function<void(QByteArray)> when_finished = {}, bool synchronous = false, bool ignore_errors = false);
void push(const QString& filename, const QUrl& url, const QString& clientCert, const QString& remotename,
const QString& commitMessage = QString(), const QString& licence = QString(), bool isPublic = false,
const QString& branch = QString("master"), bool forcePush = false, const QString& last_commit = QString());

View File

@@ -11,7 +11,7 @@
using json = nlohmann::json;
RemotePushDialog::RemotePushDialog(QWidget* parent, const QString& host, const QString& clientCert,
const QString& name, const QString& branch) :
const QString& name, const QString& branch, const QString& user) :
QDialog(parent),
ui(new Ui::RemotePushDialog),
m_host(host),
@@ -23,10 +23,16 @@ RemotePushDialog::RemotePushDialog(QWidget* parent, const QString& host, const Q
ui->setupUi(this);
ui->editName->setValidator(m_nameValidator);
ui->comboBranch->setValidator(m_branchValidator);
ui->comboUser->setValidator(m_nameValidator);
// Set start values
ui->editName->setText(name);
// Fill in usernames
ui->comboUser->addItem(RemoteNetwork::get().getInfoFromClientCert(m_clientCert, RemoteNetwork::CertInfoUser));
if(!user.isEmpty())
ui->comboUser->addItem(user);
// Enable/disable accept button
checkInput();
@@ -85,6 +91,9 @@ void RemotePushDialog::checkInput()
if(ui->comboBranch->currentText().size() < 1 || ui->comboBranch->currentText().size() > 32)
valid = false;
if(ui->comboUser->currentText().trimmed().isEmpty())
valid = false;
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(valid);
}
@@ -118,6 +127,11 @@ QString RemotePushDialog::branch() const
return ui->comboBranch->currentText();
}
QString RemotePushDialog::user() const
{
return ui->comboUser->currentText();
}
bool RemotePushDialog::forcePush() const
{
return ui->checkForce->isChecked();
@@ -127,7 +141,7 @@ void RemotePushDialog::reloadBranchList(const QString& select_branch)
{
QUrl url(m_host + "branch/list");
QUrlQuery query;
query.addQueryItem("username", RemoteNetwork::get().getInfoFromClientCert(m_clientCert, RemoteNetwork::CertInfoUser));
query.addQueryItem("username", ui->comboUser->currentText());
query.addQueryItem("folder", "/");
query.addQueryItem("dbname", ui->editName->text());
url.setQuery(query);
@@ -156,5 +170,5 @@ void RemotePushDialog::reloadBranchList(const QString& select_branch)
// If a branch was suggested, select it now
if(!select_branch.isEmpty())
ui->comboBranch->setCurrentIndex(ui->comboBranch->findText(select_branch));
});
}, false, true);
}

View File

@@ -15,7 +15,7 @@ class RemotePushDialog : public QDialog
public:
explicit RemotePushDialog(QWidget* parent, const QString& host, const QString& clientCert,
const QString& name = QString(), const QString& branch = QString());
const QString& name = QString(), const QString& branch = QString(), const QString& user = QString());
~RemotePushDialog() override;
QString name() const;
@@ -23,6 +23,7 @@ public:
QString licence() const;
bool isPublic() const;
QString branch() const;
QString user() const;
bool forcePush() const;
private:

View File

@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>583</width>
<height>300</height>
<height>315</height>
</rect>
</property>
<property name="windowTitle">
@@ -49,8 +49,8 @@
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Oxygen-Sans'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Noto Sans'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Oxygen-Sans';&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="acceptRichText">
<bool>false</bool>
@@ -110,7 +110,7 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item row="5" column="0">
<item row="6" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Force push</string>
@@ -120,9 +120,26 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item row="5" column="1">
<item row="6" column="1">
<widget class="QCheckBox" name="checkForce"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Username</string>
</property>
<property name="buddy">
<cstring>comboUser</cstring>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QComboBox" name="comboUser">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
@@ -143,6 +160,8 @@ p, li { white-space: pre-wrap; }
<tabstop>comboBranch</tabstop>
<tabstop>checkPublic</tabstop>
<tabstop>comboLicence</tabstop>
<tabstop>comboUser</tabstop>
<tabstop>checkForce</tabstop>
</tabstops>
<resources/>
<connections>
@@ -153,8 +172,8 @@ p, li { white-space: pre-wrap; }
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
<x>257</x>
<y>305</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
@@ -169,8 +188,8 @@ p, li { white-space: pre-wrap; }
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
<x>325</x>
<y>305</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
@@ -201,8 +220,8 @@ p, li { white-space: pre-wrap; }
<slot>checkInput()</slot>
<hints>
<hint type="sourcelabel">
<x>171</x>
<y>176</y>
<x>345</x>
<y>181</y>
</hint>
<hint type="destinationlabel">
<x>210</x>
@@ -249,8 +268,8 @@ p, li { white-space: pre-wrap; }
<slot>checkInput()</slot>
<hints>
<hint type="sourcelabel">
<x>172</x>
<y>138</y>
<x>346</x>
<y>160</y>
</hint>
<hint type="destinationlabel">
<x>33</x>
@@ -265,8 +284,8 @@ p, li { white-space: pre-wrap; }
<slot>checkInput()</slot>
<hints>
<hint type="sourcelabel">
<x>168</x>
<y>240</y>
<x>342</x>
<y>269</y>
</hint>
<hint type="destinationlabel">
<x>62</x>
@@ -274,6 +293,38 @@ p, li { white-space: pre-wrap; }
</hint>
</hints>
</connection>
<connection>
<sender>comboUser</sender>
<signal>currentTextChanged(QString)</signal>
<receiver>RemotePushDialog</receiver>
<slot>reloadBranchList()</slot>
<hints>
<hint type="sourcelabel">
<x>373</x>
<y>235</y>
</hint>
<hint type="destinationlabel">
<x>291</x>
<y>157</y>
</hint>
</hints>
</connection>
<connection>
<sender>comboUser</sender>
<signal>currentTextChanged(QString)</signal>
<receiver>RemotePushDialog</receiver>
<slot>checkInput()</slot>
<hints>
<hint type="sourcelabel">
<x>373</x>
<y>235</y>
</hint>
<hint type="destinationlabel">
<x>291</x>
<y>157</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>checkInput()</slot>