From 56c69f51b7af815bc75a9b297f29fad97f3cba88 Mon Sep 17 00:00:00 2001 From: JewelSam Date: Tue, 14 Feb 2017 17:54:31 +0300 Subject: [PATCH 1/3] #1040 Show email in public option --- app/controllers/registrations_controller.rb | 2 +- app/views/devise/registrations/edit.html.haml | 1 + app/views/proposals/show.html.haml | 2 +- db/migrate/20170213145807_change_email_public_from_users.rb | 5 +++++ db/schema.rb | 4 ++-- 5 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20170213145807_change_email_public_from_users.rb diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 62292bf0..423a12b4 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -24,7 +24,7 @@ class RegistrationsController < Devise::RegistrationsController def configure_permitted_parameters devise_parameter_sanitizer.for(:account_update) do |u| u. - permit(:email, :password, :password_confirmation, :current_password, :username) + permit(:email, :password, :password_confirmation, :current_password, :username, :email_public) end devise_parameter_sanitizer.for(:sign_up) do |u| u. diff --git a/app/views/devise/registrations/edit.html.haml b/app/views/devise/registrations/edit.html.haml index 964ec334..d97b4867 100644 --- a/app/views/devise/registrations/edit.html.haml +++ b/app/views/devise/registrations/edit.html.haml @@ -8,6 +8,7 @@ = semantic_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| = f.input :username, required: false, input_html: { autocomplete: 'off' } = f.input :email, required: false, input_html: { autocomplete: 'off' } + = f.input :email_public = f.input :password, hint: "(Leave blank if you don't want to change it)", input_html: { autocomplete: 'off' } = f.input :password_confirmation, input_html: { autocomplete: 'off' } = f.inputs name: 'OpenID' do diff --git a/app/views/proposals/show.html.haml b/app/views/proposals/show.html.haml index 432a5dcd..baf0e404 100644 --- a/app/views/proposals/show.html.haml +++ b/app/views/proposals/show.html.haml @@ -32,7 +32,7 @@ %h3 by = link_to @speaker.name, user_path(@speaker.id) - = "(#{@speaker.email})" + = "(#{@speaker.email})" if @speaker.email_public - if @speaker.affiliation? %br %span.muted diff --git a/db/migrate/20170213145807_change_email_public_from_users.rb b/db/migrate/20170213145807_change_email_public_from_users.rb new file mode 100644 index 00000000..2481accb --- /dev/null +++ b/db/migrate/20170213145807_change_email_public_from_users.rb @@ -0,0 +1,5 @@ +class ChangeEmailPublicFromUsers < ActiveRecord::Migration + def change + change_column_default :users, :email_public, true + end +end diff --git a/db/schema.rb b/db/schema.rb index 5b7be51c..d0d4de72 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170129075434) do +ActiveRecord::Schema.define(version: 20170213145807) do create_table "ahoy_events", force: :cascade do |t| t.uuid "visit_id", limit: 16 @@ -482,7 +482,7 @@ ActiveRecord::Schema.define(version: 20170129075434) do t.datetime "created_at" t.datetime "updated_at" t.string "name" - t.boolean "email_public" + t.boolean "email_public", default: true t.text "biography" t.string "nickname" t.string "affiliation" From e57c83c355fb10ea276b3fb15fcd605ace7f2296 Mon Sep 17 00:00:00 2001 From: JewelSam Date: Wed, 15 Feb 2017 18:07:20 +0300 Subject: [PATCH 2/3] Added reverse method to migration --- db/migrate/20170213145807_change_email_public_from_users.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/db/migrate/20170213145807_change_email_public_from_users.rb b/db/migrate/20170213145807_change_email_public_from_users.rb index 2481accb..2bbaffa6 100644 --- a/db/migrate/20170213145807_change_email_public_from_users.rb +++ b/db/migrate/20170213145807_change_email_public_from_users.rb @@ -1,5 +1,9 @@ class ChangeEmailPublicFromUsers < ActiveRecord::Migration - def change + def up change_column_default :users, :email_public, true end + + def down + change_column_default :users, :email_public, nil + end end From 36f97ad5e55f6a18f4b68c748df0b627594bb901 Mon Sep 17 00:00:00 2001 From: JewelSam Date: Wed, 15 Feb 2017 18:07:44 +0300 Subject: [PATCH 3/3] Added task for set email_public attribute true for all users --- lib/tasks/user.rake | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/tasks/user.rake b/lib/tasks/user.rake index 0e199d72..97e56e40 100644 --- a/lib/tasks/user.rake +++ b/lib/tasks/user.rake @@ -14,4 +14,8 @@ namespace :user do end end + desc "Set email_public attrubute true for all users" + task :set_email_public => :environment do + User.update_all email_public: true + end end