请求帮助降级具有无效电子邮件地址的用户

出于历史原因,我的 Google+ 导入器将用户导入到 TL1,以便为 Google+ 难民提供一个良好的开端。他们是使用 .invalid 电子邮件地址导入的, 当他们登录并通过 Google ID 连接到他们现有的用户记录时,我们会修复这个问题。

但现在我的 trust_level_1 群组充斥着数千名尚未关注其内容的未登录用户,如果他们几年后出现(他们有时会继续这样做),没有特别的理由让他们以 Basic 用户身份进入;他们应该成为 New 用户。引导期早已过去。我想将那些从未登录过的用户降级到 TL0,直到他们出现并查看为止,并仅依赖正常的晋升流程。

我在 rails 控制台中尝试过这个:

User.where(trust_level: 1) do |u|
    u.change_trust_level!(TrustLevel[0]) if !Email.is_valid?(u.primary_email&.email)
    u.save!
end

它花费了数分钟时间消耗了完整的 CPU,但什么也没做。(在此过程中,我还尝试了其他变体,例如 if !u.primary_email.is_valid?if !Email.is_valid?(u.primary_email),我知道真正的问题是我一年才接触一次 Ruby……)我确信我遗漏了一些对其他人来说显而易见的东西。如果有人能想到一个提示,我将不胜感激!

2 个赞

我明显错过了 .each

User.where(trust_level: 1).each do |u|
    u.change_trust_level!(TrustLevel[0]) if !Email.is_valid?(u.primary_email&.email)
    u.save!
end

这导致我的网站在运行时出现大量 IO 问题,并且仍然没有做出任何更改。所以我仍然做错了什么,并且不担心在实时系统上继续尝试。:smiling_face:

我确实发现 is_valid? 的意思不是这个。所以我现在正在寻找字面字符串,并通过打印电子邮件地址进行了测试。我还看到 change_trust_level 已经保存了用户,所以我不需要做两次。

User.where(trust_level: 1).each do |u|
   if u.primary_email&.email.end_with?(".invalid")
     u.change_trust_level!(TrustLevel[0])
   end
end

但是 trust_level_1 中的用户数量仍然没有改变,所以我仍然遗漏了重要的东西。

在这种情况下,您可以使用批量管理任务吗?


尽管我刚刚在我的测试用户(邮箱:test_thirteen@here.invalid,之前是 TL1,现在是 TL0)上测试了您的第二段代码,并且它对我有效。

User.where(trust_level: 1).each do |u|
   if u.primary_email&.email.end_with?(".invalid")
     u.change_trust_level!(TrustLevel[0])
   end
end
3 个赞

我会从 UserEmail 模型开始,找到电子邮件地址中包含“invalid”的用户,然后遍历它们,但这并不是我能在手机上确切弄清楚的事情。

如果那些包含无效的地址确实无效,那么它们将无法保存。

1 个赞

谢谢!

我已经手动提升了一些之前在现有社区成员中比较知名的用户,所以批量重新计算无法达到我想要的效果。(搜索时我确实找到了那个页面。)

最后一个实际上是有效的,就像对你一样。我的问题是我查看了 /g 群组概览页面并刷新它,然后寻找 trust_level_1 群组计数减少。在我运行它的时候,它没有显示计数变化,所以我用 control-C 停止了它。今天早上 trust_level_1 群组在该页面上显示的成员数量减少了数千人。所以现在我意识到那里的计数是缓存的,我_应该_点击那个卡片,然后查看 /g/trust_level_1 页面上的计数。

现在我明白了,我应该跟进 Group.ensure_consistency! 来修复该页面的计数。

这是整个过程,更简洁、更地道地表达:

User.where(trust_level: 1).each do |u|
     u.change_trust_level!(TrustLevel[0]) if u.primary_email&.email.end_with?(".invalid")
end
Group.ensure_consistency!

碰巧我记录了几位只有无效电子邮件但实际使用过网站并满足 TL1 要求的用户。我不知道这是怎么发生的,但现在我不在乎。我真正关心的是处理数千人的大部分问题,而不必担心少数例外。如果其他人也遇到这种情况,这个方法对我有用:

User.where(trust_level: 1).each do |u|
  begin
     u.change_trust_level!(TrustLevel[0]) if u.primary_email&.email.end_with?(".invalid")
  rescue
  end
end
Group.ensure_consistency!
2 个赞

Here’s the background:

script/import_scripts/friendsmegplus.rb

  def import_google_user(id, name)
    if !@emails[id].present?
      google_user_info = UserAssociatedAccount.find_by(provider_name: 'google_oauth2', provider_u
id: id.to_i)
      if google_user_info.nil?
        # create new google user on system; expect this user to merge
        # when they later log in with google authentication
        # Note that because email address is not included in G+ data, we
        # don't know if they already have another account not yet associated
        # with google ooauth2. If they didn't log in, they'll have an
        # @gplus.invalid address associated with their account
        email = "#{id}@gplus.invalid"

This means that I only care about primary_email and don’t have to start with UserEmail. I started down that path before realizing that anything that changed that not to be the primary_email would make me not want to change them anyway. So here it’s very specifically users whose only (thus primary) email literally ends with .invalid — which is what I’ve done.

1 个赞

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.