Skip to content

Commit 6cb7cb9

Browse files
committed
Provide response when user file quota exceeded
1 parent 631f464 commit 6cb7cb9

File tree

5 files changed

+88
-25
lines changed

5 files changed

+88
-25
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ Simple cloud service with HTTPs based [REST API](doc/rest_api.md) interface.
66

77
1. Store files
88
* Upload
9+
* Replace
910
* Update
1011
* Download
1112
* Set tags (alphanumeric string)
1213
* Set version
1314
* Set access rights
1415
2. User management
1516
* Add user
16-
* Modify user
17+
* Modify user (change user name, modify user groups and configure file quotas)
1718
* Remove user
1819
* Grant/revoke access to actions
1920
3. HTTPs interface
@@ -24,11 +25,11 @@ Simple cloud service with HTTPs based [REST API](doc/rest_api.md) interface.
2425
5. Submit reports
2526

2627
## Prepare build environment
27-
Initialize all submodules
28+
Initialize all sub modules
2829
```
2930
git submodule init && git submodule update --remote
3031
```
31-
Following command will attempt to download and install all required packages, therefore it must be executed under priviledged (root) user
32+
Following command will attempt to download and install all required packages, therefore it must be executed under privileged (root) user
3233
```
3334
sudo ./src/range-build-tools/prereqs.sh
3435
```
@@ -70,7 +71,7 @@ $ <install-dir>/scripts/cloud_setup.sh \
7071
Where `<deploy-dir>` is a directory where cloud instance will be deployed.
7172
_NOTE: There can be multiple deployments on the same host._
7273

73-
### Start/stop cloud as a beckground process
74+
### Start/stop cloud as a background process
7475

7576
Following command will start Cloud as a background process.
7677
```

doc/rest_api.md

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* [List files on the cloud server](#list-files-on-the-cloud-server)
99
* [Get file information](#get-file-information)
1010
* [Upload file to the cloud server](#upload-file-to-the-cloud-server)
11-
* [Replace file on the cloud server](#replace-file-to-the-cloud-server)
11+
* [Replace file on the cloud server](#replace-file-on-the-cloud-server)
1212
* [Update file on the cloud server](#update-file-on-the-cloud-server)
1313
* [Update file access owner on the cloud server](#update-file-access-owner-on-the-cloud-server)
1414
* [Update file access mode on the cloud server](#update-file-access-mode-on-the-cloud-server)
@@ -784,7 +784,14 @@ GET https://<host>:<port>/list-users/
784784
"<group-name-2>",
785785
...
786786
"<group-name-n>"
787-
]
787+
],
788+
"quotas": {
789+
"files": {
790+
"fileCount": "100",
791+
"fileSize": "104857600",
792+
"storeSize": "104857600"
793+
}
794+
}
788795
}
789796
]
790797
```
@@ -806,7 +813,14 @@ GET https://<host>:<port>/user-info/?resource-name=<user-name>
806813
"<group-name-2>",
807814
...
808815
"<group-name-n>"
809-
]
816+
],
817+
"quotas": {
818+
"files": {
819+
"fileCount": "100",
820+
"fileSize": "104857600",
821+
"storeSize": "104857600"
822+
}
823+
}
810824
}
811825
```
812826
If no `<user-name>` is provided caller user information will be returned.
@@ -828,7 +842,14 @@ GET https://<host>:<port>/user-add/?resource-name=<user-name>
828842
"<group-name-2>",
829843
...
830844
"<group-name-n>"
831-
]
845+
],
846+
"quotas": {
847+
"files": {
848+
"fileCount": "100",
849+
"fileSize": "104857600",
850+
"storeSize": "104857600"
851+
}
852+
}
832853
}
833854
```
834855

@@ -845,10 +866,18 @@ POST https://<host>:<port>/user-update/?resource-name=<user-name>
845866
"<group-name-2>",
846867
...
847868
"<group-name-n>"
848-
]
869+
],
870+
"quotas": {
871+
"files": {
872+
"fileCount": "100",
873+
"fileSize": "104857600",
874+
"storeSize": "104857600"
875+
}
876+
}
849877
}
850878
851879
```
880+
_NOTE: If **"quotas:"** object is not provided or empty, default values will be set._
852881
**Response:**
853882
```
854883
{
@@ -858,7 +887,14 @@ POST https://<host>:<port>/user-update/?resource-name=<user-name>
858887
"<group-name-2>",
859888
...
860889
"<group-name-n>"
861-
]
890+
],
891+
"quotas": {
892+
"files": {
893+
"fileCount": "100",
894+
"fileSize": "104857600",
895+
"storeSize": "104857600"
896+
}
897+
}
862898
}
863899
```
864900

@@ -881,6 +917,10 @@ GET https://<host>:<port>/user-register/?resource-name=<user-name>
881917
```
882918
**Body:**
883919
```
920+
<empty>
921+
```
922+
**Response:**
923+
```
884924
{
885925
"user": {
886926
"name": "<user-name>",
@@ -889,6 +929,13 @@ GET https://<host>:<port>/user-register/?resource-name=<user-name>
889929
"<group-name-2>"
890930
]
891931
},
932+
"quotas": {
933+
"files": {
934+
"fileCount": "100",
935+
"fileSize": "104857600",
936+
"storeSize": "104857600"
937+
}
938+
},
892939
"tokens": [
893940
{
894941
"content": "<token>",

src/cloud-tool/src/main_task.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,13 @@ void MainTask::actionFinished(const QSharedPointer<RToolAction> &action)
8282
void MainTask::actionFailed(const QSharedPointer<RToolAction> &action)
8383
{
8484
R_LOG_TRACE_IN;
85-
RHttpMessage response = action.staticCast<RCloudToolAction>().data()->getResponseMessage();
85+
RHttpMessage responseMessage = action.staticCast<RCloudToolAction>().data()->getResponseMessage();
8686
RLogger::info("Action has failed.\n");
87+
if (action.staticCast<RCloudToolAction>().data()->getType() != RCloudToolAction::FileDownload)
88+
{
89+
RLogger::info("Unhandled action response:\n");
90+
RLogger::info("%s\n",responseMessage.getBody().constData());
91+
}
8792
R_LOG_TRACE_OUT;
8893
}
8994

src/cloud/src/file_manager.cpp

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,10 @@ RError::Type FileManager::storeFile(const RUserInfo &executor, const FileObject
393393

394394
if (executor.getFileQuota().quotaExceeded(userStoreQuota))
395395
{
396-
RLogger::error("[%s] User file quota exceeded.\n",this->settings.getName().toUtf8().constData());
396+
output = QString("User file quota exceeded.").toUtf8();
397+
RLogger::error("[%s] %s.\n",
398+
this->settings.getName().toUtf8().constData(),
399+
output.constData());
397400
R_LOG_TRACE_RETURN(RError::InvalidInput);
398401
}
399402

@@ -479,20 +482,24 @@ RError::Type FileManager::replaceFile(const RUserInfo &executor, const FileObjec
479482
// Store new file object.
480483
QByteArray uploadFileOutput;
481484
RError::Type errorType = this->storeFile(executor,object,uploadFileOutput);
482-
if (errorType == RError::None)
485+
if (errorType != RError::None)
486+
{
487+
output = uploadFileOutput;
488+
R_LOG_TRACE_RETURN(errorType);
489+
}
490+
491+
if (!files.isEmpty())
483492
{
484-
if (!files.isEmpty())
493+
// Remove all replaced files.
494+
for (const RFileInfo &fileInfo : std::as_const(files))
485495
{
486-
// Remove all replaced files.
487-
for (const RFileInfo &fileInfo : std::as_const(files))
496+
QByteArray removeFileOutput;
497+
errorType = this->removeFile(executor,fileInfo.getId(),removeFileOutput);
498+
jsonRemoveFileArray.append(QJsonDocument::fromJson(removeFileOutput).object());
499+
if (errorType != RError::None)
488500
{
489-
QByteArray removeFileOutput;
490-
errorType = this->removeFile(executor,fileInfo.getId(),removeFileOutput);
491-
jsonRemoveFileArray.append(QJsonDocument::fromJson(removeFileOutput).object());
492-
if (errorType != RError::None)
493-
{
494-
break;
495-
}
501+
output = uploadFileOutput;
502+
R_LOG_TRACE_RETURN(errorType);
496503
}
497504
}
498505
}
@@ -539,7 +546,10 @@ RError::Type FileManager::updateFile(const RUserInfo &executor, const FileObject
539546

540547
if (executor.getFileQuota().quotaExceeded(userStoreQuota))
541548
{
542-
RLogger::error("[%s] User file quota exceeded.\n",this->settings.getName().toUtf8().constData());
549+
output = QString("User file quota exceeded.").toUtf8();
550+
RLogger::error("[%s] %s.\n",
551+
this->settings.getName().toUtf8().constData(),
552+
output.constData());
543553
R_LOG_TRACE_RETURN(RError::InvalidInput);
544554
}
545555

0 commit comments

Comments
 (0)