-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TSPS-357 Add admin endpoint to get a user's quota and update their quota #162
Changes from all commits
9bf2323
6b57c70
3a572f8
1852d28
27a9bdc
ce11586
b6d7199
0636274
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,10 +33,9 @@ public class QuotasService { | |
* will create a new row in the user quotas table with the default quota for the pipeline. | ||
*/ | ||
@WriteTransaction | ||
public UserQuota getQuotaForUserAndPipeline(String userId, PipelinesEnum pipelineName) { | ||
public UserQuota getOrCreateQuotaForUserAndPipeline(String userId, PipelinesEnum pipelineName) { | ||
// try to get the user quota | ||
Optional<UserQuota> userQuota = | ||
userQuotasRepository.findByUserIdAndPipelineName(userId, pipelineName); | ||
Optional<UserQuota> userQuota = getQuotaForUserAndPipeline(userId, pipelineName); | ||
// if the user quota is not found, grab the default pipeline quota and make a new row in user | ||
// quotas table | ||
if (userQuota.isEmpty()) { | ||
|
@@ -55,6 +54,14 @@ public UserQuota getQuotaForUserAndPipeline(String userId, PipelinesEnum pipelin | |
return userQuota.get(); | ||
} | ||
|
||
/** | ||
* This method gets the quota for a given user and pipeline. If the user quota does not exist, it | ||
* will return an empty optional. | ||
*/ | ||
public Optional<UserQuota> getQuotaForUserAndPipeline(String userId, PipelinesEnum pipelineName) { | ||
return userQuotasRepository.findByUserIdAndPipelineName(userId, pipelineName); | ||
} | ||
|
||
/** | ||
* This method updates the quota consumed for a given user and pipeline. It will return the | ||
* updated user quota object. | ||
|
@@ -75,4 +82,23 @@ public UserQuota updateQuotaConsumed(UserQuota userQuota, int newQuotaConsumed) | |
userQuota.setQuotaConsumed(newQuotaConsumed); | ||
return userQuotasRepository.save(userQuota); | ||
} | ||
|
||
/** | ||
* This method updates the quota limit for a given user quota. This should only be called from the | ||
* Admin Controller | ||
* | ||
* @param userQuota - the user quota to update | ||
* @param newQuotaLimit - the new quota limit | ||
* @return - the updated user quota | ||
*/ | ||
public UserQuota adminUpdateQuotaLimit(UserQuota userQuota, int newQuotaLimit) { | ||
if (newQuotaLimit < userQuota.getQuotaConsumed()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so we would allow setting the newQuotaLimit to be equal to the user's current QuotaConsumed, thereby preventing any further activity, is that right? (sounds good to me) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. correct |
||
throw new InternalServerErrorException( | ||
String.format( | ||
"New quota limit: %d, is less than the quota consumed: %d", | ||
newQuotaLimit, userQuota.getQuotaConsumed())); | ||
} | ||
userQuota.setQuota(newQuotaLimit); | ||
return userQuotasRepository.save(userQuota); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah nice catch, thanks!