Revert "FIX: error during signup saying "Password is the same as your current password" due to automatic group membership granting a trust level"

This reverts commit 9c40657ba4.

Calling this whenever a user is initialize is hurting us bad
on performance.
This commit is contained in:
Guo Xiang Tan 2017-01-16 09:44:10 +08:00
parent b2162b910b
commit ed5fa20b0c
3 changed files with 3 additions and 33 deletions

View File

@ -370,11 +370,6 @@ class Group < ActiveRecord::Base
self.where("string_to_array(incoming_email, '|') @> ARRAY[?]", Email.downcase(email)).first
end
def self.grants_by_email_domain
Group.where(automatic: false)
.where("LENGTH(COALESCE(automatic_membership_email_domains, '')) > 0")
end
def bulk_add(user_ids)
if user_ids.present?
Group.exec_sql("INSERT INTO group_users

View File

@ -932,7 +932,9 @@ class User < ActiveRecord::Base
end
def automatic_group_membership
Group.grants_by_email_domain.each do |group|
Group.where(automatic: false)
.where("LENGTH(COALESCE(automatic_membership_email_domains, '')) > 0")
.each do |group|
domains = group.automatic_membership_email_domains.gsub('.', '\.')
if self.email =~ Regexp.new("@(#{domains})$", true) && !group.users.include?(self)
group.add(self)
@ -941,14 +943,6 @@ class User < ActiveRecord::Base
end
end
def automatic_group_from_email
Group.grants_by_email_domain.each do |group|
domains = group.automatic_membership_email_domains.gsub('.', '\.')
return group if self.email =~ Regexp.new("@(#{domains})$", true)
end
nil
end
def create_user_stat
stat = UserStat.new(new_since: Time.now)
stat.user_id = id
@ -978,15 +972,7 @@ class User < ActiveRecord::Base
def add_trust_level
# there is a possibility we did not load trust level column, skip it
return unless has_attribute? :trust_level
self.trust_level ||= SiteSetting.default_trust_level
group_from_email = automatic_group_from_email
if group_from_email&.grant_trust_level &&
group_from_email.grant_trust_level > self.trust_level
self.trust_level = group_from_email.grant_trust_level
self.trust_level_locked = true
end
end
def update_username_lower

View File

@ -1196,17 +1196,6 @@ describe User do
expect(group_history.target_user).to eq(user)
end
it "get attributes from the group" do
group = Fabricate(:group, automatic_membership_email_domains: "bar.com|wat.com", grant_trust_level: 1, title: "bars and wats", primary_group: true)
user = Fabricate.build(:user, trust_level: 0, email: "foo@bar.com", password: "strongpassword4Uguys")
user.password_required!
expect(user.save).to eq(true)
user.reload
expect(user.title).to eq("bars and wats")
expect(user.trust_level).to eq(1)
expect(user.trust_level_locked).to eq(true)
end
end
describe "number_of_flags_given" do