Skip to content
Next
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Minds Backend - Engine
Project
Project
Details
Activity
Releases
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
236
Issues
236
List
Boards
Labels
Service Desk
Milestones
Merge Requests
34
Merge Requests
34
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Security & Compliance
Security & Compliance
Dependency List
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
Compare Revisions
0c4046d67731989ca89212bf24cb15d2f2a876ff...d1b2d7a489df1703c43647c0114643ac09bf3915
Source
d1b2d7a489df1703c43647c0114643ac09bf3915
Select Git revision
...
Target
0c4046d67731989ca89212bf24cb15d2f2a876ff
Select Git revision
Compare
Commits (2)
(fix): assign $entities after checking user entity
· c9f0865f
Marcelo Rivera
authored
33 minutes ago
(fix): don't need to merge the $entities array
c9f0865f
(feat): more thorough spec tests
· d1b2d7a4
Marcelo Rivera
authored
33 minutes ago
d1b2d7a4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
13 deletions
+56
-13
Core/Permissions/Manager.php
Core/Permissions/Manager.php
+1
-3
Spec/Core/Permissions/ManagerSpec.php
Spec/Core/Permissions/ManagerSpec.php
+55
-10
No files found.
Core/Permissions/Manager.php
View file @
d1b2d7a4
...
...
@@ -50,13 +50,11 @@ class Manager
throw
new
\InvalidArgumentException
(
'User does not exist'
);
}
$entities
=
empty
(
$opts
[
'entities'
])
?
$this
->
entitiesBuilder
->
get
([
'guids'
=>
$opts
[
'guids'
]])
:
$opts
[
'entities'
];
if
(
$user
&&
$user
->
getType
()
!==
'user'
)
{
throw
new
\InvalidArgumentException
(
'Entity is not a user'
);
}
$entities
=
array_merge
(
$entities
,
$opts
[
'entities'
])
;
$entities
=
empty
(
$opts
[
'entities'
])
?
$this
->
entitiesBuilder
->
get
([
'guids'
=>
$opts
[
'guids'
]])
:
$opts
[
'entities'
]
;
$roles
=
new
Roles
();
...
...
This diff is collapsed.
Click to expand it.
Spec/Core/Permissions/ManagerSpec.php
View file @
d1b2d7a4
...
...
@@ -41,16 +41,16 @@ class ManagerSpec extends ObjectBehavior
$this
->
user
->
getType
()
->
willReturn
(
'user'
);
$this
->
user
->
isAdmin
()
->
willReturn
(
false
);
$this
->
user
->
isBanned
()
->
willReturn
(
false
);
$this
->
user
->
getG
uid
()
->
willReturn
(
1
);
$this
->
user
->
getG
UID
()
->
willReturn
(
1
);
$this
->
user
->
getGUID
()
->
willReturn
(
1
);
$this
->
user
->
getMode
()
->
willReturn
(
ChannelMode
::
OPEN
);
$this
->
user
->
isSubscribed
(
1
)
->
willReturn
(
false
);
$this
->
user
->
isSubscribed
(
2
)
->
willReturn
(
true
);
$this
->
user
->
isSubscribed
(
3
)
->
willReturn
(
false
);
$this
->
subscribedChannel
->
getG
uid
()
->
willReturn
(
2
);
$this
->
subscribedChannel
->
getG
UID
()
->
willReturn
(
2
);
$this
->
subscribedChannel
->
getGUID
()
->
willReturn
(
2
);
$this
->
subscribedChannel
->
getMode
()
->
willReturn
(
ChannelMode
::
MODERATED
);
$this
->
unsubscribedChannel
->
getG
uid
()
->
willReturn
(
3
);
$this
->
unsubscribedChannel
->
getG
UID
()
->
willReturn
(
3
);
$this
->
unsubscribedChannel
->
getGUID
()
->
willReturn
(
3
);
$this
->
unsubscribedChannel
->
getMode
()
->
willReturn
(
ChannelMode
::
CLOSED
);
$this
->
group
->
getGuid
()
->
willReturn
(
100
);
...
...
@@ -63,12 +63,6 @@ class ManagerSpec extends ObjectBehavior
$this
->
entitiesBuilder
->
build
(
$this
->
user
)
->
willReturn
(
$this
->
user
);
$this
->
entitiesBuilder
->
build
(
$this
->
subscribedChannel
)
->
willReturn
(
$this
->
subscribedChannel
);
$this
->
entitiesBuilder
->
build
(
$this
->
unsubscribedChannel
)
->
willReturn
(
$this
->
unsubscribedChannel
);
$this
->
entitiesBuilder
->
get
([
"guids"
=>
[
10
,
11
,
12
,
13
]
])
->
willReturn
(
$this
->
mockEntities
());
$this
->
entitiesBuilder
->
get
([
"guids"
=>
[
10
,
11
,
12
,
13
],
])
->
willReturn
(
$this
->
mockEntities
());
$this
->
beConstructedWith
(
$this
->
entitiesBuilder
);
}
...
...
@@ -77,8 +71,19 @@ class ManagerSpec extends ObjectBehavior
$this
->
shouldHaveType
(
Manager
::
class
);
}
public
function
it_should_get_permissions
()
public
function
it_should_get_permissions
_by_guid
()
{
$this
->
entitiesBuilder
->
get
([
"guids"
=>
[
10
,
11
,
12
,
13
],
])
->
shouldBeCalled
()
->
willReturn
(
$this
->
mockEntities
());
$this
->
entitiesBuilder
->
get
([
"guids"
=>
[
10
,
11
,
12
,
13
],
])
->
shouldBeCalled
()
->
willReturn
(
$this
->
mockEntities
());
$permissions
=
$this
->
getList
([
'user_guid'
=>
1
,
'guids'
=>
[
10
,
11
,
12
,
13
],
...
...
@@ -91,6 +96,46 @@ class ManagerSpec extends ObjectBehavior
$entities
->
shouldHaveKey
(
13
);
}
public
function
it_should_get_permissions_by_sending_the_entities
()
{
$this
->
entitiesBuilder
->
get
(
Argument
::
any
())
->
shouldNotBeCalled
();
$permissions
=
$this
->
getList
([
'user_guid'
=>
1
,
'guids'
=>
[],
'entities'
=>
$this
->
mockEntities
(),
]);
$entities
=
$permissions
->
getEntities
();
$entities
->
shouldHaveKey
(
10
);
$entities
->
shouldHaveKey
(
11
);
$entities
->
shouldHaveKey
(
12
);
$entities
->
shouldHaveKey
(
13
);
}
public
function
it_should_throw_an_exception_if_no_user_guid_is_provided
()
{
$this
->
shouldThrow
(
new
\InvalidArgumentException
(
'user_guid is required'
))
->
during
(
'getList'
,
[[]]);
}
public
function
it_should_throw_an_exception_if_the_user_does_not_exist
()
{
$this
->
entitiesBuilder
->
single
(
4
)
->
shouldBeCalled
()
->
willReturn
(
null
);
$this
->
shouldThrow
(
new
\InvalidArgumentException
(
'User does not exist'
))
->
during
(
'getList'
,
[[
'user_guid'
=>
4
]]);
}
public
function
it_should_throw_an_exception_if_the_provided_user_guid_doesnt_correspond_to_a_user_entity
(
Activity
$activity
)
{
$this
->
entitiesBuilder
->
single
(
5
)
->
shouldBeCalled
()
->
willReturn
(
$activity
);
$this
->
shouldThrow
(
new
\InvalidArgumentException
(
'Entity is not a user'
))
->
during
(
'getList'
,
[[
'user_guid'
=>
5
]]);
}
private
function
mockEntities
()
{
$prophet
=
new
Prophet
();
...
...
This diff is collapsed.
Click to expand it.