2015-07-31 20:16:47 +09:30
|
|
|
import Component from 'flarum/Component';
|
|
|
|
import PermissionDropdown from 'flarum/components/PermissionDropdown';
|
|
|
|
import ConfigDropdown from 'flarum/components/ConfigDropdown';
|
|
|
|
import Button from 'flarum/components/Button';
|
|
|
|
import ItemList from 'flarum/utils/ItemList';
|
2015-09-22 17:52:16 +09:30
|
|
|
import icon from 'flarum/helpers/icon';
|
2015-07-31 20:16:47 +09:30
|
|
|
|
|
|
|
export default class PermissionGrid extends Component {
|
|
|
|
constructor(...args) {
|
|
|
|
super(...args);
|
|
|
|
|
|
|
|
this.permissions = this.permissionItems().toArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
view() {
|
|
|
|
const scopes = this.scopeItems().toArray();
|
|
|
|
|
|
|
|
const permissionCells = permission => {
|
|
|
|
return scopes.map(scope => (
|
|
|
|
<td>
|
|
|
|
{scope.render(permission)}
|
|
|
|
</td>
|
|
|
|
));
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<table className="PermissionGrid">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<td></td>
|
|
|
|
{scopes.map(scope => (
|
|
|
|
<th>
|
|
|
|
{scope.label}{' '}
|
|
|
|
{scope.onremove ? Button.component({icon: 'times', className: 'Button Button--text PermissionGrid-removeScope', onclick: scope.onremove}) : ''}
|
|
|
|
</th>
|
|
|
|
))}
|
|
|
|
<th>{this.scopeControlItems().toArray()}</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
{this.permissions.map(section => (
|
|
|
|
<tbody>
|
|
|
|
<tr className="PermissionGrid-section">
|
|
|
|
<th>{section.label}</th>
|
|
|
|
{permissionCells(section)}
|
|
|
|
<td/>
|
|
|
|
</tr>
|
|
|
|
{section.children.map(child => (
|
|
|
|
<tr className="PermissionGrid-child">
|
2015-09-22 17:52:16 +09:30
|
|
|
<th>{child.icon ? icon(child.icon) : ''}{child.label}</th>
|
2015-07-31 20:16:47 +09:30
|
|
|
{permissionCells(child)}
|
|
|
|
<td/>
|
|
|
|
</tr>
|
|
|
|
))}
|
|
|
|
</tbody>
|
|
|
|
))}
|
|
|
|
</table>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
permissionItems() {
|
|
|
|
const items = new ItemList();
|
|
|
|
|
|
|
|
items.add('view', {
|
2015-09-22 17:52:16 +09:30
|
|
|
label: 'Read',
|
2015-07-31 20:16:47 +09:30
|
|
|
children: this.viewItems().toArray()
|
2015-09-22 17:52:16 +09:30
|
|
|
}, 100);
|
2015-07-31 20:16:47 +09:30
|
|
|
|
|
|
|
items.add('start', {
|
2015-09-22 17:52:16 +09:30
|
|
|
label: 'Create',
|
2015-07-31 20:16:47 +09:30
|
|
|
children: this.startItems().toArray()
|
2015-09-22 17:52:16 +09:30
|
|
|
}, 90);
|
2015-07-31 20:16:47 +09:30
|
|
|
|
|
|
|
items.add('reply', {
|
2015-09-22 17:52:16 +09:30
|
|
|
label: 'Participate',
|
2015-07-31 20:16:47 +09:30
|
|
|
children: this.replyItems().toArray()
|
2015-09-22 17:52:16 +09:30
|
|
|
}, 80);
|
2015-07-31 20:16:47 +09:30
|
|
|
|
|
|
|
items.add('moderate', {
|
|
|
|
label: 'Moderate',
|
|
|
|
children: this.moderateItems().toArray()
|
2015-09-22 17:52:16 +09:30
|
|
|
}, 70);
|
2015-07-31 20:16:47 +09:30
|
|
|
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
|
|
|
viewItems() {
|
|
|
|
const items = new ItemList();
|
|
|
|
|
|
|
|
items.add('view', {
|
2015-09-22 17:52:16 +09:30
|
|
|
icon: 'eye',
|
2015-07-31 20:16:47 +09:30
|
|
|
label: 'View discussions',
|
|
|
|
permission: 'forum.view',
|
|
|
|
allowGuest: true
|
2015-09-22 17:52:16 +09:30
|
|
|
}, 100);
|
2015-07-31 20:16:47 +09:30
|
|
|
|
|
|
|
items.add('signUp', {
|
2015-09-22 17:52:16 +09:30
|
|
|
icon: 'user-plus',
|
2015-07-31 20:16:47 +09:30
|
|
|
label: 'Sign up',
|
|
|
|
setting: () => ConfigDropdown.component({
|
|
|
|
key: 'allow_sign_up',
|
|
|
|
options: [
|
|
|
|
{value: '1', label: 'Open'},
|
|
|
|
{value: '0', label: 'Closed'}
|
|
|
|
]
|
|
|
|
})
|
2015-09-22 17:52:16 +09:30
|
|
|
}, 90);
|
2015-07-31 20:16:47 +09:30
|
|
|
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
|
|
|
startItems() {
|
|
|
|
const items = new ItemList();
|
|
|
|
|
|
|
|
items.add('start', {
|
2015-09-22 17:52:16 +09:30
|
|
|
icon: 'edit',
|
2015-07-31 20:16:47 +09:30
|
|
|
label: 'Start discussions',
|
|
|
|
permission: 'forum.startDiscussion'
|
2015-09-22 17:52:16 +09:30
|
|
|
}, 100);
|
2015-07-31 20:16:47 +09:30
|
|
|
|
|
|
|
items.add('allowRenaming', {
|
2015-09-22 17:52:16 +09:30
|
|
|
icon: 'i-cursor',
|
2015-07-31 20:16:47 +09:30
|
|
|
label: 'Allow renaming',
|
|
|
|
setting: () => {
|
|
|
|
const minutes = parseInt(app.config.allow_renaming, 10);
|
|
|
|
|
|
|
|
return ConfigDropdown.component({
|
|
|
|
defaultLabel: minutes ? `For ${minutes} minutes` : 'Indefinitely',
|
|
|
|
key: 'allow_renaming',
|
|
|
|
options: [
|
|
|
|
{value: '-1', label: 'Indefinitely'},
|
|
|
|
{value: '10', label: 'For 10 minutes'},
|
|
|
|
{value: 'reply', label: 'Until next reply'}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
}
|
2015-09-22 17:52:16 +09:30
|
|
|
}, 90);
|
2015-07-31 20:16:47 +09:30
|
|
|
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
|
|
|
replyItems() {
|
|
|
|
const items = new ItemList();
|
|
|
|
|
|
|
|
items.add('reply', {
|
2015-09-22 17:52:16 +09:30
|
|
|
icon: 'reply',
|
2015-07-31 20:16:47 +09:30
|
|
|
label: 'Reply to discussions',
|
|
|
|
permission: 'discussion.reply'
|
2015-09-22 17:52:16 +09:30
|
|
|
}, 100);
|
2015-07-31 20:16:47 +09:30
|
|
|
|
|
|
|
items.add('allowPostEditing', {
|
2015-09-22 17:52:16 +09:30
|
|
|
icon: 'pencil',
|
2015-07-31 20:16:47 +09:30
|
|
|
label: 'Allow post editing',
|
|
|
|
setting: () => {
|
|
|
|
const minutes = parseInt(app.config.allow_post_editing, 10);
|
|
|
|
|
|
|
|
return ConfigDropdown.component({
|
|
|
|
defaultLabel: minutes ? `For ${minutes} minutes` : 'Indefinitely',
|
|
|
|
key: 'allow_post_editing',
|
|
|
|
options: [
|
|
|
|
{value: '-1', label: 'Indefinitely'},
|
|
|
|
{value: '10', label: 'For 10 minutes'},
|
|
|
|
{value: 'reply', label: 'Until next reply'}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
}
|
2015-09-22 17:52:16 +09:30
|
|
|
}, 90);
|
2015-07-31 20:16:47 +09:30
|
|
|
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
|
|
|
moderateItems() {
|
|
|
|
const items = new ItemList();
|
|
|
|
|
|
|
|
items.add('renameDiscussions', {
|
2015-09-22 17:52:16 +09:30
|
|
|
icon: 'i-cursor',
|
2015-07-31 20:16:47 +09:30
|
|
|
label: 'Rename discussions',
|
|
|
|
permission: 'discussion.rename'
|
2015-09-22 17:52:16 +09:30
|
|
|
}, 100);
|
2015-07-31 20:16:47 +09:30
|
|
|
|
2015-09-22 17:52:16 +09:30
|
|
|
items.add('hideDiscussions', {
|
|
|
|
icon: 'trash-o',
|
2015-07-31 20:16:47 +09:30
|
|
|
label: 'Delete discussions',
|
2015-09-22 17:52:16 +09:30
|
|
|
permission: 'discussion.hide'
|
|
|
|
}, 90);
|
|
|
|
|
|
|
|
items.add('deleteDiscussions', {
|
|
|
|
icon: 'times',
|
|
|
|
label: 'Delete discussions forever',
|
2015-07-31 20:16:47 +09:30
|
|
|
permission: 'discussion.delete'
|
2015-09-22 17:52:16 +09:30
|
|
|
}, 80);
|
|
|
|
|
|
|
|
items.add('editPosts', {
|
|
|
|
icon: 'pencil',
|
|
|
|
label: 'Edit and delete posts',
|
|
|
|
permission: 'discussion.editPosts'
|
|
|
|
}, 70);
|
|
|
|
|
|
|
|
items.add('deletePosts', {
|
|
|
|
icon: 'times',
|
|
|
|
label: 'Delete posts forever',
|
|
|
|
permission: 'discussion.deletePosts'
|
|
|
|
}, 60);
|
2015-07-31 20:16:47 +09:30
|
|
|
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
|
|
|
scopeItems() {
|
|
|
|
const items = new ItemList();
|
|
|
|
|
|
|
|
items.add('global', {
|
|
|
|
label: 'Global',
|
|
|
|
render: item => {
|
|
|
|
if (item.setting) {
|
|
|
|
return item.setting();
|
|
|
|
} else if (item.permission) {
|
2015-09-22 17:52:16 +09:30
|
|
|
return PermissionDropdown.component({
|
|
|
|
permission: item.permission,
|
|
|
|
allowGuest: item.allowGuest
|
|
|
|
});
|
2015-07-31 20:16:47 +09:30
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
|
|
|
}
|
2015-09-22 17:52:16 +09:30
|
|
|
}, 100);
|
2015-07-31 20:16:47 +09:30
|
|
|
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
|
|
|
scopeControlItems() {
|
|
|
|
return new ItemList();
|
|
|
|
}
|
|
|
|
}
|