Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 5 additions & 5 deletions app/Actions/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@

/**
* @property string $type
* @property User $user
* @property User $user
* @property Entity $entity
* @property string $detail
* @property string $entity_type
* @property int $entity_id
* @property int $user_id
* @property int $entity_id
* @property int $user_id
*/
class Activity extends Model
{

/**
* Get the entity for this activity.
*/
Expand All @@ -29,6 +28,7 @@ public function entity(): MorphTo
if ($this->entity_type === '') {
$this->entity_type = null;
}

return $this->morphTo('entity');
}

Expand All @@ -54,7 +54,7 @@ public function getText(): string
public function isForEntity(): bool
{
return Str::startsWith($this->type, [
'page_', 'chapter_', 'book_', 'bookshelf_'
'page_', 'chapter_', 'book_', 'bookshelf_',
]);
}

Expand Down
19 changes: 12 additions & 7 deletions app/Actions/ActivityService.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace BookStack\Actions;
<?php

namespace BookStack\Actions;

use BookStack\Auth\Permissions\PermissionService;
use BookStack\Auth\User;
Expand Down Expand Up @@ -33,6 +35,7 @@ public function addForEntity(Entity $entity, string $type)

/**
* Add a generic activity event to the database.
*
* @param string|Loggable $detail
*/
public function add(string $type, $detail = '')
Expand All @@ -54,7 +57,7 @@ protected function newActivityForUser(string $type): Activity
{
return $this->activity->newInstance()->forceFill([
'type' => strtolower($type),
'user_id' => user()->id,
'user_id' => user()->id,
]);
}

Expand All @@ -67,8 +70,8 @@ public function removeEntity(Entity $entity)
{
$entity->activity()->update([
'detail' => $entity->name,
'entity_id' => null,
'entity_type' => null,
'entity_id' => null,
'entity_type' => null,
]);
}

Expand Down Expand Up @@ -98,10 +101,10 @@ public function entityActivity(Entity $entity, int $count = 20, int $page = 1):
$queryIds = [$entity->getMorphClass() => [$entity->id]];

if ($entity->isA('book')) {
$queryIds[(new Chapter)->getMorphClass()] = $entity->chapters()->visible()->pluck('id');
$queryIds[(new Chapter())->getMorphClass()] = $entity->chapters()->visible()->pluck('id');
}
if ($entity->isA('book') || $entity->isA('chapter')) {
$queryIds[(new Page)->getMorphClass()] = $entity->pages()->visible()->pluck('id');
$queryIds[(new Page())->getMorphClass()] = $entity->pages()->visible()->pluck('id');
}

$query = $this->activity->newQuery();
Expand Down Expand Up @@ -143,7 +146,9 @@ public function userActivity(User $user, int $count = 20, int $page = 0): array

/**
* Filters out similar activity.
*
* @param Activity[] $activities
*
* @return array
*/
protected function filterSimilar(iterable $activities): array
Expand Down Expand Up @@ -185,7 +190,7 @@ public function logFailedLogin(string $username)
return;
}

$message = str_replace("%u", $username, $message);
$message = str_replace('%u', $username, $message);
$channel = config('logging.failed_login.channel');
Log::channel($channel)->warning($message);
}
Expand Down
4 changes: 3 additions & 1 deletion app/Actions/ActivityType.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace BookStack\Actions;
<?php

namespace BookStack\Actions;

class ActivityType
{
Expand Down
8 changes: 6 additions & 2 deletions app/Actions/Comment.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace BookStack\Actions;
<?php

namespace BookStack\Actions;

use BookStack\Model;
use BookStack\Traits\HasCreatorAndUpdater;
Expand All @@ -18,7 +20,7 @@ class Comment extends Model
protected $appends = ['created', 'updated'];

/**
* Get the entity that this comment belongs to
* Get the entity that this comment belongs to.
*/
public function entity(): MorphTo
{
Expand All @@ -35,6 +37,7 @@ public function isUpdated(): bool

/**
* Get created date as a relative diff.
*
* @return mixed
*/
public function getCreatedAttribute()
Expand All @@ -44,6 +47,7 @@ public function getCreatedAttribute()

/**
* Get updated date as a relative diff.
*
* @return mixed
*/
public function getUpdatedAttribute()
Expand Down
19 changes: 11 additions & 8 deletions app/Actions/CommentRepo.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<?php namespace BookStack\Actions;
<?php

namespace BookStack\Actions;

use BookStack\Entities\Models\Entity;
use League\CommonMark\CommonMarkConverter;
use BookStack\Facades\Activity as ActivityService;
use League\CommonMark\CommonMarkConverter;

/**
* Class CommentRepo
* Class CommentRepo.
*/
class CommentRepo
{

/**
* @var Comment $comment
* @var Comment
*/
protected $comment;


public function __construct(Comment $comment)
{
$this->comment = $comment;
Expand Down Expand Up @@ -46,6 +46,7 @@ public function create(Entity $entity, string $text, ?int $parent_id): Comment

$entity->comments()->save($comment);
ActivityService::addForEntity($entity, ActivityType::COMMENTED_ON);

return $comment;
}

Expand All @@ -58,6 +59,7 @@ public function update(Comment $comment, string $text): Comment
$comment->text = $text;
$comment->html = $this->commentToHtml($text);
$comment->save();

return $comment;
}

Expand All @@ -75,8 +77,8 @@ public function delete(Comment $comment)
public function commentToHtml(string $commentText): string
{
$converter = new CommonMarkConverter([
'html_input' => 'strip',
'max_nesting_level' => 10,
'html_input' => 'strip',
'max_nesting_level' => 10,
'allow_unsafe_links' => false,
]);

Expand All @@ -89,6 +91,7 @@ public function commentToHtml(string $commentText): string
protected function getNextLocalId(Entity $entity): int
{
$comments = $entity->comments(false)->orderBy('local_id', 'desc')->first();

return ($comments->local_id ?? 0) + 1;
}
}
4 changes: 3 additions & 1 deletion app/Actions/Favourite.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace BookStack\Actions;
<?php

namespace BookStack\Actions;

use BookStack\Model;
use Illuminate\Database\Eloquent\Relations\MorphTo;
Expand Down
10 changes: 6 additions & 4 deletions app/Actions/Tag.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace BookStack\Actions;
<?php

namespace BookStack\Actions;

use BookStack\Model;
use Illuminate\Database\Eloquent\Relations\MorphTo;
Expand All @@ -9,7 +11,7 @@ class Tag extends Model
protected $hidden = ['id', 'entity_id', 'entity_type', 'created_at', 'updated_at'];

/**
* Get the entity that this tag belongs to
* Get the entity that this tag belongs to.
*/
public function entity(): MorphTo
{
Expand All @@ -21,14 +23,14 @@ public function entity(): MorphTo
*/
public function nameUrl(): string
{
return url('/search?term=%5B' . urlencode($this->name) .'%5D');
return url('/search?term=%5B' . urlencode($this->name) . '%5D');
}

/**
* Get a full URL to start a tag name and value search for this tag's values.
*/
public function valueUrl(): string
{
return url('/search?term=%5B' . urlencode($this->name) .'%3D' . urlencode($this->value) . '%5D');
return url('/search?term=%5B' . urlencode($this->name) . '%3D' . urlencode($this->value) . '%5D');
}
}
10 changes: 7 additions & 3 deletions app/Actions/TagRepo.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace BookStack\Actions;
<?php

namespace BookStack\Actions;

use BookStack\Auth\Permissions\PermissionService;
use BookStack\Entities\Models\Entity;
Expand All @@ -7,7 +9,6 @@

class TagRepo
{

protected $tag;
protected $permissionService;

Expand Down Expand Up @@ -37,6 +38,7 @@ public function getNameSuggestions(?string $searchTerm): Collection
}

$query = $this->permissionService->filterRestrictedEntityRelations($query, 'tags', 'entity_id', 'entity_type');

return $query->get(['name'])->pluck('name');
}

Expand All @@ -62,11 +64,12 @@ public function getValueSuggestions(?string $searchTerm, ?string $tagName): Coll
}

$query = $this->permissionService->filterRestrictedEntityRelations($query, 'tags', 'entity_id', 'entity_type');

return $query->get(['value'])->pluck('value');
}

/**
* Save an array of tags to an entity
* Save an array of tags to an entity.
*/
public function saveTagsToEntity(Entity $entity, array $tags = []): iterable
{
Expand All @@ -89,6 +92,7 @@ protected function newInstanceFromInput(array $input): Tag
{
$name = trim($input['name']);
$value = isset($input['value']) ? trim($input['value']) : '';

return $this->tag->newInstance(['name' => $name, 'value' => $value]);
}
}
5 changes: 3 additions & 2 deletions app/Actions/View.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace BookStack\Actions;
<?php

namespace BookStack\Actions;

use BookStack\Interfaces\Viewable;
use BookStack\Model;
Expand All @@ -16,7 +18,6 @@
*/
class View extends Model
{

protected $fillable = ['user_id', 'views'];

/**
Expand Down
Loading