# 外部メールアドレスリストとのグループメンバーシップの同期

**URL:** <https://meta.discourse.org/t/sync-group-membership-with-external-list-of-email-addresses/190552>\
**Category:** Product Support\
**Created:** [2021 年 5 月 16 日午前 11:08 UTC](https://meta.discourse.org/t/sync-group-membership-with-external-list-of-email-addresses/190552 "2021-05-16T11:08:23Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [2021 年 7 月 8 日午後 6:54 UTC](https://meta.discourse.org/t/sync-group-membership-with-external-list-of-email-addresses/190552/5 "2021-07-08T18:54:50Z")

</div>

外部アプリケーションでこれらのユーザーを管理していない場合は、以下のような方法を実行できます。

```ruby
  def load_csv(path)
    CSV.parse(File.read(path), headers: true)
  end

  def update_group
   g=Group.find(43) #好きなグループID
   GroupUser.where(group_id: g.id).destroy_all
   user_emails=load_csv('/path/to/file')
    user_emails.each do |u|
      user = User.find_by_email(u['Email'])
      next unless user
      puts "found user #{uid}"
      GroupUser.find_or_create_by(group_id: g.id, user_id: user.id)
    end
  end

```

それがどう実装されるかは全く別の問題です。プラグインを使うかもしれません。

カテゴリに投稿したユーザーを自動的にグループに追加するプラグインなどはどうでしょうか？

---

_[View the full topic](https://meta.discourse.org/t/sync-group-membership-with-external-list-of-email-addresses/190552)._
