immediately show permission denied error if applicable

This commit is contained in:
Stephen Birarda 2015-08-27 14:37:44 -07:00
parent f238c1b167
commit 26757eae7a
2 changed files with 44 additions and 21 deletions

View file

@ -14,6 +14,7 @@
#include <AssetClient.h>
#include <AssetUpload.h>
#include <AssetUtils.h>
#include <NodeList.h>
#include <QtCore/QDebug>
#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() {
auto nodeList = DependencyManager::get<NodeList>();
if (nodeList->getThisNodeCanRez()) {
auto filename = QFileDialog::getOpenFileUrl(_dialogParent, "Select a file to upload");
if (!filename.isEmpty()) {
@ -55,6 +61,11 @@ void AssetUploadDialogFactory::showDialog() {
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) {
@ -78,7 +89,7 @@ void AssetUploadDialogFactory::handleUploadFinished(AssetUpload* upload, const Q
// setup the line edit to hold the copiable text
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
lineEdit->insert(atpURL);
@ -111,14 +122,14 @@ void AssetUploadDialogFactory::handleUploadFinished(AssetUpload* upload, const Q
hashCopyDialog->show();
} else {
// 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()) {
case AssetUpload::PermissionDenied:
errorMessage += "You do not have permission to upload content to this asset-server.";
additionalError = PERMISSION_DENIED_ERROR;
break;
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;
default:
// 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
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);
}

View file

@ -33,6 +33,8 @@ public slots:
private slots:
void handleUploadFinished(AssetUpload* upload, const QString& hash);
private:
void showErrorDialog(const QString& filename, const QString& additionalError);
QWidget* _dialogParent { nullptr };
};