Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.x] [extensibility] feat: allow DiscussionSearchSource to be extended #4024

Closed
wants to merge 3 commits into from
Closed
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ If you discover a security vulnerability within Flarum, please send an e-mail to
## License

Flarum is open-source software licensed under the [MIT License](https://github.com/flarum/flarum/blob/master/LICENSE).

2 changes: 1 addition & 1 deletion extensions/akismet/src/Akismet.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected function sendRequest(string $type): ResponseInterface
$client = new Client();

return $client->request('POST', "$this->apiUrl/$type", [
'headers' => [
'headers' => [
'User-Agent' => "Flarum/$this->flarumVersion | Akismet/$this->extensionVersion",
],
'form_params' => $this->params,
Expand Down
1 change: 1 addition & 0 deletions extensions/flags/src/AddCanFlagAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ protected function checkFlagOwnPostSetting(User $actor, Post $post): bool
// If $actor is the post author, check to see if the setting is enabled
return (bool) $this->settings->get('flarum-flags.can_flag_own');
}

// $actor is not the post author
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions extensions/flags/src/Api/Serializer/FlagSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ protected function getDefaultAttributes($flag)
}

return [
'type' => $flag->type,
'reason' => $flag->reason,
'type' => $flag->type,
'reason' => $flag->reason,
'reasonDetail' => $flag->reason_detail,
'createdAt' => $this->formatDate($flag->created_at),
'createdAt' => $this->formatDate($flag->created_at),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
use Carbon\Carbon;
use Flarum\Extend;
use Flarum\Formatter\Formatter;
use Flarum\Post\Post;
use Flarum\Post\CommentPost;
use Flarum\Post\Post;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
use Flarum\User\DisplayName\DriverInterface;
Expand Down Expand Up @@ -574,7 +574,6 @@ public function rendering_post_mention_without_a_context_works()

$this->assertStringContainsString('TOBY$', $renderedHtml);
}

}

class CustomOtherDisplayNameDriver implements DriverInterface
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<?php

/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/

use Illuminate\Database\Schema\Builder;

return [
Expand Down
7 changes: 7 additions & 0 deletions extensions/package-manager/src/AllValidatorRules.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<?php

/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/

namespace Flarum\ExtensionManager;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

namespace Flarum\ExtensionManager\Api\Controller;

use Flarum\Http\RequestUtil;
use Flarum\ExtensionManager\Command\CheckForUpdates;
use Flarum\ExtensionManager\Job\Dispatcher;
use Flarum\Http\RequestUtil;
use Laminas\Diactoros\Response\JsonResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

namespace Flarum\ExtensionManager\Api\Controller;

use Flarum\ExtensionManager\Composer\ComposerJson;
use Flarum\ExtensionManager\ConfigureAuthValidator;
use Flarum\ExtensionManager\ConfigureComposerValidator;
use Flarum\Foundation\Paths;
use Flarum\Http\RequestUtil;
use Flarum\ExtensionManager\Composer\ComposerJson;
use Flarum\ExtensionManager\ConfigureComposerValidator;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Arr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

namespace Flarum\ExtensionManager\Api\Controller;

use Flarum\Http\RequestUtil;
use Flarum\ExtensionManager\Command\GlobalUpdate;
use Flarum\ExtensionManager\Job\Dispatcher;
use Flarum\Http\RequestUtil;
use Laminas\Diactoros\Response\EmptyResponse;
use Laminas\Diactoros\Response\JsonResponse;
use Psr\Http\Message\ResponseInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
namespace Flarum\ExtensionManager\Api\Controller;

use Flarum\Api\Controller\AbstractListController;
use Flarum\Http\RequestUtil;
use Flarum\Http\UrlGenerator;
use Flarum\ExtensionManager\Api\Serializer\TaskSerializer;
use Flarum\ExtensionManager\Task\Task;
use Flarum\Http\RequestUtil;
use Flarum\Http\UrlGenerator;
use Psr\Http\Message\ServerRequestInterface;
use Tobscure\JsonApi\Document;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

namespace Flarum\ExtensionManager\Api\Controller;

use Flarum\Http\RequestUtil;
use Flarum\ExtensionManager\Command\MajorUpdate;
use Flarum\ExtensionManager\Job\Dispatcher;
use Flarum\Http\RequestUtil;
use Illuminate\Support\Arr;
use Laminas\Diactoros\Response\EmptyResponse;
use Laminas\Diactoros\Response\JsonResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

namespace Flarum\ExtensionManager\Api\Controller;

use Flarum\Http\RequestUtil;
use Flarum\ExtensionManager\Command\MinorUpdate;
use Flarum\ExtensionManager\Job\Dispatcher;
use Flarum\Http\RequestUtil;
use Laminas\Diactoros\Response\EmptyResponse;
use Laminas\Diactoros\Response\JsonResponse;
use Psr\Http\Message\ResponseInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

namespace Flarum\ExtensionManager\Api\Controller;

use Flarum\Http\RequestUtil;
use Flarum\ExtensionManager\Command\RemoveExtension;
use Flarum\ExtensionManager\Job\Dispatcher;
use Flarum\Http\RequestUtil;
use Illuminate\Support\Arr;
use Laminas\Diactoros\Response\EmptyResponse;
use Laminas\Diactoros\Response\JsonResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

namespace Flarum\ExtensionManager\Api\Controller;

use Flarum\Http\RequestUtil;
use Flarum\ExtensionManager\Command\RequireExtension;
use Flarum\ExtensionManager\Job\Dispatcher;
use Flarum\Http\RequestUtil;
use Illuminate\Support\Arr;
use Laminas\Diactoros\Response\JsonResponse;
use Psr\Http\Message\ResponseInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

namespace Flarum\ExtensionManager\Api\Controller;

use Flarum\Http\RequestUtil;
use Flarum\ExtensionManager\Command\UpdateExtension;
use Flarum\ExtensionManager\Job\Dispatcher;
use Flarum\Http\RequestUtil;
use Illuminate\Support\Arr;
use Laminas\Diactoros\Response\EmptyResponse;
use Laminas\Diactoros\Response\JsonResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

namespace Flarum\ExtensionManager\Api\Controller;

use Flarum\Http\RequestUtil;
use Flarum\ExtensionManager\Command\WhyNot;
use Flarum\ExtensionManager\Job\Dispatcher;
use Flarum\Http\RequestUtil;
use Illuminate\Support\Arr;
use Laminas\Diactoros\Response\JsonResponse;
use Psr\Http\Message\ResponseInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
namespace Flarum\ExtensionManager\Command;

use Flarum\Bus\Dispatcher as FlarumDispatcher;
use Flarum\Foundation\Config;
use Flarum\ExtensionManager\Composer\ComposerAdapter;
use Flarum\ExtensionManager\Event\FlarumUpdated;
use Flarum\ExtensionManager\Exception\ComposerUpdateFailedException;
use Flarum\Foundation\Config;
use Illuminate\Contracts\Events\Dispatcher;
use Symfony\Component\Console\Input\ArrayInput;

Expand Down
4 changes: 2 additions & 2 deletions extensions/package-manager/src/Composer/ComposerAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

use Composer\Config;
use Composer\Console\Application;
use Flarum\Foundation\Paths;
use Flarum\ExtensionManager\OutputLogger;
use Flarum\ExtensionManager\Support\Util;
use Flarum\ExtensionManager\Task\Task;
use Flarum\Foundation\Paths;
use Illuminate\Filesystem\Filesystem;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\BufferedOutput;
Expand Down Expand Up @@ -68,7 +68,7 @@ public function run(InputInterface $input, ?Task $task = null, bool $safeMode =
chdir($this->paths->base);

if ($safeMode) {
$temporaryVendorDir = $this->paths->base . DIRECTORY_SEPARATOR . 'temp-vendor';
$temporaryVendorDir = $this->paths->base.DIRECTORY_SEPARATOR.'temp-vendor';
if (! $this->filesystem->isDirectory($temporaryVendorDir)) {
$this->filesystem->makeDirectory($temporaryVendorDir);
}
Expand Down
2 changes: 1 addition & 1 deletion extensions/package-manager/src/Composer/ComposerJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
namespace Flarum\ExtensionManager\Composer;

use Flarum\Extension\ExtensionManager;
use Flarum\Foundation\Paths;
use Flarum\ExtensionManager\Support\Util;
use Flarum\Foundation\Paths;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Str;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
use Composer\Console\Application;
use Composer\Util\Platform;
use Flarum\Extension\ExtensionManager;
use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Foundation\Paths;
use Flarum\Frontend\RecompileFrontendAssets;
use Flarum\Locale\LocaleManager;
use Flarum\ExtensionManager\Composer\ComposerAdapter;
use Flarum\ExtensionManager\Event\FlarumUpdated;
use Flarum\ExtensionManager\Extension\Event\Updated;
use Flarum\ExtensionManager\Listener\ClearCacheAfterUpdate;
use Flarum\ExtensionManager\Listener\ReCheckForUpdates;
use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Foundation\Paths;
use Flarum\Frontend\RecompileFrontendAssets;
use Flarum\Locale\LocaleManager;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Filesystem\Filesystem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

use Composer\Command\ClearCacheCommand;
use Flarum\Database\Console\MigrateCommand;
use Flarum\Foundation\Console\AssetsPublishCommand;
use Flarum\ExtensionManager\Event\FlarumUpdated;
use Flarum\Foundation\Console\AssetsPublishCommand;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

namespace Flarum\ExtensionManager\Tests\integration;

use Flarum\Foundation\Paths;
use Flarum\ExtensionManager\Composer\ComposerAdapter;
use Flarum\ExtensionManager\Composer\ComposerJson;
use Flarum\ExtensionManager\Support\Util;
use Flarum\Foundation\Paths;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Illuminate\Support\Arr;
use Psr\Http\Message\ResponseInterface;
Expand Down
26 changes: 13 additions & 13 deletions extensions/tags/src/Api/Serializer/TagSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ protected function getDefaultAttributes($tag)
}

$attributes = [
'name' => $tag->name,
'description' => $tag->description,
'slug' => $this->slugManager->forResource(Tag::class)->toSlug($tag),
'color' => $tag->color,
'backgroundUrl' => $tag->background_path,
'backgroundMode' => $tag->background_mode,
'icon' => $tag->icon,
'discussionCount' => (int) $tag->discussion_count,
'position' => $tag->position === null ? null : (int) $tag->position,
'defaultSort' => $tag->default_sort,
'isChild' => (bool) $tag->parent_id,
'isHidden' => (bool) $tag->is_hidden,
'lastPostedAt' => $this->formatDate($tag->last_posted_at),
'name' => $tag->name,
'description' => $tag->description,
'slug' => $this->slugManager->forResource(Tag::class)->toSlug($tag),
'color' => $tag->color,
'backgroundUrl' => $tag->background_path,
'backgroundMode' => $tag->background_mode,
'icon' => $tag->icon,
'discussionCount' => (int) $tag->discussion_count,
'position' => $tag->position === null ? null : (int) $tag->position,
'defaultSort' => $tag->default_sort,
'isChild' => (bool) $tag->parent_id,
'isHidden' => (bool) $tag->is_hidden,
'lastPostedAt' => $this->formatDate($tag->last_posted_at),
'canStartDiscussion' => $this->actor->can('startDiscussion', $tag),
'canAddToDiscussion' => $this->actor->can('addToDiscussion', $tag)
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected function tags()
['id' => 11, 'name' => 'Secondary Restricted', 'slug' => 'secondary-restricted', 'position' => null, 'parent_id' => null, 'is_restricted' => true],
['id' => 12, 'name' => 'Primary Restricted 2', 'slug' => 'primary-2-restricted', 'position' => 100, 'parent_id' => null, 'is_restricted' => true],
['id' => 13, 'name' => 'Primary Restricted 2 Child 1', 'slug' => 'primary-2-restricted-child-1', 'position' => 101, 'parent_id' => 12],
['id' => 14, 'name' => 'Primary Restricted 3', 'slug' => 'primary-3-restricted', 'position' => 102, 'parent_id' =>null, 'is_restricted' => true],
['id' => 14, 'name' => 'Primary Restricted 3', 'slug' => 'primary-3-restricted', 'position' => 102, 'parent_id' => null, 'is_restricted' => true],
];
}
}
2 changes: 2 additions & 0 deletions framework/core/js/src/forum/compat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import routes from './routes';
import ForumApplication from './ForumApplication';
import isSafariMobile from './utils/isSafariMobile';
import AccessTokensList from './components/AccessTokensList';
import DiscussionsSearchItem from './components/DiscussionsSearchItem';

export default Object.assign(compat, {
'utils/PostControls': PostControls,
Expand Down Expand Up @@ -114,6 +115,7 @@ export default Object.assign(compat, {
'components/IndexPage': IndexPage,
'components/DiscussionRenamedNotification': DiscussionRenamedNotification,
'components/DiscussionsSearchSource': DiscussionsSearchSource,
'components/DiscussionsSearchItem': DiscussionsSearchItem,
'components/HeaderSecondary': HeaderSecondary,
'components/ComposerButton': ComposerButton,
'components/DiscussionList': DiscussionList,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import app from '../../forum/app';
import Component, { ComponentAttrs } from '../../common/Component';
import Link from '../../common/components/Link';
import highlight from '../../common/helpers/highlight';
import Discussion from '../../common/models/Discussion';
import Post from '../../common/models/Post';
import type Mithril from 'mithril';
import ItemList from '../../common/utils/ItemList';

export interface DiscussionsSearchItemAttrs extends ComponentAttrs {
query: string;
discussion: Discussion;
mostRelevantPost: Post;
}

export default class DiscussionsSearchItem extends Component<DiscussionsSearchItemAttrs> {
query!: string;
discussion!: Discussion;
mostRelevantPost!: Post | null | undefined;

oninit(vnode: Mithril.Vnode<DiscussionsSearchItemAttrs, this>) {
super.oninit(vnode);

this.query = this.attrs.query;
this.discussion = this.attrs.discussion;
this.mostRelevantPost = this.attrs.mostRelevantPost;
}

view() {
return (
<li className="DiscussionSearchResult" data-index={'discussions' + this.discussion.id()}>
<Link href={app.route.discussion(this.discussion, (this.mostRelevantPost && this.mostRelevantPost.number()) || 0)}>
{this.viewItems().toArray()}
</Link>
</li>
);
}

discussionTitle() {
return this.discussion.title();
}

mostRelevantPostContent() {
return this.mostRelevantPost?.contentPlain();
}

viewItems(): ItemList<Mithril.Children> {
const items = new ItemList<Mithril.Children>();

items.add('discussion-title', <div className="DiscussionSearchResult-title">{highlight(this.discussionTitle(), this.query)}</div>, 90);

!!this.mostRelevantPost &&
items.add(
'most-relevant',
<div className="DiscussionSearchResult-excerpt">{highlight(this.mostRelevantPostContent() ?? '', this.query, 100)}</div>,
80
);

return items;
}
}
Loading
Loading