maily 0.3.5 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d4dc5bfc8c0387e53578ab0b5324f1f50d184ac8
4
- data.tar.gz: 10d08a1155c7e3e4e1719282c864294b037c5d40
3
+ metadata.gz: de8e4fc672413008f9fba27e3bd37063f544035a
4
+ data.tar.gz: e4e16a797ec0e23dcfd8aefa73f04b6343f95a7b
5
5
  SHA512:
6
- metadata.gz: 9972a049fd991c8ac044e6d25621975b8125becc783a7a78d619267f33b617111aaf7194000531cc7230908277f793aea7674fb6e7594b29591b0712a502db6d
7
- data.tar.gz: 38d7d037c52e6bec3bf7bfcef49b14727bbe21d63e5849a6277e15f6aef8a3a04733b53eae23184745f7b5e5565135eb7a7f1fabcc5ce727c77aaab82a61964a
6
+ metadata.gz: d01ba2a9b7c0433dd369d32ec26da9ebc86922caca2aae774bf9fa01d199c91aa82c1b5f584dbbb8fcc58c5f1af245b5d688d868212e3db8acb40cd05103f181
7
+ data.tar.gz: 9ea9c77b7bb632d0c279cbf788ad9f44b476ade72f3289f09abade83de6d4a693ff7ad63b64c25ed669bd740a591cd631b20647b3fa992010b2cd3d00b51b5dc
data/README.md CHANGED
@@ -13,7 +13,7 @@ Maily is a Rails Engine to preview, follow up, test and edit the emails of your
13
13
  * Template edition
14
14
  * Email delivery
15
15
  * Features configurables per environment
16
- * Customizable parent controller (define permissions in your own controller)
16
+ * Flexible authorization
17
17
  * Minimalistic interface (thanks to [@gnatok](https://github.com/gnatok))
18
18
  * Easy way (named hooks) to define data for emails
19
19
  * Generator to handle a comfortable installation
@@ -21,6 +21,7 @@ Maily is a Rails Engine to preview, follow up, test and edit the emails of your
21
21
  ![](screenshot.png)
22
22
 
23
23
  ## Installation
24
+
24
25
  Add this line to you Gemfile:
25
26
 
26
27
  ```
@@ -40,41 +41,48 @@ This installator makes some tasks for you:
40
41
  * Adds a file (into `lib/maily_hooks.rb`) to define hooks
41
42
 
42
43
  ## Initialization and configuration
43
- You should configure Maily via this initializer. You can set these options per environment:
44
+
45
+ You should configure Maily via the initializer. You can set these options per environment:
44
46
 
45
47
  ```ruby
46
- Maily.enabled = ENV['MAILY_ENABLED']
48
+ Maily.enabled = ENV['MAILY_ENABLED']
49
+
50
+ Maily.enabled = Rails.env.production? ? false : true
47
51
  ```
48
52
 
49
- This is a sample of the file with the full list of options:
53
+ Initializer sample (full options list):
50
54
 
51
- ```ruby
55
+ ```ruby
52
56
  # config/initializers/maily.rb
53
57
  Maily.setup do |config|
54
- # Enable/disable engine
58
+ # On/off engine
55
59
  # config.enabled = Rails.env.production? ? false : true
56
60
 
57
- # Allow to edit templates
61
+ # Allow templates edition
58
62
  # config.allow_edition = Rails.env.production? ? false : true
59
63
 
60
64
  # Allow deliveries
61
65
  # config.allow_delivery = Rails.env.production? ? false : true
62
66
 
63
- # Define I18n available locales
67
+ # I18n.available_locales by default
64
68
  # config.available_locales = [:en, :es, :pt, :fr]
65
69
 
66
- # Define parent controller. Allow to run engine under a custom controller
70
+ # Run maily under different controller ('ActionController::Base' by default)
67
71
  # config.base_controller = '::AdminController'
72
+
73
+ # Http basic authentication (nil by default)
74
+ # config.http_authorization = { username: 'admin', password: 'secret' }
68
75
  end
69
76
  ```
70
77
 
71
78
  ### Templates edition (`allow_edition` option)
79
+
72
80
  This feature was designed for `development` environment. Since it's just a file edition and running `production` mode, code is not reloaded between requests, Rails doesn't take in account this change (without restarting the server). Also, allow arbitrary ruby code evaluation is potentially dangerous, that's not a good idea for `production`.
73
81
 
74
82
  So, templates edition is not allowed running `production` mode.
75
83
 
76
-
77
84
  ## Hooks
85
+
78
86
  Most of emails need to populate data to consume it and do intersting things. Hooks are used to define this data with a little DSL. Example:
79
87
 
80
88
  ```ruby
@@ -101,15 +109,16 @@ Maily.hooks_for('YourMailerClass') do |mailer|
101
109
  end
102
110
  ```
103
111
 
104
- ## Customize Authorization
105
- By default `Maily` runs under `ActionController::Base`, but you are able to customize that parent controller (`Maily.base_controller` option) in order to achieve (using `before_action`) a kind of access control. For example, set a different base controller:
112
+ ## Authorization
113
+
114
+ Basically, you have 2 ways to restrict the access to `Maily`.
115
+
116
+ ### Custom base controller
117
+
118
+ By default `Maily` runs under `ActionController::Base`, but you are able to customize that parent controller (`Maily.base_controller` option) in order to achieve (using `before_action`) a kind of access control system. For example, set a different base controller:
106
119
 
107
120
  ```ruby
108
- Maily.setup do |config|
109
- ...
110
- config.base_controller = '::AdminController'
111
- ...
112
- end
121
+ Maily.base_controller = '::AdminController'
113
122
  ```
114
123
 
115
124
  And write your own authorization rules in the defined `base_controller`:
@@ -126,10 +135,20 @@ class AdminController < ActionController::Base
126
135
  end
127
136
  ```
128
137
 
138
+ ### HTTP basic authentication
139
+
140
+ You can also authorize yours users via HTTP basic authentication, simply use this option:
141
+
142
+ ```ruby
143
+ Maily.http_authorization = { username: 'admin', password: 'secret' }
144
+ ```
145
+
129
146
  ## Notes
147
+
130
148
  Rails 4.1 introduced a built-in mechanism to preview the application emails. It is in fact a port of [basecamp/mail_view](https://github.com/basecamp/mail_view) gem to the core.
131
149
 
132
150
  Alternatively, there are some other plugins to get a similar functionality with different approaches and options. For example, [ryanb/letter_opener](https://github.com/ryanb/letter_opener), [sj26/mailcatcher](https://github.com/sj26/mailcatcher) or [glebm/rails_email_preview](https://github.com/glebm/rails_email_preview).
133
151
 
134
152
  ## License
153
+
135
154
  Copyright (c) 2013-2014 Marc Anguera. Maily is released under the [MIT](MIT-LICENSE) License.
@@ -1,6 +1,6 @@
1
1
  module Maily
2
2
  class ApplicationController < Maily.base_controller.constantize
3
- before_filter :maily_enabled?
3
+ before_filter :maily_enabled?, :http_authorization
4
4
 
5
5
  layout 'maily/application'
6
6
 
@@ -9,5 +9,13 @@ module Maily
9
9
  def maily_enabled?
10
10
  Maily.enabled || raise('Maily: engine disabled!')
11
11
  end
12
+
13
+ def http_authorization
14
+ if auth_hash = Maily.http_authorization
15
+ authenticate_or_request_with_http_basic do |username, password|
16
+ username == auth_hash[:username] && password == auth_hash[:password]
17
+ end
18
+ end
19
+ end
12
20
  end
13
21
  end
@@ -11,6 +11,9 @@ Maily.setup do |config|
11
11
  # I18n.available_locales by default
12
12
  # config.available_locales = [:en, :es, :pt, :fr]
13
13
 
14
- # Run maily under different controller. 'ActionController::Base' by default
15
- # config.base_controller = 'AdminController'
14
+ # Run maily under different controller ('ActionController::Base' by default)
15
+ # config.base_controller = '::AdminController'
16
+
17
+ # Http basic authentication (nil by default)
18
+ # config.http_authorization = { username: 'admin', password: 'secret' }
16
19
  end
@@ -5,14 +5,16 @@ require 'maily/email'
5
5
 
6
6
  module Maily
7
7
  class << self
8
- attr_accessor :enabled, :allow_edition, :allow_delivery, :available_locales, :base_controller
8
+ attr_accessor :enabled, :allow_edition, :allow_delivery, :available_locales,
9
+ :base_controller, :http_authorization
9
10
 
10
11
  def init!
11
- self.enabled = Rails.env.production? ? false : true
12
- self.allow_edition = Rails.env.production? ? false : true
13
- self.allow_delivery = Rails.env.production? ? false : true
14
- self.available_locales = I18n.available_locales
15
- self.base_controller = 'ActionController::Base'
12
+ self.enabled = Rails.env.production? ? false : true
13
+ self.allow_edition = Rails.env.production? ? false : true
14
+ self.allow_delivery = Rails.env.production? ? false : true
15
+ self.available_locales = I18n.available_locales
16
+ self.base_controller = 'ActionController::Base'
17
+ self.http_authorization = nil
16
18
  end
17
19
 
18
20
  def load_emails_and_hooks
@@ -1,3 +1,3 @@
1
1
  module Maily
2
- VERSION = "0.3.5"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Maily::EmailsController, type: :controller do
4
+ routes { Maily::Engine.routes }
5
+
6
+ before(:each) do
7
+ Maily.init!
8
+ end
9
+
10
+ it 'responds ok if enabled' do
11
+ expect { get :index }.not_to raise_error
12
+ end
13
+
14
+ it 'raise error if disabled' do
15
+ Maily.enabled = false
16
+ expect { get :index }.to raise_error('Maily: engine disabled!')
17
+ end
18
+
19
+ it 'responds with 401 if http authorization fails' do
20
+ Maily.http_authorization = { username: 'admin', password: 'admin' }
21
+ get :index
22
+ expect(response.status).to eq(401)
23
+ end
24
+
25
+ it 'responds ok with valid http authorization' do
26
+ Maily.http_authorization = { username: 'admin', password: 'admin' }
27
+ request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials('admin', 'admin')
28
+ get :index
29
+ expect(response.status).to eq(200)
30
+ end
31
+ end
@@ -1,6 +1,6 @@
1
1
  # Dummy App
2
2
 
3
- Dummy Rails application for testing `Maily`.
3
+ Dummy Rails application to test `Maily` engine.
4
4
 
5
5
  Run test suite (from `Maily` root path):
6
6
 
@@ -9,6 +9,7 @@ describe Maily do
9
9
  expect(Maily.allow_delivery).to be true
10
10
  expect(Maily.available_locales).to eq(I18n.available_locales)
11
11
  expect(Maily.base_controller).to eq('ActionController::Base')
12
+ expect(Maily.http_authorization).to be nil
12
13
  end
13
14
 
14
15
  it "should not allow edition if edition is disabled" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maily
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - markets
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-06 00:00:00.000000000 Z
11
+ date: 2014-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -84,6 +84,7 @@ files:
84
84
  - lib/maily/version.rb
85
85
  - maily.gemspec
86
86
  - screenshot.png
87
+ - spec/controllers_spec.rb
87
88
  - spec/dummy/README.md
88
89
  - spec/dummy/Rakefile
89
90
  - spec/dummy/app/assets/images/.keep
@@ -151,11 +152,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
152
  version: '0'
152
153
  requirements: []
153
154
  rubyforge_project:
154
- rubygems_version: 2.2.0
155
+ rubygems_version: 2.2.2
155
156
  signing_key:
156
157
  specification_version: 4
157
158
  summary: Rails Engine to preview emails in the browser.
158
159
  test_files:
160
+ - spec/controllers_spec.rb
159
161
  - spec/dummy/README.md
160
162
  - spec/dummy/Rakefile
161
163
  - spec/dummy/app/assets/images/.keep