Skip to content

Commit a9ccf52

Browse files
"Fix Lint JS and PHP"
1 parent dd257dc commit a9ccf52

15 files changed

+154
-235
lines changed

app/App/HomeController.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ public function index(
4343
$recents = $this->isSignedIn() ?
4444
$recentlyViewed->run(12 * $recentFactor, 1)
4545
: $this->queries->books->visibleForList()->orderBy('created_at', 'desc')->take(12 * $recentFactor)->get();
46-
$recents = $recents->filter(function($recent){
47-
if($recent instanceof Page) {
46+
$recents = $recents->filter(function ($recent) {
47+
if ($recent instanceof Page) {
4848
return !$recent->is_encrypted;
4949
}
5050
return true;
5151
});
5252
$favourites = $topFavourites->run(6);
5353
$recentlyUpdatedPages = $this->queries->pages->visibleForList()
5454
->where('draft', false)
55-
->where('is_encrypted',false)
55+
->where('is_encrypted', false)
5656
->orderBy('updated_at', 'desc')
5757
->take($favourites->count() > 0 ? 5 : 10)
5858
->get();

app/Entities/Controllers/PageController.php

+23-31
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,7 @@ public function edit(Request $request, string $bookSlug, string $pageSlug)
199199
$page = $this->queries->findVisibleBySlugsOrFail($bookSlug, $pageSlug);
200200
$this->checkOwnablePermission('page-update', $page);
201201

202-
if(session()->get('is_decrypt') == 'FOR_EDIT')
203-
{
202+
if (session()->get('is_decrypt') == 'FOR_EDIT') {
204203
$page->html = decrypt($page->html);
205204
session()->remove('is_decrypt');
206205
}
@@ -229,10 +228,9 @@ public function update(Request $request, string $bookSlug, string $pageSlug)
229228
$page = $this->queries->findVisibleBySlugsOrFail($bookSlug, $pageSlug);
230229
$this->checkOwnablePermission('page-update', $page);
231230

232-
if($page->is_decrypt == 'FOR_EDIT')
233-
{
231+
if (session()->get('is_decrypt') == 'FOR_EDIT') {
234232
$request['html'] = encrypt($request['html']);
235-
$request['is_decrypt'] = 'NONE';
233+
session()->put('is_decrypt', 'NONE');
236234
}
237235

238236
$this->pageRepo->update($page, $request->all());
@@ -481,56 +479,50 @@ public function copy(Request $request, Cloner $cloner, string $bookSlug, string
481479
return redirect($pageCopy->getUrl());
482480
}
483481

484-
public function encrypt(Request $request,string $bookSlug, string $pageSlug)
482+
public function encrypt(Request $request, string $bookSlug, string $pageSlug)
485483
{
486-
$page = $this->queries->findVisibleBySlugsOrFail($bookSlug,$pageSlug);
487-
return $this->pageRepo->encryptPageContent($request->all(),$page);
484+
$page = $this->queries->findVisibleBySlugsOrFail($bookSlug, $pageSlug);
485+
return $this->pageRepo->encryptPageContent($request->all(), $page);
488486
}
489487

490-
public function decrypt(Request $request,string $bookSlug, string $pageSlug)
488+
public function decrypt(Request $request, string $bookSlug, string $pageSlug)
491489
{
492-
$page = $this->queries->findVisibleBySlugsOrFail($bookSlug,$pageSlug);
493-
return $this->pageRepo->decryptPageContent($request->all(),$page);
490+
$page = $this->queries->findVisibleBySlugsOrFail($bookSlug, $pageSlug);
491+
return $this->pageRepo->decryptPageContent($request->all(), $page);
494492
}
495493

496-
public function updateEncryption(Request $request,string $bookSlug, string $pageSlug)
494+
public function updateEncryption(Request $request, string $bookSlug, string $pageSlug)
497495
{
498-
$this->validate($request,[
496+
$this->validate($request, [
499497
'html' => ['required'],
500498
'decrypt_password' => ['required'],
501499
'is_encrypted' => ['required','boolean'],
502500
]);
503501

504-
$page = $this->queries->findVisibleBySlugsOrFail($bookSlug,$pageSlug);
502+
$page = $this->queries->findVisibleBySlugsOrFail($bookSlug, $pageSlug);
505503
$this->pageRepo->update($page, $request->all());
506504
return response()->json(['message' => 'Encryption Update SuccessFully','success' => true]);
507-
508505
}
509506

510-
public function updateDecryption(Request $request,string $bookSlug, string $pageSlug)
507+
public function updateDecryption(Request $request, string $bookSlug, string $pageSlug)
511508
{
512-
$page = $this->queries->findVisibleBySlugsOrFail($bookSlug,$pageSlug);
513-
if($this->validateDecryptPassword($request, $bookSlug, $pageSlug))
514-
{
515-
if($request->has('is_decrypt'))
516-
{
517-
session()->put('is_decrypt',$request->get('is_decrypt'));
518-
\Log::info('Update : ' .session()->get('is_decrypt'));
509+
$page = $this->queries->findVisibleBySlugsOrFail($bookSlug, $pageSlug);
510+
if ($this->validateDecryptPassword($request, $bookSlug, $pageSlug)) {
511+
if ($request->has('is_decrypt')) {
512+
session()->put('is_decrypt', $request->get('is_decrypt'));
519513
}
520514
$this->pageRepo->update($page, $request->all());
521515
return response()->json(['contents' => [],'message' => 'Decrypted SuccessFully','success' => true]);
522-
}
523-
else
524-
{
516+
} else {
525517
return response()->json(['contents' => [],'message' => 'Decrypt Password is Wrong','success' => false]);
526518
}
527519
}
528520

529-
public function validateDecryptPassword(Request $request,string $bookSlug, string $pageSlug)
521+
public function validateDecryptPassword(Request $request, string $bookSlug, string $pageSlug)
530522
{
531-
$page = $this->queries->findVisibleBySlugsOrFail($bookSlug,$pageSlug);
532-
return Hash::check($request->get('decrypt_password'),$page->decrypt_password) ?
533-
response()->json(['success'=>true]) :
534-
response()->json(['success'=>false]);
523+
$page = $this->queries->findVisibleBySlugsOrFail($bookSlug, $pageSlug);
524+
return Hash::check($request->get('decrypt_password'), $page->decrypt_password) ?
525+
response()->json(['success' => true]) :
526+
response()->json(['success' => false]);
535527
}
536528
}

app/Entities/Controllers/PageExportController.php

+5-10
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function plainText(string $bookSlug, string $pageSlug)
6161
{
6262
$page = $this->queries->findVisibleBySlugsOrFail($bookSlug, $pageSlug);
6363
$this->validatePageEncrypted($page);
64-
$pageText = $this->exportFormatter->pageToPlainText($page,$page->is_encrypted);
64+
$pageText = $this->exportFormatter->pageToPlainText($page, $page->is_encrypted);
6565

6666
return $this->download()->directly($pageText, $pageSlug . '.txt');
6767
}
@@ -82,17 +82,12 @@ public function markdown(string $bookSlug, string $pageSlug)
8282

8383
public function validatePageEncrypted(Page $page)
8484
{
85-
86-
if($page->is_encrypted)
87-
{
88-
if(session()->get('is_decrypt') == 'FOR_EXPORT')
89-
{
85+
if ($page->is_encrypted) {
86+
if (session()->get('is_decrypt') == 'FOR_EXPORT') {
9087
$page->html = decrypt($page->html);
91-
session()->put('is_decrypt','NONE');
88+
session()->put('is_decrypt', 'NONE');
9289
return true;
93-
}
94-
else
95-
{
90+
} else {
9691
return redirect($page->getUrl());
9792
}
9893
}

app/Entities/Repos/BaseRepo.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ public function update(Entity $entity, array $input)
7676
}
7777

7878
$entity->rebuildPermissions();
79-
if((array_key_exists('is_encrypted',$input) && $input['is_encrypted'] == true) || !(($entity InstanceOf Page) && $entity->is_encrypted == true))
80-
{
79+
if ((array_key_exists('is_encrypted', $input) && $input['is_encrypted'] == true) || !(($entity instanceof Page) && $entity->is_encrypted == true)) {
8180
$entity->indexForSearch();
8281
}
8382
$this->referenceStore->updateForEntity($entity);

app/Entities/Repos/PageRepo.php

+11-25
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,10 @@ public function update(Page $page, array $input): Page
100100
$oldMarkdown = $page->markdown;
101101

102102
//Make Hashable decrypt Password
103-
if(array_key_exists('decrypt_password',$input))
104-
{
103+
if (array_key_exists('decrypt_password', $input)) {
105104
$input['decrypt_password'] = Hash::make($input['decrypt_password']);
106105
}
107-
106+
108107
$this->updateTemplateStatusAndContentFromInput($page, $input);
109108
$this->baseRepo->update($page, $input);
110109

@@ -124,19 +123,13 @@ public function update(Page $page, array $input): Page
124123
$this->revisionRepo->storeNewForPage($page, $summary);
125124
}
126125

127-
if(array_key_exists('is_encrypted',$input))
128-
{
129-
if($input['is_encrypted'] == true)
130-
{
126+
if (array_key_exists('is_encrypted', $input)) {
127+
if ($input['is_encrypted'] == true) {
131128
Activity::add(ActivityType::PAGE_ENCRYPTED, $page);
132-
}
133-
else if($input['is_encrypted'] == false)
134-
{
129+
} else if ($input['is_encrypted'] == false) {
135130
Activity::add(ActivityType::PAGE_DECRYPTED, $page);
136131
}
137-
}
138-
else if(!array_key_exists('is_decrypt',$input))
139-
{
132+
} else if (!array_key_exists('is_decrypt', $input)) {
140133
Activity::add(ActivityType::PAGE_UPDATE, $page);
141134
}
142135

@@ -304,28 +297,21 @@ protected function getNewPriority(Page $page): int
304297

305298
public function encryptPageContent(array $data, Page $page)
306299
{
307-
if(!$page->is_encrypted)
308-
{
300+
if (!$page->is_encrypted) {
309301
$content = encrypt($data['content']);
310302
return response()->json(['content' => $content,'message' => 'Encrypted SuccessFully','success' => true]);
311-
}
312-
else
313-
{
303+
} else {
314304
return response()->json(['content' => '','message' => 'Already Encrypted','success' => false]);
315305
}
316306
}
317307

318308
public function decryptPageContent(array $data, Page $page)
319309
{
320-
if($page->is_encrypted)
321-
{
322-
if(Hash::check($data['decrypt_password'],$page->decrypt_password))
323-
{
310+
if ($page->is_encrypted) {
311+
if (Hash::check($data['decrypt_password'], $page->decrypt_password)) {
324312
$content = decrypt($data['content']);
325313
return response()->json(['content' => $content,'message' => 'Decrypted SuccessFully','success' => true]);
326-
}
327-
else
328-
{
314+
} else {
329315
return response()->json(['contents' => [],'message' => 'Decrypt Password is Wrong','success' => false]);
330316
}
331317
}

app/Entities/Tools/BookContents.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function getTree(bool $showDrafts = false, bool $renderPages = false): Co
4444
$pages = $this->getPages($showDrafts, $renderPages);
4545

4646
// Check For Encrypted Pages
47-
$pages->each(function($page){
47+
$pages->each(function ($page) {
4848
$page->html = $page->is_encrypted ? '<p>This page is encrypted</p>' : $page->html;
4949
});
5050

app/Entities/Tools/ExportFormatter.php

+4-8
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,7 @@ public function chapterToPlainText(Chapter $chapter): string
272272

273273
$parts = [];
274274
foreach ($chapter->getVisiblePages() as $page) {
275-
if($page->is_encrypted)
276-
{
275+
if ($page->is_encrypted) {
277276
$page->html = "<p>This page is Encrypted</p>";
278277
}
279278
$parts[] = $this->pageToPlainText($page, false, true);
@@ -296,8 +295,7 @@ public function bookToPlainText(Book $book): string
296295
if ($bookChild->isA('chapter')) {
297296
$parts[] = $this->chapterToPlainText($bookChild);
298297
} else {
299-
if($bookChild->is_encrypted)
300-
{
298+
if ($bookChild->is_encrypted) {
301299
$bookChild->html = "<p>This page is Encrypted</p>";
302300
}
303301
$parts[] = $this->pageToPlainText($bookChild, true, true);
@@ -327,8 +325,7 @@ public function chapterToMarkdown(Chapter $chapter): string
327325
$text = '# ' . $chapter->name . "\n\n";
328326
$text .= $chapter->description . "\n\n";
329327
foreach ($chapter->pages as $page) {
330-
if($page->is_encrypted)
331-
{
328+
if ($page->is_encrypted) {
332329
$page->html = "<p>This page is Encrypted</p>";
333330
}
334331
$text .= $this->pageToMarkdown($page) . "\n\n";
@@ -348,8 +345,7 @@ public function bookToMarkdown(Book $book): string
348345
if ($bookChild instanceof Chapter) {
349346
$text .= $this->chapterToMarkdown($bookChild) . "\n\n";
350347
} else {
351-
if($bookChild->is_encrypted)
352-
{
348+
if ($bookChild->is_encrypted) {
353349
$bookChild->html = "<p>This page is Encrypted</p>";
354350
}
355351
$text .= $this->pageToMarkdown($bookChild) . "\n\n";

app/Search/SearchRunner.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ protected function buildQuery(SearchOptions $searchOpts, string $entityType): El
159159
$inputTerm = str_replace('\\', '\\\\', $exact->value);
160160
$query->where('name', 'like', '%' . $inputTerm . '%')
161161
->orWhere($entityModelInstance->textField, 'like', '%' . $inputTerm . '%');
162-
if ($entityModelInstance instanceof Page) {
163-
$query->Where('is_encrypted','!=',1);
164-
}
162+
if ($entityModelInstance instanceof Page) {
163+
$query->Where('is_encrypted', '!=', 1);
164+
}
165165
};
166166

167167
$exact->negated ? $entityQuery->whereNot($filter) : $entityQuery->where($filter);

database/migrations/2024_11_25_123200_add_new_permissions.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ public function up(): void
1515
{
1616
// get Admin Role Id
1717
$adminRoleId = DB::table('roles')->where('display_name', '=', 'admin')->first()->id;
18-
18+
1919
// Create & attach new entity permissions
2020
$entities = ['Book', 'Page', 'Chapter', 'bookshelf'];
2121
$ops = ['Restrict All', 'Restrict Own','Encrypt All','Encrypt Own'];
2222
foreach ($entities as $entity) {
2323
foreach ($ops as $op) {
24-
if(($op === 'Encrypt All' || $op === 'Encrypt Own') && $entity !== 'Page'){
24+
if (($op === 'Encrypt All' || $op === 'Encrypt Own') && $entity !== 'Page') {
2525
break;
2626
}
2727
$permissionId = DB::table('role_permissions')->insertGetId([
@@ -36,7 +36,6 @@ public function up(): void
3636
]);
3737
}
3838
}
39-
4039
}
4140

4241
/**

database/migrations/2024_11_27_080138_add_is_encrypted_column_in_pages.php

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
public function up(): void
1313
{
1414
Schema::table('pages', function (Blueprint $table) {
15-
1615
$table->boolean('is_encrypted')->after('priority')->default(false);
1716
$table->boolean('is_decrypt')->after('is_encrypted');
1817
$table->text('decrypt_password')->after('is_encrypted');

resources/js/components/collapsible.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class Collapsible extends Component {
1313
this.content = this.$refs.content;
1414

1515
if (this.trigger) {
16-
this.trigger.addEventListener('click',this.toggle.bind(this));
16+
this.trigger.addEventListener('click', this.toggle.bind(this));
1717
this.openIfContainsError();
1818
}
1919
}

0 commit comments

Comments
 (0)