effective_polls 0.0.1 → 0.0.2

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: b49f5df5989ddd470b3090d2ac28ab5974e902bd33f8a57e05487025074cf0a8
4
- data.tar.gz: f3465afeb7bee7279348f24f7e85128d136cac9d47add5f3c67f8a1ee740062f
3
+ metadata.gz: 68d305ba395a3d2414ebca82cd907b4e15831390d406bc963f491ebb982c76d3
4
+ data.tar.gz: 46418fe6dc4c690c64e29800ce3cc3710ece9375e057f2fbdf2f47521b637bde
5
5
  SHA512:
6
- metadata.gz: 5ea3cf981517d7d8081feae614b054114f156826b5a694410d48f3418b7cf9df2db606c290d3f89a9ca1018ff4a8c64550528b9071436d7c7c02c863217467d1
7
- data.tar.gz: 76898e90f2e456e3ccbc4b24e022ce785b1375ff0afbc91cab27b31319c4bf40dab731900d77bced3788d9acb1cdceaec4b9d6483c984c0e8e0d4a20549f598c
6
+ metadata.gz: '0379c829ce46c31baa169a070c7023d2ae4f013770667725d14f9a309b1a940cf474afef85e1717de3ffad9cdbe114e1ed676895013ff865eee3afe4aeed8d58'
7
+ data.tar.gz: 8ff57a27c6baae02974c31c43d2067759b895f1f90fdf258c573b606acb6fa5ee26871f52b6ffda86713b63bc96785d1138e74d776c6f595b5264e64e649ae5c
@@ -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
@@ -2,21 +2,24 @@
2
2
 
3
3
  Online polls and user voting.
4
4
 
5
- An admin creates polls with one or more poll_questions. The poll can be assigned to users through a poll_ballot.
5
+ An admin creates polls with one or more poll_questions. The poll can be assigned to all users, individual users or selected users (a scope) and those users complete a 4-step wizard to submit a poll.
6
6
 
7
- The user can complete the poll_ballot and anonymously vote for each option.
7
+ All results are anonymized such that the user cannot be identified from the results.
8
8
 
9
- Some reports to display results.
9
+ Works with action_text for content bodies, and active_storage for file uploads.
10
10
 
11
11
  ## Getting Started
12
12
 
13
+ This requires Rails 6+ and Twitter Bootstrap 4 and just works with Devise.
14
+
13
15
  Please first install the [effective_datatables](https://github.com/code-and-effect/effective_datatables) gem.
14
16
 
15
- Please download and install [Twitter Bootstrap4](http://getbootstrap.com)
17
+ Please download and install the [Twitter Bootstrap4](http://getbootstrap.com)
16
18
 
17
19
  Add to your Gemfile:
18
20
 
19
21
  ```ruby
22
+ gem 'haml-rails' # or try using gem 'hamlit-rails'
20
23
  gem 'effective_polls'
21
24
  ```
22
25
 
@@ -34,7 +37,7 @@ rails generate effective_polls:install
34
37
 
35
38
  The generator will install an initializer which describes all configuration options and creates a database migration.
36
39
 
37
- If you want to tweak the table name (to use something other than the default 'polls'), manually adjust both the configuration file and the migration now.
40
+ If you want to tweak the table names, manually adjust both the configuration file and the migration now.
38
41
 
39
42
  Then migrate the database:
40
43
 
@@ -42,9 +45,56 @@ Then migrate the database:
42
45
  rake db:migrate
43
46
  ```
44
47
 
45
- ## Polls
48
+ Render the "available polls for current_user" datatable on your user dashboard:
49
+
50
+ ```haml
51
+ %h2 Polls
52
+ %p You may submit a ballot for the following polls.
53
+ = render_datatable(EffectivePollsDatatable.new, simple: true)
54
+ ```
55
+
56
+ Add a link to the admin menu:
57
+
58
+ ```haml
59
+ - if can? :admin, :effective_polls
60
+ = link_to 'Polls', effective_polls.admin_polls_path
61
+ ```
62
+
63
+ Set up your permissions:
64
+
65
+ ```ruby
66
+ # Regular signed up user. Guest users not supported.
67
+ if user.persisted?
68
+ can [:show, :update], Effective::Ballot, user_id: user.id
69
+ can :show, Effective::Poll
70
+ can :index, EffectivePollsDatatable
71
+ end
72
+
73
+ if user.admin?
74
+ can :admin, :effective_polls
46
75
 
47
- TODO
76
+ can :manage, Effective::Poll
77
+ can :manage, Effective::PollNotification
78
+
79
+ can :index, Effective::PollQuestion
80
+ can :index, Admin::EffectivePollResultsDatatable
81
+
82
+ can([:new, :create, :edit, :update, :destroy], Effective::PollQuestion) do |pq|
83
+ pq.poll.present? && !pq.poll.started?
84
+ end
85
+
86
+ end
87
+ ```
88
+
89
+ And, if you want to use poll notifications, schedule the rake task to run every 10 minutes, or faster:
90
+
91
+ ```rake
92
+ rake effective_polls:notify
93
+ ```
94
+
95
+ ## Usage
96
+
97
+ You can render the results with `render('effective/poll_results/results', poll: poll)`.
48
98
 
49
99
  ## Authorization
50
100
 
@@ -97,19 +147,6 @@ rescue_from Effective::AccessDenied do |exception|
97
147
  end
98
148
  ```
99
149
 
100
- ### Permissions
101
-
102
- The permissions you actually want to define are as follows (using CanCan):
103
-
104
- ```ruby
105
- can [:index, :show], Effective::Poll
106
-
107
- if user.admin?
108
- can :manage, Effective::Poll
109
- can :admin, :effective_polls
110
- end
111
- ```
112
-
113
150
  ## License
114
151
 
115
152
  MIT License. Copyright [Code and Effect Inc.](http://www.codeandeffect.com/)
@@ -1,6 +1,6 @@
1
1
  module Admin
2
2
  class PollNotificationsController < ApplicationController
3
- layout (EffectivePolls.layout.kind_of?(Hash) ? EffectivePolls.layout[:admin] : EffectivePolls.layout)
3
+ layout EffectivePolls.layout[:admin]
4
4
 
5
5
  before_action(:authenticate_user!) if defined?(Devise)
6
6
  before_action { EffectivePolls.authorize!(self, :admin, :effective_polls) }
@@ -1,6 +1,6 @@
1
1
  module Admin
2
2
  class PollQuestionsController < ApplicationController
3
- layout (EffectivePolls.layout.kind_of?(Hash) ? EffectivePolls.layout[:admin] : EffectivePolls.layout)
3
+ layout EffectivePolls.layout[:admin]
4
4
 
5
5
  before_action(:authenticate_user!) if defined?(Devise)
6
6
  before_action { EffectivePolls.authorize!(self, :admin, :effective_polls) }
@@ -1,6 +1,6 @@
1
1
  module Admin
2
2
  class PollsController < ApplicationController
3
- layout (EffectivePolls.layout.kind_of?(Hash) ? EffectivePolls.layout[:admin] : EffectivePolls.layout)
3
+ layout EffectivePolls.layout[:admin]
4
4
 
5
5
  before_action(:authenticate_user!) if defined?(Devise)
6
6
  before_action { EffectivePolls.authorize!(self, :admin, :effective_polls) }
@@ -1,6 +1,6 @@
1
1
  module Effective
2
2
  class BallotsController < ApplicationController
3
- layout (EffectivePolls.layout.kind_of?(Hash) ? EffectivePolls.layout[:polls] : EffectivePolls.layout)
3
+ layout EffectivePolls.layout[:polls]
4
4
 
5
5
  before_action(:authenticate_user!) if defined?(Devise)
6
6
  include Effective::WizardController
@@ -23,6 +23,10 @@ module Effective
23
23
 
24
24
  acts_as_tokened
25
25
 
26
+ if respond_to?(:log_changes)
27
+ log_changes(except: [:ballots, :ballot_responses, :completed_ballots, :completed_ballot_responses])
28
+ end
29
+
26
30
  AUDIENCES = ['All Users', 'Individual Users', 'Selected Users']
27
31
 
28
32
  effective_resource do
@@ -1,6 +1,7 @@
1
1
  module Effective
2
2
  class PollNotification < ActiveRecord::Base
3
3
  belongs_to :poll
4
+ log_changes(to: :poll) if respond_to?(:log_changes)
4
5
 
5
6
  BATCHSIZE = (Rails.env.test? ? 3 : 250)
6
7
  CATEGORIES = ['Upcoming reminder', 'When poll starts', 'Reminder', 'When poll ends']
@@ -6,6 +6,7 @@ module Effective
6
6
  accepts_nested_attributes_for :poll_question_options, reject_if: :all_blank, allow_destroy: true
7
7
 
8
8
  has_rich_text :body
9
+ log_changes(to: :poll) if respond_to?(:log_changes)
9
10
 
10
11
  CATEGORIES = [
11
12
  'Choose one', # Radios
@@ -18,3 +18,7 @@
18
18
 
19
19
  - datatable = Admin::EffectivePollNotificationsDatatable.new(poll_id: poll.id)
20
20
  = render_datatable(datatable, inline: true, simple: true)
21
+
22
+ - if poll.respond_to?(:log_changes_datatable)
23
+ = tab 'Logs' do
24
+ = render_datatable(poll.log_changes_datatable)
@@ -4,6 +4,9 @@
4
4
  = f.datetime_field :start_at, input_js: { minDate: [f.object.start_at.presence, Time.zone.now].compact.min.strftime('%F') }
5
5
  = f.datetime_field :end_at
6
6
 
7
+ .alert.alert-warning
8
+ Once the start date has passed, this poll will become read only and you will be unable to make changes.
9
+
7
10
  -# Audience
8
11
  = f.radios :audience, Effective::Poll::AUDIENCES
9
12
 
@@ -53,7 +53,7 @@ EffectivePolls.setup do |config|
53
53
  #
54
54
  config.mailer = {
55
55
  layout: 'effective_polls_mailer_layout',
56
- default_from: 'info@example.com'
56
+ default_from: 'no-reply@example.com'
57
57
  }
58
58
 
59
59
  end
@@ -1,3 +1,3 @@
1
1
  module EffectivePolls
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -26,7 +26,7 @@ module EffectivePolls
26
26
  @poll_question_options_table_name = ':' + EffectivePolls.poll_question_options_table_name.to_s
27
27
  @ballots_table_name = ':' + EffectivePolls.ballots_table_name.to_s
28
28
  @ballot_responses_table_name = ':' + EffectivePolls.ballot_responses_table_name.to_s
29
- @ballot_response_options_table_name = ':' + EffectivePolls.ballot_responses_table_name.to_s
29
+ @ballot_response_options_table_name = ':' + EffectivePolls.ballot_response_options_table_name.to_s
30
30
 
31
31
  migration_template ('../' * 3) + 'db/migrate/01_create_effective_polls.rb.erb', 'db/migrate/create_effective_polls.rb'
32
32
  end
@@ -2,8 +2,9 @@
2
2
 
3
3
  class EffectivePollsMailerPreview < ActionMailer::Preview
4
4
 
5
- def poll_upcoming_reminder(poll_notification, bcc)
6
- mail(bcc: bcc, body: poll_notification.body, subject: poll_notification.subject)
5
+ def poll_upcoming_reminder
6
+ poll_notification = build_poll_notification('The poll will start soon')
7
+ Effective::PollsMailer.poll_upcoming_reminder(poll_notification, bccs)
7
8
  end
8
9
 
9
10
  def poll_start
@@ -12,7 +13,7 @@ class EffectivePollsMailerPreview < ActionMailer::Preview
12
13
  end
13
14
 
14
15
  def poll_reminder
15
- poll_notification = build_poll_notification('This is a reminder')
16
+ poll_notification = build_poll_notification('The poll started already and you have not participated')
16
17
  Effective::PollsMailer.poll_reminder(poll_notification, bccs)
17
18
  end
18
19
 
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.0.1
4
+ version: 0.0.2
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-19 00:00:00.000000000 Z
11
+ date: 2021-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails