1
0
mirror of https://github.com/flarum/core.git synced 2025-08-13 11:54:32 +02:00

Compare commits

...

10 Commits

Author SHA1 Message Date
SychO9
c5272b330c fix: Escape like strings 2021-08-29 11:57:00 +01:00
Alexander Skvortsov
da94488f7b Update lastSeenAt when authenticating via API (#3058)
Fixes https://github.com/flarum/core/issues/3025, title says it all.
2021-08-27 14:02:03 -04:00
Ian Morland
581d9517db Pass filter params to getApiDocument (#3037)
* Pass filter params to getApiDocument

* Set filters directly
2021-08-26 10:47:34 +01:00
flarum-bot
3db724e0b3 Bundled output for commit 71073b064a
Includes transpiled JS/TS, and Typescript declaration files (typings).

[skip ci]
2021-08-26 09:35:55 +00:00
Rafael Horvat
71073b064a Allow adding page parameters to PaginatedListState, like limit. (#2935) 2021-08-26 10:33:22 +01:00
flarum-bot
d82c093c0f Bundled output for commit c2a0cf8d04
Includes transpiled JS/TS, and Typescript declaration files (typings).

[skip ci]
2021-08-25 17:35:41 +00:00
Sami Mazouz
c2a0cf8d04 fix: Extension admin page erroring out (#3054)
Extension admin pages are currently not working because of a JS error.
The settings record is never defined but directly used, it used to be defined as an empty object in oninit.
2021-08-25 13:33:19 -04:00
SychO9
1b77df12b6 Merge remote-tracking branch 'upstream/1.0.5' 2021-08-25 17:00:45 +01:00
Sami Mazouz
d333d0b0e6 perf: Allow eager loading posts relations of GET discussion endpoint (#3048) 2021-08-23 20:33:21 +01:00
Sami Mazouz
b5620e0549 Throw a validation error on ico favicons. (#2949) 2021-08-21 16:14:33 +01:00
13 changed files with 85 additions and 28 deletions

4
js/dist/admin.js generated vendored

File diff suppressed because one or more lines are too long

2
js/dist/admin.js.map generated vendored

File diff suppressed because one or more lines are too long

4
js/dist/forum.js generated vendored

File diff suppressed because one or more lines are too long

2
js/dist/forum.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@@ -106,7 +106,7 @@ export type SettingsComponentOptions = HTMLInputSettingsComponentOptions | Switc
export type AdminHeaderAttrs = AdminHeaderOptions & Partial<Omit<Mithril.Attributes, 'class'>>;
export default abstract class AdminPage<CustomAttrs extends IPageAttrs = IPageAttrs> extends Page<CustomAttrs> {
settings!: Record<string, Stream<string>>;
settings: Record<string, Stream<string>> = {};
loading: boolean = false;
view(vnode: Mithril.Vnode<CustomAttrs, this>): Mithril.Children {

View File

@@ -92,7 +92,10 @@ export default abstract class PaginatedListState<T extends Model> {
*/
protected loadPage(page = 1): Promise<T[]> {
const params = this.requestParams();
params.page = { offset: this.pageSize * (page - 1) };
params.page = {
offset: this.pageSize * (page - 1),
...params.page,
};
if (Array.isArray(params.include)) {
params.include = params.include.join(',');

View File

@@ -148,13 +148,9 @@ abstract class AbstractSerializeController implements RequestHandlerInterface
abstract protected function createElement($data, SerializerInterface $serializer);
/**
* Eager loads the required relationships.
*
* @param Collection $models
* @param array $relations
* @return void
* Returns the relations to load added by extenders.
*/
protected function loadRelations(Collection $models, array $relations): void
protected function getRelationsToLoad(): array
{
$addedRelations = [];
@@ -164,6 +160,20 @@ abstract class AbstractSerializeController implements RequestHandlerInterface
}
}
return $addedRelations;
}
/**
* Eager loads the required relationships.
*
* @param Collection $models
* @param array $relations
* @return void
*/
protected function loadRelations(Collection $models, array $relations): void
{
$addedRelations = $this->getRelationsToLoad();
if (! empty($addedRelations)) {
usort($addedRelations, function ($a, $b) {
return substr_count($a, '.') - substr_count($b, '.');

View File

@@ -187,12 +187,21 @@ class ShowDiscussionController extends AbstractShowController
$query->orderBy('created_at')->skip($offset)->take($limit)->with($include);
$posts = $query->get()->all();
$posts = $query->get();
foreach ($posts as $post) {
$post->discussion = $discussion;
}
return $posts;
$this->loadRelations($posts, $include);
return $posts->all();
}
protected function getRelationsToLoad(): array
{
$addedRelations = parent::getRelationsToLoad();
return $this->getPostRelationships($addedRelations);
}
}

View File

@@ -9,9 +9,13 @@
namespace Flarum\Api\Controller;
use Flarum\Foundation\ValidationException;
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\Filesystem\Factory;
use Intervention\Image\Image;
use Intervention\Image\ImageManager;
use Psr\Http\Message\UploadedFileInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class UploadFaviconController extends UploadImageController
{
@@ -19,6 +23,22 @@ class UploadFaviconController extends UploadImageController
protected $filenamePrefix = 'favicon';
/**
* @var TranslatorInterface
*/
protected $translator;
/**
* @param SettingsRepositoryInterface $settings
* @param Factory $filesystemFactory
*/
public function __construct(SettingsRepositoryInterface $settings, Factory $filesystemFactory, TranslatorInterface $translator)
{
parent::__construct($settings, $filesystemFactory);
$this->translator = $translator;
}
/**
* {@inheritdoc}
*/
@@ -27,18 +47,24 @@ class UploadFaviconController extends UploadImageController
$this->fileExtension = pathinfo($file->getClientFilename(), PATHINFO_EXTENSION);
if ($this->fileExtension === 'ico') {
$encodedImage = $file->getStream();
} else {
$manager = new ImageManager();
$encodedImage = $manager->make($file->getStream())->resize(64, 64, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
})->encode('png');
$this->fileExtension = 'png';
// @todo remove in 2.0
throw new ValidationException([
'message' => strtr($this->translator->trans('validation.mimes'), [
':attribute' => 'favicon',
':values' => 'jpeg,png,gif,webp',
])
]);
}
$manager = new ImageManager();
$encodedImage = $manager->make($file->getStream())->resize(64, 64, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
})->encode('png');
$this->fileExtension = 'png';
return $encodedImage;
}
}

View File

@@ -68,12 +68,13 @@ class Index
$sort = Arr::pull($queryParams, 'sort');
$q = Arr::pull($queryParams, 'q');
$page = max(1, intval(Arr::pull($queryParams, 'page')));
$filters = Arr::pull($queryParams, 'filter', []);
$sortMap = $this->getSortMap();
$params = [
'sort' => $sort && isset($sortMap[$sort]) ? $sortMap[$sort] : '',
'filter' => [],
'filter' => $filters,
'page' => ['offset' => ($page - 1) * 20, 'limit' => 20]
];

View File

@@ -47,6 +47,8 @@ class AuthenticateWithHeader implements Middleware
}
if (isset($actor)) {
$actor->updateLastSeen()->save();
$request = RequestUtil::withActor($request, $actor);
$request = $request->withAttribute('bypassCsrfToken', true);
$request = $request->withoutAttribute('session');

View File

@@ -34,6 +34,8 @@ class FulltextGambit implements GambitInterface
*/
private function getUserSearchSubQuery($searchValue)
{
$searchValue = $this->users->escapeLikeString($searchValue);
return $this->users
->query()
->select('id')

View File

@@ -102,6 +102,8 @@ class UserRepository
* @param string $string
* @param User|null $actor
* @return array
*
* @deprecated remove in 2.0 (no longer used since https://github.com/flarum/core/pull/1878)
*/
public function getIdsForUsername($string, User $actor = null)
{
@@ -135,8 +137,10 @@ class UserRepository
*
* @param string $string
* @return string
*
* @internal
*/
private function escapeLikeString($string)
public function escapeLikeString($string)
{
return str_replace(['\\', '%', '_'], ['\\\\', '\%', '\_'], $string);
}