effective_polls 0.1.4 → 0.1.5

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: d41a8e03b1472d6bab3f7b4dd41b667aa039baa63196fc43d486fefcc12808df
4
+ data.tar.gz: 7ebae168fb97dc5f7669d28aaab5531875e6f49f6dd9b8680d71d604640dc508
5
5
  SHA512:
6
- metadata.gz: 83401587a66ec82a26a108575e90c9e7cfea3ad0fdfebce30179d31ef392467ba6549bdfdcbe51ee56e3a009dc1232eaf2f03ade8e6454bebd5c5002e1b3d8b4
7
- data.tar.gz: 1f208285019d5b8cec81fa03a53c0106ac86119206549589049e3eeaec51d49726dceb9e624a1fd0fbbcba1bff030b66936d260c97fde61e42f8742651d7d310
6
+ metadata.gz: '031615950f4ad6e1cfc44d08282d950f5b01a874a2257638a5cb30c8ad9ecc7866b9bee8b5345ba93025548c5b73ed138ee5dba6c7648688723beccd01fb12f1'
7
+ data.tar.gz: 52b6cba435bbd0f0d05ae3d4250a85623185dba7a4aa11990e5ee419555b9fa0119e59989c8bfc8af4c26cdf1a1ca6e2d117cea515d662d6b1d974d81af39e7c
@@ -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
@@ -35,6 +35,17 @@ module Effective
35
35
  )
36
36
  end
37
37
 
38
+ def poll_before_poll_ends(poll_notification, user)
39
+ @assigns = effective_email_templates_assigns(poll_notification, user)
40
+
41
+ mail(
42
+ to: user.email,
43
+ from: poll_notification.from,
44
+ body: poll_notification.body,
45
+ subject: poll_notification.subject
46
+ )
47
+ end
48
+
38
49
  def poll_when_poll_ends(poll_notification, user)
39
50
  @assigns = effective_email_templates_assigns(poll_notification, user)
40
51
 
@@ -59,7 +70,7 @@ module Effective
59
70
  {
60
71
  available_date: poll.available_date,
61
72
  title: poll.title,
62
- url: effective_polls.new_poll_ballot_url(poll),
73
+ url: effective_polls.poll_url(poll),
63
74
  user: {
64
75
  name: user.to_s,
65
76
  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
@@ -1,3 +1,3 @@
1
1
  module EffectivePolls
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  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.1.5
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: 2021-02-23 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,6 +171,7 @@ 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
@@ -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