0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-25 18:50:27 +01:00

IMPROVE: warn in logs when at least one user in wizard did not exist

Dieser Commit ist enthalten in:
merefield 2023-04-11 09:54:37 +01:00
Ursprung 766cae92ba
Commit 37cef2ccc2
3 geänderte Dateien mit 122 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -456,14 +456,15 @@ class CustomWizard::Action
if new_group_params[:usernames].present? if new_group_params[:usernames].present?
user_ids = get_user_ids(new_group_params[:usernames]) user_ids = get_user_ids(new_group_params[:usernames])
if user_ids.count < new_group_params[:usernames].count
log_error("Warning, group creation: some users were not found!")
end
user_ids -= owner_ids if owner_ids user_ids -= owner_ids if owner_ids
user_ids.each { |user_id| group.group_users.build(user_id: user_id) } user_ids.each { |user_id| group.group_users.build(user_id: user_id) }
end end
if group.save if group.save
log_success("Group created", group.name) log_success("Group created", group.name)
else
log_error("Group users creation failed", group.errors.messages)
end end
result.output = group.name result.output = group.name

Datei anzeigen

@ -13,6 +13,7 @@ describe CustomWizard::Action do
let(:watch_categories) { get_wizard_fixture("actions/watch_categories") } let(:watch_categories) { get_wizard_fixture("actions/watch_categories") }
let(:watch_tags) { get_wizard_fixture("actions/watch_tags") } let(:watch_tags) { get_wizard_fixture("actions/watch_tags") }
let(:create_group) { get_wizard_fixture("actions/create_group") } let(:create_group) { get_wizard_fixture("actions/create_group") }
let(:create_group_with_nonexistant_user) { get_wizard_fixture("actions/create_group_bad_user") }
let(:add_to_group) { get_wizard_fixture("actions/add_to_group") } let(:add_to_group) { get_wizard_fixture("actions/add_to_group") }
let(:send_message) { get_wizard_fixture("actions/send_message") } let(:send_message) { get_wizard_fixture("actions/send_message") }
let(:send_message_multi) { get_wizard_fixture("actions/send_message_multi") } let(:send_message_multi) { get_wizard_fixture("actions/send_message_multi") }
@ -358,6 +359,20 @@ describe CustomWizard::Action do
expect(GroupUser.where(group_id: group_id, user_id: user_id).exists?).to eq(true) expect(GroupUser.where(group_id: group_id, user_id: user_id).exists?).to eq(true)
end end
it '#create_group completes successfully when user included in usernames does not exist but excludes users who do not exist and includes warning in log' do
wizard_template['actions'] << create_group_with_nonexistant_user
update_template(wizard_template)
wizard = CustomWizard::Builder.new(@template[:id], user).build
wizard.create_updater(wizard.steps[0].id, step_1_field_1: "Text input").update
group_id = Group.where(name: wizard.current_submission.fields['action_9']).first.id
expect(CustomWizard::Log.list_query.all.last.value.include? "some users were not found").to eq(true)
expect(Group.where(name: wizard.current_submission.fields['action_9']).exists?).to eq(true)
expect(GroupUser.where(group_id: group_id).count).to eq(1)
end
it '#add_to_group' do it '#add_to_group' do
wizard_template['actions'] << create_group wizard_template['actions'] << create_group
wizard_template['actions'] << add_to_group wizard_template['actions'] << add_to_group

Datei anzeigen

@ -0,0 +1,104 @@
{
"id": "action_9",
"run_after": "step_1",
"type": "create_group",
"title": [
{
"type": "assignment",
"output": "New Group Member",
"output_type": "text",
"output_connector": "set"
}
],
"custom_fields": [
{
"type": "association",
"pairs": [
{
"index": 0,
"key": "group_custom_field",
"key_type": "text",
"value": "step_3_field_1",
"value_type": "wizard_field",
"connector": "association"
}
]
}
],
"name": [
{
"type": "assignment",
"output": "step_1_field_1",
"output_type": "wizard_field",
"output_connector": "set"
}
],
"full_name": [
{
"type": "assignment",
"output": "step_1_field_1",
"output_type": "wizard_field",
"output_connector": "set"
}
],
"usernames": [
{
"type": "assignment",
"output_type": "user",
"output_connector": "set",
"output": [
"angus3"
]
}
],
"owner_usernames": [
{
"type": "assignment",
"output_type": "user",
"output_connector": "set",
"output": [
"angus"
]
}
],
"grant_trust_level": [
{
"type": "assignment",
"output": "3",
"output_type": "text",
"output_connector": "set"
}
],
"mentionable_level": [
{
"type": "assignment",
"output": "1",
"output_type": "text",
"output_connector": "set"
}
],
"messageable_level": [
{
"type": "assignment",
"output": "2",
"output_type": "text",
"output_connector": "set"
}
],
"visibility_level": [
{
"type": "assignment",
"output": "3",
"output_type": "text",
"output_connector": "set"
}
],
"members_visibility_level": [
{
"type": "assignment",
"output": "99",
"output_type": "text",
"output_connector": "set"
}
]
}