mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Remove dead code related to user management
This commit is contained in:
@@ -76,7 +76,6 @@ module Spree
|
||||
return @collection if @collection.present?
|
||||
|
||||
if request.xhr? && params[:q].present?
|
||||
# Disabling proper nested include here due to rails 3.1 bug
|
||||
@collection = Spree::User.
|
||||
includes(:bill_address, :ship_address).
|
||||
where("spree_users.email #{LIKE} :search
|
||||
@@ -91,7 +90,7 @@ module Spree
|
||||
search: "#{params[:q].strip}%").
|
||||
limit(params[:limit] || 100)
|
||||
else
|
||||
@search = Spree::User.registered.ransack(params[:q])
|
||||
@search = Spree::User.ransack(params[:q])
|
||||
@collection = @search.
|
||||
result.
|
||||
page(params[:page]).
|
||||
|
||||
@@ -14,7 +14,6 @@ module Spree
|
||||
roles_table_name = Role.table_name
|
||||
|
||||
scope :admin, lambda { includes(:spree_roles).where("#{roles_table_name}.name" => "admin") }
|
||||
scope :registered, -> { where("#{users_table_name}.email NOT LIKE ?", "%@example.net") }
|
||||
|
||||
has_many :enterprise_roles, dependent: :destroy
|
||||
has_many :enterprises, through: :enterprise_roles
|
||||
@@ -43,16 +42,6 @@ module Spree
|
||||
|
||||
class DestroyWithOrdersError < StandardError; end
|
||||
|
||||
# Creates an anonymous user. An anonymous user is basically an auto-generated +User+ account
|
||||
# that is created for the customer behind the scenes and it's transparent to the customer.
|
||||
# All +Orders+ must have a +User+ so this is necessary when adding to the "cart" (an order)
|
||||
# and before the customer has a chance to provide an email or to register.
|
||||
def self.anonymous!
|
||||
token = User.generate_token(:persistence_token)
|
||||
User.create(email: "#{token}@example.net",
|
||||
password: token, password_confirmation: token, persistence_token: token)
|
||||
end
|
||||
|
||||
def self.admin_created?
|
||||
User.admin.count > 0
|
||||
end
|
||||
@@ -61,10 +50,6 @@ module Spree
|
||||
has_spree_role?('admin')
|
||||
end
|
||||
|
||||
def anonymous?
|
||||
email =~ /@example.net$/ ? true : false
|
||||
end
|
||||
|
||||
def send_reset_password_instructions
|
||||
generate_reset_password_token!
|
||||
UserMailer.reset_password_instructions(id).deliver
|
||||
@@ -162,14 +147,6 @@ module Spree
|
||||
SecureRandom.base64(15).tr('+/=', '-_ ').strip.delete("\n")
|
||||
end
|
||||
|
||||
# Generate a token by looping and ensuring does not already exist.
|
||||
def self.generate_token(column)
|
||||
loop do
|
||||
token = friendly_token
|
||||
break token unless find(:first, conditions: { column => token })
|
||||
end
|
||||
end
|
||||
|
||||
def limit_owned_enterprises
|
||||
return unless owned_enterprises.size > enterprise_limit
|
||||
|
||||
|
||||
@@ -188,14 +188,6 @@ describe Spree.user_class do
|
||||
expect(create(:user).admin?).to be_falsey
|
||||
end
|
||||
|
||||
context '#create' do
|
||||
let(:user) { build(:user) }
|
||||
|
||||
it 'should not be anonymous' do
|
||||
expect(user).not_to be_anonymous
|
||||
end
|
||||
end
|
||||
|
||||
context '#destroy' do
|
||||
it 'can not delete if it has completed orders' do
|
||||
order = build(:order, completed_at: Time.zone.now)
|
||||
@@ -205,20 +197,4 @@ describe Spree.user_class do
|
||||
expect { user.destroy }.to raise_exception(Spree::User::DestroyWithOrdersError)
|
||||
end
|
||||
end
|
||||
|
||||
context 'anonymous!' do
|
||||
let(:user) { Spree::User.anonymous! }
|
||||
|
||||
it 'should create a new user' do
|
||||
expect(user.new_record?).to be_falsey
|
||||
end
|
||||
|
||||
it 'should create a user with an example.net email' do
|
||||
expect(user.email).to match(/@example.net$/)
|
||||
end
|
||||
|
||||
it 'should be anonymous' do
|
||||
expect(user).to be_anonymous
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user