spree_auth 1.0.0.rc3 → 1.0.0.rc4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of spree_auth might be problematic. Click here for more details.

@@ -1,5 +1,7 @@
1
1
  module Spree
2
2
  class User < ActiveRecord::Base
3
+ include Core::UserBanners
4
+
3
5
  devise :database_authenticatable, :token_authenticatable, :registerable, :recoverable,
4
6
  :rememberable, :trackable, :validatable, :encryptable, :encryptor => 'authlogic_sha512'
5
7
 
@@ -10,6 +12,7 @@ module Spree
10
12
 
11
13
  before_save :check_admin
12
14
  before_validation :set_login
15
+ before_destroy :check_completed_orders
13
16
 
14
17
  # Setup accessible (or protected) attributes for your model
15
18
  attr_accessible :email, :password, :password_confirmation, :remember_me, :persistence_token
@@ -20,6 +23,8 @@ module Spree
20
23
  scope :admin, lambda { includes(:roles).where("#{roles_table_name}.name" => "admin") }
21
24
  scope :registered, where("#{users_table_name}.email NOT LIKE ?", "%@example.net")
22
25
 
26
+ class DestroyWithOrdersError < StandardError; end
27
+
23
28
  # has_role? simply needs to return true or false whether a user has a role or not.
24
29
  def has_role?(role_in_question)
25
30
  roles.any? { |role| role.name == role_in_question.to_s }
@@ -52,6 +57,11 @@ module Spree
52
57
  end
53
58
 
54
59
  private
60
+
61
+ def check_completed_orders
62
+ raise DestroyWithOrdersError if orders.complete.present?
63
+ end
64
+
55
65
  def check_admin
56
66
  return if self.class.admin_created?
57
67
  admin_role = Role.find_or_create_by_name 'admin'
data/db/default/users.rb CHANGED
@@ -63,15 +63,14 @@ def create_admin_user
63
63
  end
64
64
  end
65
65
 
66
- if Rails.env.development?
67
- if Spree::User.admin.empty?
66
+ if Spree::User.admin.empty?
67
+ create_admin_user
68
+ else
69
+ puts 'Admin user has already been previously created.'
70
+ if agree('Would you like to create a new admin user? (yes/no)')
68
71
  create_admin_user
69
72
  else
70
- puts 'Admin user has already been previously created.'
71
- if agree('Would you like to create a new admin user? (yes/no)')
72
- create_admin_user
73
- else
74
- puts 'No admin user created.'
75
- end
73
+ puts 'No admin user created.'
76
74
  end
77
75
  end
76
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc3
4
+ version: 1.0.0.rc4
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-31 00:00:00.000000000 Z
12
+ date: 2012-02-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: spree_core
16
- requirement: &70156358869740 !ruby/object:Gem::Requirement
16
+ requirement: &70299989919900 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - =
20
20
  - !ruby/object:Gem::Version
21
- version: 1.0.0.rc3
21
+ version: 1.0.0.rc4
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70156358869740
24
+ version_requirements: *70299989919900
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: devise
27
- requirement: &70156358868540 !ruby/object:Gem::Requirement
27
+ requirement: &70299989919360 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - =
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.4.8
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70156358868540
35
+ version_requirements: *70299989919360
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: cancan
38
- requirement: &70156358867500 !ruby/object:Gem::Requirement
38
+ requirement: &70299989918900 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - =
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: 1.6.7
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70156358867500
46
+ version_requirements: *70299989918900
47
47
  description: Required dependency for Spree
48
48
  email: sean@spreecommerce.com
49
49
  executables: []