Skip to content

Commit da941e5

Browse files
committed
Merge branch 'master' into release ready for v0.14
2 parents 65874d7 + 380f0f2 commit da941e5

File tree

199 files changed

+5193
-2916
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

199 files changed

+5193
-2916
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
### For Feature Requests
2+
23
Desired Feature:
34

45
### For Bug Reports
5-
PHP Version:
66

7-
MySQL Version:
7+
* BookStack Version:
8+
* PHP Version:
9+
* MySQL Version:
810

9-
Expected Behavior:
11+
##### Expected Behavior
1012

11-
Actual Behavior:
13+
##### Actual Behavior

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ _ide_helper.php
1313
/storage/debugbar
1414
.phpstorm.meta.php
1515
yarn.lock
16+
/bin

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ addons:
1717

1818
before_script:
1919
- mysql -u root -e 'create database `bookstack-test`;'
20-
- composer config -g github-oauth.github.com $GITHUB_ACCESS_TOKEN
2120
- phpenv config-rm xdebug.ini
22-
- composer self-update
2321
- composer dump-autoload --no-interaction
2422
- composer install --prefer-dist --no-interaction
2523
- php artisan clear-compiled -n

app/Chapter.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ class Chapter extends Entity
55
{
66
protected $fillable = ['name', 'description', 'priority', 'book_id'];
77

8+
protected $with = ['book'];
9+
810
/**
911
* Get the book this chapter is within.
1012
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
@@ -16,11 +18,12 @@ public function book()
1618

1719
/**
1820
* Get the pages that this chapter contains.
21+
* @param string $dir
1922
* @return mixed
2023
*/
21-
public function pages()
24+
public function pages($dir = 'ASC')
2225
{
23-
return $this->hasMany(Page::class)->orderBy('priority', 'ASC');
26+
return $this->hasMany(Page::class)->orderBy('priority', $dir);
2427
}
2528

2629
/**

app/Entity.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
class Entity extends Ownable
55
{
66

7+
protected $fieldsToSearch = ['name', 'description'];
8+
79
/**
810
* Compares this entity to another given entity.
911
* Matches by comparing class and id.
@@ -157,7 +159,7 @@ public function getShortName($length = 25)
157159
* @param string[] array $wheres
158160
* @return mixed
159161
*/
160-
public function fullTextSearchQuery($fieldsToSearch, $terms, $wheres = [])
162+
public function fullTextSearchQuery($terms, $wheres = [])
161163
{
162164
$exactTerms = [];
163165
$fuzzyTerms = [];
@@ -181,16 +183,16 @@ public function fullTextSearchQuery($fieldsToSearch, $terms, $wheres = [])
181183
// Perform fulltext search if relevant terms exist.
182184
if ($isFuzzy) {
183185
$termString = implode(' ', $fuzzyTerms);
184-
$fields = implode(',', $fieldsToSearch);
186+
$fields = implode(',', $this->fieldsToSearch);
185187
$search = $search->selectRaw('*, MATCH(name) AGAINST(? IN BOOLEAN MODE) AS title_relevance', [$termString]);
186188
$search = $search->whereRaw('MATCH(' . $fields . ') AGAINST(? IN BOOLEAN MODE)', [$termString]);
187189
}
188190

189191
// Ensure at least one exact term matches if in search
190192
if (count($exactTerms) > 0) {
191-
$search = $search->where(function ($query) use ($exactTerms, $fieldsToSearch) {
193+
$search = $search->where(function ($query) use ($exactTerms) {
192194
foreach ($exactTerms as $exactTerm) {
193-
foreach ($fieldsToSearch as $field) {
195+
foreach ($this->fieldsToSearch as $field) {
194196
$query->orWhere($field, 'like', $exactTerm);
195197
}
196198
}

app/Http/Controllers/AttachmentController.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@
22

33
use BookStack\Exceptions\FileUploadException;
44
use BookStack\Attachment;
5-
use BookStack\Repos\PageRepo;
5+
use BookStack\Repos\EntityRepo;
66
use BookStack\Services\AttachmentService;
77
use Illuminate\Http\Request;
88

99
class AttachmentController extends Controller
1010
{
1111
protected $attachmentService;
1212
protected $attachment;
13-
protected $pageRepo;
13+
protected $entityRepo;
1414

1515
/**
1616
* AttachmentController constructor.
1717
* @param AttachmentService $attachmentService
1818
* @param Attachment $attachment
19-
* @param PageRepo $pageRepo
19+
* @param EntityRepo $entityRepo
2020
*/
21-
public function __construct(AttachmentService $attachmentService, Attachment $attachment, PageRepo $pageRepo)
21+
public function __construct(AttachmentService $attachmentService, Attachment $attachment, EntityRepo $entityRepo)
2222
{
2323
$this->attachmentService = $attachmentService;
2424
$this->attachment = $attachment;
25-
$this->pageRepo = $pageRepo;
25+
$this->entityRepo = $entityRepo;
2626
parent::__construct();
2727
}
2828

@@ -40,7 +40,7 @@ public function upload(Request $request)
4040
]);
4141

4242
$pageId = $request->get('uploaded_to');
43-
$page = $this->pageRepo->getById($pageId, true);
43+
$page = $this->entityRepo->getById('page', $pageId, true);
4444

4545
$this->checkPermission('attachment-create-all');
4646
$this->checkOwnablePermission('page-update', $page);
@@ -70,14 +70,14 @@ public function uploadUpdate($attachmentId, Request $request)
7070
]);
7171

7272
$pageId = $request->get('uploaded_to');
73-
$page = $this->pageRepo->getById($pageId, true);
73+
$page = $this->entityRepo->getById('page', $pageId, true);
7474
$attachment = $this->attachment->findOrFail($attachmentId);
7575

7676
$this->checkOwnablePermission('page-update', $page);
7777
$this->checkOwnablePermission('attachment-create', $attachment);
7878

7979
if (intval($pageId) !== intval($attachment->uploaded_to)) {
80-
return $this->jsonError('Page mismatch during attached file update');
80+
return $this->jsonError(trans('errors.attachment_page_mismatch'));
8181
}
8282

8383
$uploadedFile = $request->file('file');
@@ -106,18 +106,18 @@ public function update($attachmentId, Request $request)
106106
]);
107107

108108
$pageId = $request->get('uploaded_to');
109-
$page = $this->pageRepo->getById($pageId, true);
109+
$page = $this->entityRepo->getById('page', $pageId, true);
110110
$attachment = $this->attachment->findOrFail($attachmentId);
111111

112112
$this->checkOwnablePermission('page-update', $page);
113113
$this->checkOwnablePermission('attachment-create', $attachment);
114114

115115
if (intval($pageId) !== intval($attachment->uploaded_to)) {
116-
return $this->jsonError('Page mismatch during attachment update');
116+
return $this->jsonError(trans('errors.attachment_page_mismatch'));
117117
}
118118

119119
$attachment = $this->attachmentService->updateFile($attachment, $request->all());
120-
return $attachment;
120+
return response()->json($attachment);
121121
}
122122

123123
/**
@@ -134,7 +134,7 @@ public function attachLink(Request $request)
134134
]);
135135

136136
$pageId = $request->get('uploaded_to');
137-
$page = $this->pageRepo->getById($pageId, true);
137+
$page = $this->entityRepo->getById('page', $pageId, true);
138138

139139
$this->checkPermission('attachment-create-all');
140140
$this->checkOwnablePermission('page-update', $page);
@@ -153,7 +153,7 @@ public function attachLink(Request $request)
153153
*/
154154
public function listForPage($pageId)
155155
{
156-
$page = $this->pageRepo->getById($pageId, true);
156+
$page = $this->entityRepo->getById('page', $pageId, true);
157157
$this->checkOwnablePermission('page-view', $page);
158158
return response()->json($page->attachments);
159159
}
@@ -170,12 +170,12 @@ public function sortForPage($pageId, Request $request)
170170
'files' => 'required|array',
171171
'files.*.id' => 'required|integer',
172172
]);
173-
$page = $this->pageRepo->getById($pageId);
173+
$page = $this->entityRepo->getById('page', $pageId);
174174
$this->checkOwnablePermission('page-update', $page);
175175

176176
$attachments = $request->get('files');
177177
$this->attachmentService->updateFileOrderWithinPage($attachments, $pageId);
178-
return response()->json(['message' => 'Attachment order updated']);
178+
return response()->json(['message' => trans('entities.attachments_order_updated')]);
179179
}
180180

181181
/**
@@ -186,7 +186,7 @@ public function sortForPage($pageId, Request $request)
186186
public function get($attachmentId)
187187
{
188188
$attachment = $this->attachment->findOrFail($attachmentId);
189-
$page = $this->pageRepo->getById($attachment->uploaded_to);
189+
$page = $this->entityRepo->getById('page', $attachment->uploaded_to);
190190
$this->checkOwnablePermission('page-view', $page);
191191

192192
if ($attachment->external) {
@@ -210,6 +210,6 @@ public function delete($attachmentId)
210210
$attachment = $this->attachment->findOrFail($attachmentId);
211211
$this->checkOwnablePermission('attachment-delete', $attachment);
212212
$this->attachmentService->deleteFile($attachment);
213-
return response()->json(['message' => 'Attachment deleted']);
213+
return response()->json(['message' => trans('entities.attachments_deleted')]);
214214
}
215215
}

app/Http/Controllers/Auth/ForgotPasswordController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function sendResetLinkEmail(Request $request)
5252
);
5353

5454
if ($response === Password::RESET_LINK_SENT) {
55-
$message = 'A password reset link has been sent to ' . $request->get('email') . '.';
55+
$message = trans('auth.reset_password_sent_success', ['email' => $request->get('email')]);
5656
session()->flash('success', $message);
5757
return back()->with('status', trans($response));
5858
}

app/Http/Controllers/Auth/LoginController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected function authenticated(Request $request, Authenticatable $user)
8787
// Check for users with same email already
8888
$alreadyUser = $user->newQuery()->where('email', '=', $user->email)->count() > 0;
8989
if ($alreadyUser) {
90-
throw new AuthException('A user with the email ' . $user->email . ' already exists but with different credentials.');
90+
throw new AuthException(trans('errors.error_user_exists_different_creds', ['email' => $user->email]));
9191
}
9292

9393
$user->save();

app/Http/Controllers/Auth/RegisterController.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace BookStack\Http\Controllers\Auth;
44

55
use BookStack\Exceptions\ConfirmationEmailException;
6+
use BookStack\Exceptions\SocialSignInException;
67
use BookStack\Exceptions\UserRegistrationException;
78
use BookStack\Repos\UserRepo;
89
use BookStack\Services\EmailConfirmationService;
@@ -82,7 +83,7 @@ protected function validator(array $data)
8283
protected function checkRegistrationAllowed()
8384
{
8485
if (!setting('registration-enabled')) {
85-
throw new UserRegistrationException('Registrations are currently disabled.', '/login');
86+
throw new UserRegistrationException(trans('auth.registrations_disabled'), '/login');
8687
}
8788
}
8889

@@ -147,7 +148,7 @@ protected function registerUser(array $userData, $socialAccount = false)
147148
$restrictedEmailDomains = explode(',', str_replace(' ', '', setting('registration-restrict')));
148149
$userEmailDomain = $domain = substr(strrchr($userData['email'], "@"), 1);
149150
if (!in_array($userEmailDomain, $restrictedEmailDomains)) {
150-
throw new UserRegistrationException('That email domain does not have access to this application', '/register');
151+
throw new UserRegistrationException(trans('auth.registration_email_domain_invalid'), '/register');
151152
}
152153
}
153154

@@ -169,7 +170,7 @@ protected function registerUser(array $userData, $socialAccount = false)
169170
}
170171

171172
auth()->login($newUser);
172-
session()->flash('success', 'Thanks for signing up! You are now registered and signed in.');
173+
session()->flash('success', trans('auth.register_success'));
173174
return redirect($this->redirectPath());
174175
}
175176

@@ -262,7 +263,7 @@ public function socialCallback($socialDriver)
262263
return $this->socialRegisterCallback($socialDriver);
263264
}
264265
} else {
265-
throw new SocialSignInException('No action defined', '/login');
266+
throw new SocialSignInException(trans('errors.social_no_action_defined'), '/login');
266267
}
267268
return redirect()->back();
268269
}

app/Http/Controllers/Auth/ResetPasswordController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function __construct()
4141
*/
4242
protected function sendResetResponse($response)
4343
{
44-
$message = 'Your password has been successfully reset.';
44+
$message = trans('auth.reset_password_success');
4545
session()->flash('success', $message);
4646
return redirect($this->redirectPath())
4747
->with('status', trans($response));

0 commit comments

Comments
 (0)