radiant-group_forum-extension 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown ADDED
@@ -0,0 +1,23 @@
1
+ # Group Forum
2
+
3
+ This is a bit of glue to link reader groups to forums. In order to make access control simple and expressible in SQL, it sets up a simple `belongs_to :group` relationship in the forum and then cascades it to topics and posts.
4
+
5
+ (this is achieved by calling `is_grouped` and `gives_group_to :topics`, plus a bit of controller fiddling)
6
+
7
+ The Radius tags supporting this are pretty basic at the moment but will improve. Access control has been the first priority.
8
+
9
+ ## Status
10
+
11
+ Very simple, reasonably well-tested, should just work.
12
+
13
+ ## Bugs and comments
14
+
15
+ In [lighthouse](http://spanner.lighthouseapp.com/projects/26912-radiant-extensions), please, or for little things an email or github message is always welcome.
16
+
17
+ ## Author and copyright
18
+
19
+ * Copyright spanner ltd 2009.
20
+ * Originally developed for MLA London's Knowledge Transfer Project
21
+ * Released under the same terms as Rails and/or Radiant.
22
+ * Contact will at spanner.org
23
+
data/Rakefile ADDED
@@ -0,0 +1,138 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |gem|
4
+ gem.name = "radiant-group_forum-extension"
5
+ gem.summary = %Q{Add group-awareness to the radiant forum extension}
6
+ gem.description = %Q{A bit of glue to add group-based access control to the radiant forum.}
7
+ gem.email = "will@spanner.org"
8
+ gem.homepage = "http://github.com/spanner/radiant-group_forum-extension"
9
+ gem.authors = ["spanner"]
10
+ gem.add_dependency "radiant", ">= 0.9.0"
11
+ gem.add_dependency 'radiant-forum-extension'
12
+ gem.add_dependency 'radiant-reader_group-extension'
13
+ end
14
+ rescue LoadError
15
+ puts "Jeweler (or a dependency) not available. This is only required if you plan to package group_forum as a gem."
16
+ end
17
+
18
+ # In rails 1.2, plugins aren't available in the path until they're loaded.
19
+ # Check to see if the rspec plugin is installed first and require
20
+ # it if it is. If not, use the gem version.
21
+
22
+ # Determine where the RSpec plugin is by loading the boot
23
+ unless defined? RADIANT_ROOT
24
+ ENV["RAILS_ENV"] = "test"
25
+ case
26
+ when ENV["RADIANT_ENV_FILE"]
27
+ require File.dirname(ENV["RADIANT_ENV_FILE"]) + "/boot"
28
+ when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
29
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../")}/config/boot"
30
+ else
31
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../")}/config/boot"
32
+ end
33
+ end
34
+
35
+ require 'rake'
36
+ require 'rake/rdoctask'
37
+ require 'rake/testtask'
38
+
39
+ rspec_base = File.expand_path(RADIANT_ROOT + '/vendor/plugins/rspec/lib')
40
+ $LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
41
+ require 'spec/rake/spectask'
42
+ require 'cucumber'
43
+ require 'cucumber/rake/task'
44
+
45
+ # Cleanup the RADIANT_ROOT constant so specs will load the environment
46
+ Object.send(:remove_const, :RADIANT_ROOT)
47
+
48
+ extension_root = File.expand_path(File.dirname(__FILE__))
49
+
50
+ task :default => :spec
51
+ task :stats => "spec:statsetup"
52
+
53
+ desc "Run all specs in spec directory"
54
+ Spec::Rake::SpecTask.new(:spec) do |t|
55
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
56
+ t.spec_files = FileList['spec/**/*_spec.rb']
57
+ end
58
+
59
+ task :features => 'spec:integration'
60
+
61
+ namespace :spec do
62
+ desc "Run all specs in spec directory with RCov"
63
+ Spec::Rake::SpecTask.new(:rcov) do |t|
64
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
65
+ t.spec_files = FileList['spec/**/*_spec.rb']
66
+ t.rcov = true
67
+ t.rcov_opts = ['--exclude', 'spec', '--rails']
68
+ end
69
+
70
+ desc "Print Specdoc for all specs"
71
+ Spec::Rake::SpecTask.new(:doc) do |t|
72
+ t.spec_opts = ["--format", "specdoc", "--dry-run"]
73
+ t.spec_files = FileList['spec/**/*_spec.rb']
74
+ end
75
+
76
+ [:models, :controllers, :views, :helpers].each do |sub|
77
+ desc "Run the specs under spec/#{sub}"
78
+ Spec::Rake::SpecTask.new(sub) do |t|
79
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
80
+ t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
81
+ end
82
+ end
83
+
84
+ desc "Run the Cucumber features"
85
+ Cucumber::Rake::Task.new(:integration) do |t|
86
+ t.fork = true
87
+ t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'pretty')]
88
+ # t.feature_pattern = "#{extension_root}/features/**/*.feature"
89
+ t.profile = "default"
90
+ end
91
+
92
+ # Setup specs for stats
93
+ task :statsetup do
94
+ require 'code_statistics'
95
+ ::STATS_DIRECTORIES << %w(Model\ specs spec/models)
96
+ ::STATS_DIRECTORIES << %w(View\ specs spec/views)
97
+ ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers)
98
+ ::STATS_DIRECTORIES << %w(Helper\ specs spec/views)
99
+ ::CodeStatistics::TEST_TYPES << "Model specs"
100
+ ::CodeStatistics::TEST_TYPES << "View specs"
101
+ ::CodeStatistics::TEST_TYPES << "Controller specs"
102
+ ::CodeStatistics::TEST_TYPES << "Helper specs"
103
+ ::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
104
+ end
105
+
106
+ namespace :db do
107
+ namespace :fixtures do
108
+ desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
109
+ task :load => :environment do
110
+ require 'active_record/fixtures'
111
+ ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
112
+ (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
113
+ Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
119
+
120
+ desc 'Generate documentation for the group_forum extension.'
121
+ Rake::RDocTask.new(:rdoc) do |rdoc|
122
+ rdoc.rdoc_dir = 'rdoc'
123
+ rdoc.title = 'GroupForumExtension'
124
+ rdoc.options << '--line-numbers' << '--inline-source'
125
+ rdoc.rdoc_files.include('README')
126
+ rdoc.rdoc_files.include('lib/**/*.rb')
127
+ end
128
+
129
+ # For extensions that are in transition
130
+ desc 'Test the group_forum extension.'
131
+ Rake::TestTask.new(:test) do |t|
132
+ t.libs << 'lib'
133
+ t.pattern = 'test/**/*_test.rb'
134
+ t.verbose = true
135
+ end
136
+
137
+ # Load any custom rakefiles for extension
138
+ Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.4.0
@@ -0,0 +1,14 @@
1
+ - include_stylesheet('admin/group')
2
+
3
+ - groups = Group.find(:all)
4
+ - if @group && @forum.new_record?
5
+ - @forum.group = @group
6
+
7
+ - fields_for @forum do |f|
8
+ .row
9
+ %p.group
10
+ = f.label :group_id, "Restrict to group:"
11
+ = f.select :group_id, groups.map { |g| [g.name, g.id] }, {:include_blank => true}
12
+ %br
13
+ %span.formnote
14
+ Leave blank for open access.
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+
3
+ end
@@ -0,0 +1,12 @@
1
+ class ForumsGroups < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :forums_groups, :id => false do |t|
4
+ t.column :forum_id, :integer
5
+ t.column :group_id, :integer
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ drop_table :forums_groups
11
+ end
12
+ end
@@ -0,0 +1,18 @@
1
+ class SimpleOwnership < ActiveRecord::Migration
2
+ def self.up
3
+ drop_table :forums_groups
4
+ add_column :forums, :group_id, :integer
5
+ add_column :topics, :group_id, :integer
6
+ add_column :posts, :group_id, :integer
7
+ end
8
+
9
+ def self.down
10
+ remove_column :forums, :group_id
11
+ remove_column :topics, :group_id
12
+ remove_column :posts, :group_id
13
+ create_table :forums_groups, :id => false do |t|
14
+ t.column :forum_id, :integer
15
+ t.column :group_id, :integer
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,24 @@
1
+ class GroupForumExtension < Radiant::Extension
2
+ version "0.4.0"
3
+ description "Just a bit of access-control glue joining reader_groups to forum"
4
+ url "http://spanner.org/radiant/group_forums"
5
+
6
+ def activate
7
+ Forum.send :include, GroupedForum
8
+ Topic.send :include, GroupedTopic
9
+ Post.send :include, GroupedPost
10
+ Page.send :include, GroupForumTags # a few tags for listing forums and latest topics on group pages
11
+
12
+ ForumsController.send :include, ForumsControllerExtensions
13
+ TopicsController.send :include, TopicsControllerExtensions
14
+ PostsController.send :include, PostsControllerExtensions
15
+
16
+ unless admin.forum.edit.form && admin.forum.edit.form.include?("forum_group")
17
+ admin.forum.edit.add :form, "forum_group"
18
+ end
19
+ end
20
+
21
+ def deactivate
22
+ end
23
+
24
+ end
@@ -0,0 +1,22 @@
1
+ module ForumsControllerExtensions
2
+
3
+ def self.included(base)
4
+ base.class_eval {
5
+ before_filter :require_visibility_of_forum
6
+
7
+ def index
8
+ @forums = Forum.visible_to(current_reader).paginate(:all, :order => "position", :page => params[:page] || 1, :per_page => params[:per_page]) #nb. visible_to is a named_scope defined in GroupedModel (in reader_group)
9
+ end
10
+
11
+ protected
12
+
13
+ def require_visibility_of_forum
14
+ if @forum && !@forum.visible_to?(current_reader)
15
+ flash[:error] = "Sorry: you don't have permission to see that discussion category."
16
+ redirect_to reader_permission_denied_url
17
+ return false
18
+ end
19
+ end
20
+ }
21
+ end
22
+ end
@@ -0,0 +1,101 @@
1
+ module GroupForumTags
2
+ include Radiant::Taggable
3
+
4
+ class TagError < StandardError; end
5
+
6
+ desc %{
7
+ Expands if this group has any forums.
8
+
9
+ <pre><code><r:group:if_forums>...</r:group:if_forums></code></pre>
10
+ }
11
+ tag "group:if_forums" do |tag|
12
+ tag.expand if tag.locals.group.forums.any?
13
+ end
14
+
15
+ desc %{
16
+ Expands if this group does not have any forums.
17
+
18
+ <pre><code><r:group:unless_forums>...</r:group:unless_forums></code></pre>
19
+ }
20
+ tag "group:unless_forums" do |tag|
21
+ tag.expand unless tag.locals.group.forums.any?
22
+ end
23
+
24
+ desc %{
25
+ Expands if this group has any topics.
26
+
27
+ <pre><code><r:group:if_topics>...</r:group:if_topics></code></pre>
28
+ }
29
+ tag "group:if_topics" do |tag|
30
+ tag.expand if tag.locals.group.topics.any?
31
+ end
32
+
33
+ desc %{
34
+ Expands if this group does not have any topics.
35
+
36
+ <pre><code><r:group:unless_topics>...</r:group:unless_topics></code></pre>
37
+ }
38
+ tag "group:unless_topics" do |tag|
39
+ tag.expand unless tag.locals.group.topics.any?
40
+ end
41
+
42
+ desc %{
43
+ Loops through the forums belonging to this group.
44
+
45
+ <pre><code><r:group:forums:each>...</r:group:forums:each /></code></pre>
46
+ }
47
+ tag "group:forums" do |tag|
48
+ tag.locals.forums = tag.locals.group.forums
49
+ tag.expand
50
+ end
51
+ tag "group:forums:each" do |tag|
52
+ result = []
53
+ tag.locals.forums.each do |forum|
54
+ tag.locals.forum = forum
55
+ result << tag.expand
56
+ end
57
+ result
58
+ end
59
+
60
+ desc %{
61
+ Loops through the latest topics in all forums belonging to this group.
62
+
63
+ <pre><code><r:group:latest_topics:each count="10">...</r:group:latest_topics:each></code></pre>
64
+ }
65
+ tag "group:latest_topics" do |tag|
66
+ count = tag.attr["count"] || 10
67
+ tag.locals.topics = tag.locals.group.topics.latest(count)
68
+ tag.expand
69
+ end
70
+ tag "group:latest_topics:each" do |tag|
71
+ result = []
72
+ tag.locals.topics.each do |topic|
73
+ tag.locals.topic = topic
74
+ result << tag.expand
75
+ end
76
+ result
77
+ end
78
+
79
+ desc %{
80
+ If the group has only one forum, this presents a simple new-topic link around the supplied text.
81
+ If it has several forums, this offers a list with the supplied text as the heading.
82
+
83
+ <pre><code><r:group:new_topic_link /></code></pre>
84
+ }
85
+ tag "group:new_topic_link" do |tag|
86
+ forums = tag.locals.group.forums
87
+ text = tag.double? ? tag.expand : "Start a new conversation"
88
+ result = ""
89
+ case forums.length
90
+ when 0
91
+ when 1
92
+ result << %{<a href="#{new_forum_topic_path(forums.first)}">#{text}</a>}
93
+ else
94
+ result << %{<h3>#{text}</h3><ul>}
95
+ result << forums.collect{|forum| %{<li><a href="#{new_forum_topic_path(forum)}">#{forum.name}</a></li>}}
96
+ result << "</ul>"
97
+ end
98
+ result
99
+ end
100
+
101
+ end
@@ -0,0 +1,10 @@
1
+ module GroupedForum
2
+
3
+ def self.included(base)
4
+ base.class_eval {
5
+ is_grouped
6
+ gives_group_to :topics # which in turn give it to posts
7
+ }
8
+ end
9
+
10
+ end
@@ -0,0 +1,10 @@
1
+ module GroupedPost
2
+
3
+ def self.included(base)
4
+ base.class_eval {
5
+ is_grouped
6
+ gets_group_from :topic
7
+ }
8
+ end
9
+
10
+ end
@@ -0,0 +1,11 @@
1
+ module GroupedTopic
2
+
3
+ def self.included(base)
4
+ base.class_eval {
5
+ is_grouped
6
+ gets_group_from :forum
7
+ gives_group_to :posts
8
+ }
9
+ end
10
+
11
+ end
@@ -0,0 +1,26 @@
1
+ module PostsControllerExtensions
2
+
3
+ def self.included(base)
4
+ base.class_eval {
5
+ before_filter :require_visibility_of_topic_and_page
6
+
7
+ protected
8
+
9
+ def require_visibility_of_topic_and_page
10
+ if @page && !@page.visible_to?(current_reader)
11
+ flash[:error] = "Sorry: you don't have permission to see that page."
12
+ redirect_to reader_permission_denied_url
13
+ return false
14
+ end
15
+ if @topic && !@topic.visible_to?(current_reader)
16
+ flash[:error] = "Sorry: you don't have permission to see that discussion."
17
+ redirect_to reader_permission_denied_url
18
+ return false
19
+ end
20
+ end
21
+ }
22
+ end
23
+ end
24
+
25
+
26
+
@@ -0,0 +1,28 @@
1
+ namespace :radiant do
2
+ namespace :extensions do
3
+ namespace :group_forum do
4
+
5
+ desc "Runs the migration of the Group Forum extension"
6
+ task :migrate => :environment do
7
+ require 'radiant/extension_migrator'
8
+ if ENV["VERSION"]
9
+ GroupForumExtension.migrator.migrate(ENV["VERSION"].to_i)
10
+ else
11
+ GroupForumExtension.migrator.migrate
12
+ end
13
+ end
14
+
15
+ desc "Copies public assets of the Group Forum to the instance public/ directory."
16
+ task :update => :environment do
17
+ is_svn_or_dir = proc {|path| path =~ /\.svn/ || File.directory?(path) }
18
+ puts "Copying assets from GroupForumExtension"
19
+ Dir[GroupForumExtension.root + "/public/**/*"].reject(&is_svn_or_dir).each do |file|
20
+ path = file.sub(GroupForumExtension.root, '')
21
+ directory = File.dirname(path)
22
+ mkdir_p RAILS_ROOT + directory
23
+ cp file, RAILS_ROOT + path
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,26 @@
1
+ module TopicsControllerExtensions
2
+
3
+ def self.included(base)
4
+ base.class_eval {
5
+ before_filter :require_visibility_of_forum_and_page
6
+
7
+ protected
8
+
9
+ def require_visibility_of_forum_and_page
10
+ if @page && !@page.visible_to?(current_reader)
11
+ flash[:error] = "Sorry: you don't have permission to see that page."
12
+ redirect_to reader_permission_denied_url
13
+ return false
14
+ end
15
+ if @forum && !@forum.visible_to?(current_reader)
16
+ flash[:error] = "Sorry: you don't have permission to see that discussion."
17
+ redirect_to reader_permission_denied_url
18
+ return false
19
+ end
20
+ end
21
+ }
22
+ end
23
+ end
24
+
25
+
26
+
@@ -0,0 +1,80 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{radiant-group_forum-extension}
8
+ s.version = "0.4.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["spanner"]
12
+ s.date = %q{2010-10-04}
13
+ s.description = %q{A bit of glue to add group-based access control to the radiant forum.}
14
+ s.email = %q{will@spanner.org}
15
+ s.extra_rdoc_files = [
16
+ "README.markdown"
17
+ ]
18
+ s.files = [
19
+ "README.markdown",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "app/views/admin/forums/_forum_group.html.haml",
23
+ "config/routes.rb",
24
+ "db/migrate/001_forums_groups.rb",
25
+ "db/migrate/20091008101339_simple_ownership.rb",
26
+ "group_forum_extension.rb",
27
+ "lib/forums_controller_extensions.rb",
28
+ "lib/group_forum_tags.rb",
29
+ "lib/grouped_forum.rb",
30
+ "lib/grouped_post.rb",
31
+ "lib/grouped_topic.rb",
32
+ "lib/posts_controller_extensions.rb",
33
+ "lib/tasks/group_forum_extension_tasks.rake",
34
+ "lib/topics_controller_extensions.rb",
35
+ "pkg/radiant-group_forum-extension-0.4.0.gem",
36
+ "radiant-group_forum-extension.gemspec",
37
+ "spec/datasets/group_forum_forums_dataset.rb",
38
+ "spec/datasets/group_forum_groups_dataset.rb",
39
+ "spec/datasets/group_forum_readers_dataset.rb",
40
+ "spec/datasets/group_forum_sites_dataset.rb",
41
+ "spec/models/forum_spec.rb",
42
+ "spec/models/group_spec.rb",
43
+ "spec/spec.opts",
44
+ "spec/spec_helper.rb"
45
+ ]
46
+ s.homepage = %q{http://github.com/spanner/radiant-group_forum-extension}
47
+ s.rdoc_options = ["--charset=UTF-8"]
48
+ s.require_paths = ["lib"]
49
+ s.rubygems_version = %q{1.3.7}
50
+ s.summary = %q{Add group-awareness to the radiant forum extension}
51
+ s.test_files = [
52
+ "spec/datasets/group_forum_forums_dataset.rb",
53
+ "spec/datasets/group_forum_groups_dataset.rb",
54
+ "spec/datasets/group_forum_readers_dataset.rb",
55
+ "spec/datasets/group_forum_sites_dataset.rb",
56
+ "spec/models/forum_spec.rb",
57
+ "spec/models/group_spec.rb",
58
+ "spec/spec_helper.rb"
59
+ ]
60
+
61
+ if s.respond_to? :specification_version then
62
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
63
+ s.specification_version = 3
64
+
65
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
66
+ s.add_runtime_dependency(%q<radiant>, [">= 0.9.0"])
67
+ s.add_runtime_dependency(%q<radiant-forum-extension>, [">= 0"])
68
+ s.add_runtime_dependency(%q<radiant-reader_group-extension>, [">= 0"])
69
+ else
70
+ s.add_dependency(%q<radiant>, [">= 0.9.0"])
71
+ s.add_dependency(%q<radiant-forum-extension>, [">= 0"])
72
+ s.add_dependency(%q<radiant-reader_group-extension>, [">= 0"])
73
+ end
74
+ else
75
+ s.add_dependency(%q<radiant>, [">= 0.9.0"])
76
+ s.add_dependency(%q<radiant-forum-extension>, [">= 0"])
77
+ s.add_dependency(%q<radiant-reader_group-extension>, [">= 0"])
78
+ end
79
+ end
80
+
@@ -0,0 +1,19 @@
1
+ class GroupForumForumsDataset < Dataset::Base
2
+ datasets = [:group_forum_groups]
3
+ datasets << :group_forum_sites if defined? Site
4
+ uses *datasets
5
+
6
+ def load
7
+ create_forum "Public"
8
+ create_forum "Grouped", :group => groups(:chatty)
9
+ create_forum "Alsogrouped", :group => groups(:chatty)
10
+ end
11
+
12
+ helpers do
13
+ def create_forum(name, attributes={})
14
+ attributes[:site] ||= sites(:test) if defined? Site
15
+ create_model :forum, name.symbolize, attributes.update(:name => name)
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,35 @@
1
+ require 'digest/sha1'
2
+ class GroupForumGroupsDataset < Dataset::Base
3
+ datasets = [:group_forum_readers]
4
+ datasets << :group_forum_sites if defined? Site
5
+ uses *datasets
6
+
7
+ def load
8
+ create_group "Normal"
9
+ create_group "Chatty"
10
+
11
+ add_readers_to_group :chatty, [:normal, :another]
12
+ end
13
+
14
+ helpers do
15
+ def create_group(name, att={})
16
+ group = create_record Group, name.symbolize, group_attributes(att.update(:name => name))
17
+ end
18
+
19
+ def group_attributes(att={})
20
+ name = att[:name] || "A group"
21
+ attributes = {
22
+ :name => name,
23
+ :description => "Test group"
24
+ }.merge(att)
25
+ attributes[:site_id] ||= site_id(:test) if defined? Site
26
+ attributes
27
+ end
28
+ end
29
+
30
+ def add_readers_to_group(g, rr)
31
+ g = groups(g) unless g.is_a?(Group)
32
+ g.readers << rr.map{|r| readers(r)}
33
+ end
34
+
35
+ end
@@ -0,0 +1,34 @@
1
+ require 'digest/sha1'
2
+ class GroupForumReadersDataset < Dataset::Base
3
+ uses :group_forum_sites if defined? Site
4
+
5
+ def load
6
+ create_reader "Normal"
7
+ create_reader "Another"
8
+ create_reader "Ungrouped"
9
+ end
10
+
11
+ helpers do
12
+ def create_reader(name, attributes={})
13
+ attributes = reader_attributes(attributes.update(:name => name))
14
+ reader = create_model Reader, name.symbolize, attributes
15
+ end
16
+
17
+ def reader_attributes(attributes={})
18
+ name = attributes[:name] || "John Doe"
19
+ symbol = name.symbolize
20
+ attributes = {
21
+ :name => name,
22
+ :email => "#{symbol}@spanner.org",
23
+ :login => "#{symbol}@spanner.org",
24
+ :activated_at => Time.now - 1.week,
25
+ :password_salt => "golly",
26
+ :password => 'password',
27
+ :password_confirmation => 'password'
28
+ }.merge(attributes)
29
+ attributes[:site] = sites(:test) if defined? Site
30
+ attributes
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,9 @@
1
+ class GroupForumSitesDataset < 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
+ Page.current_site = sites(:test)
7
+ end
8
+
9
+ end
@@ -0,0 +1,33 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Forum do
4
+ dataset :group_forum_forums
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
+ Forum.reflect_on_association(:group).should_not be_nil
12
+ end
13
+
14
+ it "should normally list only the ungrouped forums" do
15
+ Forum.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
+ forums(: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
+ forums(:grouped).visible_to?(readers(:ungrouped)).should be_false
24
+ end
25
+ end
26
+
27
+ describe "without a group" do
28
+ it "should report itself visible to everyone" do
29
+ forums(:public).visible_to?(readers(:normal)).should be_true
30
+ forums(:public).visible_to?(readers(:ungrouped)).should be_true
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,20 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Group do
4
+ dataset :group_forum_forums
5
+
6
+ before do
7
+ @site = Page.current_site = sites(:test) if defined? Site
8
+ end
9
+
10
+ it "should have a forums association" do
11
+ Group.reflect_on_association(:forums).should_not be_nil
12
+ end
13
+
14
+ it "should have a list of forums" do
15
+ group = groups(:chatty)
16
+ group.forums.any?.should be_true
17
+ group.forums.size.should == 2
18
+ end
19
+
20
+ 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,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: radiant-group_forum-extension
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 4
9
+ - 0
10
+ version: 0.4.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-forum-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
+ - !ruby/object:Gem::Dependency
52
+ name: radiant-reader_group-extension
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ type: :runtime
64
+ version_requirements: *id003
65
+ description: A bit of glue to add group-based access control to the radiant forum.
66
+ email: will@spanner.org
67
+ executables: []
68
+
69
+ extensions: []
70
+
71
+ extra_rdoc_files:
72
+ - README.markdown
73
+ files:
74
+ - README.markdown
75
+ - Rakefile
76
+ - VERSION
77
+ - app/views/admin/forums/_forum_group.html.haml
78
+ - config/routes.rb
79
+ - db/migrate/001_forums_groups.rb
80
+ - db/migrate/20091008101339_simple_ownership.rb
81
+ - group_forum_extension.rb
82
+ - lib/forums_controller_extensions.rb
83
+ - lib/group_forum_tags.rb
84
+ - lib/grouped_forum.rb
85
+ - lib/grouped_post.rb
86
+ - lib/grouped_topic.rb
87
+ - lib/posts_controller_extensions.rb
88
+ - lib/tasks/group_forum_extension_tasks.rake
89
+ - lib/topics_controller_extensions.rb
90
+ - pkg/radiant-group_forum-extension-0.4.0.gem
91
+ - radiant-group_forum-extension.gemspec
92
+ - spec/datasets/group_forum_forums_dataset.rb
93
+ - spec/datasets/group_forum_groups_dataset.rb
94
+ - spec/datasets/group_forum_readers_dataset.rb
95
+ - spec/datasets/group_forum_sites_dataset.rb
96
+ - spec/models/forum_spec.rb
97
+ - spec/models/group_spec.rb
98
+ - spec/spec.opts
99
+ - spec/spec_helper.rb
100
+ has_rdoc: true
101
+ homepage: http://github.com/spanner/radiant-group_forum-extension
102
+ licenses: []
103
+
104
+ post_install_message:
105
+ rdoc_options:
106
+ - --charset=UTF-8
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ hash: 3
124
+ segments:
125
+ - 0
126
+ version: "0"
127
+ requirements: []
128
+
129
+ rubyforge_project:
130
+ rubygems_version: 1.3.7
131
+ signing_key:
132
+ specification_version: 3
133
+ summary: Add group-awareness to the radiant forum extension
134
+ test_files:
135
+ - spec/datasets/group_forum_forums_dataset.rb
136
+ - spec/datasets/group_forum_groups_dataset.rb
137
+ - spec/datasets/group_forum_readers_dataset.rb
138
+ - spec/datasets/group_forum_sites_dataset.rb
139
+ - spec/models/forum_spec.rb
140
+ - spec/models/group_spec.rb
141
+ - spec/spec_helper.rb