mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-05-02 07:20:05 +00:00
Started rolling out user slugs to model and core controllers
This commit is contained in:
parent
3a9caea846
commit
19d79b6a0f
8 changed files with 67 additions and 29 deletions
app
Auth
Entities/Models
Http/Controllers
Interfaces
resources/views/common
routes
|
@ -1,6 +1,7 @@
|
||||||
<?php namespace BookStack\Auth;
|
<?php namespace BookStack\Auth;
|
||||||
|
|
||||||
use BookStack\Api\ApiToken;
|
use BookStack\Api\ApiToken;
|
||||||
|
use BookStack\Entities\Tools\SlugGenerator;
|
||||||
use BookStack\Interfaces\Loggable;
|
use BookStack\Interfaces\Loggable;
|
||||||
use BookStack\Interfaces\Sluggable;
|
use BookStack\Interfaces\Sluggable;
|
||||||
use BookStack\Model;
|
use BookStack\Model;
|
||||||
|
@ -266,7 +267,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
|
||||||
*/
|
*/
|
||||||
public function getProfileUrl(): string
|
public function getProfileUrl(): string
|
||||||
{
|
{
|
||||||
return url('/user/' . $this->id);
|
return url('/user/' . $this->slug);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -303,4 +304,13 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
|
||||||
{
|
{
|
||||||
return "({$this->id}) {$this->name}";
|
return "({$this->id}) {$this->name}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function refreshSlug(): string
|
||||||
|
{
|
||||||
|
$this->slug = app(SlugGenerator::class)->generate($this);
|
||||||
|
return $this->slug;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,14 @@ class UserRepo
|
||||||
return User::query()->findOrFail($id);
|
return User::query()->findOrFail($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a user by their slug.
|
||||||
|
*/
|
||||||
|
public function getBySlug(string $slug): User
|
||||||
|
{
|
||||||
|
return User::query()->where('slug', '=', $slug)->firstOrFail();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all the users with their permissions.
|
* Get all the users with their permissions.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -290,11 +290,11 @@ abstract class Entity extends Model implements Sluggable
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate and set a new URL slug for this model.
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
public function refreshSlug(): string
|
public function refreshSlug(): string
|
||||||
{
|
{
|
||||||
$this->slug = (new SlugGenerator)->generate($this);
|
$this->slug = app(SlugGenerator::class)->generate($this);
|
||||||
return $this->slug;
|
return $this->slug;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,13 @@ use BookStack\Auth\Access\SocialAuthService;
|
||||||
use BookStack\Auth\Access\UserInviteService;
|
use BookStack\Auth\Access\UserInviteService;
|
||||||
use BookStack\Auth\User;
|
use BookStack\Auth\User;
|
||||||
use BookStack\Auth\UserRepo;
|
use BookStack\Auth\UserRepo;
|
||||||
|
use BookStack\Exceptions\ImageUploadException;
|
||||||
use BookStack\Exceptions\UserUpdateException;
|
use BookStack\Exceptions\UserUpdateException;
|
||||||
use BookStack\Uploads\ImageRepo;
|
use BookStack\Uploads\ImageRepo;
|
||||||
|
use Exception;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
class UserController extends Controller
|
class UserController extends Controller
|
||||||
{
|
{
|
||||||
|
@ -61,7 +64,7 @@ class UserController extends Controller
|
||||||
/**
|
/**
|
||||||
* Store a newly created user in storage.
|
* Store a newly created user in storage.
|
||||||
* @throws UserUpdateException
|
* @throws UserUpdateException
|
||||||
* @throws \Illuminate\Validation\ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
|
@ -90,6 +93,7 @@ class UserController extends Controller
|
||||||
$user->external_auth_id = $request->get('external_auth_id');
|
$user->external_auth_id = $request->get('external_auth_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$user->refreshSlug();
|
||||||
$user->save();
|
$user->save();
|
||||||
|
|
||||||
if ($sendInvite) {
|
if ($sendInvite) {
|
||||||
|
@ -132,8 +136,8 @@ class UserController extends Controller
|
||||||
/**
|
/**
|
||||||
* Update the specified user in storage.
|
* Update the specified user in storage.
|
||||||
* @throws UserUpdateException
|
* @throws UserUpdateException
|
||||||
* @throws \BookStack\Exceptions\ImageUploadException
|
* @throws ImageUploadException
|
||||||
* @throws \Illuminate\Validation\ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
public function update(Request $request, int $id)
|
public function update(Request $request, int $id)
|
||||||
{
|
{
|
||||||
|
@ -157,6 +161,11 @@ class UserController extends Controller
|
||||||
$user->email = $request->get('email');
|
$user->email = $request->get('email');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Refresh the slug if the user's name has changed
|
||||||
|
if ($user->isDirty('name')) {
|
||||||
|
$user->refreshSlug();
|
||||||
|
}
|
||||||
|
|
||||||
// Role updates
|
// Role updates
|
||||||
if (userCan('users-manage') && $request->filled('roles')) {
|
if (userCan('users-manage') && $request->filled('roles')) {
|
||||||
$roles = $request->get('roles');
|
$roles = $request->get('roles');
|
||||||
|
@ -216,7 +225,7 @@ class UserController extends Controller
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the specified user from storage.
|
* Remove the specified user from storage.
|
||||||
* @throws \Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function destroy(Request $request, int $id)
|
public function destroy(Request $request, int $id)
|
||||||
{
|
{
|
||||||
|
@ -243,25 +252,6 @@ class UserController extends Controller
|
||||||
return redirect('/settings/users');
|
return redirect('/settings/users');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Show the user profile page
|
|
||||||
*/
|
|
||||||
public function showProfilePage($id)
|
|
||||||
{
|
|
||||||
$user = $this->userRepo->getById($id);
|
|
||||||
|
|
||||||
$userActivity = $this->userRepo->getActivity($user);
|
|
||||||
$recentlyCreated = $this->userRepo->getRecentlyCreated($user, 5);
|
|
||||||
$assetCounts = $this->userRepo->getAssetCounts($user);
|
|
||||||
|
|
||||||
return view('users.profile', [
|
|
||||||
'user' => $user,
|
|
||||||
'activity' => $userActivity,
|
|
||||||
'recentlyCreated' => $recentlyCreated,
|
|
||||||
'assetCounts' => $assetCounts
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the user's preferred book-list display setting.
|
* Update the user's preferred book-list display setting.
|
||||||
*/
|
*/
|
||||||
|
|
25
app/Http/Controllers/UserProfileController.php
Normal file
25
app/Http/Controllers/UserProfileController.php
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
<?php namespace BookStack\Http\Controllers;
|
||||||
|
|
||||||
|
use BookStack\Auth\UserRepo;
|
||||||
|
|
||||||
|
class UserProfileController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Show the user profile page
|
||||||
|
*/
|
||||||
|
public function show(UserRepo $repo, string $slug)
|
||||||
|
{
|
||||||
|
$user = $repo->getBySlug($slug);
|
||||||
|
|
||||||
|
$userActivity = $repo->getActivity($user);
|
||||||
|
$recentlyCreated = $repo->getRecentlyCreated($user, 5);
|
||||||
|
$assetCounts = $repo->getAssetCounts($user);
|
||||||
|
|
||||||
|
return view('users.profile', [
|
||||||
|
'user' => $user,
|
||||||
|
'activity' => $userActivity,
|
||||||
|
'recentlyCreated' => $recentlyCreated,
|
||||||
|
'assetCounts' => $assetCounts
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,4 +15,9 @@ use Illuminate\Database\Eloquent\Builder;
|
||||||
interface Sluggable
|
interface Sluggable
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Regenerate the slug for this model.
|
||||||
|
*/
|
||||||
|
public function refreshSlug(): string;
|
||||||
|
|
||||||
}
|
}
|
|
@ -58,10 +58,10 @@
|
||||||
</span>
|
</span>
|
||||||
<ul refs="dropdown@menu" class="dropdown-menu" role="menu">
|
<ul refs="dropdown@menu" class="dropdown-menu" role="menu">
|
||||||
<li>
|
<li>
|
||||||
<a href="{{ url("/user/{$currentUser->id}") }}">@icon('user'){{ trans('common.view_profile') }}</a>
|
<a href="{{ $currentUser->getProfileUrl() }}">@icon('user'){{ trans('common.view_profile') }}</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<a href="{{ url("/settings/users/{$currentUser->id}") }}">@icon('edit'){{ trans('common.edit_profile') }}</a>
|
<a href="{{ $currentUser->getEditUrl() }}">@icon('edit'){{ trans('common.edit_profile') }}</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
@if(config('auth.method') === 'saml2')
|
@if(config('auth.method') === 'saml2')
|
||||||
|
|
|
@ -99,7 +99,7 @@ Route::group(['middleware' => 'auth'], function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
// User Profile routes
|
// User Profile routes
|
||||||
Route::get('/user/{userId}', 'UserController@showProfilePage');
|
Route::get('/user/{slug}', 'UserProfileController@show');
|
||||||
|
|
||||||
// Image routes
|
// Image routes
|
||||||
Route::get('/images/gallery', 'Images\GalleryImageController@list');
|
Route::get('/images/gallery', 'Images\GalleryImageController@list');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue