Disable "start discussion" button if no permission

This commit is contained in:
Toby Zerner 2015-08-05 16:06:25 +09:30
parent 8be5d5af0f
commit 57e37e06ef
3 changed files with 10 additions and 4 deletions

View File

@ -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
})
);

View File

@ -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';
}

View File

@ -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()) {