radiant-reader_group-extension 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.0
1
+ 1.2.1
@@ -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
@@ -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.groups.include?(group)
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
@@ -11,26 +11,15 @@ module GroupedPage
11
11
 
12
12
  module InstanceMethods
13
13
 
14
- # this is all very inefficient recursive stuff
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
- lineage = self.ancestors
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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{radiant-reader_group-extension}
8
- s.version = "1.2.0"
8
+ s.version = "1.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["spanner"]
@@ -10,7 +10,7 @@ module ReaderGroup
10
10
  end
11
11
 
12
12
  class ReaderGroupExtension < Radiant::Extension
13
- version "1.1.2"
13
+ version "1.2.1"
14
14
  description "Page (and other) access control for site readers and groups"
15
15
  url "http://spanner.org/radiant/reader_group"
16
16
 
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: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 0
10
- version: 1.2.0
9
+ - 1
10
+ version: 1.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - spanner