Disable wizard invites step when local_logins are turned off

This commit is contained in:
Penar Musaraj 2018-11-14 07:05:32 -05:00 committed by Joffrey JAFFEUX
parent 34e4d82f1a
commit f6fb079129
5 changed files with 30 additions and 14 deletions

View File

@ -39,6 +39,8 @@ class WizardStepSerializer < ApplicationSerializer
end end
def description def description
return translate("disabled") if object.disabled
translate("description", base_path: Discourse.base_path) translate("description", base_path: Discourse.base_path)
end end

View File

@ -4112,6 +4112,7 @@ en:
invites: invites:
title: "Invite Staff" title: "Invite Staff"
description: "Youre almost done! Lets invite some people to help <a href='https://blog.discourse.org/2014/08/building-a-discourse-community/' target='blank'>seed your discussions</a> with interesting topics and replies to get your community started." description: "Youre almost done! Lets invite some people to help <a href='https://blog.discourse.org/2014/08/building-a-discourse-community/' target='blank'>seed your discussions</a> with interesting topics and replies to get your community started."
disabled: "Since local logins are disabled, its not possible to send invites to anyone. Please proceed to the next step."
finished: finished:
title: "Your Discourse is Ready!" title: "Your Discourse is Ready!"

View File

@ -233,24 +233,27 @@ class Wizard
end end
@wizard.append_step('invites') do |step| @wizard.append_step('invites') do |step|
if SiteSetting.enable_local_logins
staff_count = User.staff.human_users.where('username_lower not in (?)', reserved_usernames).count
step.add_field(id: 'staff_count', type: 'component', value: staff_count)
staff_count = User.staff.human_users.where('username_lower not in (?)', reserved_usernames).count step.add_field(id: 'invite_list', type: 'component')
step.add_field(id: 'staff_count', type: 'component', value: staff_count)
step.add_field(id: 'invite_list', type: 'component') step.on_update do |updater|
users = JSON.parse(updater.fields[:invite_list])
step.on_update do |updater| users.each do |u|
users = JSON.parse(updater.fields[:invite_list]) args = {}
args[:moderator] = true if u['role'] == 'moderator'
users.each do |u| begin
args = {} Invite.create_invite_by_email(u['email'], @wizard.user, args)
args[:moderator] = true if u['role'] == 'moderator' rescue => e
begin updater.errors.add(:invite_list, e.message.concat("<br>"))
Invite.create_invite_by_email(u['email'], @wizard.user, args) end
rescue => e
updater.errors.add(:invite_list, e.message.concat("<br>"))
end end
end end
else
step.disabled = true
end end
end end

View File

@ -1,7 +1,7 @@
class Wizard class Wizard
class Step class Step
attr_reader :id, :updater attr_reader :id, :updater
attr_accessor :index, :fields, :next, :previous, :banner attr_accessor :index, :fields, :next, :previous, :banner, :disabled
def initialize(id) def initialize(id)
@id = id @id = id

View File

@ -27,4 +27,14 @@ describe Wizard::Builder do
expect(wizard.steps).to be_blank expect(wizard.steps).to be_blank
end end
it "returns wizard with disabled invites step when local_logins are off" do
SiteSetting.enable_local_logins = false
wizard = Wizard::Builder.new(moderator).build
invites_step = wizard.steps.find { |s| s.id == "invites" }
expect(invites_step.fields).to be_blank
expect(invites_step.disabled).to be_truthy
end
end end