Fix completed? for reused wizards && ensure users with no access can get back to site
Dieser Commit ist enthalten in:
Ursprung
a295f6fe20
Commit
9a3ae6406f
12 geänderte Dateien mit 65 neuen und 28 gelöschten Zeilen
13
assets/javascripts/wizard/components/wizard-no-access.js.es6
Normale Datei
13
assets/javascripts/wizard/components/wizard-no-access.js.es6
Normale Datei
|
@ -0,0 +1,13 @@
|
|||
import CustomWizard from '../models/custom';
|
||||
|
||||
export default Ember.Component.extend({
|
||||
siteName: function() {
|
||||
return Wizard.SiteSettings.title;
|
||||
}.property(),
|
||||
|
||||
actions: {
|
||||
skip() {
|
||||
CustomWizard.skip(this.get('wizardId'));
|
||||
}
|
||||
}
|
||||
})
|
|
@ -8,6 +8,7 @@ export default {
|
|||
const ApplicationRoute = requirejs('wizard/routes/application').default;
|
||||
const ajax = requirejs('wizard/lib/ajax').ajax;
|
||||
const StepModel = requirejs('wizard/models/step').default;
|
||||
const CustomWizard = requirejs('discourse/plugins/discourse-custom-wizard/wizard/models/custom').default;
|
||||
const WizardStep = requirejs('wizard/components/wizard-step').default;
|
||||
const WizardField = requirejs('wizard/components/wizard-field').default;
|
||||
const getUrl = requirejs('discourse-common/lib/get-url').default;
|
||||
|
@ -84,7 +85,7 @@ export default {
|
|||
this.get('step').save()
|
||||
.then(response => {
|
||||
if (this.get('finalStep')) {
|
||||
this.get('wizard').finished(response);
|
||||
CustomWizard.finished(response);
|
||||
} else {
|
||||
this.sendAction('goNext', response);
|
||||
}
|
||||
|
|
|
@ -9,10 +9,16 @@ const CustomWizard = Ember.Object.extend({
|
|||
totalSteps: length => length,
|
||||
|
||||
skip() {
|
||||
if (this.get('required')) return;
|
||||
if (this.get('required') && (!this.get('completed') && this.get('permitted'))) return;
|
||||
const id = this.get('id');
|
||||
ajax({ url: `/w/${id}/skip`, type: 'PUT' }).then((result) => {
|
||||
this.finished(result);
|
||||
CustomWizard.skip(id);
|
||||
}
|
||||
});
|
||||
|
||||
CustomWizard.reopenClass({
|
||||
skip(wizardId) {
|
||||
ajax({ url: `/w/${wizardId}/skip`, type: 'PUT' }).then((result) => {
|
||||
CustomWizard.finished(result);
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -23,7 +29,7 @@ const CustomWizard = Ember.Object.extend({
|
|||
}
|
||||
window.location.href = getUrl(url);
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
export function findCustomWizard(wizardId) {
|
||||
return ajax({ url: `/w/${wizardId}` }).then(result => {
|
||||
|
|
|
@ -15,10 +15,13 @@ export default Ember.Route.extend({
|
|||
const completed = model.get('completed');
|
||||
const permitted = model.get('permitted');
|
||||
const minTrust = model.get('min_trust');
|
||||
const wizardId = model.get('id');
|
||||
|
||||
controller.setProperties({
|
||||
completed,
|
||||
notPermitted: !permitted,
|
||||
minTrust
|
||||
minTrust,
|
||||
wizardId
|
||||
});
|
||||
} else {
|
||||
controller.set('noWizard', true);
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
<div>{{text}}</div>
|
||||
<div class="no-access-gutter">
|
||||
<button class='wizard-btn primary return-to-site' {{action 'skip'}}>
|
||||
{{i18n 'wizard.return_to_site' siteName=siteName}}
|
||||
{{d-icon "sign-out"}}
|
||||
</button>
|
||||
</div>
|
|
@ -1,10 +1,10 @@
|
|||
{{#if completed}}
|
||||
{{i18n 'wizard.completed'}}
|
||||
{{wizard-no-access text=(i18n 'wizard.completed') wizardId=wizardId}}
|
||||
{{else}}
|
||||
{{#if notPermitted}}
|
||||
{{i18n 'wizard.not_permitted' level=minTrust}}
|
||||
{{wizard-no-access text=(i18n 'wizard.completed' level=minTrust) wizardId=wizardId}}
|
||||
{{/if}}
|
||||
{{#if noWizard}}
|
||||
{{i18n 'wizard.none'}}
|
||||
{{wizard-no-access text=(i18n 'wizard.none') wizardId=wizardId}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
@import 'wizard_variables';
|
||||
|
||||
.no-access-gutter {
|
||||
margin-top: 10px;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.custom-wizard {
|
||||
background-color: initial;
|
||||
font-size: 1.1em;
|
||||
|
|
|
@ -159,6 +159,7 @@ en:
|
|||
completed: "You have completed this wizard."
|
||||
not_permitted: "You need to be trust level {{level}} or higher to access this wizard."
|
||||
none: "There is no wizard here."
|
||||
return_to_site: "Return to {{siteName}}"
|
||||
|
||||
wizard_composer:
|
||||
show_preview: "Preview Your Post"
|
||||
|
|
|
@ -22,6 +22,7 @@ class CustomWizard::WizardController < ::ApplicationController
|
|||
respond_to do |format|
|
||||
format.json do
|
||||
builder = CustomWizard::Builder.new(current_user, params[:wizard_id].underscore)
|
||||
|
||||
if builder.wizard.present?
|
||||
wizard = builder.build
|
||||
render_serialized(wizard, WizardSerializer)
|
||||
|
@ -35,15 +36,18 @@ class CustomWizard::WizardController < ::ApplicationController
|
|||
|
||||
## clean up if user skips wizard
|
||||
def skip
|
||||
params.require(:wizard_id)
|
||||
|
||||
wizard_id = params[:wizard_id]
|
||||
|
||||
wizard = PluginStore.get('custom_wizard', wizard_id.underscore)
|
||||
user = current_user
|
||||
wizard_data = PluginStore.get('custom_wizard', wizard_id.underscore)
|
||||
wizard = CustomWizard::Wizard.new(user, wizard_data)
|
||||
|
||||
if wizard['required']
|
||||
if wizard.required && !wizard.completed? && wizard.permitted?
|
||||
return render json: { error: I18n.t('wizard.no_skip') }
|
||||
end
|
||||
|
||||
user = current_user
|
||||
result = success_json
|
||||
submission = Array.wrap(PluginStore.get("#{wizard_id}_submissions", user.id)).last
|
||||
|
||||
|
@ -51,8 +55,8 @@ class CustomWizard::WizardController < ::ApplicationController
|
|||
result.merge!(redirect_to: submission['redirect_to'])
|
||||
end
|
||||
|
||||
if submission && !wizard['save_submissions']
|
||||
PluginStore.remove("#{wizard['id']}_submissions", user.id)
|
||||
if submission && !wizard.save_submissions
|
||||
PluginStore.remove("#{wizard_id}_submissions", user.id)
|
||||
end
|
||||
|
||||
if user.custom_fields['redirect_to_wizard'] === wizard_id
|
||||
|
|
|
@ -8,17 +8,7 @@ class CustomWizard::Builder
|
|||
return if data.blank?
|
||||
|
||||
@steps = data['steps']
|
||||
@wizard = CustomWizard::Wizard.new(user,
|
||||
id: wizard_id,
|
||||
save_submissions: data['save_submissions'],
|
||||
multiple_submissions: data['multiple_submissions'],
|
||||
background: data["background"],
|
||||
name: data["name"],
|
||||
after_time: data["after_time"],
|
||||
after_signup: data["after_signup"],
|
||||
required: data["required"],
|
||||
min_trust: data["min_trust"]
|
||||
)
|
||||
@wizard = CustomWizard::Wizard.new(user, data)
|
||||
@submissions = Array.wrap(PluginStore.get("#{wizard_id}_submissions", user.id))
|
||||
end
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ class CustomWizard::Wizard
|
|||
:multiple_submissions,
|
||||
:min_trust,
|
||||
:after_time,
|
||||
:after_time_scheduled,
|
||||
:after_signup,
|
||||
:required,
|
||||
:prompt_completion
|
||||
|
@ -99,8 +100,8 @@ class CustomWizard::Wizard
|
|||
context: @id
|
||||
)
|
||||
|
||||
if @completed_after
|
||||
history.where("updated_at > ?", @completed_after)
|
||||
if @after_time
|
||||
history = history.where("updated_at > ?", @after_time_scheduled)
|
||||
end
|
||||
|
||||
completed = history.distinct.order(:subject).pluck(:subject)
|
||||
|
@ -165,4 +166,8 @@ class CustomWizard::Wizard
|
|||
wizard = ::JSON.parse(json)
|
||||
PluginStore.set('custom_wizard', wizard["id"], wizard)
|
||||
end
|
||||
|
||||
def self.set_redirect(user, wizard_id, url)
|
||||
PluginStore.set("#{wizard_id}_submissions", user.id, [{ redirect_to: url }])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -88,7 +88,7 @@ after_initialize do
|
|||
if Wizard.user_requires_completion?(@user)
|
||||
wizard_path = $redis.get('custom_wizard_redirect')
|
||||
unless url === '/'
|
||||
PluginStore.set("#{wizard_path.underscore}_submissions", @user.id, [{ redirect_to: url }])
|
||||
CustomWizard::Wizard.set_redirect(@user, wizard_id, url)
|
||||
end
|
||||
url = "/w/#{wizard_path}"
|
||||
end
|
||||
|
@ -112,6 +112,7 @@ after_initialize do
|
|||
def redirect_to_wizard_if_required
|
||||
@wizard_id ||= current_user.custom_fields['redirect_to_wizard']
|
||||
if @wizard_id && request.referer !~ /w/ && request.referer !~ /admin/
|
||||
CustomWizard::Wizard.set_redirect(current_user, @wizard_id, request.referer)
|
||||
redirect_to "/w/#{@wizard_id}"
|
||||
end
|
||||
end
|
||||
|
|
Laden …
In neuem Issue referenzieren