mirror of
https://github.com/flarum/framework.git
synced 2024-11-28 20:16:08 +08:00
Disable "start discussion" button if no permission
This commit is contained in:
parent
8be5d5af0f
commit
57e37e06ef
|
@ -146,14 +146,16 @@ export default class IndexPage extends Component {
|
||||||
*/
|
*/
|
||||||
sidebarItems() {
|
sidebarItems() {
|
||||||
const items = new ItemList();
|
const items = new ItemList();
|
||||||
|
const canStartDiscussion = app.forum.canStartDiscussion() || !app.session.user;
|
||||||
|
|
||||||
items.add('newDiscussion',
|
items.add('newDiscussion',
|
||||||
Button.component({
|
Button.component({
|
||||||
children: app.trans('core.start_a_discussion'),
|
children: canStartDiscussion ? app.trans('core.start_a_discussion') : 'Can\'t Start Discussion',
|
||||||
icon: 'edit',
|
icon: 'edit',
|
||||||
className: 'Button Button--primary IndexPage-newDiscussion',
|
className: 'Button Button--primary IndexPage-newDiscussion',
|
||||||
itemClassName: 'App-primaryControl',
|
itemClassName: 'App-primaryControl',
|
||||||
onclick: this.newDiscussion.bind(this)
|
onclick: this.newDiscussion.bind(this),
|
||||||
|
disabled: !canStartDiscussion
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
import Model from 'flarum/Model';
|
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() {
|
apiEndpoint() {
|
||||||
return '/forum';
|
return '/forum';
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,8 @@ class ForumSerializer extends Serializer
|
||||||
'apiUrl' => Core::config('api_url'),
|
'apiUrl' => Core::config('api_url'),
|
||||||
'welcomeTitle' => Core::config('welcome_title'),
|
'welcomeTitle' => Core::config('welcome_title'),
|
||||||
'welcomeMessage' => Core::config('welcome_message'),
|
'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()) {
|
if ($this->actor->isAdmin()) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user