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

refactor: flarum 2.0 upgrade #208

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
Draft
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
18 changes: 16 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 2

[*.{diff,md}]
trim_trailing_whitespace = false

[*.{php,xml,json}]
indent_size = 4
[*.md]

[{tsconfig.json,prettierrc.json}]
indent_size = 2
trim_trailing_whitespace = false

[*.neon]
indent_style = tab
2 changes: 1 addition & 1 deletion .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [workflow_dispatch, push, pull_request]

jobs:
run:
uses: flarum/framework/.github/workflows/REUSABLE_backend.yml@1.x
uses: flarum/framework/.github/workflows/REUSABLE_backend.yml@2.x
with:
enable_backend_testing: true
enable_phpstan: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [workflow_dispatch, push, pull_request]

jobs:
run:
uses: flarum/framework/.github/workflows/REUSABLE_frontend.yml@1.x
uses: flarum/framework/.github/workflows/REUSABLE_frontend.yml@2.x
with:
enable_bundlewatch: false
enable_prettier: true
Expand Down
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
],
"require": {
"php": "^8.0",
"flarum/core": "^1.8.6"
"flarum/core": "^2.0.0"
},
"extra": {
"flarum-extension": {
Expand Down Expand Up @@ -78,7 +78,7 @@
"fof/split": "*",
"flarum/flags": "*",
"flarum/phpstan": "*",
"flarum/testing": "^1.0.0"
"flarum/testing": "^2.0.0"
},
"scripts": {
"analyse:phpstan": "phpstan analyse",
Expand All @@ -102,5 +102,7 @@
"psr-4": {
"FoF\\Byobu\\Tests\\": "tests/"
}
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
93 changes: 40 additions & 53 deletions extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@

namespace FoF\Byobu;

use Flarum\Api\Controller;
use Flarum\Api\Serializer;
use Flarum\Discussion\Discussion;
use Flarum\Discussion\Filter\DiscussionFilterer;
use Flarum\Discussion\Search\DiscussionSearcher;
use Flarum\Extend;
use Flarum\Group\Group;
Expand All @@ -23,6 +20,11 @@
use Flarum\User\Search\UserSearcher;
use Flarum\User\User;
use FoF\Split\Events\DiscussionWasSplit;
use Flarum\Api\Context;
use Flarum\Api\Endpoint;
use Flarum\Api\Resource;
use Flarum\Api\Schema;
use Illuminate\Support\Arr;

return [
(new Extend\Frontend('admin'))
Expand All @@ -33,7 +35,8 @@
->route('/private', 'byobuPrivate', Content\PrivateDiscussionsPage::class)
->route('/private/composer', 'byobuPrivateComposer')
->css(__DIR__.'/resources/less/forum/extension.less')
->js(__DIR__.'/js/dist/forum.js'),
->js(__DIR__.'/js/dist/forum.js')
->jsDirectory(__DIR__ . '/js/dist/forum'),

new Extend\Locales(__DIR__.'/resources/locale'),

Expand Down Expand Up @@ -69,41 +72,30 @@
->wherePivot('removed_at', null);
}),

(new Extend\ApiController(Controller\ListDiscussionsController::class))
->addInclude(['recipientUsers', 'recipientGroups'])
->load(['recipientUsers', 'recipientGroups']),

(new Extend\ApiController(Controller\CreateDiscussionController::class))
->addInclude(['recipientUsers', 'recipientGroups'])
->load(['recipientUsers', 'recipientGroups']),

(new Extend\ApiController(Controller\ShowDiscussionController::class))
->addOptionalInclude(['oldRecipientUsers', 'oldRecipientGroups'])
->addInclude(['recipientUsers', 'recipientGroups'])
->load(['recipientUsers', 'recipientGroups']),

(new Extend\ApiSerializer(Serializer\BasicDiscussionSerializer::class))
->hasMany('recipientUsers', Serializer\BasicUserSerializer::class)
->hasMany('recipientGroups', Serializer\GroupSerializer::class),

(new Extend\ApiSerializer(Serializer\DiscussionSerializer::class))
->hasMany('oldRecipientUsers', Serializer\BasicUserSerializer::class)
->hasMany('oldRecipientGroups', Serializer\GroupSerializer::class),

(new Extend\ApiSerializer(Serializer\DiscussionSerializer::class))
->attributes(Api\DiscussionPermissionAttributes::class)
->attributes(Api\DiscussionDataAttributes::class),

(new Extend\ApiSerializer(Serializer\ForumSerializer::class))
->attributes(Api\ForumPermissionAttributes::class),

(new Extend\ApiSerializer(Serializer\UserSerializer::class))
->attribute('blocksPd', function ($serializer, $user) {
return (bool) $user->blocks_byobu_pd;
(new Extend\ApiResource(Resource\DiscussionResource::class))
->fieldsBefore('tags', Api\DiscussionResourceFields::class)
->field('tags', fn (Schema\Relationship\ToMany $field) => $field->writable(function (Discussion $discussion, Context $context) {
return empty(Arr::get($context->body(), 'data.relationships.recipientUsers.data'))
&& empty(Arr::get($context->body(), 'data.relationships.recipientGroups.data'));
}))
->endpoint([Endpoint\Show::class, Endpoint\Create::class, Endpoint\Index::class], function (Endpoint\Show|Endpoint\Create|Endpoint\Index $endpoint) {
return $endpoint
->addDefaultInclude(['recipientUsers', 'recipientGroups'])
->eagerLoad(['recipientUsers', 'recipientGroups']);
}),

(new Extend\ApiSerializer(Serializer\CurrentUserSerializer::class))
->hasMany('privateDiscussions', Serializer\DiscussionSerializer::class),
(new Extend\ApiResource(Resource\ForumResource::class))
->fields(Api\ForumResourceFields::class),

(new Extend\ApiResource(Resource\UserResource::class))
->fields(fn () => [
Schema\Boolean::make('blocksPd')
->property('blocks_byobu_pd')
->writable(fn (User $user, Context $context) => $context->getActor()->is($user)),
Schema\Relationship\ToMany::make('privateDiscussions')
->type('discussions')
->visible(fn (User $user, Context $context) => $context->getActor()->is($user))
]),

(new Extend\View())
->namespace('fof-byobu', __DIR__.'/resources/views'),
Expand All @@ -120,15 +112,14 @@
->type(Posts\MadePublic::class),

(new Extend\Notification())
->type(Notifications\DiscussionCreatedBlueprint::class, Serializer\DiscussionSerializer::class, ['alert', 'email'])
->type(Notifications\DiscussionRepliedBlueprint::class, Serializer\DiscussionSerializer::class, ['alert', 'email'])
->type(Notifications\DiscussionRecipientRemovedBlueprint::class, Serializer\DiscussionSerializer::class, ['alert', 'email'])
->type(Notifications\DiscussionAddedBlueprint::class, Serializer\DiscussionSerializer::class, ['alert', 'email'])
->type(Notifications\DiscussionMadePublicBlueprint::class, Serializer\DiscussionSerializer::class, ['alert']),
->type(Notifications\DiscussionCreatedBlueprint::class, ['alert', 'email'])
->type(Notifications\DiscussionRepliedBlueprint::class, ['alert', 'email'])
->type(Notifications\DiscussionRecipientRemovedBlueprint::class, ['alert', 'email'])
->type(Notifications\DiscussionAddedBlueprint::class, ['alert', 'email'])
->type(Notifications\DiscussionMadePublicBlueprint::class, ['alert']),

(new Extend\Event())
->listen(PostSaving::class, Listeners\IgnoreApprovals::class)
->listen(UserSaving::class, Listeners\SaveUserPreferences::class)
->listen(DiscussionWasSplit::class, Listeners\AddRecipientsToSplitDiscussion::class)
->subscribe(Listeners\CreatePostWhenRecipientsChanged::class)
->subscribe(Listeners\QueueNotificationJobs::class)
Expand All @@ -140,16 +131,6 @@
(new Extend\ModelPrivate(Discussion::class))
->checker(Listeners\GetModelIsPrivate::class),

(new Extend\SimpleFlarumSearch(DiscussionSearcher::class))
->addGambit(Gambits\Discussion\ByobuGambit::class)
->addGambit(Gambits\Discussion\PrivacyGambit::class),

(new Extend\SimpleFlarumSearch(UserSearcher::class))
->addGambit(Gambits\User\AllowsPdGambit::class),

(new Extend\Filter(DiscussionFilterer::class))
->addFilterMutator(Filters\Discussion\HidePrivateDiscussionsFromAllDiscussionsPage::class),

(new Extend\Settings())
// we have to use the callback here, else we risk returning empty values instead of the defaults.
// see https://github.com/flarum/core/issues/3209
Expand All @@ -160,4 +141,10 @@
return empty($value) ? 'far fa-map' : $value;
})
->default('fof-byobu.delete_on_last_recipient_left', false),

(new Extend\SearchDriver(\Flarum\Search\Database\DatabaseSearchDriver::class))
->addFilter(DiscussionSearcher::class, Filters\Discussion\ByobuFilter::class)
->addFilter(DiscussionSearcher::class, Filters\Discussion\PrivacyFilter::class)
->addMutator(DiscussionSearcher::class, Filters\Discussion\HidePrivateDiscussionsFromAllDiscussionsPage::class)
->addFilter(UserSearcher::class, Filters\User\AllowsPdFilter::class),
];
42 changes: 21 additions & 21 deletions js/package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"private": true,
"name": "@fof/byobu",
"prettier": "@flarum/prettier-config",
"dependencies": {
"@flarum/prettier-config": "^1.0.0",
"flarum-tsconfig": "^1.0.2",
"flarum-webpack-config": "^2.0.0",
"flatpickr": "^4.6.13",
"webpack": "^5.94.0",
"webpack-cli": "^5.0.0"
},
"devDependencies": {
"prettier": "^2.8.0"
},
"scripts": {
"dev": "webpack --mode development --watch",
"build": "webpack --mode production",
"format": "prettier --write src",
"format-check": "prettier --check src"
}
}
"private": true,
"name": "@fof/byobu",
"prettier": "@flarum/prettier-config",
"dependencies": {
"@flarum/prettier-config": "^1.0.0",
"flarum-tsconfig": "^2.0.0",
"flarum-webpack-config": "^3.0.0",
"flatpickr": "^4.6.13",
"webpack": "^5.94.0",
"webpack-cli": "^5.0.0"
},
"devDependencies": {
"prettier": "^2.8.0"
},
"scripts": {
"dev": "webpack --mode development --watch",
"build": "webpack --mode production",
"format": "prettier --write src",
"format-check": "prettier --check src"
}
}
90 changes: 0 additions & 90 deletions js/src/admin/addPrivateDiscussionPermission.ts

This file was deleted.

9 changes: 5 additions & 4 deletions js/src/admin/components/ByobuSettingsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Form from 'flarum/common/components/Form';
import app from 'flarum/admin/app';
import ExtensionPage from 'flarum/admin/components/ExtensionPage';
import Badge from 'flarum/common/components/Badge';
import icon from 'flarum/common/helpers/icon';
import Icon from 'flarum/common/components/Icon';
import ItemList from 'flarum/common/utils/ItemList';

import type Mithril from 'mithril';
Expand All @@ -15,10 +16,10 @@ export default class ByobuSettingsPage extends ExtensionPage {
<div className="ByobuSettingsPage">
<div className="container">
<div className="ByobuSettingsTabPage ByobuSettingsPage--settings">
<div className="Form">
<Form>
{this.settingsItems().toArray()}
<div className="Form-group">{this.submitButton()}</div>
</div>
</Form>
</div>
</div>
</div>
Expand Down Expand Up @@ -111,7 +112,7 @@ export default class ByobuSettingsPage extends ExtensionPage {
label: app.translator.trans('fof-byobu.admin.settings.post-event-icon'),
help: (
<div>
{icon(this.setting('fof-byobu.icon-postAction').toJSON() || this.postActionDefault)} {this.helpText()}
<Icon name={this.setting('fof-byobu.icon-postAction').toJSON() || this.postActionDefault} /> {this.helpText()}
</div>
),
placeholder: this.postActionDefault,
Expand Down
Loading
Loading