effective_email_templates 1.0.13 → 1.1.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 +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +3 -49
- data/app/controllers/admin/email_templates_controller.rb +8 -76
- data/app/datatables/effective_email_templates_datatable.rb +14 -5
- data/app/models/effective/email_template.rb +14 -11
- data/app/views/admin/email_templates/_form.html.haml +1 -1
- data/config/effective_email_templates.rb +1 -29
- data/lib/effective_email_templates.rb +8 -27
- data/lib/effective_email_templates/version.rb +1 -1
- metadata +2 -6
- data/app/models/effective/access_denied.rb +0 -17
- data/app/views/admin/email_templates/_actions.html.haml +0 -5
- data/app/views/admin/email_templates/edit.html.haml +0 -3
- data/app/views/admin/email_templates/index.html.haml +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42f8567bcf6351ab1762ee602ac678e4b63e8bbde2ae4e2c2858a7eff70a2a8d
|
4
|
+
data.tar.gz: df20ca47c9a70a8a4867dc961da769db6f49a490fe80756e3fe9948b75dba5cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c17a239840a85a12f9768b84be0315c7d0fddf924b435809af78bad8e203b145de905d40eef06d0473a18041e5483187deb4fc4db61df01428317d7c678a9974
|
7
|
+
data.tar.gz: f10cfa33b6973e58b2b9e82a33c019b5ef7b8f532f23048682a6367e8e654304d61556c2a3a4e5de9114536d8a36deff4150301f68a107d462b0b3d47d1fd1c8
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -114,67 +114,21 @@ EmailTemplatesMailer.welcome(user).deliver
|
|
114
114
|
|
115
115
|
## Authorization
|
116
116
|
|
117
|
-
All authorization checks are handled via the
|
117
|
+
All authorization checks are handled via the effective_resources gem found in the `config/initializers/effective_resources.rb` file.
|
118
118
|
|
119
|
-
It is intended for flow through to CanCan or Pundit, but neither of those gems are required.
|
120
|
-
|
121
|
-
This method is called by all controller actions with the appropriate action and resource
|
122
|
-
|
123
|
-
Action will be one of [:index, :show, :new, :create, :edit, :update, :destroy]
|
124
|
-
|
125
|
-
Resource will the appropriate Effective::EmailTemplate object or class
|
126
|
-
|
127
|
-
The authorization method is defined in the initializer file:
|
128
|
-
|
129
|
-
```ruby
|
130
|
-
# As a Proc (with CanCan)
|
131
|
-
config.authorization_method = Proc.new { |controller, action, resource| authorize!(action, resource) }
|
132
|
-
```
|
133
|
-
|
134
|
-
```ruby
|
135
|
-
# As a Custom Method
|
136
|
-
config.authorization_method = :my_authorization_method
|
137
|
-
```
|
138
|
-
|
139
|
-
and then in your application_controller.rb:
|
140
|
-
|
141
|
-
```ruby
|
142
|
-
def my_authorization_method(action, resource)
|
143
|
-
current_user.is?(:admin) || EffectivePunditPolicy.new(current_user, resource).send('#{action}?')
|
144
|
-
end
|
145
|
-
```
|
146
|
-
|
147
|
-
or disabled entirely:
|
148
|
-
|
149
|
-
```ruby
|
150
|
-
config.authorization_method = false
|
151
|
-
```
|
152
|
-
|
153
|
-
If the method or proc returns false (user is not authorized) an Effective::AccessDenied exception will be raised
|
154
|
-
|
155
|
-
You can rescue from this exception by adding the following to your application_controller.rb:
|
156
|
-
|
157
|
-
```ruby
|
158
|
-
rescue_from Effective::AccessDenied do |exception|
|
159
|
-
respond_to do |format|
|
160
|
-
format.html { render 'static_pages/access_denied', :status => 403 }
|
161
|
-
format.any { render :text => 'Access Denied', :status => 403 }
|
162
|
-
end
|
163
|
-
end
|
164
|
-
```
|
165
119
|
|
166
120
|
### Permissions
|
167
121
|
|
168
122
|
To allow a user to see the admin area, using CanCan:
|
169
123
|
|
170
124
|
```ruby
|
171
|
-
can :
|
125
|
+
can [:index, :edit, :update, :destroy], Effective::EmailTemplate
|
172
126
|
can :admin, :effective_email_templates
|
173
127
|
```
|
174
128
|
|
175
129
|
## License
|
176
130
|
|
177
|
-
MIT License.
|
131
|
+
MIT License. Copyright [Code and Effect Inc.](http://www.codeandeffect.com/)
|
178
132
|
|
179
133
|
|
180
134
|
## Contributing
|
@@ -1,87 +1,19 @@
|
|
1
1
|
module Admin
|
2
2
|
class EmailTemplatesController < ApplicationController
|
3
|
-
before_action
|
3
|
+
before_action(:authenticate_user!) if defined?(Devise)
|
4
|
+
before_action { EffectiveResources.authorize!(self, :admin, :effective_email_templates) }
|
4
5
|
|
5
|
-
|
6
|
+
include Effective::CrudController
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
@page_title = 'Email Templates'
|
10
|
-
|
11
|
-
authorize_effective_email_templates!
|
12
|
-
end
|
13
|
-
|
14
|
-
def new
|
15
|
-
@email_template = Effective::EmailTemplate.new
|
16
|
-
@page_title = 'New Email Template'
|
17
|
-
|
18
|
-
authorize_effective_email_templates!
|
19
|
-
end
|
20
|
-
|
21
|
-
def create
|
22
|
-
@email_template = Effective::EmailTemplate.new(email_template_params)
|
23
|
-
@page_title = 'New Email Template'
|
24
|
-
|
25
|
-
authorize_effective_email_templates!
|
26
|
-
|
27
|
-
if @email_template.save
|
28
|
-
flash[:success] = 'Successfully created email template'
|
29
|
-
redirect_to effective_email_templates.admin_email_templates_path
|
30
|
-
else
|
31
|
-
flash.now[:danger] = 'Unable to create email template'
|
32
|
-
render :new
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def edit
|
37
|
-
@email_template =
|
38
|
-
Effective::EmailTemplate.where(id: params[:id]).or(
|
39
|
-
Effective::EmailTemplate.where(template_name: params[:id])
|
40
|
-
).first!
|
41
|
-
|
42
|
-
@page_title = 'Edit Email Template'
|
43
|
-
|
44
|
-
authorize_effective_email_templates!
|
8
|
+
if (config = EffectiveEmailTemplates.layout)
|
9
|
+
layout(config.kind_of?(Hash) ? config[:admin] : config)
|
45
10
|
end
|
46
11
|
|
47
|
-
|
48
|
-
|
49
|
-
@page_title = 'Edit Email Template'
|
50
|
-
|
51
|
-
authorize_effective_email_templates!
|
52
|
-
|
53
|
-
if @email_template.update(email_template_params)
|
54
|
-
flash[:success] = 'Successfully updated email template'
|
55
|
-
redirect_to effective_email_templates.admin_email_templates_path
|
56
|
-
else
|
57
|
-
flash.now[:danger] = 'Unable to update email template'
|
58
|
-
render :edit
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def destroy
|
63
|
-
@email_template = Effective::EmailTemplate.find(params[:id])
|
64
|
-
|
65
|
-
authorize_effective_email_templates!
|
66
|
-
|
67
|
-
if @email_template.destroy
|
68
|
-
flash[:success] = 'Successfully deleted email template'
|
69
|
-
else
|
70
|
-
flash[:danger] = 'Unable to delete email template'
|
71
|
-
end
|
72
|
-
|
73
|
-
redirect_to effective_email_templates.admin_email_templates_path
|
74
|
-
end
|
75
|
-
|
76
|
-
private
|
77
|
-
|
78
|
-
def authorize_effective_email_templates!
|
79
|
-
EffectiveEmailTemplates.authorize!(self, :admin, :effective_email_templates)
|
80
|
-
EffectiveEmailTemplates.authorize!(self, action_name.to_sym, @email_template || Effective::EmailTemplate)
|
81
|
-
end
|
12
|
+
submit :save, 'Save'
|
13
|
+
submit :save, 'Save and Add New', redirect: :new
|
82
14
|
|
83
15
|
def email_template_params
|
84
|
-
params.require(:effective_email_template).permit
|
16
|
+
params.require(:effective_email_template).permit!
|
85
17
|
end
|
86
18
|
|
87
19
|
end
|
@@ -8,15 +8,24 @@ class EffectiveEmailTemplatesDatatable < Effective::Datatable
|
|
8
8
|
col :id, visible: false
|
9
9
|
|
10
10
|
col :template_name, label: 'Name'
|
11
|
-
|
12
|
-
col :
|
13
|
-
|
11
|
+
|
12
|
+
col :from do |email_template|
|
13
|
+
html_escape(email_template.from)
|
14
|
+
end
|
15
|
+
|
16
|
+
col :cc do |email_template|
|
17
|
+
html_escape(email_template.cc)
|
18
|
+
end
|
19
|
+
|
20
|
+
col :bcc do |email_template|
|
21
|
+
html_escape(email_template.cc)
|
22
|
+
end
|
23
|
+
|
14
24
|
col :subject
|
15
25
|
col :body
|
16
|
-
|
17
26
|
col :content_type, visible: false
|
18
27
|
|
19
|
-
actions_col
|
28
|
+
actions_col
|
20
29
|
end
|
21
30
|
|
22
31
|
collection do
|
@@ -2,21 +2,24 @@ module Effective
|
|
2
2
|
class EmailTemplate < ActiveRecord::Base
|
3
3
|
self.table_name = EffectiveEmailTemplates.email_templates_table_name.to_s
|
4
4
|
|
5
|
+
attr_accessor :current_user
|
6
|
+
|
5
7
|
log_changes if respond_to?(:log_changes)
|
6
8
|
|
7
9
|
CONTENT_TYPES = ['text/plain', 'text/html']
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
11
|
+
effective_resource do
|
12
|
+
template_name :string
|
13
|
+
content_type :string
|
14
|
+
|
15
|
+
subject :string
|
16
|
+
from :string
|
17
|
+
cc :string
|
18
|
+
bcc :string
|
19
|
+
body :text
|
20
|
+
|
21
|
+
timestamps
|
22
|
+
end
|
20
23
|
|
21
24
|
before_validation do
|
22
25
|
self.content_type ||= CONTENT_TYPES.first
|
@@ -4,7 +4,7 @@
|
|
4
4
|
- if EffectiveEmailTemplates.select_content_type
|
5
5
|
= f.select :content_type, Effective::EmailTemplate::CONTENT_TYPES
|
6
6
|
|
7
|
-
= f.
|
7
|
+
= f.text_field :from, hint: 'Whom the email will be sent from'
|
8
8
|
= f.text_field :cc
|
9
9
|
= f.text_field :bcc
|
10
10
|
|
@@ -2,37 +2,9 @@ EffectiveEmailTemplates.setup do |config|
|
|
2
2
|
# Configure Database Tables
|
3
3
|
config.email_templates_table_name = :email_templates
|
4
4
|
|
5
|
-
# Authorization Method
|
6
|
-
#
|
7
|
-
# This method is called by all controller actions with the appropriate action and resource
|
8
|
-
# If the method returns false, an Effective::AccessDenied Error will be raised (see README.md for complete info)
|
9
|
-
#
|
10
|
-
# Use via Proc (and with CanCan):
|
11
|
-
# config.authorization_method = Proc.new { |controller, action, resource| can?(action, resource) }
|
12
|
-
#
|
13
|
-
# Use via custom method:
|
14
|
-
# config.authorization_method = :my_authorization_method
|
15
|
-
#
|
16
|
-
# And then in your application_controller.rb:
|
17
|
-
#
|
18
|
-
# def my_authorization_method(action, resource)
|
19
|
-
# current_user.is?(:admin)
|
20
|
-
# end
|
21
|
-
#
|
22
|
-
# Or disable the check completely:
|
23
|
-
# config.authorization_method = false
|
24
|
-
config.authorization_method = Proc.new { |controller, action, resource| authorize!(action, resource) } # CanCanCan
|
25
|
-
|
26
5
|
# Layout Settings
|
27
|
-
#
|
28
|
-
|
29
|
-
# config.layout = 'application' # All EffectiveEmailTemplates controllers will use this layout
|
30
|
-
config.layout = {
|
31
|
-
email_templates: 'application',
|
32
|
-
admin_email_templates: 'admin'
|
33
|
-
}
|
6
|
+
# config.layout = { application: 'application', admin: 'admin' }
|
34
7
|
|
35
8
|
# Not allowed to select text/html by default
|
36
9
|
config.select_content_type = false
|
37
|
-
|
38
10
|
end
|
@@ -1,37 +1,18 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'liquid'
|
2
|
+
require 'effective_resources'
|
3
|
+
require 'effective_email_templates/engine'
|
4
|
+
require 'effective_email_templates/version'
|
4
5
|
|
5
6
|
module EffectiveEmailTemplates
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
mattr_accessor :select_content_type
|
10
|
-
mattr_accessor :layout
|
11
|
-
|
12
|
-
def self.setup
|
13
|
-
yield self
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.authorized?(controller, action, resource)
|
17
|
-
@_exceptions ||= [Effective::AccessDenied, (CanCan::AccessDenied if defined?(CanCan)), (Pundit::NotAuthorizedError if defined?(Pundit))].compact
|
18
|
-
|
19
|
-
return !!authorization_method unless authorization_method.respond_to?(:call)
|
20
|
-
controller = controller.controller if controller.respond_to?(:controller)
|
21
|
-
|
22
|
-
begin
|
23
|
-
!!(controller || self).instance_exec((controller || self), action, resource, &authorization_method)
|
24
|
-
rescue *@_exceptions
|
25
|
-
false
|
26
|
-
end
|
8
|
+
def self.config_keys
|
9
|
+
[:email_templates_table_name, :select_content_type, :layout]
|
27
10
|
end
|
28
11
|
|
29
|
-
|
30
|
-
raise Effective::AccessDenied.new('Access Denied', action, resource) unless authorized?(controller, action, resource)
|
31
|
-
end
|
12
|
+
include EffectiveGem
|
32
13
|
|
33
14
|
def self.permitted_params
|
34
|
-
[:from, :bcc, :cc, :subject, :body, :content_type]
|
15
|
+
@permitted_params ||= [:from, :bcc, :cc, :subject, :body, :content_type]
|
35
16
|
end
|
36
17
|
|
37
18
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_email_templates
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -94,13 +94,9 @@ files:
|
|
94
94
|
- app/helpers/effective_email_templates_helper.rb
|
95
95
|
- app/mailers/effective/email_templates_mailer.rb
|
96
96
|
- app/models/concerns/has_one_email_review.rb
|
97
|
-
- app/models/effective/access_denied.rb
|
98
97
|
- app/models/effective/email_review.rb
|
99
98
|
- app/models/effective/email_template.rb
|
100
|
-
- app/views/admin/email_templates/_actions.html.haml
|
101
99
|
- app/views/admin/email_templates/_form.html.haml
|
102
|
-
- app/views/admin/email_templates/edit.html.haml
|
103
|
-
- app/views/admin/email_templates/index.html.haml
|
104
100
|
- app/views/effective/email_reviews/_fields.html.haml
|
105
101
|
- app/views/layouts/effective_email_templates_mailer_layout.html.haml
|
106
102
|
- config/effective_email_templates.rb
|
@@ -1,17 +0,0 @@
|
|
1
|
-
unless defined?(Effective::AccessDenied)
|
2
|
-
module Effective
|
3
|
-
class AccessDenied < StandardError
|
4
|
-
attr_reader :action, :subject
|
5
|
-
|
6
|
-
def initialize(message = nil, action = nil, subject = nil)
|
7
|
-
@message = message
|
8
|
-
@action = action
|
9
|
-
@subject = subject
|
10
|
-
end
|
11
|
-
|
12
|
-
def to_s
|
13
|
-
@message || I18n.t(:'unauthorized.default', :default => 'Access Denied')
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,5 +0,0 @@
|
|
1
|
-
= dropdown(variation: :dropleft) do
|
2
|
-
= dropdown_link_to 'Edit', effective_email_templates.edit_admin_email_template_path(email_template)
|
3
|
-
|
4
|
-
= dropdown_link_to "Delete #{email_template}", effective_email_templates.admin_email_template_path(email_template),
|
5
|
-
data: { method: :delete, confirm: "Really delete #{email_template}?" }
|