caboose-cms 0.2.86 → 0.2.87

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZjcyMDc0ODUzNzNmYWYxY2MzMjk1NjA1NDQzY2EyYTc4YjQyN2Q1OA==
4
+ NjE0MjY3MzEwMzRmMmQ3NTc5ZjYxMTE1ODkzN2VmZjU4OWIwNmFiZQ==
5
5
  data.tar.gz: !binary |-
6
- MTcyYTdmMjM2YjkzZWVhOWFlMWU3MjJkMWFiOTg5NzA3ZGY5YmM0Zg==
6
+ ZjU0YjRiNzNiOTMxODFlOWJmMjE1YzUyYjMyMjFkYmU2ODgyMjcyYg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- N2Q4MzI1YmJjZDdlNzNmNGU4NmUwMzNjNjcwNTI2YzVlM2MyMGVhYTBhOTQ1
10
- M2EzYzQ2YWJmYmZhYjA0YzkwYThmNmI3MDQ4Y2MxOWVjNjNmN2IyNWI5ZDA0
11
- MzM0MzYzNmEyYWI0NjQzZDEzZmJjZjhlN2E2NDlhYjkyZGFkYzE=
9
+ ZGI0NzdjODUwZWNkMjhlNWM2MmFhMzM5ZmI4YzI1Y2RlM2M3MGE3OGY5ZjY3
10
+ N2VlZmIwYmRhMWQwNzQ1NmFjZGQ4ZjI3ZmQxOTk2NjhlNzVhZGNmZDY3ZGEz
11
+ ZjNmZjc5Y2I5MDc1MTQ4NDBlMzdlOGM5MTBlMWEyYzIyZWJhODY=
12
12
  data.tar.gz: !binary |-
13
- MDI3MjFiYjFkNmMwN2IyMTNkZmNiMjhmMTI3ZjJkZjI0NDRjNjVlZGFiNGVi
14
- ZDgzZmU3YzA2MWVkMGFiNGFhNDRhNzZlMjJiYjUwYzk1ZjQ1ZDhjMzgzZGM3
15
- ZDk2MGQ3NTQ0MTlmMTUwZDhjMGNjZTMwMDQ4MjExOTZjMDdiYzg=
13
+ MjVlNDdlN2E2MmY0MDA5ZDcwZWNjMTA0M2E4YWM1ZGYwZWZiOGFmNjViMWVm
14
+ OGI5MWY4YWFkNzhiMDBmMDA0MWIyMzdiZWIzYzYwOTViM2I2ZDVmMWE1N2M5
15
+ ZmUwNWFlNjY4MDMwY2ZkYWNhNDk1ZWNhMmI5M2QzZTZiNDUyNWM=
@@ -65,6 +65,7 @@ module Caboose
65
65
  assoc = @options['model'].constantize.where(where)
66
66
  if @options['items_per_page'] != -1
67
67
  assoc = assoc.limit(limit).offset(offset)
68
+ end
68
69
  return assoc.reorder(reorder).all
69
70
  end
70
71
 
@@ -1,166 +1,2 @@
1
- module Caboose
2
- class Pager
3
- #
4
- # Parameters:
5
- # params: array of key/value pairs that must include the following:
6
- # base_url: url without querystring onto which the parameters are added.
7
- # itemCount: Total number of items.
8
- #
9
- # In addition, the following parameters are not required but may be
10
- # included in the array:
11
- # itemsPerPage: Number of items you want to show per page. Defaults to 10 if not present.
12
- # page: Current page number. Defaults to 0 if not present.
13
- #
14
- attr_accessor :params, :options
15
-
16
- def initialize(post_get, params = nil, options = nil)
17
-
18
- params = {} if params.nil?
19
- options = {} if options.nil?
20
-
21
- # Note: a few keys are required:
22
- # base_url, page, itemCount, itemsPerPage
23
- @params = {}
24
- @options = {
25
- 'model' => '',
26
- 'sort' => '',
27
- 'desc' => false,
28
- 'base_url' => '',
29
- 'page' => 1,
30
- 'item_count' => 0,
31
- 'items_per_page' => 10
32
- }
33
- params.each { |key, val| @params[key] = val }
34
- options.each { |key, val| @options[key] = val }
35
- @params.each { |key, val| @params[key] = post_get[key].nil? ? val : post_get[key] }
36
- @options.each { |key, val| @options[key] = post_get[key].nil? ? val : post_get[key] }
37
- @options['item_count'] = @options['model'].constantize.where(where).count
38
-
39
- end
40
-
41
- def ok(val)
42
- return false if val.nil?
43
- return true if val.is_a? Array
44
- return true if val.is_a? Hash
45
- return true if val.is_a? Integer
46
- return true if val.is_a? Fixnum
47
- return true if val.is_a? Float
48
- return true if val.is_a? Bignum
49
- return true if val.is_a? TrueClass
50
- return true if val.is_a? FalseClass
51
- return false if val == ""
52
- return true
53
- end
54
-
55
- def items
56
- return @options['model'].constantize.where(where).limit(limit).offset(offset).reorder(reorder).all
57
- end
58
-
59
- def generate
60
-
61
- # Check for necessary parameter values
62
- return false if !ok(@options['base_url']) # Error: base_url is required for the page bar generator to work.
63
- return false if !ok(@options['item_count']) # Error: itemCount is required for the page bar generator to work.
64
-
65
- # Set default parameter values if not present
66
- @options['items_per_page'] = 10 if @options["items_per_page"].nil?
67
- @options['page'] = 1 if @options["page"].nil?
68
-
69
- # Variables to make the search form work
70
- vars = get_vars()
71
- page = @options["page"].to_i
72
-
73
- #Caboose.log(@options)
74
-
75
- # Max links to show (must be odd)
76
- total_links = 5
77
- prev_page = page - 1
78
- next_page = page + 1
79
- total_pages = (@options['item_count'].to_f / @options['items_per_page'].to_f).ceil
80
-
81
- if (total_pages < total_links)
82
- start = 1
83
- stop = total_pages
84
- else
85
- start = page - (total_links/2).floor
86
- start = 1 if start < 1
87
- stop = start + total_links - 1
88
-
89
- if (stop > total_pages)
90
- stop = total_pages
91
- start = stop - total_links
92
- start = 1 if start < 1
93
- end
94
- end
95
-
96
- base_url = @params['base_url']
97
- str = ''
98
- str << "<p>Results: showing page #{page} of #{total_pages}</p>\n"
99
-
100
- if (total_pages > 1)
101
- str << "<div class='page_links'>\n"
102
- if (page > 1)
103
- str << "<a href='#{base_url}?#{vars}&page=#{prev_page}'>Previous</a>"
104
- end
105
- for i in start..stop
106
- if (page != i)
107
- str << "<a href='#{base_url}?#{vars}&page=#{i}'>#{i}</a>"
108
- else
109
- str << "<span class='current_page'>#{i}</span>"
110
- end
111
- end
112
- if (page < total_pages)
113
- str << "<a href='#{base_url}?#{vars}&page=#{next_page}'>Next</a>"
114
- end
115
- str << "</div>\n"
116
- end
117
-
118
- return str
119
- end
120
-
121
- def get_vars()
122
- vars = []
123
- @params.each do |k,v|
124
- vars.push("#{k}=#{v}") if !v.nil? && v.length > 0
125
- end
126
- return URI.escape(vars.join('&'))
127
- end
128
-
129
- def sortable_table_headings(cols)
130
- vars = get_vars()
131
- str = ''
132
-
133
- # key = sort field, value = text to display
134
- cols.each do |sort, text|
135
- desc = @options['desc'] ? @options['desc'].to_i : 0
136
- arrow = @options['sort'] == sort ? (desc ? ' &uarr;' : ' &darr;') : ''
137
- link = @options['base_url'] + "?#{vars}&sort=#{sort}&desc=" + (desc ? "0" : "1")
138
- str += "<th><a href='#{link}'>#{text}#{arrow}</a></th>\n"
139
- end
140
- return str
141
- end
142
-
143
- def where
144
- vars = {}
145
- @params.each do |k,v|
146
- vars[k] = v if !v.nil? && v.length > 0
147
- end
148
- return vars
149
- end
150
-
151
- def limit
152
- return @options['items_per_page'].to_i
153
- end
154
-
155
- def offset
156
- return (@options['page'].to_i - 1) * @options['items_per_page'].to_i
157
- end
158
-
159
- def reorder
160
- if (!@options['sort'].nil? && @options['sort'].length > 0)
161
- return @options['sort']
162
- end
163
- return "id"
164
- end
165
- end
1
+ module Caboose::Pager << Caboose::PageBarGenerator
166
2
  end
@@ -1,7 +1,9 @@
1
1
 
2
2
  class Caboose::Permission < ActiveRecord::Base
3
3
  self.table_name = "permissions"
4
- has_and_belongs_to_many :roles
4
+ #has_and_belongs_to_many :roles
5
+ has_many :role_permissions
6
+ has_many :roles, :through => :role_permissions
5
7
  attr_accessible :action, :resource
6
8
 
7
9
  def self.allow(role_id, resource, action)
@@ -1,9 +1,16 @@
1
1
 
2
2
  class Caboose::Role < ActiveRecord::Base
3
3
  self.table_name = "roles"
4
- belongs_to :parent, :class_name => "Caboose::Role"
5
- has_and_belongs_to_many :users
6
- has_and_belongs_to_many :permissions
4
+ belongs_to :parent, :class_name => "Caboose::Role"
5
+
6
+ #has_and_belongs_to_many :users
7
+ has_many :role_memberships
8
+ has_many :users, :through => :role_memberships
9
+
10
+ #has_and_belongs_to_many :permissions
11
+ has_many :role_permissions
12
+ has_many :permissions, :through => :role_permissions
13
+
7
14
  has_many :page_permissions
8
15
 
9
16
  attr_accessible :name, :description, :parent_id
@@ -0,0 +1,9 @@
1
+
2
+ class Caboose::RoleMembership < ActiveRecord::Base
3
+ self.table_name = "role_memberships"
4
+
5
+ belongs_to :user
6
+ belongs_to :role
7
+ attr_accessible :user_id, :role_id
8
+
9
+ end
@@ -0,0 +1,9 @@
1
+
2
+ class Caboose::RolePermission < ActiveRecord::Base
3
+ self.table_name = "role_permissions"
4
+
5
+ belongs_to :permission
6
+ belongs_to :role
7
+ attr_accessible :permission_id, :role_id
8
+
9
+ end
@@ -1,6 +1,8 @@
1
1
  class Caboose::User < ActiveRecord::Base
2
- self.table_name = "users"
3
- has_and_belongs_to_many :roles
2
+ self.table_name = "users"
3
+ #has_and_belongs_to_many :roles
4
+ has_many :role_memberships
5
+ has_many :roles, :through => :role_memberships
4
6
  attr_accessible :email, :first_name, :last_name, :username, :token, :password
5
7
 
6
8
  def self.logged_out_user
@@ -1,3 +1,3 @@
1
1
  module Caboose
2
- VERSION = '0.2.86'
2
+ VERSION = '0.2.87'
3
3
  end
@@ -3,37 +3,15 @@ require "caboose/migrations"
3
3
 
4
4
  namespace :caboose do
5
5
 
6
- desc "Initializes the database for a caboose installation"
7
- task :db => :environment do
8
- drop_tables
9
- create_tables
10
- load_data
11
- end
12
-
13
- desc "Drops all caboose tables"
14
- task :drop_tables => :environment do drop_tables end
15
-
16
- desc "Creates all caboose tables"
17
- task :create_tables => :environment do create_tables end
18
-
19
- desc "Loads data into caboose tables"
20
- task :load_data => :environment do load_data end
21
-
22
6
  desc "Resets the admin password to 'caboose'"
23
- task :reset_admin_pass => :environment do reset_admin_pass end
24
-
25
- desc "Performs caboose migrations to transition from the first to the second version. (Unsafe.)"
26
- task :migrate_between, [:from_version, :to_version] => :environment do |t, args|
27
- args.with_defaults(from_version: nil, to_version: nil)
28
- migrate_tables(args[:from_version], args[:to_version])
7
+ task :reset_admin_pass => :environment do
8
+
9
+ admin_user = Caboose::User.where(username: 'admin').first
10
+ admin_user.password = Digest::SHA1.hexdigest(Caboose::salt + 'caboose')
11
+ admin_user.save
12
+
29
13
  end
30
-
31
- desc "Performs caboose migrations to transition from the current version to the given version"
32
- task :migrate_to, [:to_version] => :migrate_between
33
-
34
- desc "Performs caboose migrations to transition from the current version to the latest installed version"
35
- task :migrate => :migrate_between
36
-
14
+
37
15
  desc "Sync production db to development"
38
16
  task :sync_dev_db do
39
17
 
@@ -55,212 +33,5 @@ namespace :caboose do
55
33
  `pg_restore --verbose --clean --no-acl --no-owner -h #{ddb['host']} -U #{ddb['username']} -d #{ddb['database']} #{dump_file}`
56
34
 
57
35
  end
58
-
59
- #=============================================================================
60
36
 
61
- def drop_tables
62
- puts "Dropping any existing caboose tables..."
63
- c = ActiveRecord::Base.connection
64
- c.drop_table :users if c.table_exists?('users')
65
- c.drop_table :roles if c.table_exists?('roles')
66
- c.drop_table :permissions if c.table_exists?('permissions')
67
- c.drop_table :roles_users if c.table_exists?('roles_users')
68
- c.drop_table :permissions_roles if c.table_exists?('permissions_roles')
69
- c.drop_table :assets if c.table_exists?('assets')
70
- c.drop_table :pages if c.table_exists?('pages')
71
- c.drop_table :posts if c.table_exists?('posts')
72
- c.drop_table :page_permissions if c.table_exists?('page_permissions')
73
- c.drop_table :sessions if c.table_exists?('sessions')
74
- c.drop_table :settings if c.table_exists?('settings')
75
- end
76
-
77
- def create_tables
78
- puts "Creating required caboose tables..."
79
-
80
- c = ActiveRecord::Base.connection
81
-
82
- # User/Role/Permissions
83
- c.create_table :users do |t|
84
- t.string :first_name
85
- t.string :last_name
86
- t.string :username
87
- t.string :email
88
- t.string :phone
89
- t.string :password
90
- t.string :password_reset_id
91
- t.datetime :password_reset_sent
92
- t.string :token
93
- t.datetime :date_created
94
- end
95
- c.create_table :roles do |t|
96
- t.integer :parent_id
97
- t.string :name
98
- t.string :description
99
- end
100
- c.create_table :permissions do |t|
101
- t.string :resource
102
- t.string :action
103
- end
104
-
105
- # Role membership
106
- c.create_table :roles_users do |t|
107
- t.references :role
108
- t.references :user
109
- end
110
- c.add_index :roles_users, :role_id
111
- c.add_index :roles_users, :user_id
112
-
113
- # Role permissions
114
- c.create_table :permissions_roles do |t|
115
- t.references :role
116
- t.references :permission
117
- end
118
- c.add_index :permissions_roles, :role_id
119
- c.add_index :permissions_roles, :permission_id
120
-
121
- # Pages and Assets
122
- c.create_table :assets do |t|
123
- t.references :page
124
- t.references :user
125
- t.datetime :date_uploaded
126
- t.string :name
127
- t.string :filename
128
- t.string :description
129
- t.string :extension
130
- end
131
- c.create_table :pages do |t|
132
- t.integer :parent_id
133
- t.string :title
134
- t.string :menu_title
135
- t.text :content
136
- t.string :slug
137
- t.string :alias
138
- t.string :uri
139
- t.string :redirect_url
140
- t.boolean :hide, :default => false
141
- t.integer :content_format, :default => Caboose::Page::CONTENT_FORMAT_HTML
142
- t.text :custom_css
143
- t.text :custom_js
144
- t.text :linked_resources
145
- t.string :layout
146
- t.integer :sort_order, :default => 0
147
- t.boolean :custom_sort_children, :default => false
148
- t.string :seo_title, :limit => 70
149
- t.string :meta_description, :limit => 156
150
- t.string :meta_robots, :default => 'index, follow' # Multi-select options: none, noindex, nofollow, nosnippet, noodp, noarchive
151
- t.string :canonical_url
152
- t.string :fb_description, :limit => 156
153
- t.string :gp_description, :limit => 156
154
- end
155
- c.create_table :posts do |t|
156
- t.text :title
157
- t.text :body
158
- t.boolean :hide
159
- t.text :image_url
160
- t.timestamps
161
- end
162
- c.create_table :page_permissions do |t|
163
- t.references :role
164
- t.references :page
165
- t.string :action
166
- end
167
- c.create_table :sessions do |t|
168
- t.string :session_id, :null => false
169
- t.text :data
170
- t.timestamps
171
- end
172
- c.add_index :sessions, :session_id
173
- c.add_index :sessions, :updated_at
174
- c.change_column :sessions, :created_at, :datetime, :null => true
175
- c.change_column :sessions, :updated_at, :datetime, :null => true
176
- c.create_table :settings do |t|
177
- t.string :name
178
- t.text :value
179
- end
180
-
181
- end
182
-
183
- def load_data
184
- puts "Loading data into caboose tables..."
185
-
186
- admin_user = Caboose::User.create(first_name: 'Admin', last_name: 'User', username: 'admin', email: 'william@nine.is')
187
- admin_user.password = Digest::SHA1.hexdigest(Caboose::salt + 'caboose')
188
- admin_user.save
189
-
190
- admin_role = Caboose::Role.create(parent_id: -1, name: 'Admin')
191
- elo_role = Caboose::Role.create(parent_id: -1, name: 'Everyone Logged Out')
192
- eli_role = Caboose::Role.create(parent_id: elo_role.id, name: 'Everyone Logged In')
193
-
194
- elo_user = Caboose::User.create(first_name: 'John', last_name: 'Doe', username: 'elo', email: 'william@nine.is')
195
-
196
- admin_perm = Caboose::Permission.create(resource: 'all', action: 'all')
197
- Caboose::Permission.create(resource: 'users' , action: 'view')
198
- Caboose::Permission.create(resource: 'users' , action: 'edit')
199
- Caboose::Permission.create(resource: 'users' , action: 'delete')
200
- Caboose::Permission.create(resource: 'users' , action: 'add')
201
- Caboose::Permission.create(resource: 'roles' , action: 'view')
202
- Caboose::Permission.create(resource: 'roles' , action: 'edit')
203
- Caboose::Permission.create(resource: 'roles' , action: 'delete')
204
- Caboose::Permission.create(resource: 'roles' , action: 'add')
205
- Caboose::Permission.create(resource: 'permissions' , action: 'view')
206
- Caboose::Permission.create(resource: 'permissions' , action: 'edit')
207
- Caboose::Permission.create(resource: 'permissions' , action: 'delete')
208
- Caboose::Permission.create(resource: 'permissions' , action: 'add')
209
-
210
- # Add the admin user to the admin role
211
- admin_user.roles.push(admin_role)
212
- admin_user.save
213
-
214
- # Add the elo to the elo role
215
- elo_user.roles.push(elo_role)
216
- elo_user.save
217
-
218
- # Add the all/all permission to the admin role
219
- admin_role.permissions.push(admin_perm)
220
- admin_role.save
221
-
222
- # Create the home page
223
- home_page = Caboose::Page.create(title: 'Home' , parent_id: -1, hide: 0, layout: 'home' , uri: '')
224
- admin_page = Caboose::Page.create(title: 'Admin' , parent_id: home_page.id, hide: 0, layout: 'admin', alias: 'admin', slug: 'admin', uri: 'admin')
225
- login_page = Caboose::Page.create(title: 'Login' , parent_id: home_page.id, hide: 0, layout: 'login', alias: 'login', slug: 'login', uri: 'login')
226
- Caboose::PagePermission.create(role_id: elo_role.id, page_id: home_page.id, action: 'view')
227
- Caboose::PagePermission.create(role_id: elo_role.id, page_id: login_page.id, action: 'view')
228
-
229
- # Create the required settings
230
- Caboose::Setting.create(name: 'version' , value: Caboose::VERSION)
231
- Caboose::Setting.create(name: 'site_name' , value: 'New Caboose Site')
232
- Caboose::Setting.create(name: 'site_url' , value: 'www.mycaboosesite.com')
233
- Caboose::Setting.create(name: 'admin_email' , value: 'william@nine.is')
234
-
235
- end
236
-
237
- def reset_admin_pass
238
- admin_user = Caboose::User.where(username: 'admin').first
239
- admin_user.password = Digest::SHA1.hexdigest(Caboose::salt + 'caboose')
240
- admin_user.save
241
- end
242
-
243
- def migrate_tables(from_version, to_version)
244
- version_setting = Caboose::Setting.where(name: 'version').first
245
- versions = Caboose::VERSIONS
246
-
247
- from_version = version_setting.value if from_version.nil?
248
- to_version = Caboose::VERSION if to_version.nil?
249
- version_regex = /[0-9]+(\.[0-9]+)*/
250
-
251
- raise "from_version '#{from_version}' was invalid" if not version_regex.match(from_version)
252
- raise "to_version '#{to_version}' was invalid" if not version_regex.match(to_version)
253
-
254
- c = ActiveRecord::Base.connection
255
- from_to_compare = Caboose::Version.compare_version_strings(from_version, to_version)
256
-
257
- if from_to_compare < 0
258
- versions.select{ |v| v > from_version && v <= to_version }.each{ |v| v.up(c) }
259
- elsif from_to_compare > 0
260
- versions.select{ |v| v > to_version && v <= from_version }.reverse_each{ |v| v.down(c) }
261
- end
262
-
263
- version_setting.value = to_version
264
- version_setting.save
265
- end
266
37
  end
@@ -0,0 +1,228 @@
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 :posts, :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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caboose-cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.86
4
+ version: 0.2.87
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Barry
@@ -192,6 +192,8 @@ files:
192
192
  - app/models/caboose/post_category.rb
193
193
  - app/models/caboose/post_category_membership.rb
194
194
  - app/models/caboose/role.rb
195
+ - app/models/caboose/role_membership.rb
196
+ - app/models/caboose/role_permission.rb
195
197
  - app/models/caboose/setting.rb
196
198
  - app/models/caboose/std_class.rb
197
199
  - app/models/caboose/user.rb
@@ -264,6 +266,7 @@ files:
264
266
  - lib/sample_files/login.css
265
267
  - lib/sample_files/tinymce.yml
266
268
  - lib/tasks/caboose.rake
269
+ - lib/tasks/caboose_db.rake
267
270
  - MIT-LICENSE
268
271
  - Rakefile
269
272
  - README.md