Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117747181
D4594.1775175042.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
D4594.1775175042.diff
View Options
diff --git a/src/app/Http/Controllers/API/V4/PolicyController.php b/src/app/Http/Controllers/API/V4/PolicyController.php
--- a/src/app/Http/Controllers/API/V4/PolicyController.php
+++ b/src/app/Http/Controllers/API/V4/PolicyController.php
@@ -142,18 +142,21 @@
$request->save();
}
- // exempt owners that have 100% discount.
- if ($wallet->discount && $wallet->discount->discount == 100) {
- return response()->json(['response' => 'DUNNO'], 200);
- }
- // exempt owners that have made at least two payments and currently maintain a positive balance.
- if ($wallet->balance > 0) {
- $payments = $wallet->payments()->where('amount', '>', 0)->where('status', 'paid');
+ // Paying users have a 15 messages per minute limit
+ if ($wallet->hasMinimumBalanceAndPayments()) {
+ $ownerRates = RateLimit::where('owner_id', $owner->id)
+ ->where('updated_at', '>=', \Carbon\Carbon::now()->subMinute());
- if ($payments->count() >= 2) {
- return response()->json(['response' => 'DUNNO'], 200);
+ if (($count = $ownerRates->count()) >= 15) {
+ $result = [
+ 'response' => 'DEFER_IF_PERMIT',
+ 'reason' => 'The account is at 15 messages per minute, cool down.'
+ ];
+
+ return response()->json($result, 403);
}
+ return response()->json(['response' => 'DUNNO'], 200);
}
//
diff --git a/src/app/Wallet.php b/src/app/Wallet.php
--- a/src/app/Wallet.php
+++ b/src/app/Wallet.php
@@ -743,4 +743,28 @@
return $this;
}
+
+
+ /**
+ * Ensure that this wallet has a positive balance and a minimum number of payments,
+ * or a 100% discount (in which case there are no payments).
+ *
+ * @return bool
+ */
+ public function hasMinimumBalanceAndPayments($minimumPayments = 2): bool
+ {
+ if ($this->discount && $this->discount->discount == 100) {
+ return true;
+ }
+
+ if ($this->balance > 0) {
+ $payments = $this->payments()->where('amount', '>', 0)->where('status', 'paid');
+
+ if ($payments->count() >= $minimumPayments) {
+ return true;
+ }
+ }
+
+ return false;
+ }
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Apr 3, 12:10 AM (1 d, 12 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18821643
Default Alt Text
D4594.1775175042.diff (2 KB)
Attached To
Mode
D4594: 15 messages / minute rate-limit for paying users
Attached
Detach File
Event Timeline