public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
admin area for sites in multi-site configuration [Vincent, j2m]
technoweenie (author)
Sun Feb 03 11:07:02 -0800 2008
commit  ca8a7879ef2a7da78c011ab8c27004968d58dc54
tree    3421ea7bcad2b06ee1207d5badba722bb7700709
parent  885b67417c782139785cb4fc36cf251da148795b
...
15
16
17
 
18
19
20
21
22
 
 
 
 
23
24
25
...
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
0
@@ -15,11 +15,16 @@ class ApplicationController < ActionController::Base
0
   
0
   protected
0
     helper_method :admin?
0
+ helper_method :global_admin?
0
     
0
     def admin?
0
       logged_in? && (current_user.admin? || current_user.site_admin?)
0
     end
0
   
0
+ def global_admin?
0
+ logged_in? && current_user.admin?
0
+ end
0
+
0
     # so not the best place for this...
0
     def asset_image_args_for(asset, thumbnail = :tiny, options = {})
0
       thumb_size = Array.new(2).fill(Asset.attachment_options[:thumbnails][thumbnail].to_i).join('x')
...
26
27
28
29
 
30
31
32
...
41
42
43
44
 
45
46
47
...
63
64
65
66
 
67
68
 
69
70
 
71
72
 
73
74
75
...
82
83
84
85
 
 
 
 
86
87
88
89
90
91
 
 
 
 
 
 
 
92
93
94
...
297
298
299
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
300
...
26
27
28
 
29
30
31
32
...
41
42
43
 
44
45
46
47
...
63
64
65
 
66
67
 
68
69
 
70
71
 
72
73
74
75
...
82
83
84
 
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
...
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
0
@@ -26,7 +26,7 @@ class Site < ActiveRecord::Base
0
     @@template_handlers.keys
0
   end
0
 
0
- has_many :sections, :order => "position" do
0
+ has_many :sections, :order => "position", :dependent => :destroy do
0
     def home
0
       find_by_path ''
0
     end
0
@@ -41,7 +41,7 @@ class Site < ActiveRecord::Base
0
     end
0
   end
0
 
0
- has_many :articles do
0
+ has_many :articles, :dependent => :destroy do
0
     def find_by_permalink(options)
0
       conditions =
0
         returning ["(contents.published_at IS NOT NULL AND contents.published_at <= ?)", Time.now.utc] do |cond|
0
@@ -63,13 +63,13 @@ class Site < ActiveRecord::Base
0
     end
0
   end
0
   
0
- has_many :comments, :order => 'comments.created_at desc'
0
+ has_many :comments, :order => 'comments.created_at desc', :dependent => :delete_all
0
   
0
- has_many :events
0
+ has_many :events, :dependent => :destroy
0
   
0
- has_many :cached_pages
0
+ has_many :cached_pages, :dependent => :destroy
0
   
0
- has_many :assets, :order => 'created_at desc', :conditions => 'parent_id is null'
0
+ has_many :assets, :order => 'created_at desc', :conditions => 'parent_id is null', :dependent => :destroy
0
 
0
   has_many :memberships, :dependent => :destroy
0
   has_many :members, :through => :memberships, :source => :user
0
@@ -82,13 +82,23 @@ class Site < ActiveRecord::Base
0
   validates_format_of :host, :with => Format::DOMAIN
0
   validates_uniqueness_of :host
0
   validate :check_permalink_style
0
- after_create { |s| s.sections.create(:name => 'Home') }
0
+
0
+ before_create :setup_site_theme_directories
0
+ after_create { |site| site.sections.create(:name => 'Home') }
0
+ before_destroy :flush_cache_and_remove_site_directories
0
 
0
   with_options :order => 'contents.created_at DESC', :class_name => 'Comment' do |comment|
0
     comment.has_many :comments, :conditions => ['contents.approved = ?', true]
0
     comment.has_many :unapproved_comments, :conditions => ['contents.approved = ? or contents.approved is null', false]
0
     comment.has_many :all_comments
0
   end
0
+
0
+ def self.search_by_host_or_title(search_string)
0
+ conditions = search_string.blank? ? nil : ["host LIKE ? OR title LIKE ?"] + ["%#{search_string}%"] * 2
0
+ with_scope( :find => { :conditions => conditions } ) do
0
+ yield
0
+ end
0
+ end
0
 
0
   def users(options = {})
0
     User.find_all_by_site self, options
0
@@ -297,4 +307,32 @@ class Site < ActiveRecord::Base
0
       find_preferred_template(:layout, layout_template)
0
     end
0
 
0
+ private
0
+
0
+ def setup_site_theme_directories
0
+ begin
0
+ theme_path = "#{RAILS_ROOT}/themes/site-#{self.id}/simpla"
0
+ FileUtils.mkdir_p("#{RAILS_ROOT}/themes/site-#{self.id}")
0
+ FileUtils.cp_r("#{RAILS_ROOT}/themes/default", theme_path)
0
+ Dir[File.join(theme_path, '**/.svn')].each do |dir|
0
+ FileUtils.rm_rf dir
0
+ end
0
+ rescue
0
+ logger.error "ERROR: removing directories for site #{self.host}, check file permissions."
0
+ errors.add_to_base "Unable to create theme directories."
0
+ false
0
+ end
0
+ end
0
+
0
+ def flush_cache_and_remove_site_directories
0
+ begin
0
+ CachedPage.expire_pages self, self.cached_pages
0
+ FileUtils.rm_rf("#{RAILS_ROOT}/themes/site-#{self.id}")
0
+ FileUtils.rm_rf("#{RAILS_ROOT}/public/cache/#{self.host}")
0
+ rescue
0
+ logger.error "ERROR: removing directories for site #{self.host}, check file permissions."
0
+ false
0
+ end
0
+ end
0
+
0
 end
...
18
19
20
 
 
 
21
 
22
23
24
...
99
100
101
102
103
 
...
18
19
20
21
22
23
24
25
26
27
28
...
103
104
105
 
106
107
0
@@ -18,7 +18,11 @@
0
       <% if admin? -%>
0
         <li><%= link_to 'Settings', :controller => 'settings' %></li>
0
       <% end -%>
0
+ <% if Site.multi_sites_enabled && global_admin? %>
0
+ <li><%= link_to 'Sites', :controller => '/admin/sites' %></li>
0
+ <% end %>
0
         <li><%= link_to 'Account', :controller => 'users', :action => 'show', :id => current_user %></li>
0
+
0
         <li><%= link_to 'Logout', :controller => '/account', :action => 'logout' %></li>
0
       </ul>
0
 
0
@@ -99,4 +103,4 @@
0
       </div>
0
     </div>
0
   </body>
0
-</html>
0
\ No newline at end of file
0
+</html>
...
21
22
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
0
@@ -21,3 +21,49 @@ describe Site do
0
   end
0
   
0
 end
0
+require File.dirname(__FILE__) + '/../spec_helper'
0
+describe Site do
0
+ define_models do
0
+
0
+ model Site do
0
+ stub :destroy, :host => 'destroy.com'
0
+ end
0
+
0
+ model User do
0
+ stub :destroy, :login => 'destroy'
0
+ end
0
+
0
+ model Membership do
0
+ stub :destroy, :site => all_stubs(:destroy_site), :user => all_stubs(:destroy_user)
0
+ end
0
+ end
0
+
0
+ it "should delete memberships on destruction" do
0
+ sites(:destroy).memberships.should == [memberships(:destroy)]
0
+ lambda { sites(:destroy).destroy }.should change(Membership, :count).by(-1)
0
+ end
0
+
0
+end
0
+require File.dirname(__FILE__) + '/../spec_helper'
0
+describe Site do
0
+ define_models do
0
+
0
+ model Site do
0
+ stub :destroy, :host => 'destroy.com'
0
+ end
0
+
0
+ model User do
0
+ stub :destroy, :login => 'destroy'
0
+ end
0
+
0
+ model Membership do
0
+ stub :destroy, :site => all_stubs(:destroy_site), :user => all_stubs(:destroy_user)
0
+ end
0
+ end
0
+
0
+ it "should delete memberships on destruction" do
0
+ sites(:destroy).memberships.should == [memberships(:destroy)]
0
+ lambda { sites(:destroy).destroy }.should change(Membership, :count).by(-1)
0
+ end
0
+
0
+end
...
11
12
13
14
 
15
16
17
...
63
64
65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
11
12
13
 
14
15
16
17
...
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
0
@@ -11,7 +11,7 @@ class Admin::AdminNavTest < Test::Unit::TestCase
0
     @controller = Admin::AssetsController.new
0
     @request = ActionController::TestRequest.new
0
     @response = ActionController::TestResponse.new
0
- login_as :quentin
0
+ login_as :arthur
0
     get :new
0
   end
0
   
0
@@ -63,3 +63,39 @@ class Admin::MemberNavTest < Test::Unit::TestCase
0
     end
0
   end
0
 end
0
+
0
+class Admin::GlobalAdminNavTest < Test::Unit::TestCase
0
+ fixtures :sites, :users, :memberships
0
+
0
+ def setup
0
+ @old = Site.multi_sites_enabled
0
+ @controller = Admin::AssetsController.new
0
+ @request = ActionController::TestRequest.new
0
+ @response = ActionController::TestResponse.new
0
+ Site.multi_sites_enabled = true
0
+ login_as :quentin
0
+ get :new
0
+ end
0
+
0
+ def teardown
0
+ Site.multi_sites_enabled = @old
0
+ end
0
+
0
+ def test_should_show_primary_nav
0
+ assert_select "#header #nav a" do |anchors|
0
+ assert_equal %w(Overview Articles Assets), anchors[0..2].collect { |a| a.children.first.content }
0
+ end
0
+ end
0
+
0
+ def test_should_show_secondary_nav
0
+ assert_select "#header #nav #nav-r a" do |anchors|
0
+ assert_equal %w(Sections Design Users Plugins), anchors.collect { |a| a.children.first.content }
0
+ end
0
+ end
0
+
0
+ def test_should_show_user_nav
0
+ assert_select "#header #sec-nav a" do |anchors|
0
+ assert_equal %w(Website Settings Sites Account Logout), anchors.collect { |a| a.children.first.content }
0
+ end
0
+ end
0
+end

Comments

    No one has commented yet.