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
2015-12-15 19:27:36 +0000
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Commit
af331563697b30912cffdfbb6691f6d6ace03312
af331563
1 parent
123dc115
Fixed name retrieval on missing users and added tests to cover along with some test helper methods
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
89 additions
and
13 deletions
app/Http/Controllers/UserController.php
app/Repos/UserRepo.php
resources/assets/sass/styles.scss
resources/views/books/show.blade.php
resources/views/chapters/show.blade.php
resources/views/pages/show.blade.php
resources/views/partials/activity-item.blade.php
tests/EntityTest.php
tests/TestCase.php
app/Http/Controllers/UserController.php
View file @
af33156
...
...
@@ -159,16 +159,14 @@ class UserController extends Controller
$this
->
checkPermissionOr
(
'user-delete'
,
function
()
use
(
$id
)
{
return
$this
->
currentUser
->
id
==
$id
;
});
$user
=
$this
->
userRepo
->
getById
(
$id
);
// Delete social accounts
$user
=
$this
->
userRepo
->
getById
(
$id
);
if
(
$this
->
userRepo
->
isOnlyAdmin
(
$user
))
{
session
()
->
flash
(
'error'
,
'You cannot delete the only admin'
);
return
redirect
(
$user
->
getEditUrl
());
}
$this
->
userRepo
->
destroy
(
$user
);
$user
->
socialAccounts
()
->
delete
();
$user
->
delete
();
return
redirect
(
'/users'
);
}
}
...
...
app/Repos/UserRepo.php
View file @
af33156
...
...
@@ -46,14 +46,19 @@ class UserRepo
public
function
registerNew
(
array
$data
)
{
$user
=
$this
->
create
(
$data
);
$roleId
=
\Setting
::
get
(
'registration-role'
);
if
(
$roleId
===
false
)
{
$roleId
=
$this
->
role
->
getDefault
()
->
id
;
}
$this
->
attachDefaultRole
(
$user
);
return
$user
;
}
/**
* Give a user the default role. Used when creating a new user.
* @param $user
*/
public
function
attachDefaultRole
(
$user
)
{
$roleId
=
\Setting
::
get
(
'registration-role'
);
if
(
$roleId
===
false
)
$roleId
=
$this
->
role
->
getDefault
()
->
id
;
$user
->
attachRoleId
(
$roleId
);
return
$user
;
}
/**
...
...
@@ -88,4 +93,14 @@ class UserRepo
'password'
=>
bcrypt
(
$data
[
'password'
])
]);
}
/**
* Remove the given user from storage, Delete all related content.
* @param User $user
*/
public
function
destroy
(
User
$user
)
{
$user
->
socialAccounts
()
->
delete
();
$user
->
delete
();
}
}
\ No newline at end of file
...
...
resources/assets/sass/styles.scss
View file @
af33156
...
...
@@ -32,6 +32,8 @@ body.dragging, body.dragging * {
.avatar
{
border-radius
:
100%
;
background-color
:
#EEE
;
width
:
30px
;
height
:
30px
;
&
.med
{
width
:
40px
;
height
:
40px
;
...
...
resources/views/books/show.blade.php
View file @
af33156
...
...
@@ -58,7 +58,7 @@
<p
class=
"text-muted small"
>
Created {{$book->created_at->diffForHumans()}} @if($book->createdBy) by {{$book->createdBy->name}} @endif
<br>
Last Updated {{$book->updated_at->diffForHumans()}} @if($book->
cre
atedBy) by {{$book->updatedBy->name}} @endif
Last Updated {{$book->updated_at->diffForHumans()}} @if($book->
upd
atedBy) by {{$book->updatedBy->name}} @endif
</p>
</div>
</div>
...
...
resources/views/chapters/show.blade.php
View file @
af33156
...
...
@@ -56,7 +56,7 @@
<p
class=
"text-muted small"
>
Created {{$chapter->created_at->diffForHumans()}} @if($chapter->createdBy) by {{$chapter->createdBy->name}} @endif
<br>
Last Updated {{$chapter->updated_at->diffForHumans()}} @if($chapter->
cre
atedBy) by {{$chapter->updatedBy->name}} @endif
Last Updated {{$chapter->updated_at->diffForHumans()}} @if($chapter->
upd
atedBy) by {{$chapter->updatedBy->name}} @endif
</p>
</div>
<div
class=
"col-md-3 col-md-offset-1"
>
...
...
resources/views/pages/show.blade.php
View file @
af33156
...
...
@@ -53,7 +53,7 @@
<p
class=
"text-muted small"
>
Created {{$page->created_at->diffForHumans()}} @if($page->createdBy) by {{$page->createdBy->name}} @endif
<br>
Last Updated {{$page->updated_at->diffForHumans()}} @if($page->
cre
atedBy) by {{$page->updatedBy->name}} @endif
Last Updated {{$page->updated_at->diffForHumans()}} @if($page->
upd
atedBy) by {{$page->updatedBy->name}} @endif
</p>
</div>
...
...
resources/views/partials/activity-item.blade.php
View file @
af33156
...
...
@@ -10,6 +10,8 @@
<div
class=
"right"
>
@if($activity->user)
{{$activity->user->name}}
@else
A deleted user
@endif
{{ $activity->getText() }}
...
...
tests/EntityTest.php
View file @
af33156
...
...
@@ -171,4 +171,29 @@ class EntityTest extends TestCase
}
public
function
testEntitiesViewableAfterCreatorDeletion
()
{
$creator
=
$this
->
getNewUser
();
$updater
=
$this
->
getNewUser
();
$entities
=
$this
->
createEntityChainBelongingToUser
(
$creator
,
$updater
);
app
(
'BookStack\Repos\UserRepo'
)
->
destroy
(
$creator
);
$this
->
asAdmin
()
->
visit
(
$entities
[
'book'
]
->
getUrl
())
->
seeStatusCode
(
200
)
->
visit
(
$entities
[
'chapter'
]
->
getUrl
())
->
seeStatusCode
(
200
)
->
visit
(
$entities
[
'page'
]
->
getUrl
())
->
seeStatusCode
(
200
);
}
public
function
testEntitiesViewableAfterUpdaterDeletion
()
{
$creator
=
$this
->
getNewUser
();
$updater
=
$this
->
getNewUser
();
$entities
=
$this
->
createEntityChainBelongingToUser
(
$creator
,
$updater
);
app
(
'BookStack\Repos\UserRepo'
)
->
destroy
(
$updater
);
$this
->
asAdmin
()
->
visit
(
$entities
[
'book'
]
->
getUrl
())
->
seeStatusCode
(
200
)
->
visit
(
$entities
[
'chapter'
]
->
getUrl
())
->
seeStatusCode
(
200
)
->
visit
(
$entities
[
'page'
]
->
getUrl
())
->
seeStatusCode
(
200
);
}
}
...
...
tests/TestCase.php
View file @
af33156
...
...
@@ -50,6 +50,40 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
}
/**
* Create a group of entities that belong to a specific user.
* @param $creatorUser
* @param $updaterUser
* @return array
*/
protected
function
createEntityChainBelongingToUser
(
$creatorUser
,
$updaterUser
=
false
)
{
if
(
$updaterUser
===
false
)
$updaterUser
=
$creatorUser
;
$book
=
factory
(
BookStack\Book
::
class
)
->
create
([
'created_by'
=>
$creatorUser
->
id
,
'updated_by'
=>
$updaterUser
->
id
]);
$chapter
=
factory
(
BookStack\Chapter
::
class
)
->
create
([
'created_by'
=>
$creatorUser
->
id
,
'updated_by'
=>
$updaterUser
->
id
]);
$page
=
factory
(
BookStack\Page
::
class
)
->
create
([
'created_by'
=>
$creatorUser
->
id
,
'updated_by'
=>
$updaterUser
->
id
,
'book_id'
=>
$book
->
id
]);
$book
->
chapters
()
->
saveMany
([
$chapter
]);
$chapter
->
pages
()
->
saveMany
([
$page
]);
return
[
'book'
=>
$book
,
'chapter'
=>
$chapter
,
'page'
=>
$page
];
}
/**
* Quick way to create a new user
* @param array $attributes
* @return mixed
*/
protected
function
getNewUser
(
$attributes
=
[])
{
$user
=
factory
(
\BookStack\User
::
class
)
->
create
(
$attributes
);
$userRepo
=
app
(
'BookStack\Repos\UserRepo'
);
$userRepo
->
attachDefaultRole
(
$user
);
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