effective_email_templates 1.0.13 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1ea4dc4be1510a05879a7ff2c084a17126b4d8bcaa228c693a7cb8a4093a2ffc
4
- data.tar.gz: 74936efb073fc46f09e04d8543858c2a667e4737eeccc86b64882d1f5d9cf402
3
+ metadata.gz: 42f8567bcf6351ab1762ee602ac678e4b63e8bbde2ae4e2c2858a7eff70a2a8d
4
+ data.tar.gz: df20ca47c9a70a8a4867dc961da769db6f49a490fe80756e3fe9948b75dba5cc
5
5
  SHA512:
6
- metadata.gz: 9cefe7ba9a4d3da5a15e4f1e7429167e7ff1d3570f2b381f5ca2c4a2f1379066748a6b0436868099badf1eb3ea178ba347f2d7889ea170b1108e14c80f0d1d61
7
- data.tar.gz: d1e69f8c657c791cc2af22be8ef22fb5a0c4acecb1670727fc9e83b6e6de0ad0f3c9972f8990c3251b0b569148a23c763d64157a55a2ccb6c850bc11f969b200
6
+ metadata.gz: c17a239840a85a12f9768b84be0315c7d0fddf924b435809af78bad8e203b145de905d40eef06d0473a18041e5483187deb4fc4db61df01428317d7c678a9974
7
+ data.tar.gz: f10cfa33b6973e58b2b9e82a33c019b5ef7b8f532f23048682a6367e8e654304d61556c2a3a4e5de9114536d8a36deff4150301f68a107d462b0b3d47d1fd1c8
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2020 Code and Effect Inc.
1
+ Copyright 2021 Code and Effect Inc.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
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 config.authorization_method found in the `app/config/initializers/effective_email_templates.rb` file.
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 :manage, Effective::EmailTemplate
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. Copyright [Code and Effect Inc.](http://www.codeandeffect.com/)
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 :authenticate_user! if respond_to?(:authenticate_user!)
3
+ before_action(:authenticate_user!) if defined?(Devise)
4
+ before_action { EffectiveResources.authorize!(self, :admin, :effective_email_templates) }
4
5
 
5
- layout (EffectiveEmailTemplates.layout.kind_of?(Hash) ? EffectiveEmailTemplates.layout[:admin_email_templates] : EffectiveEmailTemplates.layout)
6
+ include Effective::CrudController
6
7
 
7
- def index
8
- @datatable = EffectiveEmailTemplatesDatatable.new
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
- def update
48
- @email_template = Effective::EmailTemplate.find(params[:id])
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(EffectiveEmailTemplates.permitted_params)
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
- col :from
12
- col :cc
13
- col :bcc
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 partial: '/admin/email_templates/actions', partial_as: 'email_template'
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
- # Attributes
10
- # subject :string
11
- # from :string
12
- # cc :string
13
- # bcc :string
14
- # body :text
15
- # content_type :string
16
- #
17
- # template_name :string
18
- #
19
- # timestamps
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.email_field :from, hint: 'Whom the email will be sent from'
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
- # Configure the Layout per controller, or all at once
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 "liquid"
2
- require "effective_email_templates/engine"
3
- require "effective_email_templates/version"
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
- mattr_accessor :email_templates_table_name
8
- mattr_accessor :authorization_method
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
- def self.authorize!(controller, action, resource)
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
@@ -1,3 +1,3 @@
1
1
  module EffectiveEmailTemplates
2
- VERSION = '1.0.13'.freeze
2
+ VERSION = '1.1.0'.freeze
3
3
  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.13
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-01-29 00:00:00.000000000 Z
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}?" }
@@ -1,3 +0,0 @@
1
- %h1.effective-admin-heading= @page_title
2
-
3
- = render partial: 'form', locals: { email_template: @email_template }
@@ -1,3 +0,0 @@
1
- %h1.effective-admin-heading= @page_title
2
-
3
- = render_datatable @datatable