mirror of
https://github.com/discourse/discourse.git
synced 2024-12-12 02:53:45 +08:00
63bab32816
* FEATURE: introduces minimum trust level for polls This commit makes `poll_enabled` less misleading and introduces `poll_minimum_trust_level_to_create`. If poll are enabled they will always be cooked, and if you have the required trust level you can create polls. As a side effect, it also fixes a bug where rebaking a post created by staff member when `poll_enabled=false` would end up not cooking it. It also adds more tests to ensure settings are respected. * admins should be whitelisted * checks for admin in post validation * test for >= instead of == trust level
41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
import { withPluginApi } from 'discourse/lib/plugin-api';
|
|
import computed from 'ember-addons/ember-computed-decorators';
|
|
import showModal from 'discourse/lib/show-modal';
|
|
|
|
function initializePollUIBuilder(api) {
|
|
api.modifyClass('controller:composer', {
|
|
@computed('siteSettings.poll_enabled', 'siteSettings.poll_minimum_trust_level_to_create')
|
|
canBuildPoll(pollEnabled, minimumTrustLevelToCreate) {
|
|
return pollEnabled &&
|
|
this.currentUser &&
|
|
(
|
|
this.currentUser.admin ||
|
|
this.currentUser.trust_level >= minimumTrustLevelToCreate
|
|
);
|
|
},
|
|
|
|
actions: {
|
|
showPollBuilder() {
|
|
showModal('poll-ui-builder').set('toolbarEvent', this.get('toolbarEvent'));
|
|
}
|
|
}
|
|
});
|
|
|
|
api.addToolbarPopupMenuOptionsCallback(function() {
|
|
return {
|
|
action: 'showPollBuilder',
|
|
icon: 'bar-chart-o',
|
|
label: 'poll.ui_builder.title',
|
|
condition: 'canBuildPoll'
|
|
};
|
|
});
|
|
}
|
|
|
|
export default {
|
|
name: 'add-poll-ui-builder',
|
|
|
|
initialize() {
|
|
withPluginApi('0.8.7', initializePollUIBuilder);
|
|
}
|
|
};
|