simon
10.Октябрь.2023 20:48:49
1
При рассмотрении скрипта «Добавить пользователя в группу через пользовательское поле» кажется, что есть небольшая проблема. Если выбран триггер «Первый вход пользователя», поле «Имя пользовательского поля» должно быть установлено в имя пользовательского поля, например «Родной язык». Однако если выбран триггер «Повторяющийся», поле «Имя пользовательского поля» должно быть установлено на основе id пользовательского поля, например «user_field_5».
Подробности о том, как найти имя для использования с триггером «Повторяющийся», здесь: Finding Userfield Custom Name for 'Add user to group through User Custom Field' - #2 by leonardo .
В идеале дружественное имя (например, «Родной язык») должно использоваться как правильное значение для обоих доступных триггеров. Соответствующий код находится здесь: https://github.com/discourse/discourse-automation/blob/main/lib/discourse_automation/scripts/add_user_to_group_through_custom_field.rb . То, как триггер «Первый вход пользователя» находит правильное пользовательское поле по имени поля (вместо id), показано здесь:
https://github.com/discourse/discourse-automation/blob/main/lib/discourse_automation/scripts/add_user_to_group_through_custom_field.rb#L54-L67
Возможно, существует способ применить эту логику к триггеру «Повторяющийся» с обратной совместимостью.
3 лайка
Просто для сведения, это упомянуто в пошаговом руководстве:
This guide explains how to automatically add users to groups based on their selection of a custom user field during signup or profile update.
Required user level: Administrator
Summary
Create the necessary groups
Set up a custom user field
Create an automation to add users to groups
Test the setup
Creating the groups
First, create the groups you want users to be automatically added to:
Go to your site’s Admin area
Navigate to Groups in the admin sidebar…
Я упоминал о необходимости доработки скрипта для обеспечения согласованности, хотя это пока не является приоритетом. Также есть настройки администратора «Пользовательские поля для публичных пользователей» и «Пользовательские поля для сотрудников», которые было бы неплохо привести в соответствие с этим.
(А также есть «Поля пользователей, доступные для группировки в опросах», которые используют «дружественное имя»)
4 лайка
simon
11.Октябрь.2023 01:09:13
4
Вот PR для исправления проблемы:
main ← scossar:feature-allow-either-user-field-name-or-user-custom-field-name-for-input
closed 02:20AM - 24 Oct 23 UTC
Currently the `add_user_to_group_through_custom_field` script expects the UserCu… stomField name to be used when the automation is triggered with the "Recurring" trigger, and the UserField name to be used when the automation is triggered by the "User first logged in" trigger. This is confusing for users. For both triggers, it would be better if the UserField name could be used. That's the name that is displayed on the Admin / Customize / User Fields page.
This PR attempts to fix the issue in a backwards compatible way, so that existing automations that are making use of the UserCustomField name (for example: 'user_field_5') will not be broken.
The PR also updates the "with one matching user" test to set the UserCustomField name in the way that Discourse sets the name - based on the UserField's id.
Related discussion on Meta: https://meta.discourse.org/t/add-user-to-group-script-has-different-field-input-for-the-two-triggers/281813
2 лайка
Это теперь решено с помощью нового выпадающего списка для выбора ваших существующих пользовательских полей, который работает для обоих триггеров:
committed 11:57PM - 26 Oct 23 UTC
New field to select user custom field. In addition, `add_user_to_group_through_c… ustom_field` script was adjusted to use the new component.
Also, data were migrated. Before they were not consistent.
Recurring script accepted text value which was user field identifier like `user_field_1`.
First logged in accepted text value which was user field name like `Title`.
2 лайка