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
243
Issues
243
List
Boards
Labels
Service Desk
Milestones
Merge Requests
35
Merge Requests
35
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
Commits
31f45fc5
Commit
31f45fc5
authored
34 minutes ago
by
Brian Hatchet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MR changes
parent
f7700208
epic/permissions-open-channels
1 merge request
!307
Epic/permissions open channels
Pipeline
#80587986
failed with stages
in 4 minutes and 38 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
36 additions
and
27 deletions
+36
-27
ChannelRoleCalculator.php
Core/Permissions/Delegates/ChannelRoleCalculator.php
+2
-1
GroupRoleCalculator.php
Core/Permissions/Delegates/GroupRoleCalculator.php
+2
-1
Manager.php
Core/Permissions/Entities/Manager.php
+6
-6
Manager.php
Core/Permissions/Manager.php
+8
-6
Permissions.php
Core/Permissions/Permissions.php
+16
-11
BaseRole.php
Core/Permissions/Roles/BaseRole.php
+2
-2
No files found.
Core/Permissions/Delegates/ChannelRoleCalculator.php
View file @
31f45fc5
...
...
@@ -4,6 +4,7 @@ namespace Minds\Core\Permissions\Delegates;
use
Minds\Traits\MagicAttributes
;
use
Minds\Core\Permissions\Roles\Roles
;
use
Minds\Core\Permissions\Roles\Role
;
class
ChannelRoleCalculator
extends
BaseRoleCalculator
{
...
...
@@ -20,7 +21,7 @@ class ChannelRoleCalculator extends BaseRoleCalculator
*
* @return Role
*/
public
function
calculate
(
$entity
)
public
function
calculate
(
$entity
)
:
Role
{
if
(
isset
(
$this
->
channels
[
$entity
->
getOwnerGUID
()]))
{
return
$this
->
channels
[
$entity
->
getOwnerGUID
()];
...
...
This diff is collapsed.
Click to expand it.
Core/Permissions/Delegates/GroupRoleCalculator.php
View file @
31f45fc5
...
...
@@ -7,6 +7,7 @@ use Minds\Core\Di\Di;
use
Minds\Core\Permissions\Roles\Roles
;
use
Minds\Core\EntitiesBuilder
;
use
Minds\Entities\User
;
use
Minds\Core\Permissions\Roles
;
class
GroupRoleCalculator
extends
BaseRoleCalculator
{
...
...
@@ -32,7 +33,7 @@ class GroupRoleCalculator extends BaseRoleCalculator
*
* @return Role
*/
public
function
calculate
(
$entity
)
public
function
calculate
(
$entity
)
:
Role
{
if
(
isset
(
$this
->
groups
[
$entity
->
getAccessId
()]))
{
return
$this
->
groups
[
$entity
->
getAccessId
()];
...
...
This diff is collapsed.
Click to expand it.
Core/Permissions/Entities/Manager.php
View file @
31f45fc5
...
...
@@ -6,7 +6,6 @@ use Minds\Core\Di\Di;
use
Minds\Core\EntitiesBuilder
;
use
Minds\Core\Data\Call
;
use
Minds\Core\Entities\Actions\Save
;
use
Minds\Core\Permissions\Entities\EntityPermissions
;
/*
* Manager for managing entity specific permissions
...
...
@@ -31,11 +30,12 @@ class Manager
}
/**
* Save permissions for an entity and propegate it to linked objects
* @param mixed $entity a minds entity that implements the save function
* @param Permissions $permissions the flag to apply to the entity
*/
public
function
save
(
$entity
,
EntityPermissions
$permissions
)
* Save permissions for an entity and propegate it to linked objects.
*
* @param mixed $entity a minds entity that implements the save function
* @param Permissions $permissions the flag to apply to the entity
*/
public
function
save
(
$entity
,
EntityPermissions
$permissions
)
:
void
{
$entity
->
setAllowComments
(
$permissions
->
getAllowComments
());
...
...
This diff is collapsed.
Click to expand it.
Core/Permissions/Manager.php
View file @
31f45fc5
...
...
@@ -3,8 +3,6 @@
namespace
Minds\Core\Permissions
;
use
Minds\Core\Di\Di
;
use
Minds\Core\Permissions\Permissions
;
use
Minds\Core\EntitiesBuilder
;
/*
* Manager for managing role based permissions
...
...
@@ -22,13 +20,15 @@ class Manager
/**
* 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
* 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
* - 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
=
[])
public
function
getList
(
array
$opts
=
[])
:
Permissions
{
$opts
=
array_merge
([
'user_guid'
=>
null
,
...
...
@@ -46,6 +46,8 @@ class Manager
throw
new
\InvalidArgumentException
(
'Entity is not a user'
);
}
$roles
=
new
Roles
();
/** @var Permissions */
$permissions
=
new
Permissions
(
$user
,
null
,
$entitiesBuilder
);
if
(
is_array
(
$entities
))
{
...
...
This diff is collapsed.
Click to expand it.
Core/Permissions/Permissions.php
View file @
31f45fc5
...
...
@@ -33,11 +33,6 @@ class Permissions implements \JsonSerializable
/** @var EntitiesBuilder */
private
$entitiesBuilder
;
public
function
setUser
(
User
$user
)
{
throw
new
ImmutableException
(
'User can only be set in the constructor'
);
}
public
function
__construct
(
User
$user
,
Roles
$roles
=
null
,
EntitiesBuilder
$entitiesBuilder
=
null
)
{
$this
->
entitiesBuilder
=
$entitiesBuilder
?:
Di
::
_
()
->
get
(
'EntitiesBuilder'
);
...
...
@@ -54,6 +49,16 @@ class Permissions implements \JsonSerializable
$this
->
groupRoleCalculator
=
new
GroupRoleCalculator
(
$this
->
user
,
$this
->
roles
,
$entitiesBuilder
);
}
/**
* Permissions are user aware. This bomb function is to keep the user from being changed after instantiation.
*
* @throws ImmutableException
*/
public
function
setUser
(
User
$user
)
:
void
{
throw
new
ImmutableException
(
'User can only be set in the constructor'
);
}
/**
* Takes an array of entities and checks their permissions
* Builds up collections of permissions based on the user's relationships to the entity
...
...
@@ -63,14 +68,14 @@ class Permissions implements \JsonSerializable
*
* @param array entities an array of entities for calculating permissions
*/
public
function
calculate
(
array
$entities
=
[])
public
function
calculate
(
array
$entities
=
[])
:
void
{
foreach
(
$entities
as
$entity
)
{
$this
->
entities
[
$entity
->
getGUID
()]
=
$this
->
getRoleForEntity
(
$entity
);
}
}
private
function
getRoleForEntity
(
$entity
)
private
function
getRoleForEntity
(
$entity
)
:
Role
{
$role
=
null
;
//Access id is the best way to determine what the parent entity is
...
...
@@ -102,7 +107,7 @@ class Permissions implements \JsonSerializable
*
* @return array serialized objects
*/
public
function
export
()
public
function
export
()
:
array
{
$export
=
[];
$export
[
'user'
]
=
$this
->
user
->
export
();
...
...
@@ -116,7 +121,7 @@ class Permissions implements \JsonSerializable
/**
* @return array channel guids with the user's role
*/
public
function
getChannels
()
public
function
getChannels
()
:
array
{
return
$this
->
channelRoleCalculator
->
getChannels
();
}
...
...
@@ -124,7 +129,7 @@ class Permissions implements \JsonSerializable
/**
* @return array group guids with the user's role
*/
public
function
getGroups
()
public
function
getGroups
()
:
array
{
return
$this
->
groupRoleCalculator
->
getGroups
();
}
...
...
@@ -132,7 +137,7 @@ class Permissions implements \JsonSerializable
/**
* @return array serialized objects
*/
public
function
jsonSerialize
()
public
function
jsonSerialize
()
:
array
{
return
$this
->
export
();
}
...
...
This diff is collapsed.
Click to expand it.
Core/Permissions/Roles/BaseRole.php
View file @
31f45fc5
...
...
@@ -6,7 +6,7 @@ use Zend\Permissions\Rbac;
abstract
class
BaseRole
extends
Rbac\Role
implements
\JsonSerializable
{
public
function
export
()
public
function
export
()
:
array
{
$export
=
[];
$export
[
'name'
]
=
$this
->
getName
();
...
...
@@ -15,7 +15,7 @@ abstract class BaseRole extends Rbac\Role implements \JsonSerializable
return
$export
;
}
public
function
jsonSerialize
()
public
function
jsonSerialize
()
:
array
{
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