FIX: error during signup saying "Password is the same as your current password" due to automatic group membership granting a trust level
This commit is contained in:
parent
67347432b7
commit
9c40657ba4
|
@ -370,6 +370,11 @@ class Group < ActiveRecord::Base
|
||||||
self.where("string_to_array(incoming_email, '|') @> ARRAY[?]", Email.downcase(email)).first
|
self.where("string_to_array(incoming_email, '|') @> ARRAY[?]", Email.downcase(email)).first
|
||||||
end
|
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)
|
def bulk_add(user_ids)
|
||||||
if user_ids.present?
|
if user_ids.present?
|
||||||
Group.exec_sql("INSERT INTO group_users
|
Group.exec_sql("INSERT INTO group_users
|
||||||
|
|
|
@ -930,9 +930,7 @@ class User < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def automatic_group_membership
|
def automatic_group_membership
|
||||||
Group.where(automatic: false)
|
Group.grants_by_email_domain.each do |group|
|
||||||
.where("LENGTH(COALESCE(automatic_membership_email_domains, '')) > 0")
|
|
||||||
.each do |group|
|
|
||||||
domains = group.automatic_membership_email_domains.gsub('.', '\.')
|
domains = group.automatic_membership_email_domains.gsub('.', '\.')
|
||||||
if self.email =~ Regexp.new("@(#{domains})$", true) && !group.users.include?(self)
|
if self.email =~ Regexp.new("@(#{domains})$", true) && !group.users.include?(self)
|
||||||
group.add(self)
|
group.add(self)
|
||||||
|
@ -941,6 +939,14 @@ class User < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
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
|
def create_user_stat
|
||||||
stat = UserStat.new(new_since: Time.now)
|
stat = UserStat.new(new_since: Time.now)
|
||||||
stat.user_id = id
|
stat.user_id = id
|
||||||
|
@ -970,7 +976,15 @@ class User < ActiveRecord::Base
|
||||||
def add_trust_level
|
def add_trust_level
|
||||||
# there is a possibility we did not load trust level column, skip it
|
# there is a possibility we did not load trust level column, skip it
|
||||||
return unless has_attribute? :trust_level
|
return unless has_attribute? :trust_level
|
||||||
|
|
||||||
self.trust_level ||= SiteSetting.default_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
|
end
|
||||||
|
|
||||||
def update_username_lower
|
def update_username_lower
|
||||||
|
|
|
@ -1175,6 +1175,17 @@ describe User do
|
||||||
expect(group_history.target_user).to eq(user)
|
expect(group_history.target_user).to eq(user)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe "number_of_flags_given" do
|
describe "number_of_flags_given" do
|
||||||
|
|
Loading…
Reference in New Issue