caboose-cms 0.4.42 → 0.4.43

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.
Files changed (34) hide show
  1. checksums.yaml +8 -8
  2. data/app/assets/javascripts/caboose/jquery.fileupload.js +1441 -0
  3. data/app/assets/javascripts/caboose/lodash.min.js +56 -0
  4. data/app/assets/javascripts/caboose/s3upload.js +124 -0
  5. data/app/controllers/caboose/ab_variants_controller.rb +1 -1
  6. data/app/controllers/caboose/application_controller.rb +1 -1
  7. data/app/controllers/caboose/images_controller.rb +269 -0
  8. data/app/controllers/caboose/pages_controller.rb +21 -12
  9. data/app/controllers/caboose/permissions_controller.rb +1 -1
  10. data/app/controllers/caboose/roles_controller.rb +1 -1
  11. data/app/controllers/caboose/settings_controller.rb +1 -1
  12. data/app/controllers/caboose/sites_controller.rb +156 -0
  13. data/app/controllers/caboose/users_controller.rb +1 -1
  14. data/app/models/caboose/asset.rb +2 -2
  15. data/app/models/caboose/core_plugin.rb +7 -6
  16. data/app/models/caboose/domain.rb +8 -0
  17. data/app/models/caboose/media_category.rb +18 -0
  18. data/app/models/caboose/media_file.rb +9 -0
  19. data/app/models/caboose/media_image.rb +16 -0
  20. data/app/models/caboose/page.rb +16 -9
  21. data/app/models/caboose/schema.rb +191 -158
  22. data/app/models/caboose/site.rb +9 -0
  23. data/app/models/caboose/site_membership.rb +12 -0
  24. data/app/views/caboose/blocks/admin_edit.html.erb +2 -1
  25. data/app/views/caboose/blocks/admin_new.html.erb +5 -1
  26. data/app/views/caboose/images/admin_index.html.erb +24 -0
  27. data/app/views/caboose/images/admin_new.html.erb +63 -0
  28. data/app/views/caboose/pages/admin_index.html.erb +6 -3
  29. data/app/views/caboose/sites/admin_edit.html.erb +199 -0
  30. data/app/views/caboose/sites/admin_index.html.erb +31 -0
  31. data/app/views/caboose/sites/admin_new.html.erb +33 -0
  32. data/config/routes.rb +25 -0
  33. data/lib/caboose/version.rb +1 -1
  34. metadata +18 -2
@@ -5,14 +5,14 @@ module Caboose
5
5
  helper :application
6
6
 
7
7
  def before_action
8
- @page = Page.page_with_uri('/admin')
8
+ @page = Page.page_with_uri(request.host_with_port, '/admin')
9
9
  end
10
10
 
11
11
  # GET /pages/:id
12
12
  def show
13
13
 
14
14
  # Find the page with an exact URI match
15
- page = Page.page_with_uri(request.fullpath, false)
15
+ page = Page.page_with_uri(request.host_with_port, request.fullpath, false)
16
16
 
17
17
  if (!page)
18
18
  asset
@@ -51,7 +51,7 @@ module Caboose
51
51
  uri.chop! if uri.end_with?('/')
52
52
  uri[0] = '' if uri.starts_with?('/')
53
53
 
54
- page = Page.page_with_uri(File.dirname(uri), false)
54
+ page = Page.page_with_uri(request.host_with_port, File.dirname(uri), false)
55
55
  if (page.nil? || !page)
56
56
  respond_to do |format|
57
57
  format.all { render :file => "caboose/extras/error404", :layout => "caboose/error404", :formats => [:html] }
@@ -104,8 +104,9 @@ module Caboose
104
104
 
105
105
  # GET /admin/pages
106
106
  def admin_index
107
- return if !user_is_allowed('pages', 'view')
108
- @home_page = Page.find(1)
107
+ return if !user_is_allowed('pages', 'view')
108
+ @domain = Domain.where(:domain => request.host_with_port).first
109
+ @home_page = @domain ? Page.index_page(@domain.site_id) : nil
109
110
  render :layout => 'caboose/admin'
110
111
  end
111
112
 
@@ -238,7 +239,7 @@ module Caboose
238
239
  'error' => nil,
239
240
  'redirect' => nil
240
241
  })
241
-
242
+
242
243
  parent_id = params[:parent_id]
243
244
  title = params[:title]
244
245
 
@@ -250,13 +251,20 @@ module Caboose
250
251
  resp.error = "You don't have permission to add a page there."
251
252
  end
252
253
  if (!resp.error.nil?)
253
- render json: resp
254
+ render :json => resp
254
255
  return
255
256
  end
256
257
 
257
- parent = Caboose::Page.find(parent_id)
258
-
258
+ parent = Caboose::Page.find(parent_id)
259
259
  page = Caboose::Page.new
260
+
261
+ if parent.nil?
262
+ d = Domain.where(:domain => request.host_with_port).first.site_id
263
+ page.site_id = d.site_id
264
+ else
265
+ page.site_id = parent.site_id
266
+ end
267
+
260
268
  page.title = title
261
269
  page.parent_id = parent_id
262
270
  page.hide = true
@@ -425,13 +433,14 @@ module Caboose
425
433
 
426
434
  # GET /admin/pages/sitemap-options
427
435
  def admin_sitemap_options
428
- parent_id = params[:parent_id]
429
- top_page = Page.index_page
436
+ parent_id = params[:parent_id]
437
+ d = Domain.where(:domain => request.host_with_port).first
438
+ top_page = Page.index_page(d.site_id)
430
439
  p = !parent_id.nil? ? Page.find(parent_id) : top_page
431
440
  options = []
432
441
  sitemap_helper(top_page, options)
433
442
 
434
- render json: options
443
+ render :json => options
435
444
  end
436
445
 
437
446
  def sitemap_helper(page, options, prefix = '')
@@ -3,7 +3,7 @@ module Caboose
3
3
  layout 'caboose/admin'
4
4
 
5
5
  def before_action
6
- @page = Page.page_with_uri('/admin')
6
+ @page = Page.page_with_uri(request.host_with_port, '/admin')
7
7
  end
8
8
 
9
9
  # GET /admin/permissions
@@ -3,7 +3,7 @@ module Caboose
3
3
  layout 'caboose/admin'
4
4
 
5
5
  def before_action
6
- @page = Page.page_with_uri('/admin')
6
+ @page = Page.page_with_uri(request.host_with_port, '/admin')
7
7
  end
8
8
 
9
9
  # GET /admin/roles
@@ -3,7 +3,7 @@ module Caboose
3
3
  layout 'caboose/admin'
4
4
 
5
5
  def before_action
6
- @page = Page.page_with_uri('/admin')
6
+ @page = Page.page_with_uri(request.host_with_port, '/admin')
7
7
  end
8
8
 
9
9
  # GET /admin/settings
@@ -0,0 +1,156 @@
1
+ require 'csv'
2
+
3
+ module Caboose
4
+ class SitesController < ApplicationController
5
+ layout 'caboose/admin'
6
+
7
+ def before_action
8
+ @page = Page.page_with_uri(request.host_with_port, '/admin')
9
+ end
10
+
11
+ # GET /admin/sites
12
+ def admin_index
13
+ return if !user_is_allowed('sites', 'view')
14
+
15
+ @pager = PageBarGenerator.new(params, {
16
+ 'name_like' => '',
17
+ },{
18
+ 'model' => 'Caboose::Site',
19
+ 'sort' => 'name',
20
+ 'desc' => false,
21
+ 'base_url' => '/admin/sites',
22
+ 'use_url_params' => false
23
+ })
24
+ @sites = @pager.items
25
+ end
26
+
27
+ # GET /admin/sites/new
28
+ def admin_new
29
+ return if !user_is_allowed('sites', 'add')
30
+ @site = Site.new
31
+ end
32
+
33
+ # GET /admin/sites/1/edit
34
+ def admin_edit
35
+ return if !user_is_allowed('sites', 'edit')
36
+ @site = Site.find(params[:id])
37
+ end
38
+
39
+ # POST /admin/sites
40
+ def admin_add
41
+ return if !user_is_allowed('sites', 'add')
42
+
43
+ resp = StdClass.new
44
+ site = Site.new
45
+ site.name = params[:name].strip
46
+
47
+ if site.name.length == 0
48
+ resp.error = "Please enter a valid domain."
49
+ else
50
+ site.save
51
+ resp.redirect = "/admin/sites/#{site.id}"
52
+ end
53
+
54
+ render :json => resp
55
+ end
56
+
57
+ # PUT /admin/sites/:id
58
+ def admin_update
59
+ return if !user_is_allowed('sites', 'edit')
60
+
61
+ resp = StdClass.new
62
+ site = Site.find(params[:id])
63
+
64
+ save = true
65
+ params.each do |name,value|
66
+ case name
67
+ when 'name' then site.name = value
68
+ when 'description' then site.description = value
69
+ end
70
+ end
71
+
72
+ resp.success = save && site.save
73
+ render :json => resp
74
+ end
75
+
76
+ # DELETE /admin/sites/1
77
+ def admin_delete
78
+ return if !user_is_allowed('sites', 'delete')
79
+ site = Site.find(params[:id])
80
+ site.destroy
81
+
82
+ resp = StdClass.new({
83
+ 'redirect' => '/admin/sites'
84
+ })
85
+ render :json => resp
86
+ end
87
+
88
+ # POST /admin/sites/:id/members
89
+ def admin_add_member
90
+ return if !user_is_allowed('sites', 'edit')
91
+ sm = SiteMembership.where(:site_id => params[:id], :user_id => params[:user_id]).first
92
+ sm = SiteMembership.create(:site_id => params[:id], :user_id => params[:user_id]) if sm.nil?
93
+ sm.role = params[:role]
94
+ sm.save
95
+ render :json => true
96
+ end
97
+
98
+ # DELETE /admin/sites/:id/members/:user_id
99
+ def admin_remove_member
100
+ return if !user_is_allowed('sites', 'edit')
101
+ SiteMembership.where(:site_id => params[:id], :user_id => params[:user_id]).destroy_all
102
+ render :json => true
103
+ end
104
+
105
+ # POST /admin/sites/:id/domains
106
+ def admin_add_domain
107
+ return if !user_is_allowed('sites', 'edit')
108
+
109
+ resp = Caboose::StdClass.new
110
+ d = Domain.where(:domain => params[:domain]).first
111
+
112
+ if d && d.site_id != params[:id]
113
+ resp.error = "That domain is already associated with another site."
114
+ elsif d && d.site_id == params[:id]
115
+ resp.refresh = true
116
+ elsif d.nil?
117
+ primary = Domain.where(:site_id => params[:id]).count == 0
118
+ d = Domain.create(:site_id => params[:id], :domain => params[:domain], :primary => primary)
119
+ resp.refresh = true
120
+ end
121
+ render :json => resp
122
+ end
123
+
124
+ # PUT /admin/sites/:id/domains/:domain_id/set-primary
125
+ def admin_set_primary_domain
126
+ return if !user_is_allowed('sites', 'edit')
127
+
128
+ domain_id = params[:domain_id].to_i
129
+ Domain.where(:site_id => params[:id]).all.each do |d|
130
+ d.primary = d.id == domain_id ? true : false
131
+ d.save
132
+ end
133
+ render :json => true
134
+ end
135
+
136
+ # DELETE /admin/sites/:id/domains/:domain_id
137
+ def admin_remove_domain
138
+ return if !user_is_allowed('sites', 'edit')
139
+ Domain.find(params[:domain_id]).destroy
140
+ if Domain.where(:site_id => params[:id]).count == 1
141
+ d = Domain.where(:site_id => params[:id]).first
142
+ d.primary = true
143
+ d.save
144
+ end
145
+ render :json => { 'refresh' => true }
146
+ end
147
+
148
+ # GET /admin/sites/options
149
+ def options
150
+ return if !user_is_allowed('sites', 'view')
151
+ options = Site.reorder('name').all.collect { |s| { 'value' => s.id, 'text' => s.name }}
152
+ render :json => options
153
+ end
154
+
155
+ end
156
+ end
@@ -5,7 +5,7 @@ module Caboose
5
5
  layout 'caboose/admin'
6
6
 
7
7
  def before_action
8
- @page = Page.page_with_uri('/admin')
8
+ @page = Page.page_with_uri(request.host_with_port, '/admin')
9
9
  end
10
10
 
11
11
  #===========================================================================
@@ -8,10 +8,10 @@ class Caboose::Asset < ActiveRecord::Base
8
8
  return str.gsub(' ', '_').downcase
9
9
  end
10
10
 
11
- def assets_with_uri(uri)
11
+ def assets_with_uri(host_with_port, uri)
12
12
  uri[0] = '' if uri.start_with? '/'
13
13
 
14
- page = Page.page_with_uri(File.dirname(uri), false)
14
+ page = Page.page_with_uri(host_with_port, File.dirname(uri), false)
15
15
  return false if page.nil?
16
16
 
17
17
  asset = Asset.where(:page_id => page.id,:filename => File.basename(uri)).first
@@ -21,12 +21,13 @@ class Caboose::CorePlugin < Caboose::CaboosePlugin
21
21
  'children' => []
22
22
  }
23
23
 
24
- item['children'] << { 'id' => 'users' , 'text' => 'Users' , 'href' => '/admin/users' , 'modal' => false } if user.is_allowed('users' , 'view')
25
- item['children'] << { 'id' => 'roles' , 'text' => 'Roles' , 'href' => '/admin/roles' , 'modal' => false } if user.is_allowed('roles' , 'view')
26
- item['children'] << { 'id' => 'permissions' , 'text' => 'Permissions' , 'href' => '/admin/permissions' , 'modal' => false } if user.is_allowed('permissions' , 'view')
27
- item['children'] << { 'id' => 'blocktypes' , 'text' => 'AB Test Variants' , 'href' => '/admin/ab-variants' , 'modal' => false } if user.is_allowed('abvariants' , 'view')
28
- item['children'] << { 'id' => 'variables' , 'text' => 'Variables' , 'href' => '/admin/settings' , 'modal' => false } if user.is_allowed('settings' , 'view')
29
- item['children'] << { 'id' => 'blocktypes' , 'text' => 'Block Types' , 'href' => '/admin/block-types' , 'modal' => false } if user.is_allowed('blocktypes' , 'view')
24
+ item['children'] << { 'id' => 'users' , 'text' => 'Users' , 'href' => '/admin/users' , 'modal' => false } if user.is_allowed('users' , 'view')
25
+ item['children'] << { 'id' => 'roles' , 'text' => 'Roles' , 'href' => '/admin/roles' , 'modal' => false } if user.is_allowed('roles' , 'view')
26
+ item['children'] << { 'id' => 'permissions' , 'text' => 'Permissions' , 'href' => '/admin/permissions' , 'modal' => false } if user.is_allowed('permissions' , 'view')
27
+ item['children'] << { 'id' => 'sites' , 'text' => 'Sites' , 'href' => '/admin/sites' , 'modal' => false } if user.is_allowed('sites' , 'view')
28
+ item['children'] << { 'id' => 'blocktypes' , 'text' => 'AB Test Variants' , 'href' => '/admin/ab-variants' , 'modal' => false } if user.is_allowed('abvariants' , 'view')
29
+ item['children'] << { 'id' => 'variables' , 'text' => 'Variables' , 'href' => '/admin/settings' , 'modal' => false } if user.is_allowed('settings' , 'view')
30
+ item['children'] << { 'id' => 'blocktypes' , 'text' => 'Block Types' , 'href' => '/admin/block-types' , 'modal' => false } if user.is_allowed('blocktypes' , 'view')
30
31
 
31
32
  nav << item if item['children'].count > 0
32
33
 
@@ -0,0 +1,8 @@
1
+
2
+ class Caboose::Domain < ActiveRecord::Base
3
+ self.table_name = "domains"
4
+
5
+ belongs_to :site, :class_name => 'Caboose::Site'
6
+ attr_accessible :id, :site_id, :domain, :primary
7
+
8
+ end
@@ -0,0 +1,18 @@
1
+ class Caboose::MediaCategory < ActiveRecord::Base
2
+
3
+ self.table_name = "media_categories"
4
+ belongs_to :parent, :class_name => 'Caboose::MediaCategory'
5
+ has_many :children, :class_name => 'Caboose::MediaCategory', :foreign_key => 'parent_id', :order => 'name'
6
+ has_many :media_images, :class_name => 'Caboose::MediaImage', :order => 'name'
7
+ has_many :media_files, :class_name => 'Caboose::MediaFile', :order => 'name'
8
+ attr_accessible :id, :site_id, :parent_id, :name
9
+
10
+ def self.top_image_category(site_id)
11
+ return self.where("parent_id is null and site_id = ? and name = ?", site_id, 'Images').first
12
+ end
13
+
14
+ def self.top_file_category(site_id)
15
+ return self.where("parent_id is null and site_id = ? and name = ?", site_id, 'Files').first
16
+ end
17
+
18
+ end
@@ -0,0 +1,9 @@
1
+ class Caboose::MediaFile < ActiveRecord::Base
2
+
3
+ self.table_name = "media_files"
4
+ belongs_to :media_category
5
+ has_attached_file :file, :path => 'media-files/:id.:extension'
6
+ do_not_validate_attachment_file_type :file
7
+ attr_accessible :id, :media_category_id, :name, :description
8
+
9
+ end
@@ -0,0 +1,16 @@
1
+ class Caboose::MediaImage < ActiveRecord::Base
2
+
3
+ self.table_name = "media_images"
4
+ belongs_to :media_category
5
+ has_attached_file :image,
6
+ :path => 'media-images/:id_:style.:extension',
7
+ :default_url => "#{Caboose::cdn_domain}/media-images/default_user_image.jpg",
8
+ :styles => {
9
+ :tiny => '150x200>',
10
+ :thumb => '300x400>',
11
+ :large => '600x800>'
12
+ }
13
+ do_not_validate_attachment_file_type :image
14
+ attr_accessible :id, :media_category_id, :name, :description
15
+
16
+ end
@@ -2,11 +2,14 @@
2
2
  class Caboose::Page < ActiveRecord::Base
3
3
  self.table_name = "pages"
4
4
 
5
- belongs_to :parent, :class_name => "Page"
6
- has_many :children, :class_name => "Page", :foreign_key => 'parent_id', :order => 'sort_order, title'
5
+ belongs_to :site, :class_name => 'Caboose::Site'
6
+ belongs_to :parent, :class_name => 'Caboose::Page'
7
+ has_many :children, :class_name => 'Caboose::Page', :foreign_key => 'parent_id', :order => 'sort_order, title'
7
8
  has_many :page_permissions
8
9
  has_many :blocks, :order => 'sort_order'
9
- attr_accessible :parent_id,
10
+ attr_accessible :id,
11
+ :site_id,
12
+ :parent_id,
10
13
  :title,
11
14
  :menu_title,
12
15
  # :content, # Changed from column in pages to blocks
@@ -56,12 +59,16 @@ class Caboose::Page < ActiveRecord::Base
56
59
  return self.where(:id => page_id).select(fields).first
57
60
  end
58
61
 
59
- def self.index_page
60
- return self.where(:parent_id => -1).first
62
+ def self.index_page(site_id)
63
+ return self.where(:site_id => site_id, :parent_id => -1).first
61
64
  end
62
65
 
63
- def self.page_with_uri(uri, get_closest_parent = true)
66
+ def self.page_with_uri(host_with_port, uri, get_closest_parent = true)
64
67
 
68
+ d = Caboose::Domain.where(:domain => host_with_port).first
69
+ return false if d.nil?
70
+ site_id = d.site_id
71
+
65
72
  uri = uri.to_s.gsub(/^(.*?)\?.*?$/, '\1')
66
73
  uri.chop! if uri.end_with?('/')
67
74
  uri[0] = '' if uri.starts_with?('/')
@@ -72,14 +79,14 @@ class Caboose::Page < ActiveRecord::Base
72
79
  parts = uri.split('/')
73
80
 
74
81
  # See where to start looking
75
- page_ids = self.where(:alias => parts[0]).limit(1).pluck(:id)
82
+ page_ids = self.where(:site_id => site_id, :alias => parts[0]).limit(1).pluck(:id)
76
83
  page_id = !page_ids.nil? && page_ids.count > 0 ? page_ids[0] : false
77
84
 
78
85
  # Search for the page
79
- if (page_id)
86
+ if page_id
80
87
  page_id = self.page_with_uri_helper(parts, 1, page_id)
81
88
  else
82
- parent_id = self.index_page
89
+ parent_id = self.index_page(site_id)
83
90
  page_id = self.page_with_uri_helper(parts, 0, parent_id)
84
91
  end
85
92
 
@@ -1,6 +1,6 @@
1
1
 
2
2
  class Caboose::Schema < Caboose::Utilities::Schema
3
-
3
+
4
4
  # Tables (in order) that were renamed in the development of the gem.
5
5
  def self.renamed_tables
6
6
  {
@@ -12,19 +12,19 @@ class Caboose::Schema < Caboose::Utilities::Schema
12
12
  :page_blocks => :blocks
13
13
  }
14
14
  end
15
-
15
+
16
16
  def self.renamed_columns
17
17
  {
18
18
  #Caboose::Field => { :page_block_id => :block_id,
19
- # :page_block_field_id => :field_type_id },
19
+ # :page_block_field_id => :field_type_id },
20
20
  #Caboose::FieldType => { :page_block_type_id => :block_type_id },
21
- Caboose::Block => { :page_block_type_id => :block_type_id }
21
+ Caboose::Block => { :page_block_type_id => :block_type_id }
22
22
  }
23
23
  end
24
-
24
+
25
25
  def self.removed_columns
26
26
  {
27
- Caboose::Block => [:block_type],
27
+ Caboose::Block => [:block_type],
28
28
  #Caboose::FieldType => [:model_binder_options],
29
29
  Caboose::AbValue => [:i, :text],
30
30
  Caboose::AbOption => [:text],
@@ -33,7 +33,7 @@ class Caboose::Schema < Caboose::Utilities::Schema
33
33
  Caboose::BlockType => [:layout_function]
34
34
  }
35
35
  end
36
-
36
+
37
37
  # Any column indexes that need to exist in the database
38
38
  def self.indexes
39
39
  {
@@ -42,106 +42,54 @@ class Caboose::Schema < Caboose::Utilities::Schema
42
42
  Caboose::PostCategoryMembership => [ :post_id , :post_category_id ]
43
43
  #Caboose::Session => [ :session_id , :updated_at ]
44
44
  }
45
- end
46
-
45
+ end
46
+
47
47
  # The schema of the database
48
48
  # { Model => [[name, data_type, options]] }
49
- def self.schema
49
+ def self.schema
50
50
  {
51
- Caboose::User => [
52
- [ :first_name , :string ],
53
- [ :last_name , :string ],
54
- [ :username , :string ],
55
- [ :email , :string ],
56
- [ :address , :string ],
57
- [ :address2 , :string ],
58
- [ :city , :string ],
59
- [ :state , :string ],
60
- [ :zip , :string ],
61
- [ :phone , :string ],
62
- [ :fax , :string ],
63
- [ :utc_offset , :float , { :default => -5 }],
64
- #[ :timezone , :string , { :default => 'America/Chicago' }],
65
- [ :timezone_id , :integer , { :defualt => 381 }], # Defaults to 'America/Chicago'
66
- [ :password , :string ],
67
- [ :password_reset_id , :string ],
68
- [ :password_reset_sent , :datetime ],
69
- [ :token , :string ],
70
- [ :date_created , :datetime ],
71
- [ :image , :attachment ]
72
- ],
73
- Caboose::Role => [
74
- [ :parent_id , :integer ],
75
- [ :name , :string ],
76
- [ :description , :string ]
51
+ Caboose::AbVariant => [
52
+ [ :name , :string ],
53
+ [ :analytics_name , :string ],
77
54
  ],
78
- Caboose::Permission => [
79
- [ :resource , :string ],
80
- [ :action , :string ]
55
+ Caboose::AbOption => [
56
+ [ :ab_variant_id , :integer ],
57
+ [ :value , :string ]
81
58
  ],
82
- Caboose::RoleMembership => [
83
- [ :role_id, :integer ],
84
- [ :user_id, :integer ]
59
+ Caboose::AbValue => [
60
+ [ :session_id , :string ],
61
+ [ :ab_variant_id , :integer ],
62
+ [ :ab_option_id , :integer ]
85
63
  ],
86
- Caboose::RolePermission => [
87
- [ :role_id , :integer ],
88
- [ :permission_id , :integer ]
89
- ],
90
- Caboose::Asset => [
91
- [ :page_id , :integer ],
92
- [ :user_id , :integer ],
93
- [ :date_uploaded , :datetime ],
94
- [ :name , :string ],
95
- [ :filename , :string ],
96
- [ :description , :string ],
64
+ Caboose::Asset => [
65
+ [ :page_id , :integer ],
66
+ [ :user_id , :integer ],
67
+ [ :date_uploaded , :datetime ],
68
+ [ :name , :string ],
69
+ [ :filename , :string ],
70
+ [ :description , :string ],
97
71
  [ :extension , :string ]
98
72
  ],
99
- Caboose::Page => [
100
- [ :parent_id , :integer ],
101
- [ :title , :string ],
102
- [ :menu_title , :string ],
103
- #[ :content , :text ],
104
- [ :slug , :string ],
105
- [ :alias , :string ],
106
- [ :uri , :string ],
107
- [ :redirect_url , :string ],
108
- [ :hide , :boolean , { :default => false }],
109
- [ :content_format , :integer , { :default => Caboose::Page::CONTENT_FORMAT_HTML }],
110
- [ :custom_css , :text ],
111
- [ :custom_js , :text ],
112
- [ :linked_resources , :text ],
113
- [ :layout , :string ],
114
- [ :sort_order , :integer , { :default => 0 }],
115
- [ :custom_sort_children , :boolean , { :default => false }],
116
- [ :seo_title , :string , { :limit => 70 }],
117
- [ :meta_description , :string , { :limit => 156 }],
118
- [ :meta_robots , :string , { :default => 'index, follow' }],
119
- [ :canonical_url , :string ],
120
- [ :fb_description , :string , { :limit => 156 }],
121
- [ :gp_description , :string , { :limit => 156 }]
122
- ],
123
- Caboose::Block => [
73
+ Caboose::Block => [
124
74
  [ :page_id , :integer ],
125
75
  [ :parent_id , :integer ],
126
76
  [ :block_type_id , :integer ],
127
77
  [ :sort_order , :integer , { :default => 0 }],
128
78
  [ :name , :string ],
129
- [ :value , :text ],
79
+ [ :value , :text ],
130
80
  [ :file , :attachment ],
131
81
  [ :image , :attachment ]
132
82
  ],
133
- Caboose::BlockType => [
83
+ Caboose::BlockType => [
134
84
  [ :parent_id , :integer ],
135
85
  [ :name , :string ],
136
86
  [ :description , :string ],
137
87
  [ :block_type_category_id , :integer , { :default => 2 }],
138
88
  [ :render_function , :text ],
139
- [ :use_render_function , :boolean , { :default => false }],
89
+ [ :use_render_function , :boolean , { :default => false }],
140
90
  [ :use_render_function_for_layout , :boolean , { :default => false }],
141
- [ :allow_child_blocks , :boolean , { :default => false }],
142
-
143
- # Used for field values
144
- [ :field_type , :string ],
91
+ [ :allow_child_blocks , :boolean , { :default => false }],
92
+ [ :field_type , :string ],
145
93
  [ :default , :text ],
146
94
  [ :width , :integer ],
147
95
  [ :height , :integer ],
@@ -149,15 +97,13 @@ class Caboose::Schema < Caboose::Utilities::Schema
149
97
  [ :options , :text ],
150
98
  [ :options_function , :text ],
151
99
  [ :options_url , :string ],
152
-
153
- # Used for sharing block types
154
100
  [ :share , :boolean , { :default => true }],
155
101
  [ :downloaded , :boolean , { :default => false }]
156
102
  ],
157
- Caboose::BlockTypeCategory => [
103
+ Caboose::BlockTypeCategory => [
158
104
  [ :parent_id , :integer ],
159
- [ :name , :string ]
160
- ],
105
+ [ :name , :string ]
106
+ ],
161
107
  Caboose::BlockTypeSource => [
162
108
  [ :name , :string ],
163
109
  [ :url , :string ],
@@ -165,15 +111,74 @@ class Caboose::Schema < Caboose::Utilities::Schema
165
111
  [ :priority , :integer, { :default => 0 }],
166
112
  [ :active , :boolean, { :default => true }],
167
113
  ],
168
- Caboose::BlockTypeSummary => [
114
+ Caboose::BlockTypeSummary => [
169
115
  [ :block_type_source_id , :integer ],
170
116
  [ :name , :string ],
171
- [ :description , :string ]
117
+ [ :description , :string ]
118
+ ],
119
+ Caboose::DatabaseSession => [
120
+ [ :session_id , :string , :null => false ],
121
+ [ :data , :text ],
122
+ [ :created_at , :datetime , :null => true ],
123
+ [ :updated_at , :datetime , :null => true ]
124
+ ],
125
+ Caboose::Domain => [
126
+ [ :site_id , :integer ],
127
+ [ :domain , :string ],
128
+ [ :primary , :boolean, { :default => false }]
129
+ ],
130
+ Caboose::MediaCategory => [
131
+ [ :parent_id , :integer ],
132
+ [ :site_id , :integer ],
133
+ [ :name , :string ]
134
+ ],
135
+ Caboose::MediaImage => [
136
+ [ :media_category_id , :integer ],
137
+ [ :name , :string ],
138
+ [ :description , :text ]
139
+ ],
140
+ Caboose::MediaFile => [
141
+ [ :media_category_id , :integer ],
142
+ [ :name , :string ],
143
+ [ :description , :text ]
144
+ ],
145
+ Caboose::Page => [
146
+ [ :site_id , :integer ],
147
+ [ :parent_id , :integer ],
148
+ [ :title , :string ],
149
+ [ :menu_title , :string ],
150
+ [ :slug , :string ],
151
+ [ :alias , :string ],
152
+ [ :uri , :string ],
153
+ [ :redirect_url , :string ],
154
+ [ :hide , :boolean , { :default => false }],
155
+ [ :content_format , :integer , { :default => Caboose::Page::CONTENT_FORMAT_HTML }],
156
+ [ :custom_css , :text ],
157
+ [ :custom_js , :text ],
158
+ [ :linked_resources , :text ],
159
+ [ :layout , :string ],
160
+ [ :sort_order , :integer , { :default => 0 }],
161
+ [ :custom_sort_children , :boolean , { :default => false }],
162
+ [ :seo_title , :string , { :limit => 70 }],
163
+ [ :meta_description , :string , { :limit => 156 }],
164
+ [ :meta_robots , :string , { :default => 'index, follow' }],
165
+ [ :canonical_url , :string ],
166
+ [ :fb_description , :string , { :limit => 156 }],
167
+ [ :gp_description , :string , { :limit => 156 }]
172
168
  ],
173
- Caboose::Post => [
174
- [ :title , :text ],
175
- [ :body , :text ],
176
- [ :hide , :boolean ],
169
+ Caboose::PagePermission => [
170
+ [ :role_id , :integer ],
171
+ [ :page_id , :integer ],
172
+ [ :action , :string ]
173
+ ],
174
+ Caboose::Permission => [
175
+ [ :resource , :string ],
176
+ [ :action , :string ]
177
+ ],
178
+ Caboose::Post => [
179
+ [ :title , :text ],
180
+ [ :body , :text ],
181
+ [ :hide , :boolean ],
177
182
  [ :image_url , :text ],
178
183
  [ :published , :boolean ],
179
184
  [ :created_at , :datetime ],
@@ -182,91 +187,111 @@ class Caboose::Schema < Caboose::Utilities::Schema
182
187
  ],
183
188
  Caboose::PostCategory => [
184
189
  [ :name , :string ]
185
- ],
186
- Caboose::PostCategoryMembership => [
190
+ ],
191
+ Caboose::PostCategoryMembership => [
187
192
  [ :post_id , :integer ],
188
193
  [ :post_category_id , :integer ]
189
- ],
190
- Caboose::PagePermission => [
191
- [ :role_id , :integer ],
192
- [ :page_id , :integer ],
193
- [ :action , :string ]
194
- ],
195
- Caboose::AbVariant => [
196
- [ :name , :string ],
197
- [ :analytics_name , :string ],
198
194
  ],
199
- Caboose::AbOption => [
200
- [ :ab_variant_id , :integer ],
201
- [ :value , :string ]
195
+ Caboose::Role => [
196
+ [ :parent_id , :integer ],
197
+ [ :name , :string ],
198
+ [ :description , :string ]
202
199
  ],
203
- Caboose::AbValue => [
204
- [ :session_id , :string ],
205
- [ :ab_variant_id , :integer ],
206
- [ :ab_option_id , :integer ]
200
+ Caboose::RoleMembership => [
201
+ [ :role_id, :integer ],
202
+ [ :user_id, :integer ]
207
203
  ],
208
- Caboose::DatabaseSession => [
209
- [ :session_id , :string , :null => false ],
210
- [ :data , :text ],
211
- [ :created_at , :datetime , :null => true ],
212
- [ :updated_at , :datetime , :null => true ]
213
- ],
214
- Caboose::Setting => [
204
+ Caboose::RolePermission => [
205
+ [ :role_id , :integer ],
206
+ [ :permission_id , :integer ]
207
+ ],
208
+ Caboose::Setting => [
215
209
  [ :name , :string ],
216
210
  [ :value , :text ]
217
211
  ],
212
+ Caboose::Site => [
213
+ [ :name , :string ],
214
+ [ :description , :text ]
215
+ ],
216
+ Caboose::SiteMembership => [
217
+ [ :site_id , :integer ],
218
+ [ :user_id , :integer ],
219
+ [ :role , :string ]
220
+ ],
218
221
  Caboose::Timezone => [
219
222
  [ :country_code , :string ],
220
223
  [ :name , :string ]
221
224
  ],
222
- Caboose::TimezoneAbbreviation => [
225
+ Caboose::TimezoneAbbreviation => [
223
226
  [ :abbreviation , :string ],
224
- [ :name , :string ]
227
+ [ :name , :string ]
225
228
  ],
226
229
  Caboose::TimezoneOffset => [
227
230
  [ :timezone_id , :integer ],
228
231
  [ :abbreviation , :string ],
229
232
  [ :time_start , :integer ],
230
233
  [ :gmt_offset , :integer ],
231
- [ :dst , :boolean ]
232
- ]
234
+ [ :dst , :boolean ]
235
+ ],
236
+ Caboose::User => [
237
+ [ :first_name , :string ],
238
+ [ :last_name , :string ],
239
+ [ :username , :string ],
240
+ [ :email , :string ],
241
+ [ :address , :string ],
242
+ [ :address2 , :string ],
243
+ [ :city , :string ],
244
+ [ :state , :string ],
245
+ [ :zip , :string ],
246
+ [ :phone , :string ],
247
+ [ :fax , :string ],
248
+ [ :utc_offset , :float , { :default => -5 }],
249
+ #[ :timezone , :string , { :default => 'America/Chicago' }],
250
+ [ :timezone_id , :integer , { :defualt => 381 }], # Defaults to 'America/Chicago'
251
+ [ :password , :string ],
252
+ [ :password_reset_id , :string ],
253
+ [ :password_reset_sent , :datetime ],
254
+ [ :token , :string ],
255
+ [ :date_created , :datetime ],
256
+ [ :image , :attachment ]
257
+ ]
233
258
  }
234
259
 
235
260
  end
236
-
261
+
237
262
  # Loads initial data into the database
238
263
  def self.load_data
239
264
 
240
- c = ActiveRecord::Base.connection
265
+ c = ActiveRecord::Base.connection
241
266
  #if c.column_exists?(:pages, :content)
242
267
  # Caboose::Page.reorder(:id).all.each do |p|
243
- # Caboose::PageBlock.create( :page_id => p.id, :block_type => 'richtext', :value => p.content )
244
- # end
268
+ # Caboose::PageBlock.create( :page_id => p.id, :block_type => 'richtext', :value => p.content )
269
+ # end
245
270
  # c.remove_column(:pages, :content)
246
271
  #end
247
-
272
+
248
273
  admin_user = nil
249
274
  if !Caboose::User.exists?(:username => 'admin')
250
275
  admin_user = Caboose::User.create(:first_name => 'Admin', :last_name => 'User', :username => 'admin', :email => 'william@nine.is')
251
276
  admin_user.password = Digest::SHA1.hexdigest(Caboose::salt + 'caboose')
252
277
  admin_user.save
253
278
  end
254
- admin_user = Caboose::User.where(:username => 'admin').first if admin_user.nil?
255
-
279
+ admin_user = Caboose::User.where(:username => 'admin').first if admin_user.nil?
280
+
256
281
  if !Caboose::User.where(:id => Caboose::User::LOGGED_OUT_USER_ID).exists?
257
- Caboose::User.create(:id => Caboose::User::LOGGED_OUT_USER_ID, :first_name => 'Logged', :last_name => 'Out', :username => 'elo', :email => 'elo@nine.is')
258
- end
259
-
282
+ Caboose::User.create(:id => Caboose::User::LOGGED_OUT_USER_ID, :first_name => 'Logged', :last_name => 'Out', :username => 'elo', :email => 'elo@nine.is')
283
+ end
284
+
260
285
  Caboose::Role.create(:parent_id => -1 , :name => 'Admin' ) if !Caboose::Role.exists?(:name => 'Admin' )
261
286
  admin_role = Caboose::Role.where(:name => 'Admin' ).first
262
287
  Caboose::Role.create(:parent_id => -1 , :name => 'Everyone Logged Out' ) if !Caboose::Role.exists?(:name => 'Everyone Logged Out' )
263
288
  elo_role = Caboose::Role.where(:name => 'Everyone Logged Out' ).first
264
289
  Caboose::Role.create(:parent_id => elo_role.id , :name => 'Everyone Logged In' ) if !Caboose::Role.exists?(:name => 'Everyone Logged In' )
265
290
  eli_role = Caboose::Role.where(:name => 'Everyone Logged In' ).first
266
-
291
+
267
292
  Caboose::User.create(:first_name => 'John', :last_name => 'Doe', :username => 'elo', :email => 'william@nine.is') if !Caboose::User.exists?(:username => 'elo')
268
293
  elo_user = Caboose::User.where(:username => 'elo').first
269
-
294
+
270
295
  Caboose::Permission.create(:resource => 'all' , :action => 'all' ) if !Caboose::Permission.exists?(:resource => 'all' , :action => 'all' )
271
296
  Caboose::Permission.create(:resource => 'users' , :action => 'view' ) if !Caboose::Permission.exists?(:resource => 'users' , :action => 'view' )
272
297
  Caboose::Permission.create(:resource => 'users' , :action => 'edit' ) if !Caboose::Permission.exists?(:resource => 'users' , :action => 'edit' )
@@ -280,17 +305,17 @@ class Caboose::Schema < Caboose::Utilities::Schema
280
305
  Caboose::Permission.create(:resource => 'permissions' , :action => 'edit' ) if !Caboose::Permission.exists?(:resource => 'permissions' , :action => 'edit' )
281
306
  Caboose::Permission.create(:resource => 'permissions' , :action => 'delete' ) if !Caboose::Permission.exists?(:resource => 'permissions' , :action => 'delete' )
282
307
  Caboose::Permission.create(:resource => 'permissions' , :action => 'add' ) if !Caboose::Permission.exists?(:resource => 'permissions' , :action => 'add' )
283
-
308
+
284
309
  # Add the admin user to the admin role
285
310
  Caboose::RoleMembership.create(:user_id => admin_user.id, :role_id => admin_role.id) if !Caboose::RoleMembership.exists?(:user_id => admin_user.id, :role_id => admin_role.id)
286
-
311
+
287
312
  # Add the elo to the elo role
288
313
  Caboose::RoleMembership.create(:user_id => elo_user.id, :role_id => elo_role.id) if !Caboose::RoleMembership.exists?(:user_id => elo_user.id, :role_id => elo_role.id)
289
-
314
+
290
315
  # Add the all/all permission to the admin role
291
316
  admin_perm = Caboose::Permission.where(:resource => 'all', :action => 'all').first
292
317
  Caboose::RolePermission.create(:role_id => admin_role.id, :permission_id => admin_perm.id) if !Caboose::RolePermission.exists?(:role_id => admin_role.id, :permission_id => admin_perm.id)
293
-
318
+
294
319
  # Create the necessary pages
295
320
  Caboose::Page.create(:title => 'Home' , :parent_id => -1, :hide => 0, :layout => 'home', :uri => '') if !Caboose::Page.exists?(:title => 'Home')
296
321
  home_page = Caboose::Page.where(:title => 'Home', :parent_id => -1).first
@@ -298,25 +323,25 @@ class Caboose::Schema < Caboose::Utilities::Schema
298
323
  admin_page = Caboose::Page.where(:alias => 'admin').first
299
324
  Caboose::Page.create(:title => 'Login' , :parent_id => home_page.id, :hide => 0, :layout => 'login', :alias => 'login', :slug => 'login', :uri => 'login') if !Caboose::Page.exists?(:alias => 'login')
300
325
  login_page = Caboose::Page.where(:alias => 'login').first
301
-
302
- Caboose::PagePermission.create(:role_id => elo_role.id, :page_id => home_page.id , :action => 'view') if !Caboose::PagePermission.exists?(:role_id => elo_role.id, :page_id => home_page.id , :action => 'view')
326
+
327
+ Caboose::PagePermission.create(:role_id => elo_role.id, :page_id => home_page.id , :action => 'view') if !Caboose::PagePermission.exists?(:role_id => elo_role.id, :page_id => home_page.id , :action => 'view')
303
328
  Caboose::PagePermission.create(:role_id => elo_role.id, :page_id => login_page.id , :action => 'view') if !Caboose::PagePermission.exists?(:role_id => elo_role.id, :page_id => login_page.id , :action => 'view')
304
-
329
+
305
330
  # Create a default post category
306
331
  Caboose::PostCategory.create(:name => 'General News') if !Caboose::PostCategory.exists?(:name => 'General News')
307
-
332
+
308
333
  # Create the required settings
309
334
  Caboose::Setting.create(:name => 'version' , :value => Caboose::VERSION ) if !Caboose::Setting.exists?(:name => 'version' , :value => Caboose::VERSION )
310
335
  Caboose::Setting.create(:name => 'site_name' , :value => 'New Caboose Site' ) if !Caboose::Setting.exists?(:name => 'site_name' , :value => 'New Caboose Site' )
311
336
  Caboose::Setting.create(:name => 'site_url' , :value => 'www.mycaboosesite.com' ) if !Caboose::Setting.exists?(:name => 'site_url' , :value => 'www.mycaboosesite.com' )
312
337
  Caboose::Setting.create(:name => 'admin_email' , :value => 'william@nine.is' ) if !Caboose::Setting.exists?(:name => 'admin_email' , :value => 'william@nine.is' )
313
-
338
+
314
339
  # Create default block type categories
315
340
  btc = Caboose::BlockTypeCategory
316
341
  layouts = btc.exists?(:name => 'Layouts') ? btc.where(:name => 'Layouts').first : btc.create(:name => 'Layouts')
317
342
  content = btc.exists?(:name => 'Content') ? btc.where(:name => 'Content').first : btc.create(:name => 'Content')
318
343
  btc.create(:name => 'Rows', :parent_id => content.id) if !btc.where(:name => 'Rows', :parent_id => content.id).exists?
319
-
344
+
320
345
  # Create default block types
321
346
  if !Caboose::BlockType.where(:name => 'layout_basic').exists?
322
347
  bt = Caboose::BlockType.create(:name => 'layout_basic', :description => 'Basic', :block_type_category_id => layouts.id, :use_render_function_for_layout => true, :allow_child_blocks => false, :field_type => 'block')
@@ -324,7 +349,7 @@ class Caboose::Schema < Caboose::Utilities::Schema
324
349
  Caboose::BlockType.create(:name => 'content' , :description => 'Content' , :parent_id => bt.id, :field_type => 'block', :allow_child_blocks => true)
325
350
  Caboose::BlockType.create(:name => 'footer' , :description => 'Footer' , :parent_id => bt.id, :field_type => 'block')
326
351
  end
327
-
352
+
328
353
  if !Caboose::BlockType.where(:name => 'layout_left_sidebar').exists?
329
354
  bt = Caboose::BlockType.create(:name => 'layout_left_sidebar', :description => 'Left Sidebar', :block_type_category_id => layouts.id, :use_render_function_for_layout => true, :allow_child_blocks => false, :field_type => 'block')
330
355
  Caboose::BlockType.create(:name => 'header' , :description => 'Header' , :parent_id => bt.id, :field_type => 'block')
@@ -332,7 +357,7 @@ class Caboose::Schema < Caboose::Utilities::Schema
332
357
  Caboose::BlockType.create(:name => 'content' , :description => 'Content' , :parent_id => bt.id, :field_type => 'block', :allow_child_blocks => true)
333
358
  Caboose::BlockType.create(:name => 'footer' , :description => 'Footer' , :parent_id => bt.id, :field_type => 'block')
334
359
  end
335
-
360
+
336
361
  if !Caboose::BlockType.where(:name => 'layout_right_sidebar').exists?
337
362
  bt = Caboose::BlockType.create(:name => 'layout_right_sidebar', :description => 'Right Sidebar', :block_type_category_id => layouts.id, :use_render_function_for_layout => true, :allow_child_blocks => false, :field_type => 'block')
338
363
  Caboose::BlockType.create(:name => 'header' , :description => 'Header' , :parent_id => bt.id, :field_type => 'block')
@@ -340,22 +365,22 @@ class Caboose::Schema < Caboose::Utilities::Schema
340
365
  Caboose::BlockType.create(:name => 'content' , :description => 'Content' , :parent_id => bt.id, :field_type => 'block', :allow_child_blocks => true)
341
366
  Caboose::BlockType.create(:name => 'footer' , :description => 'Footer' , :parent_id => bt.id, :field_type => 'block')
342
367
  end
343
-
344
- if !Caboose::BlockType.where(:name => 'heading').exists?
368
+
369
+ if !Caboose::BlockType.where(:name => 'heading').exists?
345
370
  bt = Caboose::BlockType.create(:name => 'heading', :description => 'Heading', :field_type => 'block')
346
371
  Caboose::BlockType.create(:parent_id => bt.id, :name => 'text', :description => 'Text', :field_type => 'text', :default => '', :width => 800, :fixed_placeholder => false)
347
372
  Caboose::BlockType.create(:parent_id => bt.id, :name => 'size', :description => 'Size', :field_type => 'text', :default => 1, :width => 800, :fixed_placeholder => false, :options => "1|2|3|4|5|6")
348
373
  end
349
-
374
+
350
375
  if !Caboose::BlockType.where(:name => 'text').exists?
351
- Caboose::BlockType.create(:name => 'text', :description => 'Text', :field_type => 'text', :default => '', :width => 800, :height => 400, :fixed_placeholder => false)
376
+ Caboose::BlockType.create(:name => 'text', :description => 'Text', :field_type => 'text', :default => '', :width => 800, :height => 400, :fixed_placeholder => false)
352
377
  end
353
- if !Caboose::BlockType.where(:name => 'richtext').exists?
378
+ if !Caboose::BlockType.where(:name => 'richtext').exists?
354
379
  Caboose::BlockType.create(:name => 'richtext', :description => 'Rich Text', :field_type => 'richtext', :default => '', :width => 800, :height => 400, :fixed_placeholder => false)
355
380
  else
356
381
  bt = Caboose::BlockType.where(:name => 'richtext').first
357
382
  bt.field_type = 'richtext'
358
- bt.save
383
+ bt.save
359
384
  end
360
385
  if !Caboose::BlockType.where(:name => 'image').exists?
361
386
  bt = Caboose::BlockType.create(:name => 'image', :description => 'Image', :field_type => 'block')
@@ -368,13 +393,21 @@ class Caboose::Schema < Caboose::Utilities::Schema
368
393
  Caboose::BlockType.create(:parent_id => bt.id, :name => 'margin_right' , :description => 'Right Margin' , :field_type => 'text' , :default => '10' , :width => 400, :fixed_placeholder => false)
369
394
  Caboose::BlockType.create(:parent_id => bt.id, :name => 'margin_bottom' , :description => 'Bottom Margin' , :field_type => 'text' , :default => '10' , :width => 400, :fixed_placeholder => false)
370
395
  Caboose::BlockType.create(:parent_id => bt.id, :name => 'margin_left' , :description => 'Left Margin' , :field_type => 'text' , :default => '10' , :width => 400, :fixed_placeholder => false)
371
- Caboose::BlockType.create(:parent_id => bt.id, :name => 'align' , :description => 'Align' , :field_type => 'select' , :default => 'None' , :width => 400, :fixed_placeholder => false, :options => "None\nCenter\nLeft\nRight")
396
+ Caboose::BlockType.create(:parent_id => bt.id, :name => 'align' , :description => 'Align' , :field_type => 'select' , :default => 'None' , :width => 400, :fixed_placeholder => false, :options => "None\nCenter\nLeft\nRight")
372
397
  end
373
398
  if !Caboose::BlockType.where(:name => 'file').exists?
374
399
  bt = Caboose::BlockType.create(:name => 'file', :description => 'File', :field_type => 'block')
375
400
  Caboose::BlockType.create(:parent_id => bt.id, :name => 'file' , :description => 'File' , :field_type => 'file', :default => '' , :width => 400, :fixed_placeholder => false)
376
401
  Caboose::BlockType.create(:parent_id => bt.id, :name => 'text' , :description => 'Text' , :field_type => 'text', :default => 'Download' , :width => 400, :fixed_placeholder => false)
377
- end
378
-
402
+ end
403
+
404
+ # Make sure a top-level media category for each site exists
405
+ Caboose::Site.all.each do |site|
406
+ cat = Caboose::MediaCategory.where("parent_id is null and site_id = ? and name = ?", site.id, 'Images').first
407
+ Caboose::MediaCategory.create(:site_id => site.id, :name => 'Images') if cat.nil?
408
+ cat = Caboose::MediaCategory.where("parent_id is null and site_id = ? and name = ?", site.id, 'Files').first
409
+ Caboose::MediaCategory.create(:site_id => site.id, :name => 'Files') if cat.nil?
410
+ end
411
+
379
412
  end
380
413
  end