匿名モードのユーザーをグループに自動追加できません

Hello everone!

I’m running a forum with Discourse 2.6.0beta3, and I think I find a bug.

I try to add anonymous users to a group name anons, so I can restrict their posts in some specific categories. I set the group anons to add user to automatically based on the email domain anon.mydomain.

When I enter anonymous mode, I find my anonymous account not be added to the group. However, If I click the Save Change button in /g/anons/manage/membership, my anonymous account can be added to this group. I just want to add anonymous user to this group when entering anonymous mode, without my clicking.

I’ve searched this bug but there’s no useful information. Thank you for your reading!

「いいね!」 1

I can reproduce what you are finding when a user enters anonymous mode. To have the user automatically added to a group based on the anonymous email domain, I’m having to go to the anonymous group’s management page and save the settings.

I am not sure if adding anonymous users to a group based on the anonymous email domain is expected to work. I can see how it would be useful to have all anonymous users in a group though. The approach of adding anonymous users to a group based on their email domain has been suggested a few times on Meta. An alternate approach would be to add an anonymous mode group setting that automatically added all anonymous users to a chosen group.

Lets see if this is functionality that Discourse wants to support before deciding if it is a bug.

「いいね!」 3

I think it would be risky to rely on the anonymous email for this functionality. I think we could consider having another automatic group for anonymous users and add them there automatically.

I don’t consider this a bug though, so I am recategorizing it.

「いいね!」 3

Hi, this topic is relevant to an issue I’m having on a forum that I’m helping to set up/administer. Some context: the forum requires people to pay to join as users who can post. We also want paid members with a certain trust level to be able to post anonymously by switching to anonymous mode. Also, we want everyone to be able to read the content (except for like, staff-only stuff obviously).

As I understand it, anonymous users are automatically part of the everyone user group. If we wanted to let the whole world post on the forum, then there’d be no issue of the anons being unable to post. However, because it’s a paid forum, we’ve set the everyone user group to read-only so that the world can read but not post.

We still want users with the required trust level to be able to anonymously post, though. The intended solution was to set up an anonymous user group with permission to write posts and add people based on the anonymous email domain we use at the forum. However, the automatic aspect of being added isn’t working - an administrator needs to go to the anonymous users group and save changes for anons to actually get added. That’s pretty annoying and messes up the flow we’d like, which is that paid member with the required trust level can switch to anonymous mode and have at it as far as posting anonymously.

I gather that having anon users added to a group automatically is a feature that is maybe being considered as an addition to Discourse but hasn’t been implemented yet. Assuming that’s the case, is there some other reasonable way I could configure my Discourse to have the outcome I want, or must I wait on the Discourse gods to hopefully add this feature? Thanks :slight_smile:

ユーザーのすべてのグループを、シャドウが作成されたときにそのシャドウにコピーするプラグインを作成しました。

免責事項:私はRubyに全くの初心者であり、私の環境では動作しますが、他の環境でも動作するかどうかは全くわかりません。

「いいね!」 2

この機能に賛成です。実装されましたか?見当たりません。あるいは、これを行うプラグインをご存知の方はいらっしゃいますか?

(参考:これはまともな回避策のように思えます。こちらで見つけました。)

ユーザーの1人が、フォーラムグループに匿名アカウントを自動的に追加するプラグインを作成しました。こちらが私が使用しているGitHubのフォークです。GitHub - curi/cf-anon-auto-group: Discourse plugin to trigger `user.set_automatic_groups` for anons on login 問題なく動作しています。

これにより、投稿を許可するために適切な権限を付与する必要があります。

他の人もこのソリューションを使用したり、より公式なプラグインを作成したり、コードをマージしたりできるかもしれません。

これは、メールによる自動グループメンバーシップ設定と組み合わせて機能します(当社の経験では、これだけでは機能しませんでした)。

参考までに、私が運営しているフォーラムでデータベースレベルでこの問題を「解決」しました。他の、より高レベルな解決策が機能しない場合にのみ使用してください(これに関して進捗はありましたか、それとも既存の返信のいずれかを「解決済み」としてフラグを立てるべきですか?)。以下はPostgreSQLコードです。

create or replace function anon_insert_copy_groups_to_anon_user()
  RETURNS TRIGGER
  LANGUAGE PLPGSQL
  AS $$
declare
  anon_user_id integer = new.user_id;
  master_user_id integer = new.master_user_id;
  active boolean = new.active;
  created_at timestamp = new.created_at;
  updated_at timestamp = new.updated_at;
BEGIN
  insert into group_users
        (group_id,                user_id,       created_at,        updated_at,        owner, notification_level,     first_unread_pm_at)
  select group_users.group_id, anon_user_id , current_timestamp, current_timestamp, false, 3 as notification_level, current_timestamp
  from group_users
  where group_users.user_id=master_user_id
  and   group_users.group_id not in (select group_id from group_users where group_users.user_id=anon_user_id)
  and   group_users.group_id not in (1, 2, 3); -- 管理者、モデレーター、スタッフを除く!

  return new;
end;
$$;

-- トリガーを作成する
CREATE TRIGGER anon_insert_trigger
AFTER INSERT ON anonymous_users
  FOR EACH ROW
    EXECUTE FUNCTION anon_insert_copy_groups_to_anon_user();