diff --git a/js/forum/src/components/IndexPage.js b/js/forum/src/components/IndexPage.js index 677c3f494..b903c7ff0 100644 --- a/js/forum/src/components/IndexPage.js +++ b/js/forum/src/components/IndexPage.js @@ -146,14 +146,16 @@ export default class IndexPage extends Component { */ sidebarItems() { const items = new ItemList(); + const canStartDiscussion = app.forum.canStartDiscussion() || !app.session.user; items.add('newDiscussion', Button.component({ - children: app.trans('core.start_a_discussion'), + children: canStartDiscussion ? app.trans('core.start_a_discussion') : 'Can\'t Start Discussion', icon: 'edit', className: 'Button Button--primary IndexPage-newDiscussion', itemClassName: 'App-primaryControl', - onclick: this.newDiscussion.bind(this) + onclick: this.newDiscussion.bind(this), + disabled: !canStartDiscussion }) ); diff --git a/js/lib/models/Forum.js b/js/lib/models/Forum.js index 2898b170b..bdda47170 100644 --- a/js/lib/models/Forum.js +++ b/js/lib/models/Forum.js @@ -1,6 +1,9 @@ import Model from 'flarum/Model'; +import mixin from 'flarum/utils/mixin'; -export default class Forum extends Model { +export default class Forum extends mixin(Model, { + canStartDiscussion: Model.attribute('canStartDiscussion') +}) { apiEndpoint() { return '/forum'; } diff --git a/src/Api/Serializers/ForumSerializer.php b/src/Api/Serializers/ForumSerializer.php index b52eb3709..381b2bd83 100644 --- a/src/Api/Serializers/ForumSerializer.php +++ b/src/Api/Serializers/ForumSerializer.php @@ -28,7 +28,8 @@ class ForumSerializer extends Serializer 'apiUrl' => Core::config('api_url'), 'welcomeTitle' => Core::config('welcome_title'), 'welcomeMessage' => Core::config('welcome_message'), - 'themePrimaryColor' => Core::config('theme_primary_color') + 'themePrimaryColor' => Core::config('theme_primary_color'), + 'canStartDiscussion' => $forum->can($this->actor, 'startDiscussion') ]; if ($this->actor->isAdmin()) {