Skip to content
Next
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Minds Backend - Engine
Project
Project
Details
Activity
Releases
Dependency List
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
185
Issues
185
List
Boards
Labels
Service Desk
Milestones
Merge Requests
31
Merge Requests
31
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
List
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Minds
Minds Backend - Engine
Commits
c1be0c6c
Commit
c1be0c6c
authored
4 minutes ago
by
Mark Harding
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(feat): max subscriptions limit
parent
9b1091df
master
No related merge requests found
Pipeline
#73672483
running with stages
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
6 deletions
+43
-6
SendNotificationDelegate.php
Core/Subscriptions/Delegates/SendNotificationDelegate.php
+14
-0
Manager.php
Core/Subscriptions/Manager.php
+8
-2
TooManySubscriptionsException.php
Core/Subscriptions/TooManySubscriptionsException.php
+7
-0
ManagerSpec.php
Spec/Core/Subscriptions/ManagerSpec.php
+14
-4
No files found.
Core/Subscriptions/Delegates/SendNotificationDelegate.php
View file @
c1be0c6c
...
...
@@ -34,4 +34,18 @@ class SendNotificationDelegate
}
public
function
onMaxSubscriptions
(
$subscription
)
{
$message
=
"You are unable to subscribe to new channels as you have over 5000 subscriptions."
;
$this
->
eventsDispatcher
->
trigger
(
'notification'
,
'all'
,
[
'to'
=>
[
$subscription
->
getSubscriberGuid
()
],
'entity'
=>
$subscription
->
getPublisherGuid
(),
'notification_view'
=>
'custom_message'
,
'from'
=>
100000000000000519
,
'message'
=>
$message
,
'params'
=>
[
'message'
=>
$message
],
]);
}
}
This diff is collapsed.
Click to expand it.
Core/Subscriptions/Manager.php
View file @
c1be0c6c
...
...
@@ -14,6 +14,7 @@ use Minds\Entities\User;
class
Manager
{
const
MAX_SUBSCRIPTIONS
=
5000
;
/** @var Repository $repository */
private
$repository
;
...
...
@@ -102,10 +103,15 @@ class Manager
$subscription
->
setSubscriberGuid
(
$this
->
subscriber
->
getGuid
())
->
setPublisherGuid
(
$publisher
->
getGuid
());
if
(
$this
->
getSubscriptionsCount
()
>=
static
::
MAX_SUBSCRIPTIONS
)
{
$this
->
sendNotificationDelegate
->
onMaxSubscriptions
(
$subscription
);
throw
new
TooManySubscriptionsException
();
}
$subscription
=
$this
->
repository
->
add
(
$subscription
);
$this
->
eventsDelegate
->
trigger
(
$subscription
);
$this
->
feedsDelegate
->
copy
(
$subscription
);
//
$this->feedsDelegate->copy($subscription);
$this
->
copyToElasticSearchDelegate
->
copy
(
$subscription
);
$this
->
cacheDelegate
->
cache
(
$subscription
);
$this
->
checkRateLimitDelegate
->
incrementCache
(
$this
->
subscriber
->
guid
);
...
...
@@ -145,7 +151,7 @@ class Manager
*/
public
function
getSubscriptionsCount
()
{
return
$this
->
subscriber
->
getSubscriptonsCount
();
//TODO: Refactor so we are the source of truth
return
$this
->
subscriber
->
getSubscript
i
onsCount
();
//TODO: Refactor so we are the source of truth
}
}
This diff is collapsed.
Click to expand it.
Core/Subscriptions/TooManySubscriptionsException.php
0 → 100644
View file @
c1be0c6c
<?php
namespace
Minds\Core\Subscriptions
;
class
TooManySubscriptionsException
extends
\Exception
{
protected
$message
=
"Subscribe to over 5000 channels"
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Spec/Core/Subscriptions/ManagerSpec.php
View file @
c1be0c6c
...
...
@@ -98,10 +98,6 @@ class ManagerSpec extends ObjectBehavior
$this
->
eventsDelegate
->
trigger
(
$subscription
)
->
shouldBeCalled
();
// Call the feeds delegate
$this
->
feedsDelegate
->
copy
(
$subscription
)
->
shouldBeCalled
();
// Call the es delegate
$this
->
copyToElasticSearchDelegate
->
copy
(
$subscription
)
->
shouldBeCalled
();
...
...
@@ -119,6 +115,20 @@ class ManagerSpec extends ObjectBehavior
->
shouldBe
(
true
);
}
function
it_should_not_allow_if_over_5000_subscriptions
(
User
$subscriber
)
{
$publisher
=
(
new
User
)
->
set
(
'guid'
,
456
);
$subscriber
->
getSubscriptionsCount
()
->
willReturn
(
5000
);
$subscriber
->
getGUID
()
->
willReturn
(
123
);
$this
->
setSubscriber
(
$subscriber
);
$this
->
shouldThrow
(
'Minds\Core\Subscriptions\TooManySubscriptionsException'
)
->
duringSubscribe
(
$publisher
);
}
function
it_should_unsubscribe
()
{
// Confusing.. but this is the returned subscription
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment