radiant-reader_group-extension 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/grouped_message.rb +1 -1
- data/lib/grouped_model.rb +24 -17
- data/radiant-reader_group-extension.gemspec +2 -2
- data/reader_group_extension.rb +1 -1
- data/spec/models/page_spec.rb +29 -0
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.3
|
data/lib/grouped_message.rb
CHANGED
data/lib/grouped_model.rb
CHANGED
@@ -13,9 +13,16 @@ module GroupedModel
|
|
13
13
|
return if has_groups?
|
14
14
|
|
15
15
|
class_eval {
|
16
|
-
extend GroupedModel::GroupedClassMethods
|
17
16
|
include GroupedModel::GroupedInstanceMethods
|
18
17
|
|
18
|
+
def self.has_groups?
|
19
|
+
true
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.visible
|
23
|
+
visible_to(nil)
|
24
|
+
end
|
25
|
+
|
19
26
|
unless instance_methods.include? 'visible_to?'
|
20
27
|
def visible_to?(reader)
|
21
28
|
return true
|
@@ -28,6 +35,20 @@ module GroupedModel
|
|
28
35
|
has_many :groups, :through => :permissions
|
29
36
|
Group.define_retrieval_methods(self.to_s)
|
30
37
|
|
38
|
+
named_scope :visible_to, lambda { |reader|
|
39
|
+
if reader.nil? || reader.groups.empty?
|
40
|
+
conditions = "pp.group_id IS NULL"
|
41
|
+
else
|
42
|
+
ids = reader.group_ids
|
43
|
+
conditions = reader.nil? ? "pp.group_id IS NULL" : ["pp.group_id IS NULL OR pp.group_id IN(#{ids.map{"?"}.join(',')})", *ids]
|
44
|
+
end
|
45
|
+
{
|
46
|
+
:joins => "LEFT OUTER JOIN permissions as pp on pp.permitted_id = #{self.table_name}.id AND pp.permitted_type = '#{self.to_s}'",
|
47
|
+
:group => column_names.map { |n| self.table_name + '.' + n }.join(','),
|
48
|
+
:conditions => conditions
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
31
52
|
named_scope :ungrouped, {
|
32
53
|
:select => "#{self.table_name}.*, count(pp.id) as group_count",
|
33
54
|
:joins => "LEFT OUTER JOIN permissions as pp on pp.permitted_id = #{self.table_name}.id AND pp.permitted_type = '#{self.to_s}'",
|
@@ -52,33 +73,19 @@ module GroupedModel
|
|
52
73
|
end
|
53
74
|
end
|
54
75
|
|
55
|
-
named_scope :
|
76
|
+
named_scope :belonging_to, lambda { |group|
|
56
77
|
{
|
57
78
|
:joins => "INNER JOIN permissions as pp on pp.permitted_id = #{self.table_name}.id AND pp.permitted_type = '#{self.to_s}'",
|
58
|
-
:conditions => ["pp.group_id = ?)", group.id],
|
59
79
|
:group => column_names.map { |n| self.table_name + '.' + n }.join(','),
|
80
|
+
:conditions => ["pp.group_id = ?)", group.id],
|
60
81
|
:readonly => false
|
61
82
|
}
|
62
83
|
}
|
63
84
|
|
64
|
-
named_scope :visible_to, lambda { |reader|
|
65
|
-
groups = reader.nil? ? [] : reader.groups
|
66
|
-
{:conditions => ["group_id IS NULL OR group_id IN(?)", groups.map(&:id).join(',')]}
|
67
|
-
}
|
68
85
|
end
|
69
86
|
alias :has_group :has_groups
|
70
87
|
end
|
71
88
|
|
72
|
-
module GroupedClassMethods
|
73
|
-
def has_groups?
|
74
|
-
true
|
75
|
-
end
|
76
|
-
|
77
|
-
def visible
|
78
|
-
ungrouped
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
89
|
module GroupedInstanceMethods
|
83
90
|
|
84
91
|
# in GroupedPage this is chained to include inherited groups
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{radiant-reader_group-extension}
|
8
|
-
s.version = "1.2.
|
8
|
+
s.version = "1.2.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["spanner"]
|
12
|
-
s.date = %q{2011-02-
|
12
|
+
s.date = %q{2011-02-16}
|
13
13
|
s.description = %q{Adds group-based page access control to radiant.}
|
14
14
|
s.email = %q{will@spanner.org}
|
15
15
|
s.extra_rdoc_files = [
|
data/reader_group_extension.rb
CHANGED
data/spec/models/page_spec.rb
CHANGED
@@ -8,6 +8,35 @@ describe Page do
|
|
8
8
|
@site = Page.current_site = sites(:test) if defined? Site
|
9
9
|
end
|
10
10
|
|
11
|
+
describe "listed" do
|
12
|
+
describe "for nobody in particular" do
|
13
|
+
it "should not include private pages" do
|
14
|
+
Page.visible.include?(pages(:news)).should be_false
|
15
|
+
end
|
16
|
+
it "should include non-private pages" do
|
17
|
+
Page.visible.include?(pages(:first)).should be_true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "for a reader without group memberships" do
|
22
|
+
it "should not include private pages" do
|
23
|
+
Page.visible_to(readers(:ungrouped)).include?(pages(:news)).should be_false
|
24
|
+
end
|
25
|
+
it "should include non-private pages" do
|
26
|
+
Page.visible_to(readers(:ungrouped)).include?(pages(:first)).should be_true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "for a reader with group memberships" do
|
31
|
+
it "should include private pages" do
|
32
|
+
Page.visible_to(readers(:another)).include?(pages(:news)).should be_true
|
33
|
+
end
|
34
|
+
it "should include non-private pages" do
|
35
|
+
Page.visible_to(readers(:another)).include?(pages(:first)).should be_true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
11
40
|
describe "with groups" do
|
12
41
|
before do
|
13
42
|
@page = pages(:parent)
|
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: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 1.2.
|
9
|
+
- 3
|
10
|
+
version: 1.2.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- spanner
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-02-
|
18
|
+
date: 2011-02-16 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|