Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Зуев Егор
/
wiki.dev
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Authored by
Dan Brown
2016-03-05 12:09:09 +0000
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Commit
268db6b1d0409766014ae9f1681ec1bf5bab7552
268db6b1
1 parent
8e274a5a
Added a whole load of permission & role tests
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
21 additions
and
7 deletions
app/Activity.php
app/Http/Controllers/UserController.php
app/Repos/BookRepo.php
app/Repos/PermissionsRepo.php
app/User.php
resources/views/partials/activity-item.blade.php
resources/views/settings/roles/form.blade.php
tests/RolesTest.php
tests/TestCase.php
app/Activity.php
View file @
268db6b
...
...
@@ -15,10 +15,10 @@ class Activity extends Model
/**
* Get the entity for this activity.
* @return bool
*/
public
function
entity
()
{
if
(
$this
->
entity_type
===
''
)
$this
->
entity_type
=
null
;
return
$this
->
morphTo
(
'entity'
);
}
...
...
app/Http/Controllers/UserController.php
View file @
268db6b
...
...
@@ -35,6 +35,7 @@ class UserController extends Controller
*/
public
function
index
()
{
$this
->
checkPermission
(
'users-manage'
);
$users
=
$this
->
userRepo
->
getAllUsers
();
$this
->
setPageTitle
(
'Users'
);
return
view
(
'users/index'
,
[
'users'
=>
$users
]);
...
...
app/Repos/BookRepo.php
View file @
268db6b
...
...
@@ -136,7 +136,7 @@ class BookRepo
*/
public
function
newFromInput
(
$input
)
{
return
$this
->
book
Query
()
->
fill
(
$input
);
return
$this
->
book
->
newInstance
(
$input
);
}
/**
...
...
app/Repos/PermissionsRepo.php
View file @
268db6b
...
...
@@ -101,6 +101,7 @@ class PermissionsRepo
public
function
assignRolePermissions
(
Role
$role
,
$permissionNameArray
=
[])
{
$permissions
=
[];
$permissionNameArray
=
array_values
(
$permissionNameArray
);
if
(
$permissionNameArray
&&
count
(
$permissionNameArray
)
>
0
)
{
$permissions
=
$this
->
permission
->
whereIn
(
'name'
,
$permissionNameArray
)
->
pluck
(
'id'
)
->
toArray
();
}
...
...
app/User.php
View file @
268db6b
...
...
@@ -67,11 +67,12 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
/**
* Get all permissions belonging to a the current user.
* @param bool $cache
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
*/
public
function
permissions
()
public
function
permissions
(
$cache
=
true
)
{
if
(
isset
(
$this
->
permissions
))
return
$this
->
permissions
;
if
(
isset
(
$this
->
permissions
)
&&
$cache
)
return
$this
->
permissions
;
$this
->
load
(
'roles.permissions'
);
$permissions
=
$this
->
roles
->
map
(
function
(
$role
)
{
return
$role
->
permissions
;
...
...
@@ -106,7 +107,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
*/
public
function
attachRoleId
(
$id
)
{
$this
->
roles
()
->
attach
(
[
$id
]
);
$this
->
roles
()
->
attach
(
$id
);
}
/**
...
...
resources/views/partials/activity-item.blade.php
View file @
268db6b
...
...
@@ -16,7 +16,7 @@
{{ $activity->getText() }}
@if($activity->entity
()
)
@if($activity->entity)
<a
href=
"{{ $activity->entity->getUrl() }}"
>
{{ $activity->entity->name }}
</a>
@endif
...
...
resources/views/settings/roles/form.blade.php
View file @
268db6b
...
...
@@ -17,7 +17,7 @@
<label>
@include('settings/roles/checkbox', ['permission' => 'users-manage']) Manage users
</label>
</div>
<div
class=
"col-md-6"
>
<label>
@include('settings/roles/checkbox', ['permission' => 'user-roles-manage']) Manage user roles
&
Permissions
</label>
<label>
@include('settings/roles/checkbox', ['permission' => 'user-roles-manage']) Manage user roles
</label>
</div>
</div>
<hr
class=
"even"
>
...
...
tests/RolesTest.php
View file @
268db6b
This diff is collapsed.
Click to expand it.
tests/TestCase.php
View file @
268db6b
...
...
@@ -85,6 +85,17 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
}
/**
* Quick way to create a new user without any permissions
* @param array $attributes
* @return mixed
*/
protected
function
getNewBlankUser
(
$attributes
=
[])
{
$user
=
factory
(
\BookStack\User
::
class
)
->
create
(
$attributes
);
return
$user
;
}
/**
* Assert that a given string is seen inside an element.
*
* @param bool|string|null $element
...
...
Please
register
or
sign in
to post a comment