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
206
Issues
206
List
Boards
Labels
Service Desk
Milestones
Merge Requests
29
Merge Requests
29
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
1111178b
Commit
1111178b
authored
18 hours ago
by
Brian Hatchet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CR updates
parent
3b020fa8
feature/permissions-rbac-600
1 merge request
!290
(feat) permissions rbac 600
Pipeline
#75491124
passed with stages
in 9 minutes and 14 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
28 deletions
+54
-28
roles.php
Controllers/api/v2/permissions/roles.php
+3
-2
ChannelRoleCalculator.php
Core/Permissions/Delegates/ChannelRoleCalculator.php
+3
-2
GroupRoleCalculator.php
Core/Permissions/Delegates/GroupRoleCalculator.php
+3
-2
Manager.php
Core/Permissions/Manager.php
+24
-14
Permissions.php
Core/Permissions/Permissions.php
+21
-8
No files found.
Controllers/api/v2/permissions/roles.php
View file @
1111178b
...
...
@@ -23,12 +23,13 @@ class roles implements Interfaces\Api
$manager
=
Di
::
_
()
->
get
(
'Permissions\Manager'
);
$opts
=
[
'user_guid'
=>
$pages
[
0
],
'guids'
=>
$_GET
[
'guids'
]
'guids'
=>
$_GET
[
'guids'
]
,
];
$permissions
=
$manager
->
getList
(
$opts
);
return
Factory
::
response
([
'status'
=>
'success'
,
'roles'
=>
$permissions
'roles'
=>
$permissions
,
]);
}
catch
(
Exception
$ex
)
{
return
Factory
::
response
([
...
...
This diff is collapsed.
Click to expand it.
Core/Permissions/Delegates/ChannelRoleCalculator.php
View file @
1111178b
...
...
@@ -12,10 +12,11 @@ class ChannelRoleCalculator extends BaseRoleCalculator
private
$channels
=
[];
/**
* @param $entity an entity from a channel
* Retrieves permissions for an entity relative to the user's role in a channel
* Retrieves the role from the in memory cache if we've seen this channel before during this request
* Else checks the user's membership against the channel
* Else checks the user's membership against the channel.
*
* @param $entity an entity from a channel
*
* @return Role
*/
...
...
This diff is collapsed.
Click to expand it.
Core/Permissions/Delegates/GroupRoleCalculator.php
View file @
1111178b
...
...
@@ -24,10 +24,11 @@ class GroupRoleCalculator extends BaseRoleCalculator
}
/**
* @param $entity an entity belonging to a group
* Retrieves permissions for an entity relative to the user's role in a group
* Retrieves the role from the in memory cache if we've seen this group before during this request
* Else gets the group and checks the user's membership
* Else gets the group and checks the user's membership.
*
* @param $entity an entity belonging to a group
*
* @return Role
*/
...
...
This diff is collapsed.
Click to expand it.
Core/Permissions/Manager.php
View file @
1111178b
...
...
@@ -3,44 +3,54 @@
namespace
Minds\Core\Permissions
;
use
Minds\Core\Di\Di
;
use
Minds\Core\EntitiesBuilder
;
use
Minds\Core\Data\Call
;
use
Minds\Core\Permissions\Roles
;
use
Minds\Core\Permissions\Permissions
;
/*
* Manager for managing role based permissions
*/
class
Manager
{
class
Manager
{
/** @var EntityBuilder */
private
$entityBuilder
;
public
function
__construct
(
$entityBuilder
=
null
)
{
public
function
__construct
(
$entityBuilder
=
null
)
{
$this
->
entitiesBuilder
=
$entitiesBuilder
?:
Di
::
_
()
->
get
(
'EntitiesBuilder'
);
}
public
function
getList
(
array
$opts
=
[])
{
/**
* Takes a user_guid and list of entity guids
* Builds up a permissions object
* Permissions contains the user's role per entity, channel and group
* @param array $opts
* - user_guid: long, the user's guid for calculating permissions
* - guids: array long, the list of entities to permit
* @return Permissions A map of channels, groups and entities with the user's role for each
*/
public
function
getList
(
array
$opts
=
[])
{
$opts
=
array_merge
([
'user_guid'
=>
null
,
'guids'
=>
[]
'guids'
=>
[]
,
],
$opts
);
if
(
$opts
[
'user_guid'
]
===
null
)
{
throw
new
\InvalidArgumentException
(
'user_guid is required'
);
}
$user
=
$this
->
entitiesBuilder
->
single
(
$opts
[
'user_guid'
]);
$entities
=
$this
->
entitiesBuilder
->
get
(
$opts
);
error_log
(
var_export
(
$user
->
getGroupMembership
(),
true
));
if
(
$user
->
getType
()
!==
'user'
)
{
throw
new
\InvalidArgumentException
(
'Entity is not a user'
);
}
/** @var Permissions */
$permissions
=
new
Permissions
(
$user
);
if
(
is_array
(
$entities
))
{
error_log
(
'calculating'
);
if
(
is_array
(
$entities
))
{
$permissions
->
calculate
(
$entities
);
}
return
$permissions
;
}
}
This diff is collapsed.
Click to expand it.
Core/Permissions/Permissions.php
View file @
1111178b
...
...
@@ -2,14 +2,12 @@
namespace
Minds\Core\Permissions
;
use
Minds\Core\Di\Di
;
use
Minds\Traits\MagicAttributes
;
use
Minds\Entities\User
;
use
Minds\Core\EntitiesBuilder
;
use
Minds\Core\Permissions\Roles\Roles
;
use
Minds\Core\Permissions\Delegates\ChannelRoleCalculator
;
use
Minds\Core\Permissions\Delegates\GroupRoleCalculator
;
use
Minds\Common\Access
;
class
Permissions
implements
\JsonSerializable
...
...
@@ -46,13 +44,13 @@ class Permissions implements \JsonSerializable
}
/**
* @param array entities an array of entities for calculating permissions
* Takes an array of entities and checks their permissions
* Builds up collections of permissions based on the user's relationships to the entity
* Any found channels and their roles are accessible in the channelRoleCalculator
* Any found groups and their roles are in the groupRoleCalculator
* All requested entities and the user's role is available in $this->entities
* @return void
* All requested entities and the user's role is available in $this->entities.
*
* @param array entities an array of entities for calculating permissions
*/
public
function
calculate
(
array
$entities
=
[])
{
...
...
@@ -88,7 +86,11 @@ class Permissions implements \JsonSerializable
return
$role
;
}
/* Export the nested objects */
/**
* Export the nested objects.
*
* @return array serialized objects
*/
public
function
export
()
{
$export
=
[];
...
...
@@ -100,14 +102,25 @@ class Permissions implements \JsonSerializable
return
$export
;
}
public
function
getChannels
()
{
/**
* @return array channel guids with the user's role
*/
public
function
getChannels
()
{
return
$this
->
channelRoleCalculator
->
getChannels
();
}
public
function
getGroups
()
{
/**
* @return array group guids with the user's role
*/
public
function
getGroups
()
{
return
$this
->
groupRoleCalculator
->
getGroups
();
}
/**
* @return array serialized objects
*/
public
function
jsonSerialize
()
{
return
$this
->
export
();
...
...
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