effective_polls 0.1.4 → 0.2.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: f66e30b255f3552e0c56f6c7b6b4fa7958360f4a6b59cd77d30e829105444491
4
- data.tar.gz: 8950bced702e1ca99e324449238156880b3659a542838fb761fe1291d492109d
3
+ metadata.gz: 57df19aaa933dd133ba655525265e129ca1c2bd7a60a78a5a8f2fe89ec1aa5cc
4
+ data.tar.gz: 86fe4a6defeef051e4ff9c8543480fd6db703e213d80cf100781f4c71cc60e4b
5
5
  SHA512:
6
- metadata.gz: 83401587a66ec82a26a108575e90c9e7cfea3ad0fdfebce30179d31ef392467ba6549bdfdcbe51ee56e3a009dc1232eaf2f03ade8e6454bebd5c5002e1b3d8b4
7
- data.tar.gz: 1f208285019d5b8cec81fa03a53c0106ac86119206549589049e3eeaec51d49726dceb9e624a1fd0fbbcba1bff030b66936d260c97fde61e42f8742651d7d310
6
+ metadata.gz: 1b6f6ace193a55d55b49184f8a2b9a1a0766b0e1249c5c3daa65bfac034a7bb7b8ae1920b66ed04d1605137a88798d749951f0f714e2289774f63dfc5d820ca4
7
+ data.tar.gz: e0b94cefd83a9af17f232cedc37369615ed0042543b886a496174fd807a3117cab3a876bcb6eb34d61f2ca50a70ede2c2c92d965df67d4b0619dc9a3fd05f052
@@ -1,9 +1,7 @@
1
1
  module Admin
2
2
  class PollNotificationsController < ApplicationController
3
- layout EffectivePolls.layout[:admin]
4
-
5
3
  before_action(:authenticate_user!) if defined?(Devise)
6
- before_action { EffectivePolls.authorize!(self, :admin, :effective_polls) }
4
+ before_action { EffectiveResources.authorize!(self, :admin, :effective_polls) }
7
5
 
8
6
  include Effective::CrudController
9
7
 
@@ -1,9 +1,7 @@
1
1
  module Admin
2
2
  class PollQuestionsController < ApplicationController
3
- layout EffectivePolls.layout[:admin]
4
-
5
3
  before_action(:authenticate_user!) if defined?(Devise)
6
- before_action { EffectivePolls.authorize!(self, :admin, :effective_polls) }
4
+ before_action { EffectiveResources.authorize!(self, :admin, :effective_polls) }
7
5
 
8
6
  include Effective::CrudController
9
7
 
@@ -1,15 +1,13 @@
1
1
  module Admin
2
2
  class PollsController < ApplicationController
3
- layout EffectivePolls.layout[:admin]
4
-
5
3
  before_action(:authenticate_user!) if defined?(Devise)
6
- before_action { EffectivePolls.authorize!(self, :admin, :effective_polls) }
4
+ before_action { EffectiveResources.authorize!(self, :admin, :effective_polls) }
7
5
 
8
6
  include Effective::CrudController
9
7
 
10
8
  def results
11
9
  @poll = Effective::Poll.find(params[:id])
12
- EffectivePolls.authorize!(self, :results, @poll)
10
+ EffectiveResources.authorize!(self, :results, @poll)
13
11
 
14
12
  @datatable = Admin::EffectivePollResultsDatatable.new(poll_token: @poll.token)
15
13
  @page_title = "#{@poll} Results"
@@ -1,8 +1,7 @@
1
1
  module Effective
2
2
  class BallotsController < ApplicationController
3
- layout EffectivePolls.layout[:polls]
4
-
5
3
  before_action(:authenticate_user!) if defined?(Devise)
4
+
6
5
  include Effective::WizardController
7
6
 
8
7
  resource_scope do
@@ -19,7 +18,7 @@ module Effective
19
18
  flash[:danger] = 'You have already completed a ballot for this poll.'
20
19
  redirect_to(root_path)
21
20
  elsif existing.present?
22
- flash[:success] = "You have been redirected to the #{resource_wizard_step_title(existing.next_step)} step."
21
+ flash[:success] = "You have been redirected to the #{resource_wizard_step_title(existing, existing.next_step)} step."
23
22
  redirect_to effective_polls.poll_ballot_build_path(existing.poll, existing, existing.next_step)
24
23
  end
25
24
  end
@@ -4,7 +4,8 @@ module Effective
4
4
 
5
5
  def show
6
6
  poll = Effective::Poll.find(params[:id])
7
- EffectivePolls.authorize!(self, :show, poll)
7
+
8
+ EffectiveResources.authorize!(self, :show, poll)
8
9
 
9
10
  ballot = Effective::Ballot.where(poll: poll, user: current_user).first
10
11
 
@@ -23,6 +23,8 @@ class Admin::EffectivePollNotificationsDatatable < Effective::Datatable
23
23
  Effective::PollNotification::UPCOMING_REMINDERS.invert[poll_notification.reminder]
24
24
  when 'Reminder'
25
25
  Effective::PollNotification::REMINDERS.invert[poll_notification.reminder]
26
+ when 'Before poll ends'
27
+ Effective::PollNotification::UPCOMING_REMINDERS.invert[poll_notification.reminder]
26
28
  else
27
29
  raise('unexpected category')
28
30
  end
@@ -1,6 +1,8 @@
1
1
  module Effective
2
- class PollsMailer < EffectivePolls.mailer_class
3
- layout EffectivePolls.mailer[:layout].presence || 'effective_polls_mailer_layout'
2
+ class PollsMailer < EffectivePolls.parent_mailer_class
3
+
4
+ include EffectiveMailer
5
+ include EffectiveEmailTemplatesMailer if EffectivePolls.use_effective_email_templates
4
6
 
5
7
  def poll_upcoming_reminder(poll_notification, user)
6
8
  @assigns = effective_email_templates_assigns(poll_notification, user)
@@ -35,6 +37,17 @@ module Effective
35
37
  )
36
38
  end
37
39
 
40
+ def poll_before_poll_ends(poll_notification, user)
41
+ @assigns = effective_email_templates_assigns(poll_notification, user)
42
+
43
+ mail(
44
+ to: user.email,
45
+ from: poll_notification.from,
46
+ body: poll_notification.body,
47
+ subject: poll_notification.subject
48
+ )
49
+ end
50
+
38
51
  def poll_when_poll_ends(poll_notification, user)
39
52
  @assigns = effective_email_templates_assigns(poll_notification, user)
40
53
 
@@ -57,9 +70,10 @@ module Effective
57
70
  raise('expected poll to be persisted') unless poll&.persisted?
58
71
 
59
72
  {
73
+ subject: poll_notification.subject,
60
74
  available_date: poll.available_date,
61
75
  title: poll.title,
62
- url: effective_polls.new_poll_ballot_url(poll),
76
+ url: effective_polls.poll_url(poll),
63
77
  user: {
64
78
  name: user.to_s,
65
79
  email: user.email
@@ -3,7 +3,7 @@ module Effective
3
3
  belongs_to :poll
4
4
  log_changes(to: :poll) if respond_to?(:log_changes)
5
5
 
6
- CATEGORIES = ['Upcoming reminder', 'When poll starts', 'Reminder', 'When poll ends']
6
+ CATEGORIES = ['Upcoming reminder', 'When poll starts', 'Reminder', 'Before poll ends', 'When poll ends']
7
7
  EMAIL_TEMPLATE_VARIABLES = ['available_date', 'title', 'url', 'user.name', 'user.email']
8
8
 
9
9
  UPCOMING_REMINDERS = {
@@ -77,7 +77,7 @@ module Effective
77
77
  validates :subject, liquid: true
78
78
  end
79
79
 
80
- validates :reminder, if: -> { reminder? || upcoming_reminder? },
80
+ validates :reminder, if: -> { reminder? || upcoming_reminder? || before_poll_ends? },
81
81
  presence: true, uniqueness: { scope: [:poll_id, :category], message: 'already exists' }
82
82
 
83
83
  def to_s
@@ -100,6 +100,10 @@ module Effective
100
100
  category == 'Reminder'
101
101
  end
102
102
 
103
+ def before_poll_ends?
104
+ category == 'Before poll ends'
105
+ end
106
+
103
107
  def poll_end?
104
108
  category == 'When poll ends'
105
109
  end
@@ -120,16 +124,18 @@ module Effective
120
124
  !poll.started? && poll.start_at < (Time.zone.now + reminder)
121
125
  when 'Reminder'
122
126
  !poll.ended? && poll.start_at < (Time.zone.now - reminder)
127
+ when 'Before poll ends'
128
+ !poll.ended? && poll.end_at.present? && poll.end_at < (Time.zone.now + reminder)
123
129
  else
124
130
  raise('unexpected category')
125
131
  end
126
132
  end
127
133
 
128
- def notify!
129
- return false unless notify_now?
134
+ def notify!(force: false)
135
+ return false unless (notify_now? || force)
130
136
 
131
137
  # We send to all users, except for the 'Reminder' that exclude completed users
132
- users = poll.users(except_completed: (category == 'Reminder'))
138
+ users = poll.users(except_completed: (category == 'Reminder' || category == 'Before poll ends'))
133
139
 
134
140
  update_column(:started_at, Time.zone.now)
135
141
 
@@ -0,0 +1,8 @@
1
+ = f.select :reminder, Effective::PollNotification::UPCOMING_REMINDERS, label: false,
2
+ hint: "before the poll ends on #{f.object.poll&.end_at&.strftime('%F') || 'never'}."
3
+
4
+ .alert.alert-warning
5
+ %strong Before Poll Ends
6
+ reminders are sent to users in the audience who have not yet completed their ballot.
7
+ %br
8
+ Use before poll ends notifications to remind people to vote.
@@ -0,0 +1,13 @@
1
+ ---
2
+ subject: 'Please submit your ballot for {{ title }}'
3
+ from: 'admin@example.com'
4
+ ---
5
+ Hello {{ user.name }},
6
+
7
+ The {{ title }} poll is almost complete.
8
+
9
+ Please remember to submit your ballot.
10
+
11
+ {{ url }}
12
+
13
+ Thank you
@@ -7,34 +7,9 @@ EffectivePolls.setup do |config|
7
7
  config.ballot_responses_table_name = :ballot_responses
8
8
  config.ballot_response_options_table_name = :ballot_response_options
9
9
 
10
- # Authorization Method
11
- #
12
- # This method is called by all controller actions with the appropriate action and resource
13
- # If it raises an exception or returns false, an Effective::AccessDenied Error will be raised
14
- #
15
- # Use via Proc:
16
- # Proc.new { |controller, action, resource| authorize!(action, resource) } # CanCan
17
- # Proc.new { |controller, action, resource| can?(action, resource) } # CanCan with skip_authorization_check
18
- # Proc.new { |controller, action, resource| authorize "#{action}?", resource } # Pundit
19
- # Proc.new { |controller, action, resource| current_user.is?(:admin) } # Custom logic
20
- #
21
- # Use via Boolean:
22
- # config.authorization_method = true # Always authorized
23
- # config.authorization_method = false # Always unauthorized
24
- #
25
- # Use via Method (probably in your application_controller.rb):
26
- # config.authorization_method = :my_authorization_method
27
- # def my_authorization_method(resource, action)
28
- # true
29
- # end
30
- config.authorization_method = Proc.new { |controller, action, resource| authorize!(action, resource) }
31
-
32
10
  # Layout Settings
33
11
  # Configure the Layout per controller, or all at once
34
- config.layout = {
35
- polls: 'application',
36
- admin: 'admin'
37
- }
12
+ # config.layout = { application: 'application', admin: 'admin' }
38
13
 
39
14
  # Audience Scope Collection
40
15
  #
@@ -51,14 +26,19 @@ EffectivePolls.setup do |config|
51
26
  # Schedule rake effective_polls:notify to run every 10 minutes
52
27
  # to send out email poll notifications
53
28
  #
54
- config.mailer = {
55
- layout: 'effective_polls_mailer_layout',
56
- default_from: 'no-reply@example.com'
57
- }
58
-
59
- # Will work with effective_email_templates gem:
60
- # - The poll notifications email content will be preopulated based off the template
61
- # - Uses a EmailTemplatesMailer mailer instead of ActionMailer::Base
62
- config.use_effective_email_templates = false
29
+ # Please see config/initializers/effective_resources.rb for default effective_* gem mailer settings
30
+ #
31
+ # Configure the class responsible to send e-mails.
32
+ # config.mailer = 'Effective::EventsMailer'
33
+ #
34
+ # Override effective_resource mailer defaults
35
+ #
36
+ # config.parent_mailer = nil # The parent class responsible for sending emails
37
+ # config.deliver_method = nil # The deliver method, deliver_later or deliver_now
38
+ # config.mailer_layout = nil # Default mailer layout
39
+ # config.mailer_sender = nil # Default From value
40
+ # config.mailer_admin = nil # Default To value for Admin correspondence
63
41
 
42
+ # Use effective email templates for event notifications
43
+ config.use_effective_email_templates = true
64
44
  end
@@ -1,3 +1,3 @@
1
1
  module EffectivePolls
2
- VERSION = '0.1.4'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -4,52 +4,20 @@ require 'effective_polls/engine'
4
4
  require 'effective_polls/version'
5
5
 
6
6
  module EffectivePolls
7
- mattr_accessor :polls_table_name
8
- mattr_accessor :poll_notifications_table_name
9
- mattr_accessor :poll_questions_table_name
10
- mattr_accessor :poll_question_options_table_name
11
- mattr_accessor :ballots_table_name
12
- mattr_accessor :ballot_responses_table_name
13
- mattr_accessor :ballot_response_options_table_name
14
7
 
15
- mattr_accessor :authorization_method
16
-
17
- mattr_accessor :layout
18
-
19
- mattr_accessor :audience_user_scopes
20
-
21
- # Hashes of configs
22
- mattr_accessor :use_effective_email_templates
23
- mattr_accessor :mailer
24
-
25
- def self.setup
26
- yield self
8
+ def self.config_keys
9
+ [
10
+ :polls_table_name, :poll_notifications_table_name, :poll_questions_table_name, :poll_question_options_table_name,
11
+ :ballots_table_name, :ballot_responses_table_name, :ballot_response_options_table_name,
12
+ :layout, :audience_user_scopes,
13
+ :mailer, :parent_mailer, :deliver_method, :mailer_layout, :mailer_sender, :mailer_admin, :mailer_subject, :use_effective_email_templates
14
+ ]
27
15
  end
28
16
 
29
- def self.authorized?(controller, action, resource)
30
- @_exceptions ||= [Effective::AccessDenied, (CanCan::AccessDenied if defined?(CanCan)), (Pundit::NotAuthorizedError if defined?(Pundit))].compact
31
-
32
- return !!authorization_method unless authorization_method.respond_to?(:call)
33
- controller = controller.controller if controller.respond_to?(:controller)
34
-
35
- begin
36
- !!(controller || self).instance_exec((controller || self), action, resource, &authorization_method)
37
- rescue *@_exceptions
38
- false
39
- end
40
- end
41
-
42
- def self.authorize!(controller, action, resource)
43
- raise Effective::AccessDenied.new('Access Denied', action, resource) unless authorized?(controller, action, resource)
44
- end
17
+ include EffectiveGem
45
18
 
46
19
  def self.mailer_class
47
- if use_effective_email_templates
48
- require 'effective_email_templates'
49
- Effective::EmailTemplatesMailer
50
- else
51
- ActionMailer::Base
52
- end
20
+ mailer&.constantize || Effective::PollsMailer
53
21
  end
54
22
 
55
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_polls
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.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-02-12 00:00:00.000000000 Z
11
+ date: 2022-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -104,7 +104,6 @@ files:
104
104
  - app/datatables/effective_polls_datatable.rb
105
105
  - app/helpers/effective_polls_helper.rb
106
106
  - app/mailers/effective/polls_mailer.rb
107
- - app/models/effective/access_denied.rb
108
107
  - app/models/effective/ballot.rb
109
108
  - app/models/effective/ballot_response.rb
110
109
  - app/models/effective/ballot_response_option.rb
@@ -113,6 +112,7 @@ files:
113
112
  - app/models/effective/poll_question.rb
114
113
  - app/models/effective/poll_question_option.rb
115
114
  - app/views/admin/poll_notifications/_form.html.haml
115
+ - app/views/admin/poll_notifications/_form_poll_before_poll_ends.html.haml
116
116
  - app/views/admin/poll_notifications/_form_poll_reminder.html.haml
117
117
  - app/views/admin/poll_notifications/_form_poll_upcoming_reminder.html.haml
118
118
  - app/views/admin/poll_notifications/_form_poll_when_poll_ends.html.haml
@@ -171,11 +171,11 @@ files:
171
171
  - app/views/effective/poll_results/results/_select_up_to_5.html.haml
172
172
  - app/views/effective/poll_results/results/_short_answer.html.haml
173
173
  - app/views/effective/poll_results/results/_upload_file.html.haml
174
+ - app/views/effective/polls_mailer/poll_before_poll_ends.liquid
174
175
  - app/views/effective/polls_mailer/poll_reminder.liquid
175
176
  - app/views/effective/polls_mailer/poll_upcoming_reminder.liquid
176
177
  - app/views/effective/polls_mailer/poll_when_poll_ends.liquid
177
178
  - app/views/effective/polls_mailer/poll_when_poll_starts.liquid
178
- - app/views/layouts/effective_polls_mailer_layout.html.haml
179
179
  - config/effective_polls.rb
180
180
  - config/routes.rb
181
181
  - db/migrate/01_create_effective_polls.rb.erb
@@ -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,7 +0,0 @@
1
- !!!
2
- %html{style: 'background: #fff;'}
3
- %head
4
- %meta{:content => 'text/html; charset=UTF-8', 'http-equiv' => 'Content-Type'}
5
-
6
- %body{style: 'background: #fff;'}
7
- = yield