mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 01:32:42 +08:00
FEATURE: introduces minimum trust level for polls (#5391)
* 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
This commit is contained in:

committed by
Régis Hanol

parent
f466791a15
commit
63bab32816
@ -1,15 +1,22 @@
|
||||
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) {
|
||||
const siteSettings = api.container.lookup('site-settings:main');
|
||||
|
||||
if (!siteSettings.poll_enabled && (api.getCurrentUser() && !api.getCurrentUser().staff)) return;
|
||||
|
||||
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"));
|
||||
showModal('poll-ui-builder').set('toolbarEvent', this.get('toolbarEvent'));
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -18,13 +25,14 @@ function initializePollUIBuilder(api) {
|
||||
return {
|
||||
action: 'showPollBuilder',
|
||||
icon: 'bar-chart-o',
|
||||
label: 'poll.ui_builder.title'
|
||||
label: 'poll.ui_builder.title',
|
||||
condition: 'canBuildPoll'
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export default {
|
||||
name: "add-poll-ui-builder",
|
||||
name: 'add-poll-ui-builder',
|
||||
|
||||
initialize() {
|
||||
withPluginApi('0.8.7', initializePollUIBuilder);
|
||||
|
Reference in New Issue
Block a user