# User.set\_automatic\_groups 未针对所有社交登录被调用

**URL:** <https://meta.discourse.org/t/user-set-automatic-groups-is-not-called-for-all-social-logins/81579>\
**Category:** Bug\
**Created:** [2018年二月26日 18:50 UTC](https://meta.discourse.org/t/user-set-automatic-groups-is-not-called-for-all-social-logins/81579 "2018-02-26T18:50:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)\
**Post date:** [2018年二月26日 18:50 UTC](https://meta.discourse.org/t/user-set-automatic-groups-is-not-called-for-all-social-logins/81579/1 "2018-02-26T18:50:21Z")

</div>

Our Google login provider has the following code:

```plaintext
def after_create_account(user, auth)
  data = auth[:extra_data]
  GoogleUserInfo.create({ user_id: user.id }.merge(data))
  if auth[:email_valid].to_s == 'true' && data[:email]&.downcase == user.email
    EmailToken.confirm(user.email_tokens.first.token)
    user.set_automatic_groups
  end
end

```

Specifically, `user.set_automatic_groups` ensures that automatic group rules are applied to the user. This function is not called by our other auto providers, including GitHub, Facebook, and Twitter. We should ensure that all social login provider call `user.set_automatic_groups`, or that the call is extracted to a shared function that all providers use.

cc @supermathie @n-b-sonar

---

<div class="post-metadata">

**Author:** ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)\
**Post date:** [2018年二月26日 19:02 UTC](https://meta.discourse.org/t/user-set-automatic-groups-is-not-called-for-all-social-logins/81579/2 "2018-02-26T19:02:31Z")

</div>

I was pondering earlier whether it would make sense to just fire this in e.g. `User.logged_in` so that it’s refreshed on login, but without delving into it it probably makes sense to trigger this:

- in the UserEmail controller when a user’s (verified) email address is updated
- when the autogroup rules change

---

<div class="post-metadata">

**Author:** ![Osama](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/osama/32/98013_2.png) [@Osama](https://meta.discourse.org/u/Osama)\
**Post date:** [2018年五月21日 00:29 UTC](https://meta.discourse.org/t/user-set-automatic-groups-is-not-called-for-all-social-logins/81579/9 "2018-05-21T00:29:37Z")

</div>

I’ve sent a PR for this:

[https://github.com/discourse/discourse/pull/5848](https://github.com/discourse/discourse/pull/5848)

---

<div class="post-metadata">

**Author:** ![Osama](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/osama/32/98013_2.png) [@Osama](https://meta.discourse.org/u/Osama)\
**Post date:** [2018年五月23日 06:34 UTC](https://meta.discourse.org/t/user-set-automatic-groups-is-not-called-for-all-social-logins/81579/10 "2018-05-23T06:34:19Z")

</div>

PR merged thanks to @tgxworld 🎉 🎊

---

<div class="post-metadata">

**Author:** ![Osama](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/osama/32/98013_2.png) [@Osama](https://meta.discourse.org/u/Osama)\
**Post date:** [2018年五月23日 06:34 UTC](https://meta.discourse.org/t/user-set-automatic-groups-is-not-called-for-all-social-logins/81579/11 "2018-05-23T06:34:31Z")

</div>


