rails-canhaz 1.0.1 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +1 -1
- data/lib/rails-canhaz/extensions_object.rb +1 -5
- data/lib/rails-canhaz/extensions_subject.rb +2 -6
- data/rails-canhaz.gemspec +2 -2
- metadata +2 -2
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
|
-
|
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
|
-
|
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
|
69
|
-
|
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.
|
4
|
-
s.date = '2012-
|
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.
|
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-
|
12
|
+
date: 2012-11-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|