rails-canhaz 1.0.1 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -75,7 +75,7 @@ user.can?(:read, article) # Will be true
75
75
 
76
76
  user.objects_with_permission(Article, :read) # Will return all the articles w/ read permissions for this user
77
77
 
78
- artice.subjects_with_permission(User, :read) # Will return all the users hat are able to read this article
78
+ article.subjects_with_permission(User, :read) # Will return all the users hat are able to read this article
79
79
 
80
80
  #You can also remove permissions
81
81
 
@@ -17,11 +17,7 @@ module CanHaz
17
17
  # @param type [Class] The type of the subjects we're looking for
18
18
  # @param permission [String, Symbol] The permission
19
19
  def subjects_with_permission(type, permission)
20
- results = CanHazPermission.where('cobject_id = ? AND cobject_type = ?', self.id, self.class.to_s).where('csubject_type = ?', type.to_s).where('permission_name = ?', permission)
21
-
22
- ids = results.collect { |r| r.csubject_id }
23
-
24
- type.where('id IN (?)', ids)
20
+ type.joins("INNER JOIN can_haz_permissions ON can_haz_permissions.csubject_id = #{type.table_name}.id").where('cobject_id = ? AND cobject_type = ?', self.id, self.class.to_s).where('csubject_type = ?', type.to_s).where('permission_name = ?', permission)
25
21
  end
26
22
 
27
23
  # Removes all rights on this object
@@ -65,12 +65,8 @@ module CanHaz
65
65
  # @param type [Class] The type of the objects
66
66
  # @param permission [String, Symbol] The name of the permission
67
67
  # @return The macthing objects in an array
68
- def objects_with_permission(type, permission = nil)
69
- results = CanHazPermission.where('csubject_id = ? AND csubject_type = ?', self.id, self.class.to_s).where('cobject_type = ?', type.to_s).where('permission_name = ?', permission)
70
-
71
- ids = results.collect { |r| r.cobject_id }
72
-
73
- type.where('id IN (?)', ids)
68
+ def objects_with_permission(type, permission)
69
+ type.joins("INNER JOIN can_haz_permissions ON can_haz_permissions.cobject_id = #{type.table_name}.id").where('cobject_type = ?', type.to_s).where('permission_name = ?', permission)
74
70
  end
75
71
 
76
72
  def canhaz_subject?
data/rails-canhaz.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'rails-canhaz'
3
- s.version = '1.0.1'
4
- s.date = '2012-06-19'
3
+ s.version = '1.0.4'
4
+ s.date = '2012-11-01'
5
5
  s.summary = "A simple gem for managing permissions between rails models"
6
6
  s.description = "A simple gem for managing permissions between rails models"
7
7
  s.authors = ["Adrien Siami (Intrepidd)"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-canhaz
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-19 00:00:00.000000000 Z
12
+ date: 2012-11-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord