radiant-vhost-extension 2.1.0
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/.gitmodules +3 -0
- data/README +64 -0
- data/Rakefile +125 -0
- data/VERSION +1 -0
- data/app/controllers/admin/sites_controller.rb +16 -0
- data/app/models/site.rb +26 -0
- data/app/models/site_association_observer.rb +8 -0
- data/app/views/admin/sites/_form.html.haml +19 -0
- data/app/views/admin/sites/edit.html.haml +5 -0
- data/app/views/admin/sites/index.html.haml +24 -0
- data/app/views/admin/sites/new.html.haml +5 -0
- data/app/views/admin/sites/remove.html.haml +19 -0
- data/app/views/admin/users/_edit_sites.html.haml +4 -0
- data/app/views/admin/users/_site_admin_roles.html.haml +5 -0
- data/app/views/admin/users/_sites_td.html.haml +2 -0
- data/app/views/admin/users/_sites_th.html.haml +2 -0
- data/config/routes.rb +5 -0
- data/db/migrate/001_create_sites.rb +11 -0
- data/db/migrate/002_add_sites_users.rb +18 -0
- data/db/migrate/003_replace_snippet_name_unique_index.rb +10 -0
- data/db/migrate/004_add_site_admin_to_users.rb +9 -0
- data/db/templates/empty.yml +7 -0
- data/db/templates/simple-blog.yml +213 -0
- data/lib/bootstrap_with_site_id.rb +50 -0
- data/lib/radiant-vhost-extension.rb +0 -0
- data/lib/site_scope.rb +65 -0
- data/lib/tasks/add_site_columns.rb +44 -0
- data/lib/tasks/vhost_extension_tasks.rake +115 -0
- data/lib/vhost/admin_users_controller_extensions.rb +22 -0
- data/lib/vhost/admin_users_helper_extensions.rb +17 -0
- data/lib/vhost/application_controller_extensions.rb +36 -0
- data/lib/vhost/application_helper_extensions.rb +15 -0
- data/lib/vhost/controller_access_extensions.rb +16 -0
- data/lib/vhost/pages_controller_extensions.rb +11 -0
- data/lib/vhost/radiant_cache_extensions.rb +53 -0
- data/lib/vhost/site_scoped_model_extensions.rb +46 -0
- data/lib/vhost_default_config.yml +22 -0
- data/spec/controllers/admin/pages_controller_spec.rb +173 -0
- data/spec/controllers/admin/sites_controller_spec.rb +33 -0
- data/spec/controllers/site_controller_spec.rb +33 -0
- data/spec/datasets/site_home_pages_dataset.rb +76 -0
- data/spec/datasets/site_pages_dataset.rb +31 -0
- data/spec/datasets/site_users_dataset.rb +50 -0
- data/spec/datasets/sites_dataset.rb +10 -0
- data/spec/datasets/sites_site_users_and_site_pages_dataset.rb +8 -0
- data/spec/datasets/sites_site_users_dataset.rb +13 -0
- data/spec/fixtures/page_parts.yml +11 -0
- data/spec/fixtures/pages.yml +19 -0
- data/spec/fixtures/sites.yml +7 -0
- data/spec/fixtures/sites_users.yml +6 -0
- data/spec/fixtures/users.yml +35 -0
- data/spec/models/page_spec.rb +22 -0
- data/spec/models/site_spec.rb +19 -0
- data/spec/models/user_spec.rb +16 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +42 -0
- data/test/fixtures/page_parts.yml +11 -0
- data/test/fixtures/pages.yml +19 -0
- data/test/fixtures/sites.yml +7 -0
- data/test/fixtures/sites_users.yml +6 -0
- data/test/fixtures/users.yml +35 -0
- data/test/functional/admin/pages_controller_test.rb +142 -0
- data/test/functional/admin/site_controller_test.rb +53 -0
- data/test/functional/vhost_extension_test.rb +37 -0
- data/test/helpers/page_part_test_helper.rb +49 -0
- data/test/test_helper.rb +17 -0
- data/test/unit/site_test.rb +26 -0
- data/vhost_extension.rb +154 -0
- metadata +167 -0
@@ -0,0 +1,35 @@
|
|
1
|
+
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
2
|
+
existing:
|
3
|
+
id: 1
|
4
|
+
name: Existing User
|
5
|
+
login: existing
|
6
|
+
salt: 42ddb5b6479872565981adc78e86ddc50fa21637
|
7
|
+
password: 4c5f9d5a0d4cd65d61f6b1505890576d1272986c # password
|
8
|
+
email: existing.user@gmail.com
|
9
|
+
another:
|
10
|
+
id: 2
|
11
|
+
name: Another User
|
12
|
+
login: another
|
13
|
+
salt: 42ddb5b6479872565981adc78e86ddc50fa21637
|
14
|
+
password: 4c5f9d5a0d4cd65d61f6b1505890576d1272986c # password
|
15
|
+
admin:
|
16
|
+
id: 3
|
17
|
+
name: Admin User
|
18
|
+
login: admin
|
19
|
+
salt: 42ddb5b6479872565981adc78e86ddc50fa21637
|
20
|
+
password: 4c5f9d5a0d4cd65d61f6b1505890576d1272986c # password
|
21
|
+
admin: true
|
22
|
+
developer:
|
23
|
+
id: 4
|
24
|
+
name: Developer User
|
25
|
+
login: developer
|
26
|
+
salt: 42ddb5b6479872565981adc78e86ddc50fa21637
|
27
|
+
password: 4c5f9d5a0d4cd65d61f6b1505890576d1272986c # password
|
28
|
+
developer: true
|
29
|
+
non_admin:
|
30
|
+
id: 5
|
31
|
+
name: Non-Admin User
|
32
|
+
login: non-admin
|
33
|
+
salt: 42ddb5b6479872565981adc78e86ddc50fa21637
|
34
|
+
password: 4c5f9d5a0d4cd65d61f6b1505890576d1272986c # password
|
35
|
+
admin: false
|
@@ -0,0 +1,142 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper'
|
2
|
+
require 'admin/pages_controller'
|
3
|
+
|
4
|
+
# Re-raise errors caught by the controller.
|
5
|
+
class Admin::PagesController; def rescue_action(e) raise e end; end
|
6
|
+
|
7
|
+
class Admin::PagesControllerTest < Test::Unit::TestCase
|
8
|
+
fixtures :users, :pages, :sites, :sites_users
|
9
|
+
test_helper :pages, :page_parts
|
10
|
+
|
11
|
+
def setup
|
12
|
+
@controller = Admin::PagesController.new
|
13
|
+
@request = ActionController::TestRequest.new
|
14
|
+
@response = ActionController::TestResponse.new
|
15
|
+
@request.session['user'] = users(:another)
|
16
|
+
@request.host = sites(:two).hostname
|
17
|
+
|
18
|
+
@page_title = 'Just a Test'
|
19
|
+
|
20
|
+
destroy_test_page
|
21
|
+
destroy_test_part
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_index
|
25
|
+
get :index
|
26
|
+
assert_response :success
|
27
|
+
assert_kind_of Page, assigns(:homepage)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_index__without_pages
|
31
|
+
Page.destroy_all
|
32
|
+
get :index
|
33
|
+
assert_response :success
|
34
|
+
assert_nil assigns(:homepage)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_new
|
38
|
+
@controller.config = {
|
39
|
+
'defaults.page.parts' => 'body, extended, summary',
|
40
|
+
'defaults.page.status' => 'published'
|
41
|
+
}
|
42
|
+
|
43
|
+
get :new, :parent_id => '2', :page => page_params
|
44
|
+
assert_response :success
|
45
|
+
assert_template 'admin/page/edit'
|
46
|
+
|
47
|
+
@page = assigns(:page)
|
48
|
+
assert_kind_of Page, @page
|
49
|
+
assert_nil @page.title
|
50
|
+
|
51
|
+
@expected_parent = Page.find(2)
|
52
|
+
assert_equal @expected_parent, @page.parent
|
53
|
+
|
54
|
+
assert_equal 3, @page.parts.size
|
55
|
+
assert_equal Status[:published], @page.status
|
56
|
+
end
|
57
|
+
def test_new__post_with_parts
|
58
|
+
post(:new, :parent_id => '2', :page => page_params,
|
59
|
+
:part => {
|
60
|
+
'1' => part_params(:name => 'test-part-1'),
|
61
|
+
'2' => part_params(:name => 'test-part-2')
|
62
|
+
}
|
63
|
+
)
|
64
|
+
assert_redirected_to '/admin/pages'
|
65
|
+
|
66
|
+
@page = get_test_page
|
67
|
+
assert_kind_of Page, @page
|
68
|
+
assert_equal sites(:two).id, @page.site_id
|
69
|
+
names = @page.parts.collect { |part| part.name }.sort
|
70
|
+
assert_equal ['test-part-1', 'test-part-2'], names
|
71
|
+
end
|
72
|
+
def test_new__save_and_continue_editing
|
73
|
+
post :new, :parent_id => '2', :page => page_params, :continue => 'Save and Continue Editing'
|
74
|
+
@page = get_test_page
|
75
|
+
assert_equal sites(:two).id, @page.site_id
|
76
|
+
assert_redirected_to page_edit_url(:id => @page.id)
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_edit
|
80
|
+
get :edit, :id => '2', :page => page_params
|
81
|
+
assert_response :success
|
82
|
+
|
83
|
+
@page = assigns(:page)
|
84
|
+
assert_kind_of Page, @page
|
85
|
+
assert_equal 'Rails Home Page', @page.title
|
86
|
+
assert_equal sites(:two).id, @page.site_id
|
87
|
+
end
|
88
|
+
def test_edit__post
|
89
|
+
@page = create_test_page(:site_id => sites(:two).id)
|
90
|
+
post :edit, :id => @page.id, :page => page_params(:status_id => '1')
|
91
|
+
assert_response :redirect
|
92
|
+
assert_equal 1, get_test_page.status.id
|
93
|
+
end
|
94
|
+
def test_edit__post_with_parts
|
95
|
+
@page = create_test_page(:no_part => true, :site_id => sites(:two).id)
|
96
|
+
@page.parts.create(part_params(:name => 'test-part-1'))
|
97
|
+
@page.parts.create(part_params(:name => 'test-part-2'))
|
98
|
+
|
99
|
+
assert_equal 2, @page.parts.size
|
100
|
+
|
101
|
+
post :edit, :id => @page.id, :page => page_params, :part => {'1' => part_params(:name => 'test-part-1', :content => 'changed')}
|
102
|
+
assert_response :redirect
|
103
|
+
|
104
|
+
@page = get_test_page
|
105
|
+
assert_equal 1, @page.parts.size
|
106
|
+
assert_equal 'changed', @page.parts.first.content
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_remove
|
110
|
+
@page = create_test_page(:site_id => sites(:two).id)
|
111
|
+
get :remove, :id => @page.id
|
112
|
+
assert_response :success
|
113
|
+
assert_equal @page, assigns(:page)
|
114
|
+
assert_not_nil get_test_page
|
115
|
+
end
|
116
|
+
def test_remove__post
|
117
|
+
@page = create_test_page(:site_id => sites(:two).id)
|
118
|
+
post :remove, :id => @page.id
|
119
|
+
assert_redirected_to '/admin/pages'
|
120
|
+
assert_match /removed/, flash[:notice]
|
121
|
+
assert_nil get_test_page
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_access_prohibited_to_user_without_access_to_site
|
125
|
+
@request.session['user'] = users(:existing)
|
126
|
+
get :edit, :id => '2'
|
127
|
+
assert_response :redirect
|
128
|
+
assert_equal 'Access denied.', flash[:error]
|
129
|
+
end
|
130
|
+
|
131
|
+
protected
|
132
|
+
|
133
|
+
def assert_rendered_nodes_where(&block)
|
134
|
+
wanted, unwanted = Page.find(:all).partition(&block)
|
135
|
+
wanted.each do |page|
|
136
|
+
assert_tag :tag => 'tr', :attributes => {:id => "page-#{page.id}" }
|
137
|
+
end
|
138
|
+
unwanted.each do |page|
|
139
|
+
assert_no_tag :tag => 'tr', :attributes => {:id => "page-#{page.id}" }
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
# Load the environment
|
3
|
+
unless defined? RADIANT_ROOT
|
4
|
+
ENV["RAILS_ENV"] = "test"
|
5
|
+
case
|
6
|
+
when ENV["RADIANT_ENV_FILE"]
|
7
|
+
require ENV["RADIANT_ENV_FILE"]
|
8
|
+
when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
|
9
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../../")}/config/environment"
|
10
|
+
else
|
11
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/environment"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
require "#{RADIANT_ROOT}/test/test_helper"
|
15
|
+
|
16
|
+
#class Test::Unit::TestCase
|
17
|
+
# self.use_transactional_fixtures = true
|
18
|
+
# self.use_instantiated_fixtures = false
|
19
|
+
#end
|
20
|
+
|
21
|
+
# Re-raise errors caught by the controller.
|
22
|
+
Admin::SiteController.class_eval { def rescue_action(e) raise e end }
|
23
|
+
|
24
|
+
class SiteControllerTest < Test::Unit::TestCase
|
25
|
+
fixtures :users, :sites, :sites_users
|
26
|
+
|
27
|
+
def setup
|
28
|
+
@controller = Admin::SiteController.new
|
29
|
+
@request = ActionController::TestRequest.new
|
30
|
+
@response = ActionController::TestResponse.new
|
31
|
+
@request.host = sites(:two).hostname
|
32
|
+
end
|
33
|
+
|
34
|
+
[:index, :new, :edit, :remove].each do |action|
|
35
|
+
define_method "test_#{action}_action_allowed_if_admin" do
|
36
|
+
get action, { :id => 1 }, { 'user' => users(:admin) }
|
37
|
+
assert_response :success, "action: #{action}"
|
38
|
+
end
|
39
|
+
|
40
|
+
define_method "test_#{action}_action_not_allowed_if_other" do
|
41
|
+
get action, { :id => 1 }, { 'user' => users(:non_admin) }
|
42
|
+
assert_redirected_to '/admin/login', "action: #{action}"
|
43
|
+
assert_match /privileges/, flash[:error], "action: #{action}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_new_creates_root_page
|
48
|
+
post :new, {:site => {:hostname => 'test3.host'}}, { 'user' => users(:admin) }
|
49
|
+
assert_response :redirect
|
50
|
+
assert_not_nil Site.find_by_hostname('test3.host')
|
51
|
+
assert_not_nil Page.find_by_slug_and_site_id('/', Site.find_by_hostname('test3.host').id)
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
require_dependency 'site_controller'
|
3
|
+
|
4
|
+
# Re-raise errors caught by the controller.
|
5
|
+
class SiteController; def rescue_action(e) raise e end; end
|
6
|
+
|
7
|
+
class VhostExtensionTest < Test::Unit::TestCase
|
8
|
+
fixtures :pages, :page_parts, :sites
|
9
|
+
test_helper :pages
|
10
|
+
|
11
|
+
def setup
|
12
|
+
@controller = SiteController.new
|
13
|
+
@request = ActionController::TestRequest.new
|
14
|
+
@response = ActionController::TestResponse.new
|
15
|
+
@cache = @controller.cache
|
16
|
+
@cache.perform_caching = false
|
17
|
+
@cache.clear
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_initialization
|
21
|
+
assert_equal File.join(File.expand_path(RAILS_ROOT), 'vendor', 'extensions', 'vhost'), VhostExtension.root
|
22
|
+
assert_equal 'Vhost', VhostExtension.extension_name
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_show_page_differentiates_between_sites
|
26
|
+
get :show_page, :url => ''
|
27
|
+
assert_response :success
|
28
|
+
assert_equal 'This is the body portion of the Ruby home page.', @response.body
|
29
|
+
|
30
|
+
@controller = SiteController.new
|
31
|
+
@request.host = sites(:two).hostname
|
32
|
+
get :show_page, :url => ''
|
33
|
+
assert_response :success
|
34
|
+
assert_equal 'This is the Rails home page.', @response.body
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module PagePartTestHelper
|
2
|
+
VALID_PAGE_PART_PARAMS = {
|
3
|
+
:name => 'custom',
|
4
|
+
:content => 'Some simple content.',
|
5
|
+
:page_id => '1'
|
6
|
+
}
|
7
|
+
|
8
|
+
def part_params(options = {})
|
9
|
+
params = VALID_PAGE_PART_PARAMS.dup
|
10
|
+
params.delete(:page_id)
|
11
|
+
params.merge!(:name => @part_name) if @part_name
|
12
|
+
params.merge!(options)
|
13
|
+
params
|
14
|
+
end
|
15
|
+
|
16
|
+
def destroy_test_part(title = @part_name)
|
17
|
+
while part = get_test_part(title) do
|
18
|
+
part.destroy
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_test_part(name = @part_name)
|
23
|
+
PagePart.find_by_name(name)
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_test_part(name = @part_name)
|
27
|
+
params = part_params
|
28
|
+
params.merge!(:name => name)
|
29
|
+
part = PagePart.new(params)
|
30
|
+
if part.save
|
31
|
+
part
|
32
|
+
else
|
33
|
+
raise "part <#{part.inspect}> could not be saved"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# must be included after PageTestHelper to work
|
38
|
+
def create_test_page(options = {})
|
39
|
+
no_part = options.delete(:no_part)
|
40
|
+
page = super(options)
|
41
|
+
unless no_part
|
42
|
+
part = PagePart.new part_params(:name => 'body', :content => 'test')
|
43
|
+
page.parts << part
|
44
|
+
page.save
|
45
|
+
part.save
|
46
|
+
end
|
47
|
+
page
|
48
|
+
end
|
49
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Load the the environment
|
2
|
+
unless defined? RADIANT_ROOT
|
3
|
+
ENV["RAILS_ENV"] = "test"
|
4
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/boot"
|
5
|
+
end
|
6
|
+
require "#{RADIANT_ROOT}/test/test_helper"
|
7
|
+
|
8
|
+
class ActiveSupport::TestCase
|
9
|
+
|
10
|
+
# Include a helper to make testing Radius tags easier
|
11
|
+
#test_helper :extension_tags
|
12
|
+
|
13
|
+
# Add the fixture directory to the fixture path
|
14
|
+
self.fixture_path << File.dirname(__FILE__) + "/fixtures"
|
15
|
+
|
16
|
+
# Add more helper methods to be used by all extension tests here...
|
17
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class SiteTest < Test::Unit::TestCase
|
4
|
+
fixtures :sites, :pages, :users, :sites_users
|
5
|
+
|
6
|
+
def test_overridden_validation_scope
|
7
|
+
s = Site.create(:hostname => 'test3.host')
|
8
|
+
assert_valid Page.create(:title => "Site 3 home", :slug => '/', :breadcrumb => 'Home', :site_id => s.id)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_site_has_many_users
|
12
|
+
assert_equal users(:existing), sites(:one).users.first
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_allow_access_for_allowed_user
|
16
|
+
assert sites(:one).allow_access_for(users(:existing))
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_allow_access_for_disallowed_user
|
20
|
+
assert !sites(:one).allow_access_for(users(:another))
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_allow_access_for_administrator
|
24
|
+
assert sites(:one).allow_access_for(users(:admin))
|
25
|
+
end
|
26
|
+
end
|
data/vhost_extension.rb
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
# FIXME - Enable multiple hostnames to be associated with the same site
|
2
|
+
require 'yaml'
|
3
|
+
require 'ostruct'
|
4
|
+
require_dependency 'application_controller'
|
5
|
+
require File.join(File.dirname(__FILE__), 'vendor/scoped_access/lib/scoped_access')
|
6
|
+
|
7
|
+
class VhostExtension < Radiant::Extension
|
8
|
+
version "#{File.read(File.expand_path(File.dirname(__FILE__)) + '/VERSION')}"
|
9
|
+
description "Host multiple sites on a single instance."
|
10
|
+
url "http://github.com/saturnflyer/radiant-vhost-extension"
|
11
|
+
|
12
|
+
# FIXME - Clear up the configuration stuff, it's kinda crufty
|
13
|
+
|
14
|
+
class << self
|
15
|
+
# Set during tests and used to simulate having a populated request.host
|
16
|
+
attr_accessor :HOST
|
17
|
+
# Sets the models that are scoped down to a site
|
18
|
+
attr_accessor :MODELS
|
19
|
+
attr_accessor :MODEL_UNIQUENESS_VALIDATIONS
|
20
|
+
attr_accessor :REDIRECT_TO_PRIMARY_SITE
|
21
|
+
end
|
22
|
+
|
23
|
+
# extension_config do |config|
|
24
|
+
# config.gem 'ancestry'
|
25
|
+
# end
|
26
|
+
|
27
|
+
def activate
|
28
|
+
process_config
|
29
|
+
basic_extension_config
|
30
|
+
init_scoped_access
|
31
|
+
enable_caching
|
32
|
+
modify_classes
|
33
|
+
end
|
34
|
+
|
35
|
+
def deactivate
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.read_config
|
39
|
+
# Enable quick SiteScoping of other Models via vhost.yml config file
|
40
|
+
default_config = YAML.load(ERB.new(File.read(File.dirname(__FILE__) + '/lib/vhost_default_config.yml')).result).symbolize_keys
|
41
|
+
begin
|
42
|
+
custom_config = YAML.load(ERB.new(File.read(RAILS_ROOT + '/config/vhost.yml')).result).symbolize_keys rescue nil
|
43
|
+
default_config[:models].merge!(custom_config[:models]) unless custom_config[:models].nil?
|
44
|
+
default_config[:redirect_to_primary_site] = custom_config[:redirect_to_primary_site] unless custom_config[:redirect_to_primary_site].nil?
|
45
|
+
rescue
|
46
|
+
end
|
47
|
+
config = {}
|
48
|
+
config[:redirect_to_primary_site] = default_config[:redirect_to_primary_site]
|
49
|
+
config[:models] = default_config[:models].collect{|key,val| key.to_s}
|
50
|
+
config[:model_uniqueness_validations] = default_config[:models]
|
51
|
+
config
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def basic_extension_config
|
57
|
+
tab "Settings" do
|
58
|
+
add_item "Sites", "/admin/sites"
|
59
|
+
end
|
60
|
+
admin.user.index.add :thead, 'sites_th', :before => 'modify_header'
|
61
|
+
admin.user.index.add :tbody, 'sites_td', :before => 'modify_cell'
|
62
|
+
admin.user.edit.add :form, 'admin/users/site_admin_roles', :after => 'edit_roles'
|
63
|
+
admin.user.edit.add :form, 'admin/users/edit_sites', :after => 'edit_roles'
|
64
|
+
|
65
|
+
Radiant::AdminUI.class_eval do
|
66
|
+
attr_accessor :sites
|
67
|
+
end
|
68
|
+
# initialize regions for help (which we created above)
|
69
|
+
admin.sites = load_default_site_regions
|
70
|
+
end
|
71
|
+
|
72
|
+
def process_config
|
73
|
+
config = VhostExtension.read_config
|
74
|
+
|
75
|
+
VhostExtension.REDIRECT_TO_PRIMARY_SITE = config[:redirect_to_primary_site]
|
76
|
+
|
77
|
+
# Set the MODELS and MODEL_VALIDATIONS class variables so everything else can access it
|
78
|
+
VhostExtension.MODELS = config[:models]
|
79
|
+
VhostExtension.MODEL_UNIQUENESS_VALIDATIONS = config[:model_uniqueness_validations]
|
80
|
+
end
|
81
|
+
|
82
|
+
def init_scoped_access
|
83
|
+
# Configure the ScopedAccess stuff to scope models to Sites
|
84
|
+
# Unfortunately adding the filters to the ApplicationController isn't enough
|
85
|
+
# they need to also be added to all of the subclasses (which, surprisingly
|
86
|
+
# only shows as the Admin::PagesController and Admin::ResourceController)
|
87
|
+
controllers = ['ApplicationController']
|
88
|
+
controllers.concat ApplicationController.subclasses
|
89
|
+
controllers.each do |controller| controller.constantize.send :include, SiteScope end
|
90
|
+
|
91
|
+
VhostExtension.MODELS.each do |model|
|
92
|
+
# Instantiate the ScopedAccess filter for each model
|
93
|
+
controllers.each do |controller| controller.constantize.send :prepend_around_filter, ScopedAccess::Filter.new(model.constantize, :site_scope) end
|
94
|
+
scoper = lambda {|m|
|
95
|
+
# Enable class level calls like 'Layout.class.current_site' for each model (overkill?)
|
96
|
+
m.constantize.send :cattr_accessor, :current_site
|
97
|
+
m.constantize.send :extend, Vhost::SiteScopedModelExtensions::ClassMethods
|
98
|
+
m.constantize.send :include, Vhost::SiteScopedModelExtensions::InstanceMethods
|
99
|
+
}
|
100
|
+
model_config = VhostExtension.read_config[:model_uniqueness_validations][model]
|
101
|
+
scoper.call(model)
|
102
|
+
# Set any single table inheritance classes from the config file
|
103
|
+
if model_config['sti_classes']
|
104
|
+
model_config['sti_classes'].each do |klass|
|
105
|
+
scoper.call(klass)
|
106
|
+
controllers.each do |controller| controller.constantize.send :prepend_around_filter, ScopedAccess::Filter.new(klass.constantize, :site_scope) end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
# Enable instance level calls like 'my_layout.current_site' for each model (overkill?)
|
111
|
+
controllers.each do |controller| controller.constantize.send :before_filter, :set_site_scope_in_models end
|
112
|
+
|
113
|
+
# Wrap UsersController with site scoping for Site Admins
|
114
|
+
Admin::UsersController.send :prepend_around_filter, ScopedAccess::Filter.new(User, :users_site_scope)
|
115
|
+
end
|
116
|
+
|
117
|
+
def enable_caching
|
118
|
+
# Enable caching per site
|
119
|
+
Radiant::Cache.send :include, Vhost::RadiantCacheExtensions::RadiantCache
|
120
|
+
Radiant::Cache::MetaStore.send :include, Vhost::RadiantCacheExtensions::MetaStore
|
121
|
+
Admin::PagesController.send :include, Vhost::PagesControllerExtensions
|
122
|
+
end
|
123
|
+
|
124
|
+
def modify_classes
|
125
|
+
# Send all of the Vhost extensions and class modifications
|
126
|
+
User.send :has_and_belongs_to_many, :sites
|
127
|
+
ApplicationHelper.send :include, Vhost::ApplicationHelperExtensions
|
128
|
+
Admin::UsersHelper.send :include, Vhost::AdminUsersHelperExtensions
|
129
|
+
Admin::UsersController.send :include, Vhost::AdminUsersControllerExtensions
|
130
|
+
# Prevents a user from Site A logging into Site B's admin area (need a spec
|
131
|
+
# for this to ensure it's working)
|
132
|
+
Admin::ResourceController.send :include, Vhost::ControllerAccessExtensions
|
133
|
+
Admin::PagesController.send :include, Vhost::ControllerAccessExtensions
|
134
|
+
ApplicationController.send :include, Vhost::ApplicationControllerExtensions
|
135
|
+
end
|
136
|
+
|
137
|
+
# Defines this extension's default regions (so that we can incorporate shards
|
138
|
+
# into its views).
|
139
|
+
def load_default_site_regions
|
140
|
+
returning OpenStruct.new do |site|
|
141
|
+
site.edit = Radiant::AdminUI::RegionSet.new do |edit|
|
142
|
+
edit.main.concat %w{edit_header edit_form}
|
143
|
+
edit.form.concat %w{edit_hostname edit_users}
|
144
|
+
edit.form_bottom.concat %w{edit_buttons}
|
145
|
+
end
|
146
|
+
site.new = Radiant::AdminUI::RegionSet.new do |new|
|
147
|
+
new.main.concat %w{edit_header edit_form}
|
148
|
+
new.form.concat %w{edit_hostname edit_users}
|
149
|
+
new.form_bottom.concat %w{edit_buttons}
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
metadata
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: radiant-vhost-extension
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 11
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 2
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 2.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jason Garber
|
14
|
+
- Kaleb Walton
|
15
|
+
- Jim Gay
|
16
|
+
autorequire:
|
17
|
+
bindir: bin
|
18
|
+
cert_chain: []
|
19
|
+
|
20
|
+
date: 2010-06-13 00:00:00 -04:00
|
21
|
+
default_executable:
|
22
|
+
dependencies:
|
23
|
+
- !ruby/object:Gem::Dependency
|
24
|
+
name: radiant
|
25
|
+
prerelease: false
|
26
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
hash: 3
|
32
|
+
segments:
|
33
|
+
- 0
|
34
|
+
version: "0"
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
description: Host more than one site in a single instance of Radiant.
|
38
|
+
email: jim@saturnflyer.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- README
|
45
|
+
files:
|
46
|
+
- .gitmodules
|
47
|
+
- README
|
48
|
+
- Rakefile
|
49
|
+
- VERSION
|
50
|
+
- app/controllers/admin/sites_controller.rb
|
51
|
+
- app/models/site.rb
|
52
|
+
- app/models/site_association_observer.rb
|
53
|
+
- app/views/admin/sites/_form.html.haml
|
54
|
+
- app/views/admin/sites/edit.html.haml
|
55
|
+
- app/views/admin/sites/index.html.haml
|
56
|
+
- app/views/admin/sites/new.html.haml
|
57
|
+
- app/views/admin/sites/remove.html.haml
|
58
|
+
- app/views/admin/users/_edit_sites.html.haml
|
59
|
+
- app/views/admin/users/_site_admin_roles.html.haml
|
60
|
+
- app/views/admin/users/_sites_td.html.haml
|
61
|
+
- app/views/admin/users/_sites_th.html.haml
|
62
|
+
- config/routes.rb
|
63
|
+
- db/migrate/001_create_sites.rb
|
64
|
+
- db/migrate/002_add_sites_users.rb
|
65
|
+
- db/migrate/003_replace_snippet_name_unique_index.rb
|
66
|
+
- db/migrate/004_add_site_admin_to_users.rb
|
67
|
+
- db/templates/empty.yml
|
68
|
+
- db/templates/simple-blog.yml
|
69
|
+
- lib/bootstrap_with_site_id.rb
|
70
|
+
- lib/radiant-vhost-extension.rb
|
71
|
+
- lib/site_scope.rb
|
72
|
+
- lib/tasks/add_site_columns.rb
|
73
|
+
- lib/tasks/vhost_extension_tasks.rake
|
74
|
+
- lib/vhost/admin_users_controller_extensions.rb
|
75
|
+
- lib/vhost/admin_users_helper_extensions.rb
|
76
|
+
- lib/vhost/application_controller_extensions.rb
|
77
|
+
- lib/vhost/application_helper_extensions.rb
|
78
|
+
- lib/vhost/controller_access_extensions.rb
|
79
|
+
- lib/vhost/pages_controller_extensions.rb
|
80
|
+
- lib/vhost/radiant_cache_extensions.rb
|
81
|
+
- lib/vhost/site_scoped_model_extensions.rb
|
82
|
+
- lib/vhost_default_config.yml
|
83
|
+
- spec/controllers/admin/pages_controller_spec.rb
|
84
|
+
- spec/controllers/admin/sites_controller_spec.rb
|
85
|
+
- spec/controllers/site_controller_spec.rb
|
86
|
+
- spec/datasets/site_home_pages_dataset.rb
|
87
|
+
- spec/datasets/site_pages_dataset.rb
|
88
|
+
- spec/datasets/site_users_dataset.rb
|
89
|
+
- spec/datasets/sites_dataset.rb
|
90
|
+
- spec/datasets/sites_site_users_and_site_pages_dataset.rb
|
91
|
+
- spec/datasets/sites_site_users_dataset.rb
|
92
|
+
- spec/fixtures/page_parts.yml
|
93
|
+
- spec/fixtures/pages.yml
|
94
|
+
- spec/fixtures/sites.yml
|
95
|
+
- spec/fixtures/sites_users.yml
|
96
|
+
- spec/fixtures/users.yml
|
97
|
+
- spec/models/page_spec.rb
|
98
|
+
- spec/models/site_spec.rb
|
99
|
+
- spec/models/user_spec.rb
|
100
|
+
- spec/spec.opts
|
101
|
+
- spec/spec_helper.rb
|
102
|
+
- test/fixtures/page_parts.yml
|
103
|
+
- test/fixtures/pages.yml
|
104
|
+
- test/fixtures/sites.yml
|
105
|
+
- test/fixtures/sites_users.yml
|
106
|
+
- test/fixtures/users.yml
|
107
|
+
- test/functional/admin/pages_controller_test.rb
|
108
|
+
- test/functional/admin/site_controller_test.rb
|
109
|
+
- test/functional/vhost_extension_test.rb
|
110
|
+
- test/helpers/page_part_test_helper.rb
|
111
|
+
- test/test_helper.rb
|
112
|
+
- test/unit/site_test.rb
|
113
|
+
- vhost_extension.rb
|
114
|
+
has_rdoc: true
|
115
|
+
homepage: http://github.com/saturnflyer/radiant-vhost-extension
|
116
|
+
licenses: []
|
117
|
+
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options:
|
120
|
+
- --charset=UTF-8
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
hash: 3
|
129
|
+
segments:
|
130
|
+
- 0
|
131
|
+
version: "0"
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
none: false
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
hash: 3
|
138
|
+
segments:
|
139
|
+
- 0
|
140
|
+
version: "0"
|
141
|
+
requirements: []
|
142
|
+
|
143
|
+
rubyforge_project:
|
144
|
+
rubygems_version: 1.3.7
|
145
|
+
signing_key:
|
146
|
+
specification_version: 3
|
147
|
+
summary: Vhost Extension for Radiant CMS
|
148
|
+
test_files:
|
149
|
+
- spec/controllers/admin/pages_controller_spec.rb
|
150
|
+
- spec/controllers/admin/sites_controller_spec.rb
|
151
|
+
- spec/controllers/site_controller_spec.rb
|
152
|
+
- spec/datasets/site_home_pages_dataset.rb
|
153
|
+
- spec/datasets/site_pages_dataset.rb
|
154
|
+
- spec/datasets/site_users_dataset.rb
|
155
|
+
- spec/datasets/sites_dataset.rb
|
156
|
+
- spec/datasets/sites_site_users_and_site_pages_dataset.rb
|
157
|
+
- spec/datasets/sites_site_users_dataset.rb
|
158
|
+
- spec/models/page_spec.rb
|
159
|
+
- spec/models/site_spec.rb
|
160
|
+
- spec/models/user_spec.rb
|
161
|
+
- spec/spec_helper.rb
|
162
|
+
- test/functional/admin/pages_controller_test.rb
|
163
|
+
- test/functional/admin/site_controller_test.rb
|
164
|
+
- test/functional/vhost_extension_test.rb
|
165
|
+
- test/helpers/page_part_test_helper.rb
|
166
|
+
- test/test_helper.rb
|
167
|
+
- test/unit/site_test.rb
|