radiant-reader_group-extension 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/.gitignore +2 -0
  2. data/README.markdown +44 -0
  3. data/Rakefile +137 -0
  4. data/VERSION +1 -0
  5. data/app/controllers/admin/group_invitations_controller.rb +84 -0
  6. data/app/controllers/admin/groups_controller.rb +4 -0
  7. data/app/controllers/admin/memberships_controller.rb +42 -0
  8. data/app/controllers/admin/permissions_controller.rb +42 -0
  9. data/app/helpers/admin/groups_helper.rb +36 -0
  10. data/app/models/group.rb +43 -0
  11. data/app/models/membership.rb +13 -0
  12. data/app/models/permission.rb +13 -0
  13. data/app/views/admin/group_invitations/new.html.haml +45 -0
  14. data/app/views/admin/group_invitations/preview.html.haml +63 -0
  15. data/app/views/admin/groups/_add_readers.html.haml +0 -0
  16. data/app/views/admin/groups/_form.html.haml +61 -0
  17. data/app/views/admin/groups/_list_head.html.haml +12 -0
  18. data/app/views/admin/groups/_listed.html.haml +25 -0
  19. data/app/views/admin/groups/edit.html.haml +8 -0
  20. data/app/views/admin/groups/index.html.haml +19 -0
  21. data/app/views/admin/groups/new.html.haml +6 -0
  22. data/app/views/admin/groups/remove.html.haml +31 -0
  23. data/app/views/admin/groups/show.html.haml +41 -0
  24. data/app/views/admin/memberships/_reader.html.haml +9 -0
  25. data/app/views/admin/messages/_list_notes.html.haml +9 -0
  26. data/app/views/admin/messages/_message_description.html.haml +7 -0
  27. data/app/views/admin/messages/_message_group.html.haml +3 -0
  28. data/app/views/admin/pages/_listed.html.haml +16 -0
  29. data/app/views/admin/pages/_page_groups.html.haml +17 -0
  30. data/app/views/admin/permissions/_page.html.haml +24 -0
  31. data/app/views/admin/reader_settings/_group_welcomes.html.haml +11 -0
  32. data/app/views/admin/readers/_reader_groups.html.haml +7 -0
  33. data/app/views/messages/show.html.haml +11 -0
  34. data/app/views/reader_activations/_on_activation.html.haml +10 -0
  35. data/app/views/readers/_memberships.html.haml +11 -0
  36. data/app/views/site/not_allowed.html.haml +4 -0
  37. data/config/routes.rb +8 -0
  38. data/db/migrate/001_create_groups.rb +32 -0
  39. data/db/migrate/20090921125654_group_messages.rb +9 -0
  40. data/db/migrate/20091120083119_groups_public.rb +11 -0
  41. data/lib/admin_messages_controller_extensions.rb +15 -0
  42. data/lib/group_message_tags.rb +82 -0
  43. data/lib/group_ui.rb +37 -0
  44. data/lib/grouped_message.rb +38 -0
  45. data/lib/grouped_model.rb +100 -0
  46. data/lib/grouped_page.rb +59 -0
  47. data/lib/grouped_reader.rb +63 -0
  48. data/lib/reader_activations_controller_extensions.rb +21 -0
  49. data/lib/reader_notifier_extensions.rb +14 -0
  50. data/lib/reader_sessions_controller_extensions.rb +21 -0
  51. data/lib/readers_controller_extensions.rb +22 -0
  52. data/lib/site_controller_extensions.rb +37 -0
  53. data/lib/tasks/reader_group_extension_tasks.rake +28 -0
  54. data/pkg/radiant-reader_group-extension-0.9.0.gem +0 -0
  55. data/public/images/admin/chk_auto.png +0 -0
  56. data/public/images/admin/chk_off.png +0 -0
  57. data/public/images/admin/chk_on.png +0 -0
  58. data/public/images/admin/edit.png +0 -0
  59. data/public/images/admin/error.png +0 -0
  60. data/public/images/admin/message.png +0 -0
  61. data/public/images/admin/new-group.png +0 -0
  62. data/public/images/admin/populate.png +0 -0
  63. data/public/images/admin/rdo_off.png +0 -0
  64. data/public/images/admin/rdo_on.png +0 -0
  65. data/public/stylesheets/sass/admin/group.sass +66 -0
  66. data/radiant-reader_group-extension.gemspec +134 -0
  67. data/reader_group_extension.rb +53 -0
  68. data/spec/controllers/readers_controller_spec.rb +44 -0
  69. data/spec/controllers/site_controller_spec.rb +64 -0
  70. data/spec/datasets/group_messages_dataset.rb +32 -0
  71. data/spec/datasets/group_readers_dataset.rb +49 -0
  72. data/spec/datasets/group_sites_dataset.rb +11 -0
  73. data/spec/datasets/groups_dataset.rb +48 -0
  74. data/spec/models/group_spec.rb +45 -0
  75. data/spec/models/message_spec.rb +42 -0
  76. data/spec/models/page_spec.rb +53 -0
  77. data/spec/models/reader_spec.rb +16 -0
  78. data/spec/spec.opts +6 -0
  79. data/spec/spec_helper.rb +36 -0
  80. metadata +184 -0
@@ -0,0 +1,32 @@
1
+ require "authlogic/test_case"
2
+
3
+ class GroupMessagesDataset < Dataset::Base
4
+ datasets = [:groups]
5
+ datasets << :group_sites if defined? Site
6
+ uses *datasets
7
+
8
+ def load
9
+ create_message "Normal"
10
+ create_message "Grouped", :group => groups(:normal)
11
+ end
12
+
13
+ helpers do
14
+ def create_message(subject, attributes={})
15
+ attributes = message_attributes(attributes.update(:subject => subject))
16
+ message = create_model Message, subject.symbolize, attributes
17
+ end
18
+
19
+ def message_attributes(attributes={})
20
+ subject = attributes[:subject] || "Message"
21
+ symbol = subject.symbolize
22
+ attributes = {
23
+ :subject => subject,
24
+ :body => "This is the #{subject} message"
25
+ }.merge(attributes)
26
+ attributes[:site] = sites(:test) if defined? Site
27
+ attributes
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -0,0 +1,49 @@
1
+ require "authlogic/test_case"
2
+
3
+ class GroupReadersDataset < Dataset::Base
4
+ uses :group_sites if defined? Site
5
+
6
+ def load
7
+ create_reader "Normal"
8
+ create_reader "Another"
9
+ create_reader "Ungrouped"
10
+ create_reader "Inactive", :activated_at => nil
11
+ end
12
+
13
+ helpers do
14
+ def create_reader(name, attributes={})
15
+ attributes = reader_attributes(attributes.update(:name => name))
16
+ reader = create_model Reader, name.symbolize, attributes
17
+ end
18
+
19
+ def reader_attributes(attributes={})
20
+ name = attributes[:name] || "John Doe"
21
+ symbol = name.symbolize
22
+ attributes = {
23
+ :name => name,
24
+ :email => "#{symbol}@spanner.org",
25
+ :login => "#{symbol}@spanner.org",
26
+ :activated_at => Time.now - 1.week,
27
+ :password_salt => "golly",
28
+ :password => 'password',
29
+ :password_confirmation => 'password'
30
+ }.merge(attributes)
31
+ attributes[:site] = sites(:test) if defined? Site
32
+ attributes
33
+ end
34
+
35
+ def login_as_reader(reader)
36
+ activate_authlogic
37
+ login_reader = reader.is_a?(Reader) ? reader : readers(reader)
38
+ ReaderSession.create(login_reader)
39
+ login_reader
40
+ end
41
+
42
+ def logout_reader
43
+ if session = ReaderSession.find
44
+ session.destroy
45
+ end
46
+ end
47
+ end
48
+
49
+ end
@@ -0,0 +1,11 @@
1
+ class GroupSitesDataset < Dataset::Base
2
+ uses :pages
3
+
4
+ def load
5
+ create_record Site, :test, :name => 'Test Site', :domain => 'test', :base_domain => 'test.host', :position => 1, :mail_from_name => 'test sender', :mail_from_address => 'sender@spanner.org', :homepage_id => page_id(:home)
6
+ create_record Site, :elsewhere, :name => 'Another Site', :domain => '^elsewhere', :base_domain => 'elsewhere.test.com', :position => 2
7
+ create_record Site, :default, :name => 'Default', :domain => '', :base_domain => 'spanner.org', :position => 3
8
+ Page.current_site = sites(:test)
9
+ end
10
+
11
+ end
@@ -0,0 +1,48 @@
1
+ require 'digest/sha1'
2
+ class GroupsDataset < Dataset::Base
3
+ datasets = [:pages, :group_readers]
4
+ datasets << :group_sites if defined? Site
5
+ uses *datasets
6
+
7
+ def load
8
+ create_group "Normal"
9
+ create_group "Special"
10
+ create_group "Homed", :homepage_id => page_id(:parent)
11
+ create_group "Elsewhere", :site_id => site_id(:elsewhere) if defined? Site
12
+
13
+ add_pages_to_group :homed, [:parent, :childless]
14
+ add_readers_to_group :homed, [:normal]
15
+
16
+ add_readers_to_group :special, [:another]
17
+ add_pages_to_group :special, [:news]
18
+
19
+ add_readers_to_group :normal, [:normal, :inactive]
20
+ end
21
+
22
+ helpers do
23
+ def create_group(name, att={})
24
+ group = create_record Group, name.symbolize, group_attributes(att.update(:name => name))
25
+ end
26
+
27
+ def group_attributes(att={})
28
+ name = att[:name] || "A group"
29
+ attributes = {
30
+ :name => name,
31
+ :description => "Test group"
32
+ }.merge(att)
33
+ attributes[:site_id] ||= site_id(:test) if defined? Site
34
+ attributes
35
+ end
36
+ end
37
+
38
+ def add_pages_to_group(g, pp)
39
+ g = g.is_a?(Group) ? g : groups(g)
40
+ g.pages << pp.map{|p| pages(p)}
41
+ end
42
+
43
+ def add_readers_to_group(g, rr)
44
+ g = g.is_a?(Group) ? g : groups(g)
45
+ g.readers << rr.map{|r| readers(r)}
46
+ end
47
+
48
+ end
@@ -0,0 +1,45 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Group do
4
+ dataset :groups, :pages
5
+
6
+ describe "on validation" do
7
+ before do
8
+ @group = Group.new :name => "Unique Test Group"
9
+ @group.should be_valid
10
+ end
11
+
12
+ it "should require a name" do
13
+ @group.name = nil
14
+ @group.should_not be_valid
15
+ @group.errors.on(:name).should_not be_empty
16
+ end
17
+
18
+ it "should require a unique name" do
19
+ duplicate = Group.new :name => "Normal"
20
+ duplicate.should_not be_valid
21
+ duplicate.errors.on(:name).should_not be_empty
22
+ end
23
+ end
24
+
25
+ it "should have a homepage association" do
26
+ Group.reflect_on_association(:homepage).should_not be_nil
27
+ group = groups(:homed)
28
+ group.homepage.should be_a(Page)
29
+ group.homepage = pages(:child)
30
+ group.homepage.should == pages(:child)
31
+ end
32
+
33
+ it "should have a group of readers" do
34
+ group = groups(:normal)
35
+ group.readers.any?.should be_true
36
+ group.readers.size.should == 2
37
+ end
38
+
39
+ it "should have a group of pages" do
40
+ group = groups(:homed)
41
+ group.pages.any?.should be_true
42
+ group.pages.size.should == 2
43
+ end
44
+
45
+ end
@@ -0,0 +1,42 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Message do
4
+ dataset :group_messages
5
+
6
+ before do
7
+ @site = Page.current_site = sites(:test) if defined? Site
8
+ end
9
+
10
+ it "should have a group association" do
11
+ Message.reflect_on_association(:group).should_not be_nil
12
+ end
13
+
14
+ it "should normally list only the ungrouped messages" do
15
+ Message.visible.count.should == 1
16
+ end
17
+
18
+ describe "with a group" do
19
+ it "should report itself visible to a reader who is a group member" do
20
+ messages(:grouped).visible_to?(readers(:normal)).should be_true
21
+ end
22
+ it "should report itself invisible to a reader who is not a group member" do
23
+ messages(:grouped).visible_to?(readers(:ungrouped)).should be_false
24
+ end
25
+ it "should list only group members as possible readers" do
26
+ messages(:grouped).possible_readers.include?(readers(:normal)).should be_true
27
+ messages(:grouped).possible_readers.include?(readers(:ungrouped)).should be_false
28
+ end
29
+ end
30
+
31
+ describe "without a group" do
32
+ it "should report itself visible to everyone" do
33
+ messages(:normal).visible_to?(readers(:normal)).should be_true
34
+ messages(:normal).visible_to?(readers(:ungrouped)).should be_true
35
+ end
36
+
37
+ it "should list all readers as possible readers" do
38
+ messages(:normal).possible_readers.include?(readers(:normal)).should be_true
39
+ messages(:normal).possible_readers.include?(readers(:ungrouped)).should be_true
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,53 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Page do
4
+ dataset :groups
5
+ dataset :pages
6
+
7
+ before do
8
+ @site = Page.current_site = sites(:test) if defined? Site
9
+ end
10
+
11
+ describe "with groups" do
12
+ before do
13
+ @page = pages(:parent)
14
+ end
15
+ it "should have some groups" do
16
+ @page.groups.any?.should be_true
17
+ @page.groups.size.should == 1
18
+ end
19
+
20
+ it "should be visible to group members" do
21
+ @page.visible_to?(readers(:normal)).should be_true
22
+ end
23
+
24
+ it "should not be visible to non-members" do
25
+ @page.visible_to?(readers(:ungrouped)).should be_false
26
+ end
27
+ end
28
+
29
+ describe "with inherited groups" do
30
+ before do
31
+ @page = pages(:child)
32
+ end
33
+
34
+ it "should be visible to group members" do
35
+ @page.visible_to?(readers(:normal)).should be_true
36
+ end
37
+
38
+ it "should not be visible to non-members" do
39
+ @page.visible_to?(readers(:ungrouped)).should be_false
40
+ end
41
+ end
42
+
43
+ describe "without groups" do
44
+ before do
45
+ @page = pages(:home)
46
+ end
47
+ it "should be visible to everyone" do
48
+ @page.visible_to?(readers(:ungrouped)).should be_true
49
+ end
50
+
51
+ end
52
+
53
+ end
@@ -0,0 +1,16 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Reader do
4
+ dataset :groups
5
+
6
+ before do
7
+ @site = Page.current_site = sites(:test) if defined? Site
8
+ end
9
+
10
+ it "should have some groups" do
11
+ reader = readers(:normal)
12
+ reader.groups.any?.should be_true
13
+ reader.groups.size.should == 2
14
+ end
15
+
16
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,6 @@
1
+ --colour
2
+ --format
3
+ progress
4
+ --loadby
5
+ mtime
6
+ --reverse
@@ -0,0 +1,36 @@
1
+ unless defined? RADIANT_ROOT
2
+ ENV["RAILS_ENV"] = "test"
3
+ case
4
+ when ENV["RADIANT_ENV_FILE"]
5
+ require ENV["RADIANT_ENV_FILE"]
6
+ when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
7
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../../")}/config/environment"
8
+ else
9
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/environment"
10
+ end
11
+ end
12
+ require "#{RADIANT_ROOT}/spec/spec_helper"
13
+
14
+ Dataset::Resolver.default << (File.dirname(__FILE__) + "/datasets")
15
+
16
+ if File.directory?(File.dirname(__FILE__) + "/matchers")
17
+ Dir[File.dirname(__FILE__) + "/matchers/*.rb"].each {|file| require file }
18
+ end
19
+
20
+ Spec::Runner.configure do |config|
21
+ # config.use_transactional_fixtures = true
22
+ # config.use_instantiated_fixtures = false
23
+ # config.fixture_path = RAILS_ROOT + '/spec/fixtures'
24
+
25
+ # You can declare fixtures for each behaviour like this:
26
+ # describe "...." do
27
+ # fixtures :table_a, :table_b
28
+ #
29
+ # Alternatively, if you prefer to declare them only once, you can
30
+ # do so here, like so ...
31
+ #
32
+ # config.global_fixtures = :table_a, :table_b
33
+ #
34
+ # If you declare global fixtures, be aware that they will be declared
35
+ # for all of your examples, even those that don't use them.
36
+ end
metadata ADDED
@@ -0,0 +1,184 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: radiant-reader_group-extension
3
+ version: !ruby/object:Gem::Version
4
+ hash: 59
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 9
9
+ - 0
10
+ version: 0.9.0
11
+ platform: ruby
12
+ authors:
13
+ - spanner
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-04 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: radiant
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 59
30
+ segments:
31
+ - 0
32
+ - 9
33
+ - 0
34
+ version: 0.9.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: radiant-reader-extension
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ description: Adds group-based page access control to radiant.
52
+ email: will@spanner.org
53
+ executables: []
54
+
55
+ extensions: []
56
+
57
+ extra_rdoc_files:
58
+ - README.markdown
59
+ files:
60
+ - .gitignore
61
+ - README.markdown
62
+ - Rakefile
63
+ - VERSION
64
+ - app/controllers/admin/group_invitations_controller.rb
65
+ - app/controllers/admin/groups_controller.rb
66
+ - app/controllers/admin/memberships_controller.rb
67
+ - app/controllers/admin/permissions_controller.rb
68
+ - app/helpers/admin/groups_helper.rb
69
+ - app/models/group.rb
70
+ - app/models/membership.rb
71
+ - app/models/permission.rb
72
+ - app/views/admin/group_invitations/new.html.haml
73
+ - app/views/admin/group_invitations/preview.html.haml
74
+ - app/views/admin/groups/_add_readers.html.haml
75
+ - app/views/admin/groups/_form.html.haml
76
+ - app/views/admin/groups/_list_head.html.haml
77
+ - app/views/admin/groups/_listed.html.haml
78
+ - app/views/admin/groups/edit.html.haml
79
+ - app/views/admin/groups/index.html.haml
80
+ - app/views/admin/groups/new.html.haml
81
+ - app/views/admin/groups/remove.html.haml
82
+ - app/views/admin/groups/show.html.haml
83
+ - app/views/admin/memberships/_reader.html.haml
84
+ - app/views/admin/messages/_list_notes.html.haml
85
+ - app/views/admin/messages/_message_description.html.haml
86
+ - app/views/admin/messages/_message_group.html.haml
87
+ - app/views/admin/pages/_listed.html.haml
88
+ - app/views/admin/pages/_page_groups.html.haml
89
+ - app/views/admin/permissions/_page.html.haml
90
+ - app/views/admin/reader_settings/_group_welcomes.html.haml
91
+ - app/views/admin/readers/_reader_groups.html.haml
92
+ - app/views/messages/show.html.haml
93
+ - app/views/reader_activations/_on_activation.html.haml
94
+ - app/views/readers/_memberships.html.haml
95
+ - app/views/site/not_allowed.html.haml
96
+ - config/routes.rb
97
+ - db/migrate/001_create_groups.rb
98
+ - db/migrate/20090921125654_group_messages.rb
99
+ - db/migrate/20091120083119_groups_public.rb
100
+ - lib/admin_messages_controller_extensions.rb
101
+ - lib/group_message_tags.rb
102
+ - lib/group_ui.rb
103
+ - lib/grouped_message.rb
104
+ - lib/grouped_model.rb
105
+ - lib/grouped_page.rb
106
+ - lib/grouped_reader.rb
107
+ - lib/reader_activations_controller_extensions.rb
108
+ - lib/reader_notifier_extensions.rb
109
+ - lib/reader_sessions_controller_extensions.rb
110
+ - lib/readers_controller_extensions.rb
111
+ - lib/site_controller_extensions.rb
112
+ - lib/tasks/reader_group_extension_tasks.rake
113
+ - pkg/radiant-reader_group-extension-0.9.0.gem
114
+ - public/images/admin/chk_auto.png
115
+ - public/images/admin/chk_off.png
116
+ - public/images/admin/chk_on.png
117
+ - public/images/admin/edit.png
118
+ - public/images/admin/error.png
119
+ - public/images/admin/message.png
120
+ - public/images/admin/new-group.png
121
+ - public/images/admin/populate.png
122
+ - public/images/admin/rdo_off.png
123
+ - public/images/admin/rdo_on.png
124
+ - public/stylesheets/sass/admin/group.sass
125
+ - radiant-reader_group-extension.gemspec
126
+ - reader_group_extension.rb
127
+ - spec/controllers/readers_controller_spec.rb
128
+ - spec/controllers/site_controller_spec.rb
129
+ - spec/datasets/group_messages_dataset.rb
130
+ - spec/datasets/group_readers_dataset.rb
131
+ - spec/datasets/group_sites_dataset.rb
132
+ - spec/datasets/groups_dataset.rb
133
+ - spec/models/group_spec.rb
134
+ - spec/models/message_spec.rb
135
+ - spec/models/page_spec.rb
136
+ - spec/models/reader_spec.rb
137
+ - spec/spec.opts
138
+ - spec/spec_helper.rb
139
+ has_rdoc: true
140
+ homepage: http://github.com/spanner/radiant-reader_group-extension
141
+ licenses: []
142
+
143
+ post_install_message:
144
+ rdoc_options:
145
+ - --charset=UTF-8
146
+ require_paths:
147
+ - lib
148
+ required_ruby_version: !ruby/object:Gem::Requirement
149
+ none: false
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ hash: 3
154
+ segments:
155
+ - 0
156
+ version: "0"
157
+ required_rubygems_version: !ruby/object:Gem::Requirement
158
+ none: false
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ hash: 3
163
+ segments:
164
+ - 0
165
+ version: "0"
166
+ requirements: []
167
+
168
+ rubyforge_project:
169
+ rubygems_version: 1.3.7
170
+ signing_key:
171
+ specification_version: 3
172
+ summary: Group-based access control for the radiant CMS
173
+ test_files:
174
+ - spec/controllers/readers_controller_spec.rb
175
+ - spec/controllers/site_controller_spec.rb
176
+ - spec/datasets/group_messages_dataset.rb
177
+ - spec/datasets/group_readers_dataset.rb
178
+ - spec/datasets/group_sites_dataset.rb
179
+ - spec/datasets/groups_dataset.rb
180
+ - spec/models/group_spec.rb
181
+ - spec/models/message_spec.rb
182
+ - spec/models/page_spec.rb
183
+ - spec/models/reader_spec.rb
184
+ - spec/spec_helper.rb