0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-22 17:30:29 +01:00

Add min trust setting

Dieser Commit ist enthalten in:
Angus McLeod 2017-11-29 17:48:49 +08:00
Ursprung 40465a3fb7
Commit f7c1170e07
10 geänderte Dateien mit 75 neuen und 23 gelöschten Zeilen

Datei anzeigen

@ -9,7 +9,8 @@ const wizardProperties = [
'after_time', 'after_time',
'after_time_scheduled', 'after_time_scheduled',
'required', 'required',
'prompt_completion' 'prompt_completion',
'min_trust'
]; ];
const CustomWizard = Discourse.Model.extend({ const CustomWizard = Discourse.Model.extend({
@ -245,6 +246,7 @@ CustomWizard.reopenClass({
props['after_time'] = false; props['after_time'] = false;
props['required'] = false; props['required'] = false;
props['prompt_completion'] = false; props['prompt_completion'] = false;
props['min_trust'] = 0;
props['steps'] = Ember.A(); props['steps'] = Ember.A();
}; };

Datei anzeigen

@ -37,7 +37,7 @@
</div> </div>
<div class="setting-value"> <div class="setting-value">
{{input type='checkbox' checked=model.save_submissions}} {{input type='checkbox' checked=model.save_submissions}}
<span for="save">{{i18n 'admin.wizard.save_submissions_label'}}</span> <span>{{i18n 'admin.wizard.save_submissions_label'}}</span>
</div> </div>
</div> </div>
@ -47,7 +47,7 @@
</div> </div>
<div class="setting-value"> <div class="setting-value">
{{input type='checkbox' checked=model.multiple_submissions}} {{input type='checkbox' checked=model.multiple_submissions}}
<span for="save">{{i18n 'admin.wizard.multiple_submissions_label'}}</span> <span>{{i18n 'admin.wizard.multiple_submissions_label'}}</span>
</div> </div>
</div> </div>
@ -57,7 +57,7 @@
</div> </div>
<div class="setting-value"> <div class="setting-value">
{{input type='checkbox' checked=model.required}} {{input type='checkbox' checked=model.required}}
<span for="save">{{i18n 'admin.wizard.required_label'}}</span> <span>{{i18n 'admin.wizard.required_label'}}</span>
</div> </div>
</div> </div>
@ -67,7 +67,7 @@
</div> </div>
<div class="setting-value"> <div class="setting-value">
{{input type='checkbox' checked=model.after_signup}} {{input type='checkbox' checked=model.after_signup}}
<span for="save">{{i18n 'admin.wizard.after_signup_label'}}</span> <span>{{i18n 'admin.wizard.after_signup_label'}}</span>
</div> </div>
</div> </div>
@ -77,7 +77,7 @@
</div> </div>
<div class="setting-value"> <div class="setting-value">
{{input type='checkbox' checked=model.after_time}} {{input type='checkbox' checked=model.after_time}}
<span for="save">{{i18n 'admin.wizard.after_time_label'}}</span> <span>{{i18n 'admin.wizard.after_time_label'}}</span>
{{d-button action='setNextSessionScheduled' translatedLabel=nextSessionScheduledLabel icon='calendar-o'}} {{d-button action='setNextSessionScheduled' translatedLabel=nextSessionScheduledLabel icon='calendar-o'}}
</div> </div>
</div> </div>
@ -88,7 +88,17 @@
</div> </div>
<div class="setting-value"> <div class="setting-value">
{{input type='checkbox' checked=model.prompt_completion}} {{input type='checkbox' checked=model.prompt_completion}}
<span for="save">{{i18n 'admin.wizard.prompt_completion_label'}}</span> <span>{{i18n 'admin.wizard.prompt_completion_label'}}</span>
</div>
</div>
<div class="setting">
<div class="setting-label">
<h3>{{i18n 'admin.wizard.min_trust'}}</h3>
</div>
<div class="setting-value">
<span>{{i18n 'admin.wizard.min_trust_label'}}</span>
{{input type='number' value=model.min_trust class='input-small'}}
</div> </div>
</div> </div>

Datei anzeigen

@ -1,18 +1,23 @@
export default Ember.Route.extend({ export default Ember.Route.extend({
beforeModel() { beforeModel() {
const appModel = this.modelFor('custom'); const appModel = this.modelFor('custom');
if (appModel.permitted && !appModel.completed && appModel.start) {
if (appModel) {
if (appModel.completed) {
this.set('completed', true);
} else if (appModel.start) {
this.replaceWith('custom.step', appModel.start); this.replaceWith('custom.step', appModel.start);
} }
}
}, },
setupController(controller) { model() {
const completed = this.get('completed'); return this.modelFor('custom');
controller.set('completed', completed); },
setupController(controller, model) {
const completed = model.get('completed');
const permitted = model.get('permitted');
const minTrust = model.get('min_trust');
controller.setProperties({
completed,
notPermitted: !permitted,
minTrust
});
} }
}); });

Datei anzeigen

@ -1,3 +1,7 @@
{{#if completed}} {{#if completed}}
{{i18n 'wizard.completed'}} {{i18n 'wizard.completed'}}
{{else}}
{{#if notPermitted}}
{{i18n 'wizard.not_permitted' level=minTrust}}
{{/if}}
{{/if}} {{/if}}

Datei anzeigen

@ -3,6 +3,8 @@
.wizard-step-contents { .wizard-step-contents {
position: relative; position: relative;
display: inline-block;
width: 100%;
} }
.wizard-step-description { .wizard-step-description {
@ -19,7 +21,8 @@
} }
.image-container { .image-container {
padding: 0 40px; padding: 0 20px;
margin: 60px 0;
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
flex-wrap: wrap; flex-wrap: wrap;
@ -39,7 +42,7 @@
img.small { img.small {
width: 120; width: 120;
padding: 10px; padding: 10px 15px;
} }
img.x-small { img.x-small {
@ -57,6 +60,7 @@
position: absolute; position: absolute;
bottom: 0; bottom: 0;
font-style: italic; font-style: italic;
margin-bottom: 20px;
img { img {
width: 30px; width: 30px;
@ -94,7 +98,7 @@
.wizard-step-form .wizard-btn { .wizard-step-form .wizard-btn {
display: block; display: block;
margin: 10px 0; margin: 20px 0;
} }
.wizard-column .wizard-field .input-area { .wizard-column .wizard-field .input-area {

Datei anzeigen

@ -32,6 +32,8 @@ en:
required_label: "Users cannot skip the wizard." required_label: "Users cannot skip the wizard."
prompt_completion: "Prompt" prompt_completion: "Prompt"
prompt_completion_label: "Prompt user to complete wizard." prompt_completion_label: "Prompt user to complete wizard."
min_trust: "Trust"
min_trust_label: "Trust level required to access wizard."
save: "Save Changes" save: "Save Changes"
remove: "Delete Wizard" remove: "Delete Wizard"
header: "Wizard" header: "Wizard"
@ -145,3 +147,4 @@ en:
wizard: wizard:
completed: "You have completed this wizard." completed: "You have completed this wizard."
not_permitted: "You need to be trust level {{level}} or higher to access this wizard."

Datei anzeigen

@ -16,7 +16,8 @@ class CustomWizard::Builder
name: data["name"], name: data["name"],
after_time: data["after_time"], after_time: data["after_time"],
after_signup: data["after_signup"], after_signup: data["after_signup"],
required: data["required"] required: data["required"],
min_trust: data["min_trust"]
) )
@submissions = Array.wrap(PluginStore.get("#{wizard_id}_submissions", user.id)) @submissions = Array.wrap(PluginStore.get("#{wizard_id}_submissions", user.id))
end end
@ -48,7 +49,7 @@ class CustomWizard::Builder
end end
def build def build
unless (@wizard.completed? && !@wizard.multiple_submissions) || !@steps unless (@wizard.completed? && !@wizard.multiple_submissions) || !@steps || !@wizard.permitted?
@steps.each do |s| @steps.each do |s|
@wizard.append_step(s['id']) do |step| @wizard.append_step(s['id']) do |step|
step.title = s['title'] if s['title'] step.title = s['title'] if s['title']

Datei anzeigen

@ -7,6 +7,7 @@ class CustomWizard::Template
:save_submissions, :save_submissions,
:multiple_submissions, :multiple_submissions,
:prompt_completion, :prompt_completion,
:min_trust,
:after_signup, :after_signup,
:after_time, :after_time,
:after_time_scheduled, :after_time_scheduled,
@ -21,6 +22,7 @@ class CustomWizard::Template
@save_submissions = data['save_submissions'] || false @save_submissions = data['save_submissions'] || false
@multiple_submissions = data['multiple_submissions'] || false @multiple_submissions = data['multiple_submissions'] || false
@prompt_completion = data['prompt_completion'] || false @prompt_completion = data['prompt_completion'] || false
@min_trust = data['min_trust'] || 0
@after_signup = data['after_signup'] @after_signup = data['after_signup']
@after_time = data['after_time'] @after_time = data['after_time']
@after_time_scheduled = data['after_time_scheduled'] @after_time_scheduled = data['after_time_scheduled']

Datei anzeigen

@ -11,6 +11,7 @@ class CustomWizard::Wizard
:background, :background,
:save_submissions, :save_submissions,
:multiple_submissions, :multiple_submissions,
:min_trust,
:after_time, :after_time,
:after_signup, :after_signup,
:required, :required,
@ -107,6 +108,10 @@ class CustomWizard::Wizard
(steps - completed).empty? (steps - completed).empty?
end end
def permitted?
user.staff? || user.trust_level.to_i >= min_trust.to_i
end
def self.after_signup def self.after_signup
rows = PluginStoreRow.where(plugin_name: 'custom_wizard') rows = PluginStoreRow.where(plugin_name: 'custom_wizard')
wizards = [*rows].select { |r| r.value['after_signup'] } wizards = [*rows].select { |r| r.value['after_signup'] }

Datei anzeigen

@ -48,7 +48,7 @@ class ::Wizard::Step
end end
::WizardSerializer.class_eval do ::WizardSerializer.class_eval do
attributes :id, :background, :completed, :required attributes :id, :background, :completed, :required, :min_trust, :permitted
def id def id
object.id object.id
@ -74,6 +74,22 @@ end
object.completed? && (!object.respond_to?(:multiple_submissions) || !object.multiple_submissions) object.completed? && (!object.respond_to?(:multiple_submissions) || !object.multiple_submissions)
end end
def min_trust
object.min_trust
end
def include_min_trust?
object.respond_to?(:min_trust)
end
def permitted
object.permitted?
end
def inlcude_permitted?
object.respond_to?(:permitted)
end
def include_start? def include_start?
object.start && include_steps? object.start && include_steps?
end end