milia 1.2.1 → 1.3.1.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/confirmations_controller.rb +7 -7
  3. data/app/controllers/registrations_controller.rb +13 -19
  4. data/app/views/devise/registrations/new.html.haml +53 -0
  5. data/lib/generators/milia/install_generator.rb +44 -41
  6. data/lib/generators/milia/templates/devise_permitted_parameters.rb +18 -0
  7. data/lib/generators/milia/templates/initializer.rb +3 -9
  8. data/lib/milia.rb +3 -22
  9. data/lib/milia/base.rb +88 -109
  10. data/lib/milia/control.rb +25 -25
  11. data/lib/milia/invite_member.rb +6 -6
  12. data/lib/milia/version.rb +1 -1
  13. metadata +16 -184
  14. data/.document +0 -5
  15. data/.gitignore +0 -94
  16. data/.ruby-gemset +0 -1
  17. data/.ruby-version +0 -1
  18. data/.slugignore +0 -2
  19. data/.travis.yml +0 -4
  20. data/Gemfile +0 -4
  21. data/LICENSE.txt +0 -20
  22. data/README.md +0 -1207
  23. data/Rakefile +0 -1
  24. data/doc/gemfile_addition.txt +0 -28
  25. data/doc/manual_sample.sh +0 -816
  26. data/doc/ref_notes.txt +0 -155
  27. data/doc/sample.sh +0 -276
  28. data/markdown.rb +0 -38
  29. data/milia.gemspec +0 -29
  30. data/test/.ruby-gemset +0 -1
  31. data/test/.ruby-version +0 -1
  32. data/test/Gemfile +0 -81
  33. data/test/Gemfile.lock +0 -223
  34. data/test/README.md +0 -83
  35. data/test/Rakefile +0 -6
  36. data/test/app/assets/javascripts/application.js +0 -16
  37. data/test/app/assets/stylesheets/application.css +0 -13
  38. data/test/app/controllers/application_controller.rb +0 -13
  39. data/test/app/controllers/home_controller.rb +0 -10
  40. data/test/app/helpers/application_helper.rb +0 -2
  41. data/test/app/models/member.rb +0 -34
  42. data/test/app/models/post.rb +0 -14
  43. data/test/app/models/team.rb +0 -9
  44. data/test/app/models/team_asset.rb +0 -6
  45. data/test/app/models/tenant.rb +0 -54
  46. data/test/app/models/user.rb +0 -14
  47. data/test/app/models/zine.rb +0 -8
  48. data/test/app/views/home/index.html.erb +0 -2
  49. data/test/app/views/home/show.html.erb +0 -2
  50. data/test/app/views/layouts/application.html.erb +0 -14
  51. data/test/bin/bundle +0 -3
  52. data/test/bin/rails +0 -4
  53. data/test/bin/rake +0 -4
  54. data/test/config/application.rb +0 -36
  55. data/test/config/boot.rb +0 -4
  56. data/test/config/database.yml +0 -25
  57. data/test/config/environment.rb +0 -5
  58. data/test/config/environments/development.rb +0 -48
  59. data/test/config/environments/production.rb +0 -95
  60. data/test/config/environments/test.rb +0 -42
  61. data/test/config/initializers/backtrace_silencers.rb +0 -7
  62. data/test/config/initializers/devise.rb +0 -254
  63. data/test/config/initializers/filter_parameter_logging.rb +0 -4
  64. data/test/config/initializers/inflections.rb +0 -16
  65. data/test/config/initializers/milia.rb +0 -51
  66. data/test/config/initializers/mime_types.rb +0 -5
  67. data/test/config/initializers/secret_token.rb +0 -12
  68. data/test/config/initializers/session_store.rb +0 -3
  69. data/test/config/initializers/wrap_parameters.rb +0 -14
  70. data/test/config/locales/en.yml +0 -23
  71. data/test/config/routes.rb +0 -77
  72. data/test/db/migrate/20111012050200_add_sessions_table.rb +0 -12
  73. data/test/db/migrate/20111012050340_devise_create_users.rb +0 -48
  74. data/test/db/migrate/20111012050532_create_tenants.rb +0 -11
  75. data/test/db/migrate/20111012050600_create_tenants_users_join_table.rb +0 -8
  76. data/test/db/migrate/20111012050650_create_members.rb +0 -12
  77. data/test/db/migrate/20111012231923_create_posts.rb +0 -12
  78. data/test/db/migrate/20111013050657_create_zines.rb +0 -10
  79. data/test/db/migrate/20111013050753_create_teams.rb +0 -10
  80. data/test/db/migrate/20111013050837_create_team_assets.rb +0 -11
  81. data/test/db/schema.rb +0 -126
  82. data/test/db/seeds.rb +0 -7
  83. data/test/test/controllers/home_controller_test.rb +0 -132
  84. data/test/test/ctlr_test_helper.rb +0 -11
  85. data/test/test/fixtures/members.yml +0 -35
  86. data/test/test/fixtures/posts.yml +0 -96
  87. data/test/test/fixtures/team_assets.yml +0 -30
  88. data/test/test/fixtures/teams.yml +0 -17
  89. data/test/test/fixtures/tenants.yml +0 -12
  90. data/test/test/fixtures/tenants_users.yml +0 -15
  91. data/test/test/fixtures/users.yml +0 -33
  92. data/test/test/fixtures/zines.yml +0 -25
  93. data/test/test/models/member_test.rb +0 -75
  94. data/test/test/models/post_test.rb +0 -66
  95. data/test/test/models/team_test.rb +0 -49
  96. data/test/test/models/tenant_test.rb +0 -228
  97. data/test/test/models/user_test.rb +0 -182
  98. data/test/test/models/zine_test.rb +0 -40
  99. data/test/test/test_helper.rb +0 -31
data/Rakefile DELETED
@@ -1 +0,0 @@
1
- require "bundler/gem_tasks"
@@ -1,28 +0,0 @@
1
- ruby "2.1.3" # heroku likes this at the head, as line 2
2
-
3
- # =========================================================
4
- # sample-milia-app specific stuff
5
- # =========================================================
6
- # Bundle the extra gems:
7
-
8
- gem 'haml-rails'
9
- gem 'html2haml', :git => 'git://github.com/haml/html2haml.git' # "2.0.0.beta.2",
10
-
11
- # stuff that heroku likes to have
12
- gem 'thin'
13
- gem "SystemTimer", :require => "system_timer", :platforms => :ruby_18
14
- gem "rack-timeout"
15
- gem 'rails_12factor'
16
-
17
- gem 'web-app-theme', :git => 'git://github.com/dsaronin/web-app-theme.git'
18
- gem 'devise', '~>3.4.0'
19
- gem 'milia', :git => 'git://github.com/dsaronin/milia.git', :branch => 'newdev'
20
-
21
- # airbrake is optional and configured by config.use_airbrake in milia initializer
22
- # default is false; if you change it to true, uncomment out the line below
23
- # gem 'airbrake' # uncomment this if you will use airbrake for exception notifications
24
-
25
- # recaptcha is optional and configured by config.use_recaptcha in milia initializer
26
- # default is true; if you change it to false, comment out the line below
27
- # gem 'recaptcha', :require => "recaptcha/rails"
28
-
@@ -1,816 +0,0 @@
1
- # *********************************************************************
2
- # HOW TO SET IT UP -- sample-milia-app
3
- # *********************************************************************
4
- #
5
- # NOTE: this is now an archivial copy of instructions for creating an
6
- # app with rails/milia/devise. After v1.0.0-beta-3, all of this is now
7
- # implemented using generators. But this is a reference for how to
8
- # do everything manually, as of v1.1.0
9
- #
10
- # *********************************************************************
11
- # This is a capture of everything I did to create a sample app for milia.
12
- # There's enough brief comments for anyone to follow step-by-step.
13
- # It is based on my dev environment which is Ubuntu 14.04 on a PC. YMMV.
14
- #
15
- # The "app" itself is merely a simple barebones structure to display
16
- # an index page, require sign-in to do anything else, has a sign-up
17
- # page for starting a new organization (ie tenant), a way to send
18
- # invitations to other members, and a single tenanted model to prove
19
- # that tenanting is working.
20
- #
21
- # you can see an exact copy of the sample on github:
22
- # https://github.com/dsaronin/sample-milia-app
23
- #
24
- # *********************************************************************
25
- # RESOURCES
26
- # *********************************************************************
27
- # doc/sample.sh -- this document will ALWAYS be the most recent
28
- # (for example in the edge branch: "newdev")
29
- # github.com/milia/wiki/sample-milia-app-tutorial
30
- # this should be the same as the sample.sh doc for the current
31
- # stable release (or last beta version); but markdown formatted
32
- # https://github.com/dsaronin/milia/wiki/sample-milia-app-tutorial
33
- # milia README:
34
- # this will be the knowledgable programmer's digest of the essentials
35
- # and thus it won't cover some of the intricacies of actually
36
- # implementing milia: either the tutorial or sample.sh will do that
37
- #
38
- # *********************************************************************
39
- # FEEDBACK
40
- # *********************************************************************
41
- # If you run into difficulties while following the steps here,
42
- # please be sure to reference the LINE NUMBER of the point at which
43
- # had a problem, as well as any output from that step.
44
- # BUT (caveat)
45
- # if you've gone commando and been making changes & enhancements OR
46
- # have been trying to roll out a full app, you're more or less on your
47
- # own. I strongly recommend experimenting with milia first in this
48
- # simple format, get it working, then ADD in increasing layers of
49
- # complexity and difficulty. Trying to make too many changes at once
50
- # is a recipe for difficulty in troubleshooting.
51
- # *********************************************************************
52
- # NOTES
53
- # *********************************************************************
54
- # Although this file has a ".sh" extension, it isn't fully executable
55
- # as a shell script. There are just too many things you'll have to
56
- # to do to help things along.
57
- # 1. Instructions for you to do things are in comments;
58
- # things you should type or cut&paste, are not.
59
- # commands preceded by a "$" prompt indicate shell level command.
60
- # commands preceded by a ">" prompt indicate some other program command.
61
- # in either case, don't type the prompt as part of the command!
62
- # 2. I've bracketed groups of text to be edited/added to a file
63
- # with the following style:
64
- # # EDIT: <path/filename> >>>>>>>>>>>>
65
- # things to do &/or edit or add
66
- # # ADD: stuff to add follows
67
- # things to add
68
- # #<<< ADD <<<<<<<<<<<<<<<<<<<<<<<<<< up to here
69
- # maybe some more edit stuff
70
- # #<<< EDIT <<<<<<<<<<<<<<<<<<<<<<<<<< up to here
71
- # 3. follow everything exactly in the order given
72
- # 4. there's non-milia related stuff if you'll be using heroku to host
73
- # treat this as optional, if you'd like. but at least I know it
74
- # works as a completed app.
75
- # *********************************************************************
76
-
77
- # *********************************************************************
78
- # STEP 0 - PREREQUISITES & EXPECTED BACKGROUND PREPARATION
79
- # *********************************************************************
80
-
81
- # this background is what I've done on my Ubuntu dev workstation
82
- # so if you want to follow exactly, you'll need similar.
83
- # none of this is required for milia; only to exactly bring up
84
- # this sample-milia-app.
85
-
86
- # make sure you have your ssh keys gen'd
87
- $ ssh-keygen
88
-
89
- # make sure you have some basic packages on your system
90
- $ sudo apt-get install curl git vim vim-gnome
91
-
92
- # make sure you've set up a github account, and git globals
93
-
94
- # Install RVM on your system; see rvm.io for more information
95
- $ \curl -L https://get.rvm.io | bash -s stable
96
- # do any adjustments to your .bashrc, etc files as needed
97
-
98
- # make sure to install ruby 2.1.3
99
- $ rvm install 2.1.3
100
-
101
- # I have all my projects in a directory called "projectspace'
102
- $ mkdir projectspace
103
- $ rvm gemset create projectspace
104
- $ echo "projectspace" > projectspace/.ruby-gemset
105
- $ echo "2.1.3" > projectspace/.ruby-version
106
- $ cd projectspace
107
-
108
- # install rails (latest version)
109
- $ gem install rails
110
-
111
- # OPTIONAL -- get ready for heroku
112
- # set up a heroku account at: heroku.com
113
- # install heroku toolbelt: heroku, foreman
114
- $ wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh
115
- $ heroku login
116
-
117
- # set environment variable for later Procfile and later recaptcha
118
- # I put them in .bashrc
119
- export PORT=3000
120
- export RACK_ENV=development
121
- export SMTP_ENTRY=<my smtp password>
122
- # OPTIONAL: recaptcha keys
123
- export RECAPTCHA_PUBLIC_KEY=6LeYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKpT
124
- export RECAPTCHA_PRIVATE_KEY=6LeBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBgQBv
125
-
126
-
127
- # *********************************************************************
128
- # STEP 1 - CREATION OF SKELETON APP & REPOSITORY
129
- # *********************************************************************
130
-
131
- # GITHUB: create a new repository <your-new-app> for <git-user> (you)
132
- # anywhere below where you see "sample-milia-app", change it to <your-new-app>
133
-
134
- $ cd projectspace # if not there already
135
-
136
- $ rails new sample-milia-app --skip-bundle
137
- $ echo "sample-milia-app" > sample-milia-app/.ruby-gemset
138
- $ echo "2.1.3" > sample-milia-app/.ruby-version
139
- $ echo "web: bundle exec thin start -R config.ru -p $PORT -e $RACK_ENV" > sample-milia-app/Procfile
140
- $ rvm gemset create sample-milia-app
141
- $ cd sample-milia-app
142
- $ git init
143
- $ git add --all .
144
- $ git commit -am 'initial commit'
145
- $ git remote add origin git@github.com:<git-user>/sample-milia-app.git
146
- $ git push -u origin master
147
-
148
-
149
- # *********************************************************************
150
- # STEP 2 - SET UP GEMFILE, BUNDLE INSTALL GEMS
151
- # *********************************************************************
152
- # change .gitignore to match your development environment
153
- # I just copy my standard .gitignore from another project
154
- # but you can copy mine from sample-milia-app on github.
155
- $ cp ../swalapala/.gitignore .
156
-
157
- # EDIT Gemfile >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
158
- $ vim Gemfile
159
-
160
- # First, comment OUT the turbolinks gem
161
- # gem 'turbolinks'
162
-
163
- # then, enable rubyracer in Gemfile by de-commenting
164
- gem 'therubyracer', platforms: :ruby
165
-
166
- # finally, ADD the following lines to Gemfile >>>>>>>>>>>>>>>>>>>>>>
167
-
168
- ruby "2.1.3" # heroku likes this at the head, as line 2
169
-
170
- # =========================================================
171
- # sample-milia-app specific stuff
172
- # =========================================================
173
- # Bundle the extra gems:
174
- gem 'haml-rails'
175
- gem 'html2haml', :git => 'git://github.com/haml/html2haml.git' # "2.0.0.beta.2",
176
-
177
- # stuff that heroku likes to have
178
- gem 'thin'
179
- gem "SystemTimer", :require => "system_timer", :platforms => :ruby_18
180
- gem "rack-timeout"
181
- gem 'rails_12factor'
182
-
183
- # airbrake is optional and configured by config.use_airbrake in milia initializer
184
- # default is false; if you change it to true, uncomment out the line below
185
- # gem 'airbrake' # uncomment this if you will use airbrake for exception notifications
186
-
187
- gem 'web-app-theme', :git => 'git://github.com/dsaronin/web-app-theme.git'
188
- gem 'devise', '~>3.4.0'
189
- gem 'milia', :git => 'git://github.com/dsaronin/milia.git', :branch => 'v1.1.0'
190
-
191
- # recaptcha is optional and configured by config.use_recaptcha in milia initializer
192
- # default is true; if you change it to false, comment out the line below
193
- gem 'recaptcha', :require => "recaptcha/rails"
194
- #<<<< ADD <<<<<<<<<<<<<<<<<
195
- #<<<< EDIT <<<<<<<<<<<<<<<<<
196
-
197
- # EDIT: app/assets/javascripts/application.js >>>>>>>>>>>>>>>>>>>>>>>>
198
- # comment out turbolinks in your Javascript manifest file
199
- # we won't need turbolinks for this simple sample.
200
- // require turbolinks
201
- #<<<< EDIT <<<<<<<<<<<<<<<<<
202
-
203
- # BUNDLE install all the gems
204
- $ bundle install
205
-
206
- # *********************************************************************
207
- # STEP 3 - PREP APP UI TEMPLATES & CHECK OUT DISPLAYS
208
- # *********************************************************************
209
- # Source for web-app-theme notes and revisions:
210
- # http://blog.bryanbibat.net/2011/09/24/starting-a-professional-rails-3-1-app-with-web-app-theme-devise-and-kaminari/
211
- # *********************************************************************
212
-
213
- # Generate home page
214
- $ rails g controller home index
215
-
216
-
217
- # EDIT the config/routes.rb >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
218
- # ADD the root :to => "home#index" within the do..end block
219
-
220
- SampleMiliaApp::Application.routes.draw do
221
-
222
- root :to => "home#index"
223
-
224
- end
225
- #<<<< EDIT <<<<<<<<<<<<<<<<<
226
-
227
-
228
- # create the database
229
- $ rake db:create
230
-
231
- # test by starting server:
232
- $ foreman start
233
-
234
- # CHECK-OUT: at your browser:
235
- http://localhost:3000/
236
- # you should see an empty template page for home/index
237
-
238
-
239
- # ******* NOW WE'LL GENERATE A THEME with web-app-theme ********
240
- $ rails g web_app_theme:theme --engine=haml --theme="red" --app-name="Simple Milia App"
241
-
242
- # Delete the default layout originally generated
243
- $ rm app/views/layouts/application.html.erb
244
-
245
- # generate some sample text for the page to flesh it out
246
- $ rails g web_app_theme:themed home --themed-type=text --theme="red" --engine=haml
247
-
248
- $ mv app/views/home/show.html.haml app/views/home/index.html.haml
249
-
250
-
251
- # STEP 4 - SIMPLE devise SET UP (pre-installing milia)
252
- $ rails g devise:install
253
- $ rails g devise user
254
-
255
- # EDIT: config/environments/development.rb >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
256
- # ADD: following AFTER the final config.action_xxxxx stuff >>>>>>>>>>>>>>>>>>>>>>>
257
- # of course, you will want to change your domain, email user_name and password
258
- # to match your actual values!
259
-
260
- # devise says to define default url
261
- config.action_mailer.default_url_options = { :host => 'localhost:3000' }
262
-
263
- # set up for email sending even in dev mode
264
- # Don't care if the mailer can't send
265
- config.action_mailer.raise_delivery_errors = false
266
-
267
- config.action_mailer.delivery_method = :smtp
268
-
269
- ActionMailer::Base.smtp_settings = {
270
- :address => "smtp.gmail.com",
271
- :port => "587",
272
- :authentication => :plain,
273
- :user_name => "my-email@simple-milia-app.com",
274
- :password => "my-password",
275
- :enable_starttls_auto => true
276
- }
277
- #<<<<<< EDIT <<<<<<<<<<<<
278
-
279
-
280
- # EDIT: config/environments/production.rb >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
281
- # this sample is showing as how it would be if your production server
282
- # is hosted via heroku.com using the SENDGRID plugin for emailing
283
- # ADD: following AFTER the final config.action_xxxxx stuff >>>>>>>>>>>>>>>>>>>>>>
284
-
285
- # devise says to define default url
286
- config.action_mailer.default_url_options = { :host => 'secure.simple-milia-app.com', :protocol => 'https' }
287
-
288
- ActionMailer::Base.delivery_method = :smtp
289
-
290
- ActionMailer::Base.smtp_settings = {
291
- :address => 'smtp.sendgrid.net',
292
- :port => '587',
293
- :authentication => :plain,
294
- :user_name => ENV['SENDGRID_USERNAME'],
295
- :password => ENV['SENDGRID_PASSWORD'],
296
- :domain => 'heroku.com'
297
- }
298
- #<<<<<< EDIT <<<<<<<<<<<<
299
-
300
- # EDIT: config/environments/test.rb >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
301
- # ADD: following AFTER the final config.action_xxxxx stuff >>>>>>>>>>>>>>>>
302
- # devise says to define default url
303
- config.action_mailer.default_url_options = { :host => "www.example.com" }
304
- #<<<<<< EDIT <<<<<<<<<<<<
305
-
306
- # set up scopes for devise
307
- # EDIT: app/models/user.rb >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
308
- # add confirmable to line 4
309
- devise :database_authenticatable, :registerable, :confirmable,
310
- #<<<< EDIT <<<<<<<<<<<<<<<<<
311
-
312
- # EDIT: db/migrate/xxxxxxx_devise_create_users.rb >>>>>>>>>>>>>>>>>>>>>>>>>
313
- # uncomment the confirmable section, it will then look as follows:
314
-
315
- ## Confirmable
316
- t.string :confirmation_token
317
- t.datetime :confirmed_at
318
- t.datetime :confirmation_sent_at
319
- t.string :unconfirmed_email # Only if using reconfirmable
320
-
321
- # and uncomment the confirmation_token index line
322
- add_index :users, :confirmation_token, :unique => true
323
-
324
- #<<<< EDIT <<<<<<<<<<<<<<<<<
325
-
326
- # EDIT: config/initializers/devise.rb >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
327
- # change mailer_sender to be your from: email address
328
- config.mailer_sender = "my-email@simple-milia-app.com"
329
-
330
- # locate and uncomment the following lines:
331
- config.pepper = '46f2....'
332
- config.confirmation_keys = [ :email ]
333
- config.email_regexp = /\A[^@]+@[^@]+\z/
334
-
335
- #<<<< EDIT <<<<<<<<<<<<<<<<<
336
-
337
- # run the migration
338
- $ rake db:migrate
339
-
340
- # CHECK-OUT: check things out at browser before proceeding
341
- # stop/restart foreman
342
- # ^c stops foreman; foreman start restarts it; F5 refreshes the browser page
343
-
344
- # customize login screen
345
- # generate the sign-in/sign-out layout:
346
-
347
- $ rails g web_app_theme:theme sign --layout-type=sign --theme="red" --engine=haml --app-name="Simple Milia App"
348
-
349
- # EDIT: config/application.rb >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
350
- # NOTE: please see details and cautions at:
351
- # http://guides.rubyonrails.org/asset_pipeline.html
352
- # Section 4.1 Precompiling Assets
353
-
354
- # uncomment the config.time_zone line and set it to your timezone
355
- config.time_zone = 'Pacific Time (US & Canada)'
356
-
357
- # IF: you will be deploying production on heroku, then
358
- # ADD: following AFTER the config.time_zone line >>>>>>>>>>>>>>>>>>>>>>>>>>>
359
- # For faster asset precompiles, you can partially load your application.
360
- # In that case, templates cannot see application objects or methods.
361
- # Heroku requires this to be false.
362
- config.assets.initialize_on_precompile = false
363
- #<<<<<< ADD <<<<<<<<<<<<
364
-
365
- # change the layout for sign-in/sign-up
366
- # by adding the following into the class .... end block
367
-
368
- config.to_prepare do
369
- Devise::SessionsController.layout "sign"
370
- Devise::RegistrationsController.layout "sign"
371
- Devise::ConfirmationsController.layout "sign"
372
- Devise::PasswordsController.layout "sign"
373
- end
374
- #<<<< EDIT <<<<<<<<<<<<<<<<<
375
-
376
- # if we use devise to gen the views, they'll be genned in erb and
377
- # a different format from the layout style we're using.
378
- # my web_app_theme has a generator to gen them automagically
379
- $ rails g web_app_theme:devise
380
-
381
- # EDIT: app/controllers/application_controller.rb >>>>>>>>>>>>>>>>>>>>>
382
- # NOTE: this line is only for the basic devise (no milia) version;
383
- # we will later uncomment or remove this line when we install milia
384
- # ADD following lines immediately after line 4 protect_from_forgery ...
385
- before_action :authenticate_user!
386
- #<<<< EDIT <<<<<<<<<<<<<<<<<
387
-
388
- # EDIT: app/controllers/home_controller.rb
389
- # ADD immediately after line 1 class HomeController
390
- skip_before_action :authenticate_user!, :only => [ :index ]
391
- #<<<< EDIT <<<<<<<<<<<<<<<<<
392
-
393
- # CHECK-OUT:
394
- # http://localhost:3000/users/sign_in
395
- # to view the sign-in form
396
- # then click SIGN UP and view the sign-up form
397
-
398
- # *********************************************************************
399
- # STEP 4 - TEST devise SIGN UP, ACTIVATION, SIGN IN, SIGN OUT
400
- # *********************************************************************
401
- # NOTE: we will later DELETE all users added in this manner BEFORE we
402
- # install milia. Reason is because currently there is no tenanting.
403
- # DO NOT TRY TO LATER MANUALLY ATTEMPT TO CONVERT THESE INITIAL USERS
404
- # TO A TENANTING MODEL: it is poor software practice to do that.
405
- # you are just testing and verifying that we've got devise up and enabled.
406
- # *********************************************************************
407
-
408
- # CHECK-OUT:
409
- # sign up as a new user,
410
- # the log file will show that an email was sent
411
- # together with the activation code & URL
412
- # and if your email/password are correct, an email should have been sent as well!
413
- # copy & paste this address as-is into the browser address area & go to it to activate
414
- # it will take you to a sign in screen; sign in
415
- # REFRESH index page (to refresh the logout validity token)
416
- # sign out
417
- # sign in again as the user
418
-
419
- # *********************************************************************
420
- # STEP 5 - adding in milia and making multi-tenantable
421
- # *********************************************************************
422
- # remove any users created above in STEP 4
423
- # start the rails console
424
- $ rail c
425
- > User.all.each{|x| x.destroy}
426
- > exit
427
-
428
- # rollback the initial migration (because we'll be changing it slightly)
429
- $ rake db:rollback
430
-
431
- # Milia expects a user session, so please set one up
432
- # EDIT: Gemfile
433
- # ADD
434
- gem 'activerecord-session_store', github: 'rails/activerecord-session_store'
435
- #<<<< EDIT <<<<<<<<<<<<<<<<<
436
-
437
- # BUNDLE install to get the new gems
438
- $ bundle install
439
-
440
- # now generate the session migration
441
- $ rails g active_record:session_migration
442
-
443
- # EDIT: db/migrate/xxxxxxx_devise_create_users.rb >>>>>>>>>>>>>>>>>>>>>>>>>
444
- # add above the t.timestamps line:
445
- # milia member_invitable
446
- t.boolean :skip_confirm_change_password, :default => false
447
-
448
- t.references :tenant
449
- #<<<< EDIT <<<<<<<<<<<<<<<<<
450
-
451
- # generate the tenant migration
452
- $ rails g model tenant tenant:references name:string:index
453
-
454
- # generate the tenants_users join table migration
455
- $ rails g migration CreateTenantsUsersJoinTable tenants users
456
-
457
- # EDIT: db/migrate/20131119092046_create_tenants_users_join_table.rb >>>>>>>>>>
458
- # then uncomment the first index line as follows:
459
- t.index [:tenant_id, :user_id]
460
- #<<<< EDIT <<<<<<<<<<<<<<<<<
461
-
462
- # EDIT: app/controllers/application_controller.rb >>>>>>>>>>>>>>>>>>>>>
463
- # NOTE: before all tenanted controllers, you MUST HAVE a
464
- # before_action :authenticate_tenant!
465
- # It is best to have it at the start of your application_controller
466
- # If you happen to have any general universal access controllers,
467
- # then you can place at the top of those specific controllers:
468
- # skip_before_action :authenticate_tenant!, :only => [ <action name> ]
469
- #
470
- # CHANGE: comment authenticate_user! line to authenticate_tenant!
471
- # (make it look like the statement below)
472
- before_action :authenticate_tenant! # authenticates user and sets up tenant
473
-
474
- # ADD following lines immediately after that: >>>>>>>>>>>>>>>>>>>>>>>>>>
475
-
476
- rescue_from ::Milia::Control::MaxTenantExceeded, :with => :max_tenants
477
- rescue_from ::Milia::Control::InvalidTenantAccess, :with => :invalid_tenant
478
- # milia defines a default max_tenants, invalid_tenant exception handling
479
- # but you can override if you wish to handle directly
480
- #<<<<<< ADD <<<<<<<<<<<<
481
-
482
- #<<<< EDIT <<<<<<<<<<<<<<<<<
483
-
484
- # EDIT: config/routes.rb >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
485
- # ADD the :controllers clause to the existing devise_for :users :
486
-
487
- as :user do # *MUST* come *BEFORE* devise's definitions (below)
488
- match '/user/confirmation' => 'milia/confirmations#update', :via => :put, :as => :update_user_confirmation
489
- end
490
-
491
- devise_for :users, :controllers => {
492
- :registrations => "milia/registrations",
493
- :confirmations => "milia/confirmations",
494
- :sessions => "milia/sessions",
495
- :passwords => "milia/passwords",
496
- }
497
-
498
- #<<<< EDIT <<<<<<<<<<<<<<<<<
499
-
500
- # EDIT: app/models/user.rb >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
501
- # ADD after the class User line:
502
- acts_as_universal_and_determines_account
503
- #<<<< EDIT <<<<<<<<<<<<<<<<<
504
-
505
-
506
- # EDIT: app/models/tenant.rb >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
507
- # DELETE
508
- belongs_to :tenant
509
-
510
- # ADD after the class Tenant line: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
511
- acts_as_universal_and_determines_tenant
512
-
513
- def self.create_new_tenant(tenant_params, coupon_params)
514
-
515
- tenant = Tenant.new(:name => tenant_params[:name])
516
-
517
- if new_signups_not_permitted?(coupon_params)
518
-
519
- raise ::Milia::Control::MaxTenantExceeded, "Sorry, new accounts not permitted at this time"
520
-
521
- else
522
- tenant.save # create the tenant
523
- end
524
- return tenant
525
- end
526
-
527
- # ------------------------------------------------------------------------
528
- # new_signups_not_permitted? -- returns true if no further signups allowed
529
- # args: params from user input; might contain a special 'coupon' code
530
- # used to determine whether or not to allow another signup
531
- # ------------------------------------------------------------------------
532
- def self.new_signups_not_permitted?(params)
533
- return false
534
- end
535
-
536
- # ------------------------------------------------------------------------
537
- # tenant_signup -- setup a new tenant in the system
538
- # CALLBACK from devise RegistrationsController (milia override)
539
- # AFTER user creation and current_tenant established
540
- # args:
541
- # user -- new user obj
542
- # tenant -- new tenant obj
543
- # other -- any other parameter string from initial request
544
- # ------------------------------------------------------------------------
545
- def self.tenant_signup(user, tenant, other = nil)
546
- # StartupJob.queue_startup( tenant, user, other )
547
- # any special seeding required for a new organizational tenant
548
- end
549
- #<<<<<< ADD <<<<<<<<<<<<
550
-
551
- #<<<< EDIT <<<<<<<<<<<<<<<<<
552
-
553
- # EDIT: app/controllers/home_controller.rb
554
- # CHANGE skip_authenticate_user! to skip_authenticate_tenant!
555
- skip_before_action :authenticate_tenant!, :only => [ :index ]
556
-
557
- # REPLACE the empty def index ... end with following ADD:
558
- # this will give you improved handling for letting user know
559
- # what is expected. If you want to have a welcome page for
560
- # signed in users, uncomment the redirect_to line, etc.
561
- def index
562
- if user_signed_in?
563
-
564
- # was there a previous error msg carry over? make sure it shows in flasher
565
- flash[:notice] = flash[:error] unless flash[:error].blank?
566
- # redirect_to( welcome_path() )
567
-
568
- else
569
-
570
- if flash[:notice].blank?
571
- flash[:notice] = "sign in if your organization has an account"
572
- end
573
-
574
- end # if logged in .. else first time
575
-
576
- end
577
- #<<<< ADD <<<<<<<<<<<<<<<<<
578
- #<<<< EDIT <<<<<<<<<<<<<<<<<
579
-
580
- # run the migration
581
- $ rake db:migrate
582
-
583
- # config/initializers/milia.rb now supported for config parameters
584
- # OPTIONAL: change milia configuration options
585
- # copy doc/milia-initializer.rb to config/initializers/
586
- # then edit values as appropriate
587
-
588
- # NOTE: if Milia.use_coupon is true (default configuration option),
589
- # then your sign up form MUST return a parameter
590
- # :coupon => { :coupon => <string> }
591
- # which can also be blank.
592
-
593
- # OPTIONAL: edit config/application.rb and add the following to alter
594
- # default behavior for handling strong_parameters in Rails
595
- # see: https://github.com/rails/strong_parameters#handling-of-unpermitted-keys
596
- # choose one of the two options: :raise OR :log
597
- ActionController::Parameters.action_on_unpermitted_parameters = :raise | :log
598
-
599
- # CHECK-OUT: restart foreman and check out at your browser:
600
- http://localhost:3000/
601
- # click sign up to sign up a new account, get confirmation email (or view in log)
602
- # activate the new account, sign in, sign out, etc.
603
-
604
-
605
- # *********************************************************************
606
- # STEP 6 - adding a tenanted members table, then inviting a member
607
- # *********************************************************************
608
- # remove any users, and tenants created above in STEP 5
609
- # start the rails console
610
- $ rails c
611
- > User.all.each{|x| x.destroy}
612
- > Tenant.all.each{|x| x.destroy}
613
- > exit
614
-
615
-
616
- $ rails g resource member tenant:references user:references first_name:string last_name:string favorite_color:string
617
-
618
- # ADD to app/models/tenant.rb
619
- has_many :members, dependent: :destroy
620
-
621
- # EDIT self.tenant_signup method
622
- # ------------------------------------------------------------------------
623
- def self.tenant_signup(user, tenant, other = nil)
624
- # StartupJob.queue_startup( tenant, user, other )
625
- # any special seeding required for a new organizational tenant
626
-
627
- Member.create_org_admin(user)
628
- end
629
-
630
-
631
- # EDIT app/models/user.rb >>>>>>>>>>>>>>>>>>>>
632
- # ADD
633
- has_one :member, :dependent => :destroy
634
- #<<<< EDIT <<<<<<<<<<<<<<<<<
635
-
636
-
637
-
638
- # EDIT app/models/member.rb
639
- # REMOVE belongs_to :tenant
640
- # ADD
641
- acts_as_tenant
642
-
643
- DEFAULT_ADMIN = {
644
- first_name: "Admin",
645
- last_name: "Please edit me",
646
- favorite_color: "blue"
647
- }
648
-
649
- def self.create_new_member(user, params)
650
- # add any other initialization for a new member
651
- return user.create_member( params )
652
- end
653
-
654
- def self.create_org_admin(user)
655
- new_member = create_new_member(user, DEFAULT_ADMIN)
656
- unless new_member.errors.empty?
657
- raise ArgumentError, new_member.errors.full_messages.uniq.join(", ")
658
- end
659
-
660
- return new_member
661
-
662
- end
663
-
664
-
665
- # EDIT: app/views/members/new.html.haml >>>>>>>>>>>>>>>>>>>>>>>>>>>>
666
- %h1 Simple Milia App
667
- .block#block-signup
668
- %h2 Invite a new member into #{@org_name}
669
- .content.login
670
- .flash
671
- - flash.each do |type, message|
672
- %div{ :class => "message #{type}" }
673
- %p= message
674
- - flash.clear # clear contents so we won't see it again
675
-
676
- = form_for(@member, :html => { :class => "form login" }) do |f|
677
- - unless @member.errors.empty? && @user.errors.empty?
678
- #errorExplanation.group
679
- %ul
680
- = @member.errors.full_messages.uniq.inject(''){|str, msg| (str << "<li> #{msg}") }.html_safe
681
- = @user.errors.full_messages.uniq.inject(''){|str, msg| (str << "<li> #{msg}") }.html_safe
682
-
683
- = fields_for( :user ) do |w|
684
- .group
685
- = w.label :email, :class => "label "
686
- = w.text_field :email, :class => "text_field"
687
- %span.description Ex. test@example.com; must be unique
688
-
689
- .group
690
- = f.label :first_name, :class => "label "
691
- = f.text_field :first_name, :class => "text_field"
692
-
693
- .group
694
- = f.label :last_name, :class => "label "
695
- = f.text_field :last_name, :class => "text_field"
696
-
697
- .group
698
- = f.label :favorite_color, :class => "label "
699
- = f.text_field :favorite_color, :class => "text_field"
700
- %span.description What is your favorite color?
701
-
702
- .group.navform.wat-cf
703
- %button.button{ :type => "submit" }
704
- = image_tag "web-app-theme/icons/key.png"
705
- Create user and invite
706
- #<<<< ADD <<<<<<<<<<<<<<<<<
707
- #<<<< EDIT <<<<<<<<<<<<<<<<<
708
-
709
- # EDIT app/controllers/application_controller.rb
710
- # ADD:
711
- before_action :prep_org_name
712
-
713
- private
714
-
715
- # org_name will be passed to layout & view
716
- def prep_org_name()
717
- @org_name = ( user_signed_in? ?
718
- Tenant.current_tenant.name :
719
- "Simple Milia App"
720
- )
721
-
722
- end
723
-
724
- # EDIT app/views/layouts/application.rb >>>>>>>>>>>>>>>>>>>>
725
- # the following is not a requirement, but serves to show
726
- # how to handle tenanted sign ins and welcome pages
727
- # replaces the two instances of "Simple Milia App" with
728
- # (everything bewtween the quotes but not including the quotes):
729
- # "= @org_name", make the results look like the two lines below
730
-
731
- %title= @org_name
732
-
733
- = link_to @org_name, "/"
734
-
735
- # make changes to layout for invite member; change the portion
736
- # with the "sign_up" link to look like the following:
737
- %li
738
- - if user_signed_in?
739
- = link_to t("web-app-theme.invite", :default => "Invite member"), new_member_path
740
- - else
741
- = link_to( t("web-app-theme.signup", :default => "Sign up"), new_user_registration_path )
742
-
743
- #<<<< EDIT <<<<<<<<<<<<<<<<<
744
-
745
- # EDIT: app/controllers/members_controller.rb >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
746
-
747
- # ADD after the class line: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
748
-
749
- layout "sign", :only => [:new, :edit, :create]
750
-
751
- def new()
752
- @member = Member.new()
753
- @user = User.new()
754
- end
755
-
756
- def create()
757
- @user = User.new( user_params )
758
-
759
- # ok to create user, member
760
- if @user.save_and_invite_member() && @user.create_member( member_params )
761
- flash[:notice] = "New member added and invitation email sent to #{@user.email}."
762
- redirect_to root_path
763
- else
764
- flash[:error] = "errors occurred!"
765
- @member = Member.new( member_params ) # only used if need to revisit form
766
- render :new
767
- end
768
-
769
- end
770
-
771
-
772
- private
773
-
774
- def member_params()
775
- params.require(:member).permit(:first_name, :last_name, :favorite_color)
776
- end
777
-
778
- def user_params()
779
- params.require(:user).permit(:email, :password, :password_confirmation)
780
- end
781
-
782
- #<<<< ADD <<<<<<<<<<<<<<<<<
783
- #<<<< EDIT <<<<<<<<<<<<<<<<<
784
-
785
-
786
- # run the migration
787
- $ rake db:migrate
788
-
789
- # CHECK-OUT: check things out at browser before proceeding
790
- # stop/restart foreman
791
- # you will have to first sign-up, confirm, then you can invite_member
792
- # sign-out, confirm new member, etc
793
-
794
- # MILIA API EXPLAINED: Tenant.current_tenant, etc
795
-
796
- # from controller-level:
797
-
798
- set_current_tenant( tenant_id )
799
- raise InvalidTenantAccess unless tenant_id is one of the current_user valid tenants
800
-
801
- # from model-level:
802
- Tenant.current_tenant -- return tenant object for the current tenant; nil if none
803
-
804
- Tenant.current_tenant_id -- returns tenant_id for the current tenant; nil if none
805
-
806
- # from background job s (only at the start of the task);
807
- # tenant can either be a tenant object or an integer tenant_id; anything else will raise
808
- # exception
809
- # set_current_tenant -- model-level ability to set the current tenant
810
- # NOTE: *USE WITH CAUTION* normally this should *NEVER* be done from
811
- # the models ... it is only useful and safe WHEN performed at the start
812
- # of a background job (DelayedJob#perform)
813
-
814
- Tenant.set_current_tenant( tenant )
815
- raise ArgumentError, "invalid tenant object or id"
816
-