radiant-reader_group-extension 1.2.0 → 1.2.1
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/VERSION +1 -1
- data/app/models/group.rb +4 -0
- data/lib/grouped_model.rb +4 -4
- data/lib/grouped_page.rb +2 -13
- data/radiant-reader_group-extension.gemspec +1 -1
- data/reader_group_extension.rb +1 -1
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.1
|
data/app/models/group.rb
CHANGED
@@ -20,6 +20,10 @@ class Group < ActiveRecord::Base
|
|
20
20
|
named_scope :subscribable, { :conditions => "public = 1" }
|
21
21
|
named_scope :unsubscribable, { :conditions => "public = 0" }
|
22
22
|
|
23
|
+
named_scope :from_list, lambda { |ids|
|
24
|
+
{ :conditions => ["groups.id IN (#{ids.map{"?"}.join(',')})", *ids] }
|
25
|
+
}
|
26
|
+
|
23
27
|
named_scope :attached_to, lambda { |objects|
|
24
28
|
conditions = objects.map{|o| "(pp.permitted_type = ? AND pp.permitted_id = ?)" }.join(" OR ")
|
25
29
|
binds = objects.map{|o| [o.class.to_s, o.id]}.flatten
|
data/lib/grouped_model.rb
CHANGED
@@ -26,7 +26,6 @@ module GroupedModel
|
|
26
26
|
|
27
27
|
has_many :permissions, :as => :permitted
|
28
28
|
has_many :groups, :through => :permissions
|
29
|
-
accepts_nested_attributes_for :permissions
|
30
29
|
Group.define_retrieval_methods(self.to_s)
|
31
30
|
|
32
31
|
named_scope :ungrouped, {
|
@@ -103,15 +102,16 @@ module GroupedModel
|
|
103
102
|
permitted_groups.any? ? Reader.in_groups(permitted_groups) : Reader.all
|
104
103
|
end
|
105
104
|
|
106
|
-
# GroupedPage also defines a separate has_inherited_group? method
|
107
|
-
# so here we don't call permitted_groups
|
108
105
|
def has_group?(group)
|
109
|
-
return self.
|
106
|
+
return self.permitted_groups.include?(group)
|
110
107
|
end
|
111
108
|
|
112
109
|
def permit(group)
|
113
110
|
self.groups << group unless self.has_group?(group)
|
114
111
|
end
|
115
112
|
|
113
|
+
def group_ids=(ids)
|
114
|
+
self.groups = Group.from_list(ids)
|
115
|
+
end
|
116
116
|
end
|
117
117
|
end
|
data/lib/grouped_page.rb
CHANGED
@@ -11,26 +11,15 @@ module GroupedPage
|
|
11
11
|
|
12
12
|
module InstanceMethods
|
13
13
|
|
14
|
-
|
15
|
-
# but the ancestor pages should be in memory already
|
16
|
-
# and the groups check is now a single query
|
17
|
-
|
14
|
+
attr_reader :inherited_groups
|
18
15
|
def inherited_groups
|
19
|
-
|
20
|
-
if lineage.any?
|
21
|
-
Group.attached_to(lineage)
|
22
|
-
else
|
23
|
-
[]
|
24
|
-
end
|
16
|
+
@inherited_groups ||= self.parent ? Group.attached_to(self.ancestors) : []
|
25
17
|
end
|
26
18
|
|
27
19
|
def permitted_groups_with_inheritance
|
28
20
|
permitted_groups_without_inheritance + inherited_groups
|
29
21
|
end
|
30
22
|
|
31
|
-
# any page with a group-marker is never cached
|
32
|
-
# so that we can return cache hits with confidence
|
33
|
-
# this call is regrettably expensive
|
34
23
|
def cache?
|
35
24
|
self.permitted_groups.empty?
|
36
25
|
end
|
data/reader_group_extension.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: radiant-reader_group-extension
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 1.2.
|
9
|
+
- 1
|
10
|
+
version: 1.2.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- spanner
|