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
234
Issues
234
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
Compare Revisions
c9daabe0a7021b4df8a38f7f9c6bb34a582afdde...1559425f2f418aea06935802d61215e6f87fe5cb
Source
1559425f2f418aea06935802d61215e6f87fe5cb
Select Git revision
...
Target
c9daabe0a7021b4df8a38f7f9c6bb34a582afdde
Select Git revision
Compare
Commits (2)
Chore refactor permissions export
· 21171789
Brian Hatchet
authored
1 hour ago
21171789
Merge branch 'chore-refactor-permissions-export' into 'epic/permissions-28'
· 1559425f
Brian Hatchet
authored
1 hour ago
Chore refactor permissions export See merge request
!349
1559425f
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
55 additions
and
40 deletions
+55
-40
Api/Exportable.php
Api/Exportable.php
+2
-2
Api/Factory.php
Api/Factory.php
+31
-25
Controllers/api/v1/newsfeed.php
Controllers/api/v1/newsfeed.php
+1
-1
Core/Permissions/Manager.php
Core/Permissions/Manager.php
+2
-5
Core/Permissions/Permissions.php
Core/Permissions/Permissions.php
+13
-0
Core/Permissions/Roles/ChannelOwnerRole.php
Core/Permissions/Roles/ChannelOwnerRole.php
+1
-0
Spec/Core/Permissions/ManagerSpec.php
Spec/Core/Permissions/ManagerSpec.php
+5
-7
No files found.
Api/Exportable.php
View file @
1559425f
...
...
@@ -120,9 +120,9 @@ class Exportable implements \JsonSerializable
]);
if
(
$item
instanceof
FeedSyncEntity
)
{
$exported
[
'entity'
][
'permissions'
]
=
$permissions
->
export
(
);
$exported
[
'entity'
][
'permissions'
]
=
$permissions
->
export
Permission
(
$entity
->
getGuid
()
);
}
else
{
$exported
[
'permissions'
]
=
$permissions
->
export
(
);
$exported
[
'permissions'
]
=
$permissions
->
export
Permission
(
$entity
->
getGuid
()
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Api/Factory.php
View file @
1559425f
...
...
@@ -209,35 +209,41 @@ class Factory
* @return array - an array of the entities
* @deprecated
*/
public
static
function
exportable
(
$entities
,
$exceptions
=
[],
$exportContext
=
false
,
$includePermissions
=
true
)
public
static
function
exportable
(
$entities
=
[]
,
$exceptions
=
[],
$exportContext
=
false
,
$includePermissions
=
true
)
{
$permissionsManager
=
Di
::
_
()
->
get
(
'Permissions\Manager'
);
if
(
!
$entities
)
{
return
[];
foreach
(
$entities
as
$k
=>
$entity
)
{
$entities
[
$k
]
=
Factory
::
export
(
$entity
,
$exceptions
,
$exportContext
,
$includePermissions
);
}
return
$entities
;
}
foreach
(
$entities
as
$k
=>
$entity
)
{
if
(
$exportContext
&&
method_exists
(
$entity
,
'setExportContext'
))
{
$entity
->
setExportContext
(
$exportContext
);
}
/**
* Exports a single entity, called by exportable for arrays
*/
public
static
function
export
(
$entity
,
$exceptions
=
false
,
$exportContext
=
false
,
$includePermissions
=
true
)
{
if
(
$exportContext
&&
method_exists
(
$entity
,
'setExportContext'
))
{
$entity
->
setExportContext
(
$exportContext
);
}
$entities
[
$k
]
=
$entity
->
export
();
//Calculate new permissions object with the entities
if
(
$includePermissions
&&
$entity
&&
Di
::
_
()
->
get
(
'Features\Manager'
)
->
has
(
'permissions'
))
{
$permissions
=
$permissionsManager
->
getList
([
'user_guid'
=>
Session
::
getLoggedinUser
(),
'entities'
=>
[
$entity
],
]);
$entities
[
$k
][
'permissions'
]
=
$permissions
->
export
();
}
$entities
[
$k
][
'guid'
]
=
(
string
)
$entities
[
$k
][
'guid'
];
//javascript doesn't like long numbers..
if
(
isset
(
$entities
[
$k
][
'ownerObj'
][
'guid'
]))
{
$entities
[
$k
][
'ownerObj'
][
'guid'
]
=
(
string
)
$entity
->
ownerObj
[
'guid'
];
}
foreach
(
$exceptions
as
$exception
)
{
$entities
[
$k
][
$exception
]
=
$entity
->
$exception
;
}
$export
=
$entity
->
export
();
//Calculate new permissions object with the entities
if
(
$includePermissions
&&
$entity
&&
Di
::
_
()
->
get
(
'Features\Manager'
)
->
has
(
'permissions'
))
{
/** @var Manager $permissionsManager */
$permissionsManager
=
Di
::
_
()
->
get
(
'Permissions\Manager'
);
$permissions
=
$permissionsManager
->
getList
([
'user_guid'
=>
Session
::
getLoggedinUser
(),
'entities'
=>
[
$entity
],
]);
$export
[
'permissions'
]
=
$permissions
->
exportPermission
(
$entity
->
getGuid
());
}
return
$entities
;
$export
[
'guid'
]
=
(
string
)
$export
[
'guid'
];
//javascript doesn't like long numbers..
if
(
isset
(
$export
[
'ownerObj'
][
'guid'
]))
{
$export
[
'ownerObj'
][
'guid'
]
=
(
string
)
$entity
->
ownerObj
[
'guid'
];
}
foreach
(
$exceptions
as
$exception
)
{
$export
[
$exception
]
=
$export
->
$exception
;
}
return
$export
;
}
}
This diff is collapsed.
Click to expand it.
Controllers/api/v1/newsfeed.php
View file @
1559425f
...
...
@@ -54,7 +54,7 @@ class newsfeed implements Interfaces\Api
return
Factory
::
response
([
'status'
=>
'error'
]);
}
return
Factory
::
response
([
'activity'
=>
$activity
->
export
(
)]);
return
Factory
::
response
([
'activity'
=>
Factory
::
export
(
$activity
)]);
break
;
default
:
case
'personal'
:
...
...
This diff is collapsed.
Click to expand it.
Core/Permissions/Manager.php
View file @
1559425f
...
...
@@ -44,17 +44,14 @@ class Manager
throw
new
\InvalidArgumentException
(
'user_guid is required'
);
}
$guids
=
$opts
[
'guids'
]
?:
array_map
(
function
(
$item
)
{
return
$item
->
getGuid
();
},
$opts
[
'entities'
]);
$user
=
$this
->
entitiesBuilder
->
single
(
$opts
[
'user_guid'
]);
$entities
=
$this
->
entitiesBuilder
->
get
([
'guids'
=>
$guids
]);
if
(
!
$user
)
{
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'
);
}
...
...
This diff is collapsed.
Click to expand it.
Core/Permissions/Permissions.php
View file @
1559425f
...
...
@@ -150,6 +150,19 @@ class Permissions implements \JsonSerializable
return
$export
;
}
/**
* Export the exact permissions for a calculated entity only
*
* @return array serialized individual permission for an entity
*/
public
function
exportPermission
(
$guid
)
:
array
{
if
(
isset
(
$this
->
entities
[
$guid
]))
{
return
$this
->
entities
[
$guid
]
->
export
();
}
return
[];
}
/**
* @return array channel guids with the user's role
*/
...
...
This diff is collapsed.
Click to expand it.
Core/Permissions/Roles/ChannelOwnerRole.php
View file @
1559425f
...
...
@@ -9,6 +9,7 @@ class ChannelOwnerRole extends BaseRole
parent
::
__construct
(
Roles
::
ROLE_CHANNEL_OWNER
);
$this
->
addPermission
(
Flags
::
FLAG_APPOINT_ADMIN
);
$this
->
addPermission
(
Flags
::
FLAG_CREATE_POST
);
$this
->
addPermission
(
Flags
::
FLAG_CREATE_GROUP
);
$this
->
addPermission
(
Flags
::
FLAG_EDIT_CHANNEL
);
$this
->
addPermission
(
Flags
::
FLAG_EDIT_POST
);
$this
->
addPermission
(
Flags
::
FLAG_DELETE_CHANNEL
);
...
...
This diff is collapsed.
Click to expand it.
Spec/Core/Permissions/ManagerSpec.php
View file @
1559425f
...
...
@@ -64,12 +64,10 @@ class ManagerSpec extends ObjectBehavior
$this
->
entitiesBuilder
->
build
(
$this
->
subscribedChannel
)
->
willReturn
(
$this
->
subscribedChannel
);
$this
->
entitiesBuilder
->
build
(
$this
->
unsubscribedChannel
)
->
willReturn
(
$this
->
unsubscribedChannel
);
$this
->
entitiesBuilder
->
get
([
"user_guid"
=>
1
,
"guids"
=>
[
10
,
11
,
12
,
13
],
"entities"
=>
[],
"guids"
=>
[
10
,
11
,
12
,
13
]
])
->
willReturn
(
$this
->
mockEntities
());
$this
->
entitiesBuilder
->
get
([
"guids"
=>
[
10
,
11
,
12
,
13
]
"guids"
=>
[
10
,
11
,
12
,
13
]
,
])
->
willReturn
(
$this
->
mockEntities
());
$this
->
beConstructedWith
(
$this
->
entitiesBuilder
);
}
...
...
@@ -83,9 +81,9 @@ class ManagerSpec extends ObjectBehavior
{
$permissions
=
$this
->
getList
([
'user_guid'
=>
1
,
'guids'
=>
[
10
,
11
,
12
,
13
],
'entities'
=>
[]
]);
'guids'
=>
[
10
,
11
,
12
,
13
],
'entities'
=>
[]
,
]);
$entities
=
$permissions
->
getEntities
();
$entities
->
shouldHaveKey
(
10
);
$entities
->
shouldHaveKey
(
11
);
...
...
This diff is collapsed.
Click to expand it.