mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 15:09:24 +02:00
immediately show permission denied error if applicable
This commit is contained in:
parent
f238c1b167
commit
26757eae7a
2 changed files with 44 additions and 21 deletions
|
@ -14,6 +14,7 @@
|
||||||
#include <AssetClient.h>
|
#include <AssetClient.h>
|
||||||
#include <AssetUpload.h>
|
#include <AssetUpload.h>
|
||||||
#include <AssetUtils.h>
|
#include <AssetUtils.h>
|
||||||
|
#include <NodeList.h>
|
||||||
|
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
#include <QtWidgets/QDialogButtonBox>
|
#include <QtWidgets/QDialogButtonBox>
|
||||||
|
@ -32,7 +33,12 @@ AssetUploadDialogFactory::AssetUploadDialogFactory() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const QString PERMISSION_DENIED_ERROR = "You do not have permission to upload content to this asset-server.";
|
||||||
|
|
||||||
void AssetUploadDialogFactory::showDialog() {
|
void AssetUploadDialogFactory::showDialog() {
|
||||||
|
auto nodeList = DependencyManager::get<NodeList>();
|
||||||
|
|
||||||
|
if (nodeList->getThisNodeCanRez()) {
|
||||||
auto filename = QFileDialog::getOpenFileUrl(_dialogParent, "Select a file to upload");
|
auto filename = QFileDialog::getOpenFileUrl(_dialogParent, "Select a file to upload");
|
||||||
|
|
||||||
if (!filename.isEmpty()) {
|
if (!filename.isEmpty()) {
|
||||||
|
@ -55,6 +61,11 @@ void AssetUploadDialogFactory::showDialog() {
|
||||||
QMessageBox::information(_dialogParent, "Failed to Upload", messageBoxText);
|
QMessageBox::information(_dialogParent, "Failed to Upload", messageBoxText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// we don't have permission to upload to asset server in this domain - show the permission denied error
|
||||||
|
showErrorDialog(QString(), PERMISSION_DENIED_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssetUploadDialogFactory::handleUploadFinished(AssetUpload* upload, const QString& hash) {
|
void AssetUploadDialogFactory::handleUploadFinished(AssetUpload* upload, const QString& hash) {
|
||||||
|
@ -78,7 +89,7 @@ void AssetUploadDialogFactory::handleUploadFinished(AssetUpload* upload, const Q
|
||||||
// setup the line edit to hold the copiable text
|
// setup the line edit to hold the copiable text
|
||||||
QLineEdit* lineEdit = new QLineEdit;
|
QLineEdit* lineEdit = new QLineEdit;
|
||||||
|
|
||||||
QString atpURL = QString("%1://%2.%3").arg(ATP_SCHEME).arg(hash).arg(upload->getExtension);
|
QString atpURL = QString("%1://%2.%3").arg(ATP_SCHEME).arg(hash).arg(upload->getExtension());
|
||||||
|
|
||||||
// set the ATP URL as the text value so it's copiable
|
// set the ATP URL as the text value so it's copiable
|
||||||
lineEdit->insert(atpURL);
|
lineEdit->insert(atpURL);
|
||||||
|
@ -111,14 +122,14 @@ void AssetUploadDialogFactory::handleUploadFinished(AssetUpload* upload, const Q
|
||||||
hashCopyDialog->show();
|
hashCopyDialog->show();
|
||||||
} else {
|
} else {
|
||||||
// figure out the right error message for the message box
|
// figure out the right error message for the message box
|
||||||
QString errorMessage = QString("Failed to upload %1.\n\n").arg(QFileInfo(upload->getFilename()).fileName());
|
QString additionalError;
|
||||||
|
|
||||||
switch (upload->getResult()) {
|
switch (upload->getResult()) {
|
||||||
case AssetUpload::PermissionDenied:
|
case AssetUpload::PermissionDenied:
|
||||||
errorMessage += "You do not have permission to upload content to this asset-server.";
|
additionalError = PERMISSION_DENIED_ERROR;
|
||||||
break;
|
break;
|
||||||
case AssetUpload::TooLarge:
|
case AssetUpload::TooLarge:
|
||||||
errorMessage += "The uploaded content was too large and could not be stored in the asset-server.";
|
additionalError = "The uploaded content was too large and could not be stored in the asset-server.";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// not handled, do not show a message box
|
// not handled, do not show a message box
|
||||||
|
@ -126,6 +137,16 @@ void AssetUploadDialogFactory::handleUploadFinished(AssetUpload* upload, const Q
|
||||||
}
|
}
|
||||||
|
|
||||||
// display a message box with the error
|
// display a message box with the error
|
||||||
QMessageBox::warning(_dialogParent, "Failed Upload", errorMessage);
|
showErrorDialog(QFileInfo(upload->getFilename()).fileName(), additionalError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AssetUploadDialogFactory::showErrorDialog(const QString& filename, const QString& additionalError) {
|
||||||
|
QString errorMessage;
|
||||||
|
|
||||||
|
if (!filename.isEmpty()) {
|
||||||
|
errorMessage += QString("Failed to upload %1.\n\n").arg(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
QMessageBox::warning(_dialogParent, "Failed Upload", errorMessage);
|
||||||
|
}
|
||||||
|
|
|
@ -33,6 +33,8 @@ public slots:
|
||||||
private slots:
|
private slots:
|
||||||
void handleUploadFinished(AssetUpload* upload, const QString& hash);
|
void handleUploadFinished(AssetUpload* upload, const QString& hash);
|
||||||
private:
|
private:
|
||||||
|
void showErrorDialog(const QString& filename, const QString& additionalError);
|
||||||
|
|
||||||
QWidget* _dialogParent { nullptr };
|
QWidget* _dialogParent { nullptr };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue