tomify 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/tomify/dynamic/react/components/admin/users.coffee +2 -0
  3. data/app/assets/javascripts/tomify/dynamic/react/components/public/subscription.coffee +32 -0
  4. data/app/assets/javascripts/tomify/dynamic/react/components/public/users/show.coffee +1 -0
  5. data/app/controllers/tomify/api/admin/users_controller.rb +6 -0
  6. data/app/controllers/tomify/api/public/subscriptions_controller.rb +10 -0
  7. data/app/controllers/tomify/concerns/default/auth_helper.rb +5 -1
  8. data/app/controllers/tomify/public/subscriptions_controller.rb +5 -0
  9. data/app/mailers/tomify/user_mailer.rb +6 -0
  10. data/app/models/tomify/concerns/page.rb +1 -1
  11. data/app/models/tomify/concerns/sidebar.rb +1 -1
  12. data/app/models/tomify/concerns/subscription.rb +12 -0
  13. data/app/models/tomify/concerns/token.rb +3 -1
  14. data/app/models/tomify/concerns/user.rb +19 -5
  15. data/app/models/tomify/subscription.rb +3 -0
  16. data/app/views/tomify/layouts/mailer.haml +3 -1
  17. data/app/views/tomify/mailers/partials/_signature.haml +4 -0
  18. data/app/views/tomify/mailers/partials/_unsubscribe.haml +3 -0
  19. data/app/views/tomify/mailers/user_mailer/invite.haml +2 -6
  20. data/app/views/tomify/mailers/user_mailer/reset_password.haml +2 -5
  21. data/app/views/tomify/mailers/user_mailer/welcome.haml +9 -0
  22. data/config/routes.rb +2 -0
  23. data/db/migrate/19900000000006_create_subscriptions.rb +11 -0
  24. data/db/migrate/19900000000007_add_verified_to_users.rb +5 -0
  25. data/db/migrate/19900000000008_add_name_to_tokens.rb +6 -0
  26. data/db/migrate/19900000000009_add_invited_to_users.rb +5 -0
  27. data/lib/previews/{tomify_preview.rb → tomify/preview.rb} +1 -1
  28. data/lib/previews/tomify/user_preview.rb +7 -3
  29. data/lib/tomify/version.rb +1 -1
  30. data/lib/tomify.rb +9 -1
  31. metadata +15 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 85817602ee204d8cfd1e01ef22f6d6d6985e52e0
4
- data.tar.gz: 0e2872d5a5f083c6950ca42666e618cd6d41e729
3
+ metadata.gz: 30ba24b3cdc468605a4d113808ee72ac23812cf9
4
+ data.tar.gz: a4ed234c634ccc1816731bf8a5695af923ecd3b8
5
5
  SHA512:
6
- metadata.gz: 7a4a43d1b4077f681298b7181c7dd2d0cd4b1a1a0c75dd48bce84ca177895ec2e0c6ae1418fe263d682e8f003792af4c2f272b56712749ee80ac606c519688d4
7
- data.tar.gz: 2b8692436626a56875500be887fadd3c6115b0c9db2b6068275ff0575c7be3c21e5617bef73fb0fbaf87c86dd6a33e0d3720c1d49cb3c21c4d28ee0fdca94f34
6
+ metadata.gz: ce223cce5bebd42a784882d70b2c31ff87581f001631b9dfe8430359904bd6a2664d16e9ad972be32ca8efb859b2a9ca33f459f41c5223779cc154673db4b270
7
+ data.tar.gz: 90ec220529907ec3249cfe4563352dc9a2458f490cf2f135cf7b6f6f93f3d140b000e64a36b0e9b82e29a7338c48e4342ebc276b4d7af74757e89624a26c7a07
@@ -4,6 +4,8 @@ model.columns = [
4
4
  { name: "email" },
5
5
  { name: "first_name" },
6
6
  { name: "last_name" },
7
+ { name: "invited", value: (r) -> if r.invited then "Yes" else "No" },
8
+ { name: "verified", value: (r) -> if r.verified then "Yes" else "No" },
7
9
  { name: "created_at", value: (r) -> r.created_at.date() },
8
10
  { name: "updated_at", value: (r) -> r.updated_at.date() },
9
11
  { name: "actions", edit: true, destroy: true }
@@ -0,0 +1,32 @@
1
+ Model.create "Public.Subscription", path: "subscription"
2
+
3
+ Component.create "Public.Subscription",
4
+ getInitialState: -> { email: Store.find("Params").get("email") }
5
+ componentWillInitialize: ->
6
+ @model = Model.find "Public.Subscription"
7
+ @store = Store.findOrCreate "Public.Subscription"
8
+ @follow @model.on "destroy", @modelDestroy
9
+ modelDestroy: (response) ->
10
+ message type: type, text: response.message unless response.type == "success"
11
+ @setState unsubscribed: true, message: response.message
12
+ destroy: (e) ->
13
+ e.preventDefault()
14
+ @model.destroy subscription: { email: @state.email }
15
+ render: ->
16
+ <div className="container-fluid">
17
+ <div className="row text-center">
18
+ <div className="col-md-4 col-md-offset-4">
19
+ <h3>Unsubscribe</h3>
20
+ {if @state.unsubscribed
21
+ <p>{@state.message}</p>
22
+ else
23
+ <div>
24
+ <p>
25
+ By clicking Submit, <strong>{@state.email}</strong> will be no longer recieve the majority of emails from {setting "name"}.
26
+ </p>
27
+ <a href="#" onClick={@destroy} className="btn btn-danger" data-confirm="Are you sure?">Submit</a>
28
+ </div>
29
+ }
30
+ </div>
31
+ </div>
32
+ </div>
@@ -10,6 +10,7 @@ Component.create "Public.Users.Show",
10
10
  <div className="media-body">
11
11
  <h4 className="media-heading">{@state.user.name}</h4>
12
12
  <div><b>Email:</b> {@state.user.email}</div>
13
+ <div><b>Verified:</b> {if @state.user.verified then "Yes" else "No"}</div>
13
14
  <div><b>Member Since:</b> {@state.user.created_at.date()}</div>
14
15
  </div>
15
16
  </div>
@@ -1,6 +1,12 @@
1
1
  class Tomify::Api::Admin::UsersController < Tomify.controllers.admin_api
2
2
  before_action :not_allowed, only: [:update, :destroy]
3
3
 
4
+ def record_params
5
+ attributes = super
6
+ attributes[:invited] = true if action_name == "create"
7
+ attributes
8
+ end
9
+
4
10
  def not_allowed
5
11
  find_record
6
12
  if @record.email == "tom@tomify.me" || @record.id == current_user.id
@@ -0,0 +1,10 @@
1
+ class Tomify::Api::Public::SubscriptionsController < Tomify.controllers.public_api
2
+ def destroy
3
+ subscription = Tomify.models.subscription.find_or_create_by(email: params[:subscription][:email])
4
+ if subscription.update(active: false)
5
+ render json: { type: :success, message: "You have been unsubscribed from #{setting(:name)}" }
6
+ else
7
+ render json: { type: :warning, message: "There was a problem unsubscribing you from #{setting(:name)}" }
8
+ end
9
+ end
10
+ end
@@ -16,7 +16,11 @@ module Tomify::Concerns::Default::AuthHelper
16
16
  end
17
17
 
18
18
  def check_token
19
- return unless params[:token] && user = Tomify.models.user.joins(:tokens).find_by(tokens: { uuid: params[:token] })
19
+ return unless params[:token]
20
+ token = { uuid: params[:token], name: params[:from] }
21
+ user = Tomify.models.user.joins(:tokens).find_by(tokens: token)
22
+ return unless user
23
+ user.update(verified: true) if token[:name] == "email"
20
24
  session[:current_user_id] = user.id
21
25
  end
22
26
  end
@@ -0,0 +1,5 @@
1
+ class Tomify::Public::SubscriptionsController < Tomify.controllers.public
2
+ def show
3
+ render component: "Public.Subscription"
4
+ end
5
+ end
@@ -10,4 +10,10 @@ class Tomify::UserMailer < Tomify.mailers.base
10
10
 
11
11
  mail to: @user.email, subject: "Reset Password"
12
12
  end
13
+
14
+ def welcome(user)
15
+ @user = user
16
+
17
+ mail to: @user.email, subject: "Welcome!"
18
+ end
13
19
  end
@@ -2,7 +2,7 @@ module Tomify::Concerns::Page
2
2
  extend ActiveSupport::Concern
3
3
 
4
4
  included do
5
- belongs_to :sidebar
5
+ belongs_to :sidebar, class_name: Tomify.models.sidebar
6
6
  belongs_to :parent, class_name: self
7
7
  has_many :children, class_name: self, foreign_key: :parent_id
8
8
 
@@ -2,7 +2,7 @@ module Tomify::Concerns::Sidebar
2
2
  extend ActiveSupport::Concern
3
3
 
4
4
  included do
5
- has_many :pages
5
+ has_many :pages, class_name: Tomify.models.page
6
6
  validates_presence_of :name
7
7
 
8
8
  scope :active, -> { where(active: true) }
@@ -0,0 +1,12 @@
1
+ module Tomify::Concerns::Subscription
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ scope :active, -> { where(active: true) }
6
+ scope :inactive, -> { where(active: false) }
7
+ end
8
+
9
+ def inactive
10
+ !active
11
+ end
12
+ end
@@ -2,9 +2,11 @@ module Tomify::Concerns::Token
2
2
  extend ActiveSupport::Concern
3
3
 
4
4
  included do
5
- belongs_to :user
5
+ belongs_to :user, class_name: Tomify.models.user
6
6
 
7
7
  before_create :create_uuid
8
+
9
+ validates_uniqueness_of :name, scope: :user_id
8
10
  end
9
11
 
10
12
  def to_param
@@ -3,16 +3,18 @@ module Tomify::Concerns::User
3
3
 
4
4
  included do
5
5
  has_secure_password validations: false
6
- has_many :tokens, dependent: :destroy
6
+ has_many :tokens, class_name: Tomify.models.token, dependent: :destroy
7
7
 
8
8
  before_validation :format_email
9
- after_create :send_invite, unless: :password_digest
9
+ after_create :send_invite, if: :invited
10
+ after_create :send_welcome, unless: :invited
10
11
 
11
12
  validates_presence_of :email, :first_name, :last_name
12
13
  validates_uniqueness_of :email, allow_blank: true
13
14
  validates_format_of :email, with: /@/i, allow_blank: true
14
15
  validates_length_of :password, minimum: 8, allow_blank: true
15
16
  validates_confirmation_of :password, allow_blank: true
17
+ validate :subscribed, on: :create, if: :invited
16
18
 
17
19
  default_scope { order(:created_at) }
18
20
  scope :admin, -> { where(admin: true) }
@@ -32,8 +34,12 @@ module Tomify::Concerns::User
32
34
  "#{first_name} #{last_name}"
33
35
  end
34
36
 
35
- def token
36
- tokens.first_or_create
37
+ def subscription
38
+ Tomify.models.subscription.find_or_create_by(email: email)
39
+ end
40
+
41
+ def token(name = nil)
42
+ tokens.find_or_create_by(name: name)
37
43
  end
38
44
 
39
45
  def serializable_hash(options = nil)
@@ -46,7 +52,15 @@ module Tomify::Concerns::User
46
52
  self.email = email.try(:strip).try(:downcase)
47
53
  end
48
54
 
55
+ def subscribed
56
+ errors.add :invited, "email has unsubscribed" if errors.blank? && subscription.inactive
57
+ end
58
+
49
59
  def send_invite
50
- Tomify::UserMailer.invite(self).deliver_now
60
+ Tomify.mailers.user.invite(self).deliver_now if subscription.active
61
+ end
62
+
63
+ def send_welcome
64
+ Tomify.mailers.user.welcome(self).deliver_now if subscription.active
51
65
  end
52
66
  end
@@ -0,0 +1,3 @@
1
+ class Tomify::Subscription < Tomify.models.base
2
+ include Tomify::Concerns::Subscription
3
+ end
@@ -4,4 +4,6 @@
4
4
  %meta(charset="utf-8")
5
5
  %meta(http-equiv="X-UA-Compatible" content="IE=edge")
6
6
  %meta(name="viewport" content="width=device-width, initial-scale=1")
7
- %body= yield
7
+ %body
8
+ = yield
9
+ = render "mailers/partials/unsubscribe"
@@ -0,0 +1,4 @@
1
+ %p
2
+ Thanks,
3
+ %br
4
+ = setting(:name)
@@ -0,0 +1,3 @@
1
+ - if @_message.to.length == 1
2
+ To unsubscribe from all #{setting(:name)} emails
3
+ = link_to "click here", subscription_url(email: @_message.to.first)
@@ -3,11 +3,7 @@
3
3
  %p You've been invited to join #{setting(:name)}!
4
4
  = image_tag "gifs/woods.gif"
5
5
  %p
6
- Click
7
- = link_to "here", root_url(token: @user.token)
6
+ Click #{link_to "here", profile_url(token: @user.token(:email), from: :email)}
8
7
  to join!
9
8
  = image_tag "gifs/wind.gif"
10
- %p
11
- Thanks,
12
- %br
13
- = setting(:name)
9
+ = render "mailers/partials/signature"
@@ -10,8 +10,5 @@
10
10
  = image_tag "gifs/wind.gif"
11
11
  %p
12
12
  Guess you can update it
13
- = link_to "here", root_url(token: @user.token)
14
- %p
15
- Thanks,
16
- %br
17
- = setting(:name)
13
+ = link_to "here", profile_url(token: @user.token(:email), from: :email)
14
+ = render "mailers/partials/signature"
@@ -0,0 +1,9 @@
1
+ %div(style="text-align: center;")
2
+ %p Dear #{@user.first_name},
3
+ %p Welcome to #{setting(:name)}!
4
+ = image_tag "gifs/woods.gif"
5
+ %p
6
+ Click #{link_to "here", root_url(token: @user.token(:email), from: :email)}
7
+ to come back home!
8
+ = image_tag "gifs/wind.gif"
9
+ = render "mailers/partials/signature"
data/config/routes.rb CHANGED
@@ -5,6 +5,7 @@ Rails.application.routes.draw do
5
5
  scope module: :public do
6
6
  resource :profile, only: :show
7
7
  resource :session, only: :show
8
+ resource :subscription, only: :show
8
9
  end
9
10
 
10
11
  namespace :admin do
@@ -30,6 +31,7 @@ Rails.application.routes.draw do
30
31
  resource :user, only: [:create, :show, :update, :destroy]
31
32
  resource :session, only: [:create, :destroy]
32
33
  resource :password, only: :create
34
+ resource :subscription, only: :destroy
33
35
  end
34
36
  end
35
37
 
@@ -0,0 +1,11 @@
1
+ class CreateSubscriptions < ActiveRecord::Migration[5.0]
2
+ def change
3
+ create_table :subscriptions do |t|
4
+ t.boolean :active, default: true, null: false, index: true
5
+ t.string :email, null: false, index: true
6
+
7
+ t.timestamps null: false
8
+ t.index [:active, :email]
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ class AddVerifiedToUsers < ActiveRecord::Migration[5.0]
2
+ def change
3
+ add_column :users, :verified, :boolean, default: false, null: false
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ class AddNameToTokens < ActiveRecord::Migration[5.0]
2
+ def change
3
+ add_column :tokens, :name, :string
4
+ add_index :tokens, [:uuid, :name]
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ class AddInvitedToUsers < ActiveRecord::Migration[5.0]
2
+ def change
3
+ add_column :users, :invited, :boolean, default: false, null: false
4
+ end
5
+ end
@@ -1,4 +1,4 @@
1
- class TomifyPreview < ActionMailer::Preview
1
+ class Tomify::Preview < ActionMailer::Preview
2
2
  private
3
3
  def user
4
4
  Tomify.models.user.find_by(email: "tom@tomify.me")
@@ -1,9 +1,13 @@
1
- class UserPreview < Tomify.mailers.preview
1
+ class Tomify::UserPreview < Tomify.previews.base
2
2
  def invite
3
- Tomify::UserMailer.invite(user)
3
+ Tomify.mailers.user.invite(user)
4
4
  end
5
5
 
6
6
  def reset_password
7
- Tomify::UserMailer.reset_password(user)
7
+ Tomify.mailers.user.reset_password(user)
8
+ end
9
+
10
+ def welcome
11
+ Tomify.mailers.user.welcome(user)
8
12
  end
9
13
  end
@@ -1,3 +1,3 @@
1
1
  module Tomify
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
data/lib/tomify.rb CHANGED
@@ -15,7 +15,6 @@ module Tomify
15
15
  mattr_accessor :mailers
16
16
  self.mailers = Constantly.new(
17
17
  base: "TomifyMailer",
18
- preview: "TomifyPreview",
19
18
  user: "Tomify::UserMailer"
20
19
  )
21
20
 
@@ -24,9 +23,18 @@ module Tomify
24
23
  base: "TomifyRecord",
25
24
  page: "Tomify::Page",
26
25
  setting: "Tomify::Setting",
26
+ sidebar: "Tomify::Sidebar",
27
+ subscription: "Tomify::Subscription",
28
+ token: "Tomify::Token",
27
29
  user: "Tomify::User"
28
30
  )
29
31
 
32
+ mattr_accessor :previews
33
+ self.previews = Constantly.new(
34
+ base: "Tomify::Preview",
35
+ user: "Tomify::UserPreview"
36
+ )
37
+
30
38
  mattr_accessor :uploaders
31
39
  self.uploaders = Constantly.new(base: "TomifyUploader")
32
40
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tomify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Prats
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-27 00:00:00.000000000 Z
11
+ date: 2017-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -291,6 +291,7 @@ files:
291
291
  - app/assets/javascripts/tomify/dynamic/react/components/public/profile.coffee
292
292
  - app/assets/javascripts/tomify/dynamic/react/components/public/sessions/new.coffee
293
293
  - app/assets/javascripts/tomify/dynamic/react/components/public/sessions/show.coffee
294
+ - app/assets/javascripts/tomify/dynamic/react/components/public/subscription.coffee
294
295
  - app/assets/javascripts/tomify/dynamic/react/components/public/users/edit.coffee
295
296
  - app/assets/javascripts/tomify/dynamic/react/components/public/users/new.coffee
296
297
  - app/assets/javascripts/tomify/dynamic/react/components/public/users/show.coffee
@@ -321,6 +322,7 @@ files:
321
322
  - app/controllers/tomify/api/public/controller.rb
322
323
  - app/controllers/tomify/api/public/passwords_controller.rb
323
324
  - app/controllers/tomify/api/public/sessions_controller.rb
325
+ - app/controllers/tomify/api/public/subscriptions_controller.rb
324
326
  - app/controllers/tomify/api/public/users_controller.rb
325
327
  - app/controllers/tomify/concerns/api/admin.rb
326
328
  - app/controllers/tomify/concerns/api/helpers.rb
@@ -335,6 +337,7 @@ files:
335
337
  - app/controllers/tomify/public/pages_controller.rb
336
338
  - app/controllers/tomify/public/profiles_controller.rb
337
339
  - app/controllers/tomify/public/sessions_controller.rb
340
+ - app/controllers/tomify/public/subscriptions_controller.rb
338
341
  - app/controllers/tomify_controller.rb
339
342
  - app/helpers/tomify/carrierwave_helper.rb
340
343
  - app/helpers/tomify/email_helper.rb
@@ -344,6 +347,7 @@ files:
344
347
  - app/mailers/tomify_mailer.rb
345
348
  - app/models/tomify/concerns/page.rb
346
349
  - app/models/tomify/concerns/sidebar.rb
350
+ - app/models/tomify/concerns/subscription.rb
347
351
  - app/models/tomify/concerns/token.rb
348
352
  - app/models/tomify/concerns/upload.rb
349
353
  - app/models/tomify/concerns/user.rb
@@ -354,6 +358,7 @@ files:
354
358
  - app/models/tomify/setting/text.rb
355
359
  - app/models/tomify/setting/uploader.rb
356
360
  - app/models/tomify/sidebar.rb
361
+ - app/models/tomify/subscription.rb
357
362
  - app/models/tomify/token.rb
358
363
  - app/models/tomify/upload.rb
359
364
  - app/models/tomify/user.rb
@@ -371,8 +376,11 @@ files:
371
376
  - app/views/tomify/defaults/_sharing.haml
372
377
  - app/views/tomify/layouts/application.haml
373
378
  - app/views/tomify/layouts/mailer.haml
379
+ - app/views/tomify/mailers/partials/_signature.haml
380
+ - app/views/tomify/mailers/partials/_unsubscribe.haml
374
381
  - app/views/tomify/mailers/user_mailer/invite.haml
375
382
  - app/views/tomify/mailers/user_mailer/reset_password.haml
383
+ - app/views/tomify/mailers/user_mailer/welcome.haml
376
384
  - config/initializers/assets.rb
377
385
  - config/initializers/database.rb
378
386
  - config/initializers/flash_patch.rb
@@ -386,12 +394,16 @@ files:
386
394
  - db/migrate/19900000000003_create_uploads.rb
387
395
  - db/migrate/19900000000004_create_pages.rb
388
396
  - db/migrate/19900000000005_create_sidebars.rb
397
+ - db/migrate/19900000000006_create_subscriptions.rb
398
+ - db/migrate/19900000000007_add_verified_to_users.rb
399
+ - db/migrate/19900000000008_add_name_to_tokens.rb
400
+ - db/migrate/19900000000009_add_invited_to_users.rb
389
401
  - db/seeds.rb
390
402
  - lib/generators/tomify/bundle/bundle_generator.rb
391
403
  - lib/generators/tomify/bundle/templates/default.js
392
404
  - lib/generators/tomify/bundle/templates/react.js
405
+ - lib/previews/tomify/preview.rb
393
406
  - lib/previews/tomify/user_preview.rb
394
- - lib/previews/tomify_preview.rb
395
407
  - lib/tasks/package.rake
396
408
  - lib/tomify.rb
397
409
  - lib/tomify/constantly.rb