caboose-cms 0.2.95 → 0.2.96

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MTk4NzgwZDZiMDIyOGM5ZDhlMDY3YmMwYTE1MjIxZGQ0ZDA3ODA0NA==
4
+ YzlhMjFjOGFmMmMxMjU5MTRjZDA0MWQ3ODAxZDQ4NDdmZjVhOWIxOA==
5
5
  data.tar.gz: !binary |-
6
- ODcwMTk0ZWZkOWUyNDRmOTM2YzRlYmY2MDYxMjA0YzE3ZDAxNzdhZA==
6
+ OGQ4ZThiOTM1NDkyOGQxMzFmYzM5ODk5M2ZhZjMyNzJmMjU5MTA4Nw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NWJkMGQ0ZjkyMTljM2NjZTA2M2MxYTgwYjRhNjZkYmNjMTk0MjEwOGY5Mzc1
10
- ZGVhMzQ3NjRlNDhkZTQwMWMwMTI4ZmU4ZmFkZDE3OTg3MjQ4MjAyOTdmNjVi
11
- NGEzMTQzNWY1MWNkY2U2NGFkYjM2ZGEyMjNkMTVjYzNiOGQ3Yjk=
9
+ YmZjOTcwMzY4MGI5NDRkODMzODlkZTgxMzE4OGQ3Mzg1ZmVjNDEzMWYyNmQ0
10
+ ZmI3NzQ0ZDAwMTVhOGI2ZTMwMTA2ZGZiYjQ0ZmYwNjEzNzBjNDRjNDQ2Yjk1
11
+ Y2U1MzIwZDUzMGQ3MzMzOGVkYjZlZGJlNDVhNjAyNTI2NWU2ODU=
12
12
  data.tar.gz: !binary |-
13
- NGQ1NDkxYzE4NTIzMDM1ZWMwYzU2YzFkZTZlMTc0NTJmYTU3NmI5NzE0YzNh
14
- M2U3YTZiM2YwNzcwNTkyZTM4YzI2MmZlN2U3M2NiZDY3ZTNkODIxNzVjY2Iy
15
- MjdkY2VkZDU3N2I5YjA5YTNmODI3OTcxMmUwNTA1YTRmMjQ3MDU=
13
+ YjQ5MDc4MTczM2Y5MGVjYmEwMmYyMTg1MDZiYzU2MmI1Nzk0MzVkYTc2YTg1
14
+ ZjkyOTY4YTVhMzAwMTI5OTc4MTgxMjA4Y2QyOWVkY2FjMzY3NDMwMTUzNDJm
15
+ Mzk2ZWQwY2ExY2M1MTMxNTlmZDY1MDQ0MTViYThmYjYxNzRkNTU=
@@ -0,0 +1,5 @@
1
+
2
+ class Caboose::DatabaseSession < ActiveRecord::Base
3
+ self.table_name = "sessions"
4
+ attr_accessible :session_id, :data, :created_at, :updated_at
5
+ end
@@ -0,0 +1,188 @@
1
+
2
+ class Caboose::Schema < Caboose::Utilities::Schema
3
+
4
+ # Tables (in order) that were renamed in the development of the gem.
5
+ def self.renamed_tables
6
+ {
7
+ :roles_users => :role_memberships,
8
+ :permissions_roles => :role_permissions
9
+ }
10
+ end
11
+
12
+ # Any column indexes that need to exist in the database
13
+ def self.indexes
14
+ {
15
+ :role_memberships => [ :role_id , :user_id ],
16
+ :role_permissions => [ :role_id , :permission_id ],
17
+ :post_category_memberships => [ :post_id , :post_category_id ],
18
+ :sessions => [ :session_id , :updated_at ]
19
+ }
20
+ end
21
+
22
+ # The schema of the database
23
+ # { Model => [[name, data_type, options]] }
24
+ def self.schema
25
+ {
26
+ Caboose::User => [
27
+ [ :first_name , :string ],
28
+ [ :last_name , :string ],
29
+ [ :username , :string ],
30
+ [ :email , :string ],
31
+ [ :phone , :string ],
32
+ [ :password , :string ],
33
+ [ :password_reset_id , :string ],
34
+ [ :password_reset_sent , :datetime ],
35
+ [ :token , :string ],
36
+ [ :date_created , :datetime ]
37
+ ],
38
+ Caboose::Role => [
39
+ [ :parent_id , :integer ],
40
+ [ :name , :string ],
41
+ [ :description , :string ]
42
+ ],
43
+ Caboose::Permission => [
44
+ [ :resource , :string ],
45
+ [ :action , :string ]
46
+ ],
47
+ Caboose::RoleMembership => [
48
+ [ :role_id, :integer ],
49
+ [ :user_id, :integer ]
50
+ ],
51
+ Caboose::RolePermission => [
52
+ [ :role_id , :integer ],
53
+ [ :permission_id , :integer ]
54
+ ],
55
+ Caboose::Asset => [
56
+ [ :page_id , :integer ],
57
+ [ :user_id , :integer ],
58
+ [ :date_uploaded , :datetime ],
59
+ [ :name , :string ],
60
+ [ :filename , :string ],
61
+ [ :description , :string ],
62
+ [ :extension , :string ]
63
+ ],
64
+ Caboose::Page => [
65
+ [ :parent_id , :integer ],
66
+ [ :title , :string ],
67
+ [ :menu_title , :string ],
68
+ [ :content , :text ],
69
+ [ :slug , :string ],
70
+ [ :alias , :string ],
71
+ [ :uri , :string ],
72
+ [ :redirect_url , :string ],
73
+ [ :hide , :boolean , :default => false ],
74
+ [ :content_format , :integer , :default => Caboose::Page::CONTENT_FORMAT_HTML ],
75
+ [ :custom_css , :text ],
76
+ [ :custom_js , :text ],
77
+ [ :linked_resources , :text ],
78
+ [ :layout , :string ],
79
+ [ :sort_order , :integer , :default => 0 ],
80
+ [ :custom_sort_children , :boolean , :default => false ],
81
+ [ :seo_title , :string , :limit => 70 ],
82
+ [ :meta_description , :string , :limit => 156 ],
83
+ [ :meta_robots , :string , :default => 'index, follow' ],
84
+ [ :canonical_url , :string ],
85
+ [ :fb_description , :string , :limit => 156 ],
86
+ [ :gp_description , :string , :limit => 156 ]
87
+ ],
88
+ Caboose::Post => [
89
+ [ :title , :text ],
90
+ [ :body , :text ],
91
+ [ :hide , :boolean ],
92
+ [ :image_url , :text ],
93
+ [ :created_at , :datetime ],
94
+ [ :updated_at , :datetime ]
95
+ ],
96
+ Caboose::PostCategory => [
97
+ [ :name , :string ]
98
+ ],
99
+ Caboose::PostCategoryMembership => [
100
+ [ :post_id , :integer ],
101
+ [ :post_category_id , :integer ]
102
+ ],
103
+ Caboose::PagePermission => [
104
+ [ :role_id , :integer ],
105
+ [ :page_id , :integer ],
106
+ [ :action , :string ]
107
+ ],
108
+ Caboose::DatabaseSession => [
109
+ [ :session_id , :string , :null => false ],
110
+ [ :data , :text ],
111
+ [ :created_at , :datetime , :null => true ],
112
+ [ :updated_at , :datetime , :null => true ]
113
+ ],
114
+ Caboose::Setting => [
115
+ [ :name , :string ],
116
+ [ :value , :text ]
117
+ ]
118
+ }
119
+
120
+ end
121
+
122
+ # Loads initial data into the database
123
+ def self.load_data
124
+
125
+ admin_user = nil
126
+ if !Caboose::User.exists?(:username => 'admin')
127
+ admin_user = Caboose::User.create(:first_name => 'Admin', :last_name => 'User', :username => 'admin', :email => 'william@nine.is')
128
+ admin_user.password = Digest::SHA1.hexdigest(Caboose::salt + 'caboose')
129
+ admin_user.save
130
+ end
131
+ admin_user = Caboose::User.where(:username => 'admin').first if admin_user.nil?
132
+
133
+ Caboose::Role.create(:parent_id => -1 , :name => 'Admin' ) if !Caboose::Role.exists?(:name => 'Admin' )
134
+ admin_role = Caboose::Role.where(:name => 'Admin' ).first
135
+ Caboose::Role.create(:parent_id => -1 , :name => 'Everyone Logged Out' ) if !Caboose::Role.exists?(:name => 'Everyone Logged Out' )
136
+ elo_role = Caboose::Role.where(:name => 'Everyone Logged Out' ).first
137
+ Caboose::Role.create(:parent_id => elo_role.id , :name => 'Everyone Logged In' ) if !Caboose::Role.exists?(:name => 'Everyone Logged In' )
138
+ eli_role = Caboose::Role.where(:name => 'Everyone Logged In' ).first
139
+
140
+ Caboose::User.create(:first_name => 'John', :last_name => 'Doe', :username => 'elo', :email => 'william@nine.is') if !Caboose::User.exists?(:username => 'elo')
141
+ elo_user = Caboose::User.where(:username => 'elo').first
142
+
143
+ Caboose::Permission.create(:resource => 'all' , :action => 'all' ) if !Caboose::Permission.exists?(:resource => 'all' , :action => 'all' )
144
+ Caboose::Permission.create(:resource => 'users' , :action => 'view' ) if !Caboose::Permission.exists?(:resource => 'users' , :action => 'view' )
145
+ Caboose::Permission.create(:resource => 'users' , :action => 'edit' ) if !Caboose::Permission.exists?(:resource => 'users' , :action => 'edit' )
146
+ Caboose::Permission.create(:resource => 'users' , :action => 'delete' ) if !Caboose::Permission.exists?(:resource => 'users' , :action => 'delete' )
147
+ Caboose::Permission.create(:resource => 'users' , :action => 'add' ) if !Caboose::Permission.exists?(:resource => 'users' , :action => 'add' )
148
+ Caboose::Permission.create(:resource => 'roles' , :action => 'view' ) if !Caboose::Permission.exists?(:resource => 'roles' , :action => 'view' )
149
+ Caboose::Permission.create(:resource => 'roles' , :action => 'edit' ) if !Caboose::Permission.exists?(:resource => 'roles' , :action => 'edit' )
150
+ Caboose::Permission.create(:resource => 'roles' , :action => 'delete' ) if !Caboose::Permission.exists?(:resource => 'roles' , :action => 'delete' )
151
+ Caboose::Permission.create(:resource => 'roles' , :action => 'add' ) if !Caboose::Permission.exists?(:resource => 'roles' , :action => 'add' )
152
+ Caboose::Permission.create(:resource => 'permissions' , :action => 'view' ) if !Caboose::Permission.exists?(:resource => 'permissions' , :action => 'view' )
153
+ Caboose::Permission.create(:resource => 'permissions' , :action => 'edit' ) if !Caboose::Permission.exists?(:resource => 'permissions' , :action => 'edit' )
154
+ Caboose::Permission.create(:resource => 'permissions' , :action => 'delete' ) if !Caboose::Permission.exists?(:resource => 'permissions' , :action => 'delete' )
155
+ Caboose::Permission.create(:resource => 'permissions' , :action => 'add' ) if !Caboose::Permission.exists?(:resource => 'permissions' , :action => 'add' )
156
+
157
+ # Add the admin user to the admin role
158
+ 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)
159
+
160
+ # Add the elo to the elo role
161
+ 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)
162
+
163
+ # Add the all/all permission to the admin role
164
+ admin_perm = Caboose::Permission.where(:resource => 'all', :action => 'all').first
165
+ 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)
166
+
167
+ # Create the necessary pages
168
+ Caboose::Page.create(:title => 'Home' , :parent_id => -1, :hide => 0, :layout => 'home', :uri => '') if !Caboose::Page.exists?(:title => 'Home')
169
+ home_page = Caboose::Page.where(:title => 'Home', :parent_id => -1).first
170
+ Caboose::Page.create(:title => 'Admin' , :parent_id => home_page.id, :hide => 0, :layout => 'admin', :alias => 'admin', :slug => 'admin', :uri => 'admin') if !Caboose::Page.exists?(:alias => 'admin')
171
+ admin_page = Caboose::Page.where(:alias => 'admin').first
172
+ 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')
173
+ login_page = Caboose::Page.where(:alias => 'login').first
174
+
175
+ 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')
176
+ 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')
177
+
178
+ # Create a default post category
179
+ Caboose::PostCategory.create(:name => 'General News') if !Caboose::PostCategory.exists?(:name => 'General News')
180
+
181
+ # Create the required settings
182
+ Caboose::Setting.create(:name => 'version' , :value => Caboose::VERSION ) if !Caboose::Setting.exists?(:name => 'version' , :value => Caboose::VERSION )
183
+ Caboose::Setting.create(:name => 'site_name' , :value => 'New Caboose Site' ) if !Caboose::Setting.exists?(:name => 'site_name' , :value => 'New Caboose Site' )
184
+ Caboose::Setting.create(:name => 'site_url' , :value => 'www.mycaboosesite.com' ) if !Caboose::Setting.exists?(:name => 'site_url' , :value => 'www.mycaboosesite.com' )
185
+ Caboose::Setting.create(:name => 'admin_email' , :value => 'william@nine.is' ) if !Caboose::Setting.exists?(:name => 'admin_email' , :value => 'william@nine.is' )
186
+
187
+ end
188
+ end
@@ -0,0 +1,106 @@
1
+
2
+ class Caboose::Utilities::Schema
3
+
4
+ # Tables (in order) that were renamed in the development of the gem.
5
+ def self.renamed_tables
6
+ return nil
7
+ end
8
+
9
+ # Any column indexes that need to exist in the database
10
+ def self.indexes
11
+ return nil
12
+ end
13
+
14
+ # The schema of the database
15
+ # { Model => [[name, data_type, options]] }
16
+ def self.schema
17
+ raise NotImplementedError.new("You must implement this")
18
+ end
19
+
20
+ # Loads initial data into the database
21
+ def self.load_data
22
+ end
23
+
24
+ #===========================================================================
25
+ # Methods that extended classes will use
26
+ #===========================================================================
27
+
28
+ # Verifies (non-destructively) that the given schema exists in the database.
29
+ def self.create_schema
30
+ return if self.schema.nil?
31
+
32
+ rename_tables
33
+ c = ActiveRecord::Base.connection
34
+ self.schema.each do |model, columns|
35
+ tbl = model.table_name
36
+ #puts "Creating table #{tbl}..."
37
+ c.create_table tbl if !c.table_exists?(tbl)
38
+ columns.each do |col|
39
+ #puts "Creating column #{tbl}.#{col[0]}..."
40
+
41
+ # Skip if the column exists with the proper data type
42
+ next if c.column_exists?(tbl, col[0], col[1])
43
+
44
+ # If the column doesn't exists, add it
45
+ if !c.column_exists?(tbl, col[0])
46
+ if col.count > 2
47
+ c.add_column tbl, col[0], col[1], col[2]
48
+ else
49
+ c.add_column tbl, col[0], col[1]
50
+ end
51
+
52
+ # Column exists, but not with the correct data type, try to change it
53
+ else
54
+
55
+ # Add a temp column
56
+ if col.count > 2
57
+ c.add_column tbl, "#{col[0]}_temp", col[1], col[2]
58
+ else
59
+ c.add_column tbl, "#{col[0]}_temp", col[1]
60
+ end
61
+
62
+ # Copy the old column and cast with correct data type to the new column
63
+ model.all.each do |m|
64
+ m["#{col[0]}_temp"] = case col[1]
65
+ when :integer then m[col[0]].to_i
66
+ when :string then m[col[0]].to_s
67
+ when :text then m[col[0]].to_s
68
+ when :numeric then m[col[0]].to_f
69
+ when :datetime then DateTime.parse(m[col[0]])
70
+ when :boolean then m[col[0]].to_i == 1
71
+ else nil
72
+ end
73
+ m.save
74
+ end
75
+
76
+ # Remove the old column and rename the new one
77
+ c.remove_column tbl, col[0]
78
+ c.rename_column tbl, "#{col[0]}_temp", col[0]
79
+
80
+ end
81
+ end
82
+ end
83
+ create_indexes
84
+ end
85
+
86
+ # Verifies (non-destructively) that the given indexes exist in the database.
87
+ def self.create_indexes
88
+ return if self.indexes.nil?
89
+ c = ActiveRecord::Base.connection
90
+ self.indexes.each do |table, indexes|
91
+ indexes.each do |index|
92
+ c.add_index table, index if !c.index_exists?(table, index)
93
+ end
94
+ end
95
+ end
96
+
97
+ # Renames a set of tables
98
+ def self.rename_tables
99
+ return if self.renamed_tables.nil?
100
+ c = ActiveRecord::Base.connection
101
+ self.renamed_tables.each do |old_name, new_name|
102
+ c.rename_table old_name, new_name if c.table_exists?(old_name)
103
+ end
104
+ end
105
+
106
+ end
@@ -48,58 +48,6 @@ module Caboose
48
48
  return obj.to_json
49
49
  end
50
50
 
51
- # Verifies (non-destructively) that the given schema exists in the database.
52
- def Caboose.create_schema(schema)
53
- c = ActiveRecord::Base.connection
54
- schema.each do |model, columns|
55
- tbl = model.table_name
56
- c.create_table tbl if !c.table_exists?(tbl)
57
- columns.each do |col|
58
-
59
- # Skip if the column exists with the proper data type
60
- next if c.column_exists?(tbl, col[0], col[1])
61
-
62
- # If the column doesn't exists, add it
63
- if !c.column_exists?(tbl, col[0])
64
- if col.count > 2
65
- c.add_column tbl, col[0], col[1], col[2]
66
- else
67
- c.add_column tbl, col[0], col[1]
68
- end
69
-
70
- # Column exists, but not with the correct data type, try to change it
71
- else
72
-
73
- # Add a temp column
74
- if col.count > 2
75
- c.add_column tbl, "#{col[0]}_temp", col[1], col[2]
76
- else
77
- c.add_column tbl, "#{col[0]}_temp", col[1]
78
- end
79
-
80
- # Copy the old column and cast with correct data type to the new column
81
- model.all.each do |m|
82
- m["#{col[0]}_temp"] = case col[1]
83
- when :integer then m[col[0]].to_i
84
- when :string then m[col[0]].to_s
85
- when :text then m[col[0]].to_s
86
- when :numeric then m[col[0]].to_f
87
- when :datetime then DateTime.parse(m[col[0]])
88
- when :boolean then m[col[0]].to_i == 1
89
- else nil
90
- end
91
- m.save
92
- end
93
-
94
- # Remove the old column and rename the new one
95
- c.remove_column tbl, col[0]
96
- c.rename_column tbl, "#{col[0]}_temp", col[0]
97
-
98
- end
99
- end
100
- end
101
- end
102
-
103
51
  # Strips html and returns the text that breaks closest to the given length
104
52
  def Caboose.teaser_text(str, length = 100)
105
53
  return "" if str.nil?
@@ -1,3 +1,3 @@
1
1
  module Caboose
2
- VERSION = '0.2.95'
2
+ VERSION = '0.2.96'
3
3
  end
@@ -1,15 +1,27 @@
1
1
  require "caboose/version"
2
2
  require "caboose/migrations"
3
3
 
4
- namespace :caboose do
4
+ namespace :caboose do
5
+
6
+ desc "Creates/verifies that all database tables and fields are correctly added."
7
+ task :db => :environment do
8
+ Caboose::Schema.create_schema
9
+ Caboose::Schema.load_data
10
+ end
11
+
12
+ desc "Creates all caboose tables"
13
+ task :create_schema => :environment do Caboose::Schema.create_schema end
14
+
15
+ desc "Loads data into caboose tables"
16
+ task :load_data => :environment do Caboose::Schema.load_data end
5
17
 
18
+ #=============================================================================
19
+
6
20
  desc "Resets the admin password to 'caboose'"
7
- task :reset_admin_pass => :environment do
8
-
21
+ task :reset_admin_pass => :environment do
9
22
  admin_user = Caboose::User.where(username: 'admin').first
10
23
  admin_user.password = Digest::SHA1.hexdigest(Caboose::salt + 'caboose')
11
- admin_user.save
12
-
24
+ admin_user.save
13
25
  end
14
26
 
15
27
  desc "Sync production db to development"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caboose-cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.95
4
+ version: 0.2.96
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Barry
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-03 00:00:00.000000000 Z
11
+ date: 2013-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -181,6 +181,7 @@ files:
181
181
  - app/models/caboose/authenticator.rb
182
182
  - app/models/caboose/caboose_plugin.rb
183
183
  - app/models/caboose/core_plugin.rb
184
+ - app/models/caboose/database_session.rb
184
185
  - app/models/caboose/menu_block.rb
185
186
  - app/models/caboose/page.rb
186
187
  - app/models/caboose/page_bar_generator.rb
@@ -194,9 +195,11 @@ files:
194
195
  - app/models/caboose/role.rb
195
196
  - app/models/caboose/role_membership.rb
196
197
  - app/models/caboose/role_permission.rb
198
+ - app/models/caboose/schema.rb
197
199
  - app/models/caboose/setting.rb
198
200
  - app/models/caboose/std_class.rb
199
201
  - app/models/caboose/user.rb
202
+ - app/models/caboose/utilities/schema.rb
200
203
  - app/views/caboose/admin/index.html.erb
201
204
  - app/views/caboose/application/show.html.erb
202
205
  - app/views/caboose/extras/error.html.erb
@@ -266,7 +269,6 @@ files:
266
269
  - lib/sample_files/login.css
267
270
  - lib/sample_files/tinymce.yml
268
271
  - lib/tasks/caboose.rake
269
- - lib/tasks/caboose_db.rake
270
272
  - MIT-LICENSE
271
273
  - Rakefile
272
274
  - README.md
@@ -1,228 +0,0 @@
1
- require "caboose/version"
2
- require "caboose/migrations"
3
-
4
- namespace :caboose do
5
-
6
- desc "Creates/verifies that all database tables and fields are correctly added."
7
- task :db => :environment do
8
- create_tables
9
- load_data
10
- end
11
-
12
- desc "Drops all caboose tables"
13
- task :drop_tables => :environment do drop_tables end
14
-
15
- desc "Creates all caboose tables"
16
- task :create_tables => :environment do create_tables end
17
-
18
- desc "Loads data into caboose tables"
19
- task :load_data => :environment do load_data end
20
-
21
- #=============================================================================
22
-
23
- def drop_tables
24
- puts "Dropping any existing caboose tables..."
25
- c = ActiveRecord::Base.connection
26
- c.drop_table :users if c.table_exists?('users')
27
- c.drop_table :roles if c.table_exists?('roles')
28
- c.drop_table :permissions if c.table_exists?('permissions')
29
- c.drop_table :roles_users if c.table_exists?('roles_users')
30
- c.drop_table :permissions_roles if c.table_exists?('permissions_roles')
31
- c.drop_table :assets if c.table_exists?('assets')
32
- c.drop_table :pages if c.table_exists?('pages')
33
- c.drop_table :posts if c.table_exists?('posts')
34
- c.drop_table :page_permissions if c.table_exists?('page_permissions')
35
- c.drop_table :sessions if c.table_exists?('sessions')
36
- c.drop_table :settings if c.table_exists?('settings')
37
- end
38
-
39
- def create_tables
40
- puts "Creating required caboose tables..."
41
-
42
- c = ActiveRecord::Base.connection
43
-
44
- # Users
45
- c.create_table :users if !c.table_exists?(:users)
46
- c.add_column :users, :first_name , :string if !c.column_exists?(:users, :first_name )
47
- c.add_column :users, :last_name , :string if !c.column_exists?(:users, :last_name )
48
- c.add_column :users, :username , :string if !c.column_exists?(:users, :username )
49
- c.add_column :users, :email , :string if !c.column_exists?(:users, :email )
50
- c.add_column :users, :phone , :string if !c.column_exists?(:users, :phone )
51
- c.add_column :users, :password , :string if !c.column_exists?(:users, :password )
52
- c.add_column :users, :password_reset_id , :string if !c.column_exists?(:users, :password_reset_id )
53
- c.add_column :users, :password_reset_sent , :datetime if !c.column_exists?(:users, :password_reset_sent )
54
- c.add_column :users, :token , :string if !c.column_exists?(:users, :token )
55
- c.add_column :users, :date_created , :datetime if !c.column_exists?(:users, :date_created )
56
-
57
- # Roles
58
- c.create_table :roles if !c.table_exists?(:roles)
59
- c.add_column :roles, :parent_id , :integer if !c.column_exists?(:roles, :parent_id )
60
- c.add_column :roles, :name , :string if !c.column_exists?(:roles, :name )
61
- c.add_column :roles, :description , :string if !c.column_exists?(:roles, :description )
62
-
63
- # Permissions
64
- c.create_table :permissions if !c.table_exists?(:permissions)
65
- c.add_column :permissions, :resource , :string if !c.column_exists?(:permissions, :resource )
66
- c.add_column :permissions, :action , :string if !c.column_exists?(:permissions, :action )
67
-
68
- # Role membership
69
- c.rename_table :roles_users, :role_memberships if c.table_exists?(:roles_users)
70
- c.create_table :role_memberships if !c.table_exists?(:role_memberships)
71
- c.add_column :role_memberships, :role_id, :integer if !c.column_exists?(:role_memberships, :role_id)
72
- c.add_column :role_memberships, :user_id, :integer if !c.column_exists?(:role_memberships, :user_id)
73
- c.add_index :role_memberships, :role_id if !c.index_exists?( :role_memberships, :role_id)
74
- c.add_index :role_memberships, :user_id if !c.index_exists?( :role_memberships, :user_id)
75
-
76
- # Role permissions
77
- c.rename_table :permissions_roles, :role_permissions if c.table_exists?(:permissions_roles)
78
- c.create_table :role_permissions if !c.table_exists?(:role_permissions)
79
- c.add_column :role_permissions, :role_id , :integer if !c.column_exists?(:role_permissions, :role_id )
80
- c.add_column :role_permissions, :permission_id , :integer if !c.column_exists?(:role_permissions, :permission_id )
81
- c.add_index :role_permissions, :role_id if !c.index_exists?( :role_permissions, :role_id )
82
- c.add_index :role_permissions, :permission_id if !c.index_exists?( :role_permissions, :permission_id )
83
-
84
- # Assets
85
- c.create_table :assets if !c.table_exists?(:assets)
86
- c.add_column :assets, :page_id , :integer if !c.column_exists?(:assets, :page_id )
87
- c.add_column :assets, :user_id , :integer if !c.column_exists?(:assets, :user_id )
88
- c.add_column :assets, :date_uploaded , :datetime if !c.column_exists?(:assets, :date_uploaded )
89
- c.add_column :assets, :name , :string if !c.column_exists?(:assets, :name )
90
- c.add_column :assets, :filename , :string if !c.column_exists?(:assets, :filename )
91
- c.add_column :assets, :description , :string if !c.column_exists?(:assets, :description )
92
- c.add_column :assets, :extension , :string if !c.column_exists?(:assets, :extension )
93
-
94
- # Pages
95
- c.create_table :pages if !c.table_exists?(:pages)
96
- c.add_column :pages, :parent_id , :integer if !c.column_exists?(:pages, :parent_id )
97
- c.add_column :pages, :title , :string if !c.column_exists?(:pages, :title )
98
- c.add_column :pages, :menu_title , :string if !c.column_exists?(:pages, :menu_title )
99
- c.add_column :pages, :content , :text if !c.column_exists?(:pages, :content )
100
- c.add_column :pages, :slug , :string if !c.column_exists?(:pages, :slug )
101
- c.add_column :pages, :alias , :string if !c.column_exists?(:pages, :alias )
102
- c.add_column :pages, :uri , :string if !c.column_exists?(:pages, :uri )
103
- c.add_column :pages, :redirect_url , :string if !c.column_exists?(:pages, :redirect_url )
104
- c.add_column :pages, :hide , :boolean , :default => false if !c.column_exists?(:pages, :hide )
105
- c.add_column :pages, :content_format , :integer , :default => Caboose::Page::CONTENT_FORMAT_HTML if !c.column_exists?(:pages, :content_format )
106
- c.add_column :pages, :custom_css , :text if !c.column_exists?(:pages, :custom_css )
107
- c.add_column :pages, :custom_js , :text if !c.column_exists?(:pages, :custom_js )
108
- c.add_column :pages, :linked_resources , :text if !c.column_exists?(:pages, :linked_resources )
109
- c.add_column :pages, :layout , :string if !c.column_exists?(:pages, :layout )
110
- c.add_column :pages, :sort_order , :integer , :default => 0 if !c.column_exists?(:pages, :sort_order )
111
- c.add_column :pages, :custom_sort_children , :boolean , :default => false if !c.column_exists?(:pages, :custom_sort_children )
112
- c.add_column :pages, :seo_title , :string , :limit => 70 if !c.column_exists?(:pages, :seo_title )
113
- c.add_column :pages, :meta_description , :string , :limit => 156 if !c.column_exists?(:pages, :meta_description )
114
- c.add_column :pages, :meta_robots , :string , :default => 'index, follow' if !c.column_exists?(:pages, :meta_robots )
115
- c.add_column :pages, :canonical_url , :string if !c.column_exists?(:pages, :canonical_url )
116
- c.add_column :pages, :fb_description , :string , :limit => 156 if !c.column_exists?(:pages, :fb_description )
117
- c.add_column :pages, :gp_description , :string , :limit => 156 if !c.column_exists?(:pages, :gp_description )
118
-
119
- # Posts
120
- c.create_table :posts if !c.table_exists?(:posts)
121
- c.add_column :posts, :title , :text if !c.column_exists?(:posts, :title )
122
- c.add_column :posts, :body , :text if !c.column_exists?(:posts, :body )
123
- c.add_column :posts, :hide , :boolean if !c.column_exists?(:posts, :hide )
124
- c.add_column :posts, :image_url , :text if !c.column_exists?(:posts, :image_url )
125
- c.add_column :posts, :created_at , :datetime if !c.column_exists?(:posts, :created_at )
126
- c.add_column :posts, :updated_at , :datetime if !c.column_exists?(:posts, :updated_at )
127
-
128
- # Post categories
129
- c.create_table :post_categories if !c.table_exists?(:post_categories)
130
- c.add_column :post_categories, :name , :string if !c.column_exists?(:post_categories, :name)
131
-
132
- # Post category membership
133
- c.create_table :post_category_memberships if !c.table_exists?(:post_category_memberships)
134
- c.add_column :post_category_memberships, :post_id , :integer if !c.column_exists?(:post_category_memberships, :post_id )
135
- c.add_column :post_category_memberships, :post_category_id , :integer if !c.column_exists?(:post_category_memberships, :post_category_id )
136
- c.add_index :post_category_memberships, :post_id if !c.index_exists?( :post_category_memberships, :post_id )
137
- c.add_index :post_category_memberships, :post_category_id if !c.index_exists?( :post_category_memberships, :post_category_id )
138
-
139
- # Page permissions
140
- c.create_table :page_permissions if !c.table_exists?(:page_permissions)
141
- c.add_column :page_permissions, :role_id , :integer if !c.column_exists?(:page_permissions, :role_id )
142
- c.add_column :page_permissions, :page_id , :integer if !c.column_exists?(:page_permissions, :page_id )
143
- c.add_column :page_permissions, :action , :string if !c.column_exists?(:page_permissions, :action )
144
-
145
- # Sessions
146
- c.create_table :sessions if !c.table_exists?(:sessions)
147
- c.add_column :sessions, :session_id , :string , :null => false if !c.column_exists?(:sessions, :session_id )
148
- c.add_column :sessions, :data , :text if !c.column_exists?(:sessions, :data )
149
- c.add_column :sessions, :created_at , :datetime , :null => true if !c.column_exists?(:sessions, :created_at )
150
- c.add_column :sessions, :updated_at , :datetime , :null => true if !c.column_exists?(:sessions, :updated_at )
151
- c.add_index :sessions, :session_id if !c.index_exists?( :sessions, :session_id )
152
- c.add_index :sessions, :updated_at if !c.index_exists?( :sessions, :updated_at )
153
-
154
- # Settings
155
- c.create_table :settings if !c.table_exists?(:settings)
156
- c.add_column :settings, :name , :string if !c.column_exists?(:settings, :name )
157
- c.add_column :settings, :value , :text if !c.column_exists?(:settings, :value )
158
-
159
- end
160
-
161
- def load_data
162
- puts "Loading data into caboose tables..."
163
-
164
- admin_user = nil
165
- if !Caboose::User.exists?(:username => 'admin')
166
- admin_user = Caboose::User.create(:first_name => 'Admin', :last_name => 'User', :username => 'admin', :email => 'william@nine.is')
167
- admin_user.password = Digest::SHA1.hexdigest(Caboose::salt + 'caboose')
168
- admin_user.save
169
- end
170
- admin_user = Caboose::User.where(:username => 'admin').first if admin_user.nil?
171
-
172
- Caboose::Role.create(:parent_id => -1 , :name => 'Admin' ) if !Caboose::Role.exists?(:name => 'Admin' )
173
- Caboose::Role.create(:parent_id => -1 , :name => 'Everyone Logged Out' ) if !Caboose::Role.exists?(:name => 'Everyone Logged Out' )
174
- Caboose::Role.create(:parent_id => elo_role.id , :name => 'Everyone Logged In' ) if !Caboose::Role.exists?(:name => 'Everyone Logged In' )
175
-
176
- admin_role = Caboose::Role.where(:name => 'Admin' ).first
177
- elo_role = Caboose::Role.where(:name => 'Everyone Logged Out' ).first
178
- eli_role = Caboose::Role.where(:name => 'Everyone Logged In' ).first
179
-
180
- Caboose::User.create(:first_name => 'John', :last_name => 'Doe', :username => 'elo', :email => 'william@nine.is') if !Caboose::User.exists?(:username => 'elo')
181
- elo_user = Caboose::User.where(:username => 'elo').first
182
-
183
- Caboose::Permission.create(:resource => 'all' , :action => 'all' ) if !Caboose::Permission.exists?(:resource => 'all' , :action => 'all' )
184
- Caboose::Permission.create(:resource => 'users' , :action => 'view' ) if !Caboose::Permission.exists?(:resource => 'users' , :action => 'view' )
185
- Caboose::Permission.create(:resource => 'users' , :action => 'edit' ) if !Caboose::Permission.exists?(:resource => 'users' , :action => 'edit' )
186
- Caboose::Permission.create(:resource => 'users' , :action => 'delete' ) if !Caboose::Permission.exists?(:resource => 'users' , :action => 'delete' )
187
- Caboose::Permission.create(:resource => 'users' , :action => 'add' ) if !Caboose::Permission.exists?(:resource => 'users' , :action => 'add' )
188
- Caboose::Permission.create(:resource => 'roles' , :action => 'view' ) if !Caboose::Permission.exists?(:resource => 'roles' , :action => 'view' )
189
- Caboose::Permission.create(:resource => 'roles' , :action => 'edit' ) if !Caboose::Permission.exists?(:resource => 'roles' , :action => 'edit' )
190
- Caboose::Permission.create(:resource => 'roles' , :action => 'delete' ) if !Caboose::Permission.exists?(:resource => 'roles' , :action => 'delete' )
191
- Caboose::Permission.create(:resource => 'roles' , :action => 'add' ) if !Caboose::Permission.exists?(:resource => 'roles' , :action => 'add' )
192
- Caboose::Permission.create(:resource => 'permissions' , :action => 'view' ) if !Caboose::Permission.exists?(:resource => 'permissions' , :action => 'view' )
193
- Caboose::Permission.create(:resource => 'permissions' , :action => 'edit' ) if !Caboose::Permission.exists?(:resource => 'permissions' , :action => 'edit' )
194
- Caboose::Permission.create(:resource => 'permissions' , :action => 'delete' ) if !Caboose::Permission.exists?(:resource => 'permissions' , :action => 'delete' )
195
- Caboose::Permission.create(:resource => 'permissions' , :action => 'add' ) if !Caboose::Permission.exists?(:resource => 'permissions' , :action => 'add' )
196
-
197
- # Add the admin user to the admin role
198
- 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)
199
-
200
- # Add the elo to the elo role
201
- 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)
202
-
203
- # Add the all/all permission to the admin role
204
- admin_perm = Caboose::Permission.where(:resource => 'all', :action => 'all').first
205
- 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)
206
-
207
- # Create the necessary pages
208
- Caboose::Page.create(:title => 'Home' , :parent_id => -1, :hide => 0, :layout => 'home', :uri => '') if !Caboose::Page.exists?(:title => 'Home')
209
- home_page = Caboose::Page.where(:title => 'Home', :parent_id => -1).first
210
- Caboose::Page.create(:title => 'Admin' , :parent_id => home_page.id, :hide => 0, :layout => 'admin', :alias => 'admin', :slug => 'admin', :uri => 'admin') if !Caboose::Page.exists?(:alias => 'admin')
211
- admin_page = Caboose::Page.where(:alias => 'admin').first
212
- 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')
213
- login_page = Caboose::Page.where(:alias => 'login').first
214
-
215
- 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')
216
- 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')
217
-
218
- # Create a default post category
219
- Caboose::PostCategory.create(:name => 'General News') if !Caboose::PostCategory.exists?(:name => 'General News')
220
-
221
- # Create the required settings
222
- Caboose::Setting.create(:name => 'version' , :value => Caboose::VERSION ) if !Caboose::Setting.exists?(:name => 'version' , :value => Caboose::VERSION )
223
- Caboose::Setting.create(:name => 'site_name' , :value => 'New Caboose Site' ) if !Caboose::Setting.exists?(:name => 'site_name' , :value => 'New Caboose Site' )
224
- Caboose::Setting.create(:name => 'site_url' , :value => 'www.mycaboosesite.com' ) if !Caboose::Setting.exists?(:name => 'site_url' , :value => 'www.mycaboosesite.com' )
225
- Caboose::Setting.create(:name => 'admin_email' , :value => 'william@nine.is' ) if !Caboose::Setting.exists?(:name => 'admin_email' , :value => 'william@nine.is' )
226
-
227
- end
228
- end