challah 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## Challah 0.5.0
2
+
3
+ * Modified user permission key lookup to use caching of permission keys.
4
+ * Added timestamps to roles migration.
5
+
1
6
  ## Challah 0.4.1
2
7
 
3
8
  * Added User#protect_attributes to allow for the addition of app-specific protected attributes in User
@@ -5,6 +5,7 @@ class CreateRoles < ActiveRecord::Migration
5
5
  t.text :description
6
6
  t.string :default_path, :default => '/'
7
7
  t.boolean :locked, :default => false
8
+ t.timestamps
8
9
  end
9
10
  end
10
11
 
@@ -15,7 +15,7 @@ module Challah
15
15
 
16
16
  before_save :before_save_password
17
17
 
18
- belongs_to :role
18
+ belongs_to :role, :touch => true
19
19
  has_many :permission_users, :dependent => :destroy
20
20
  has_many :permissions, :through => :permission_users, :order => 'permissions.name'
21
21
 
@@ -131,8 +131,28 @@ module Challah
131
131
  def permission_keys
132
132
  return @permission_keys if @permission_keys
133
133
 
134
- role_keys = self.role(true) ? self.role.permission_keys.clone : []
135
- user_keys = new_record? ? [] : self.user_permission_keys.clone
134
+ role_keys = if role(true)
135
+ role_key = "#{role.cache_key}/permissions"
136
+
137
+ keys = Rails.cache.fetch(role_key) do
138
+ role.permission_keys.clone
139
+ end
140
+
141
+ Rails.cache.write(role_key, keys)
142
+ keys
143
+ else
144
+ []
145
+ end
146
+
147
+ user_key = "#{self.cache_key}/permissions"
148
+
149
+ user_keys = Rails.cache.fetch(user_key) do
150
+ user_permission_keys.clone
151
+ end
152
+
153
+ user_keys = [] unless user_keys
154
+
155
+ Rails.cache.write(user_key, keys) unless new_record?
136
156
 
137
157
  @permission_keys = (role_keys + user_keys).uniq
138
158
  end
@@ -145,6 +165,8 @@ module Challah
145
165
 
146
166
  # Set the permission keys that this role can access
147
167
  def permission_keys=(value)
168
+ Rails.cache.delete("#{self.cache_key}/permissions")
169
+
148
170
  @permission_keys = value
149
171
  @permission_keys
150
172
  end
@@ -181,7 +203,7 @@ module Challah
181
203
 
182
204
  # Returns the permission keys used by this specific user, does not include any role-based permissions.
183
205
  def user_permission_keys
184
- self.permissions(true).collect(&:key)
206
+ new_record? ? [] : self.permissions(true).collect(&:key)
185
207
  end
186
208
 
187
209
  # Is this user valid and ready for a user session?
@@ -1,3 +1,3 @@
1
1
  module Challah
2
- VERSION = "0.4.1" unless defined?(::Challah::VERSION)
2
+ VERSION = "0.5.0" unless defined?(::Challah::VERSION)
3
3
  end
data/test/user_test.rb CHANGED
@@ -181,7 +181,7 @@ class UserTest < ActiveSupport::TestCase
181
181
  assert_raises NoMethodError do
182
182
  user.does_not_exist
183
183
  end
184
- end
184
+ end
185
185
 
186
186
  should "authenticate through various means by default" do
187
187
  user = Factory(:user)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: challah
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-09 00:00:00.000000000Z
12
+ date: 2012-02-20 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: highline
16
- requirement: &70149861857320 !ruby/object:Gem::Requirement
16
+ requirement: &70359908531280 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70149861857320
24
+ version_requirements: *70359908531280
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rails
27
- requirement: &70149861950500 !ruby/object:Gem::Requirement
27
+ requirement: &70359908624460 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '3.1'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70149861950500
35
+ version_requirements: *70359908624460
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &70149861950000 !ruby/object:Gem::Requirement
38
+ requirement: &70359908623960 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.9.2
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70149861950000
46
+ version_requirements: *70359908623960
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bcrypt-ruby
49
- requirement: &70149861949540 !ruby/object:Gem::Requirement
49
+ requirement: &70359908623500 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70149861949540
57
+ version_requirements: *70359908623500
58
58
  description: A simple ruby gem for authentication, users, roles and permissions.
59
59
  email:
60
60
  - john@johntornow.com