Merge pull request #1666 from consul/users-without-email
Users without email
This commit is contained in:
@@ -6,7 +6,13 @@ class Management::UsersController < Management::BaseController
|
||||
|
||||
def create
|
||||
@user = User.new(user_params)
|
||||
@user.skip_password_validation = true
|
||||
|
||||
if @user.email.blank?
|
||||
user_without_email
|
||||
else
|
||||
user_with_email
|
||||
end
|
||||
|
||||
@user.terms_of_service = '1'
|
||||
@user.residence_verified_at = Time.current
|
||||
@user.verified_at = Time.current
|
||||
@@ -40,4 +46,24 @@ class Management::UsersController < Management::BaseController
|
||||
session[:document_number] = nil
|
||||
end
|
||||
|
||||
def user_without_email
|
||||
new_password = "aAbcdeEfghiJkmnpqrstuUvwxyz23456789$!".split('').sample(10).join('')
|
||||
@user.password = new_password
|
||||
@user.password_confirmation = new_password
|
||||
|
||||
@user.email = nil
|
||||
@user.confirmed_at = Time.current
|
||||
|
||||
@user.newsletter = false
|
||||
@user.email_on_proposal_notification = false
|
||||
@user.email_digest = false
|
||||
@user.email_on_direct_message = false
|
||||
@user.email_on_comment = false
|
||||
@user.email_on_comment_reply = false
|
||||
end
|
||||
|
||||
def user_with_email
|
||||
@user.skip_password_validation = true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
class Mailer < ApplicationMailer
|
||||
after_action :prevent_delivery_to_users_without_email
|
||||
|
||||
helper :text_with_links
|
||||
helper :mailer
|
||||
helper :users
|
||||
@@ -6,8 +8,10 @@ class Mailer < ApplicationMailer
|
||||
def comment(comment)
|
||||
@comment = comment
|
||||
@commentable = comment.commentable
|
||||
@email_to = @commentable.author.email
|
||||
|
||||
with_user(@commentable.author) do
|
||||
mail(to: @commentable.author.email, subject: t('mailers.comment.subject', commentable: t("activerecord.models.#{@commentable.class.name.underscore}", count: 1).downcase)) if @commentable.present? && @commentable.author.present?
|
||||
mail(to: @email_to, subject: t('mailers.comment.subject', commentable: t("activerecord.models.#{@commentable.class.name.underscore}", count: 1).downcase)) if @commentable.present? && @commentable.author.present?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,96 +20,108 @@ class Mailer < ApplicationMailer
|
||||
@commentable = @reply.commentable
|
||||
parent = Comment.find(@reply.parent_id)
|
||||
@recipient = parent.author
|
||||
@email_to = @recipient.email
|
||||
|
||||
with_user(@recipient) do
|
||||
mail(to: @recipient.email, subject: t('mailers.reply.subject')) if @commentable.present? && @recipient.present?
|
||||
mail(to: @email_to, subject: t('mailers.reply.subject')) if @commentable.present? && @recipient.present?
|
||||
end
|
||||
end
|
||||
|
||||
def email_verification(user, recipient, token, document_type, document_number)
|
||||
@user = user
|
||||
@recipient = recipient
|
||||
@email_to = recipient
|
||||
@token = token
|
||||
@document_type = document_type
|
||||
@document_number = document_number
|
||||
|
||||
with_user(user) do
|
||||
mail(to: @recipient, subject: t('mailers.email_verification.subject'))
|
||||
mail(to: @email_to, subject: t('mailers.email_verification.subject'))
|
||||
end
|
||||
end
|
||||
|
||||
def unfeasible_spending_proposal(spending_proposal)
|
||||
@spending_proposal = spending_proposal
|
||||
@author = spending_proposal.author
|
||||
@email_to = @author.email
|
||||
|
||||
with_user(@author) do
|
||||
mail(to: @author.email, subject: t('mailers.unfeasible_spending_proposal.subject', code: @spending_proposal.code))
|
||||
mail(to: @email_to, subject: t('mailers.unfeasible_spending_proposal.subject', code: @spending_proposal.code))
|
||||
end
|
||||
end
|
||||
|
||||
def direct_message_for_receiver(direct_message)
|
||||
@direct_message = direct_message
|
||||
@receiver = @direct_message.receiver
|
||||
@email_to = @receiver.email
|
||||
|
||||
with_user(@receiver) do
|
||||
mail(to: @receiver.email, subject: t('mailers.direct_message_for_receiver.subject'))
|
||||
mail(to: @email_to, subject: t('mailers.direct_message_for_receiver.subject'))
|
||||
end
|
||||
end
|
||||
|
||||
def direct_message_for_sender(direct_message)
|
||||
@direct_message = direct_message
|
||||
@sender = @direct_message.sender
|
||||
@email_to = @sender.email
|
||||
|
||||
with_user(@sender) do
|
||||
mail(to: @sender.email, subject: t('mailers.direct_message_for_sender.subject'))
|
||||
mail(to: @email_to, subject: t('mailers.direct_message_for_sender.subject'))
|
||||
end
|
||||
end
|
||||
|
||||
def proposal_notification_digest(user, notifications)
|
||||
@notifications = notifications
|
||||
@email_to = user.email
|
||||
|
||||
with_user(user) do
|
||||
mail(to: user.email, subject: t('mailers.proposal_notification_digest.title', org_name: Setting['org_name']))
|
||||
mail(to: @email_to, subject: t('mailers.proposal_notification_digest.title', org_name: Setting['org_name']))
|
||||
end
|
||||
end
|
||||
|
||||
def user_invite(email)
|
||||
@email_to = email
|
||||
|
||||
I18n.with_locale(I18n.default_locale) do
|
||||
mail(to: email, subject: t('mailers.user_invite.subject', org_name: Setting["org_name"]))
|
||||
mail(to: @email_to, subject: t('mailers.user_invite.subject', org_name: Setting["org_name"]))
|
||||
end
|
||||
end
|
||||
|
||||
def budget_investment_created(investment)
|
||||
@investment = investment
|
||||
@email_to = @investment.author.email
|
||||
|
||||
with_user(@investment.author) do
|
||||
mail(to: @investment.author.email, subject: t('mailers.budget_investment_created.subject'))
|
||||
mail(to: @email_to, subject: t('mailers.budget_investment_created.subject'))
|
||||
end
|
||||
end
|
||||
|
||||
def budget_investment_unfeasible(investment)
|
||||
@investment = investment
|
||||
@author = investment.author
|
||||
@email_to = @author.email
|
||||
|
||||
with_user(@author) do
|
||||
mail(to: @author.email, subject: t('mailers.budget_investment_unfeasible.subject', code: @investment.code))
|
||||
mail(to: @email_to, subject: t('mailers.budget_investment_unfeasible.subject', code: @investment.code))
|
||||
end
|
||||
end
|
||||
|
||||
def budget_investment_selected(investment)
|
||||
@investment = investment
|
||||
@author = investment.author
|
||||
@email_to = @author.email
|
||||
|
||||
with_user(@author) do
|
||||
mail(to: @author.email, subject: t('mailers.budget_investment_selected.subject', code: @investment.code))
|
||||
mail(to: @email_to, subject: t('mailers.budget_investment_selected.subject', code: @investment.code))
|
||||
end
|
||||
end
|
||||
|
||||
def budget_investment_unselected(investment)
|
||||
@investment = investment
|
||||
@author = investment.author
|
||||
@email_to = @author.email
|
||||
|
||||
with_user(@author) do
|
||||
mail(to: @author.email, subject: t('mailers.budget_investment_unselected.subject', code: @investment.code))
|
||||
mail(to: @email_to, subject: t('mailers.budget_investment_unselected.subject', code: @investment.code))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -116,4 +132,11 @@ class Mailer < ApplicationMailer
|
||||
block.call
|
||||
end
|
||||
end
|
||||
|
||||
def prevent_delivery_to_users_without_email
|
||||
if @email_to.blank?
|
||||
mail.perform_deliveries = false
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -247,7 +247,7 @@ class User < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def email_required?
|
||||
!erased?
|
||||
!erased? && unverified?
|
||||
end
|
||||
|
||||
def locale
|
||||
|
||||
@@ -40,52 +40,54 @@
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<h2><%= t("account.show.notifications")%></h2>
|
||||
<% if @account.email.present? %>
|
||||
<h2><%= t("account.show.notifications")%></h2>
|
||||
|
||||
<div>
|
||||
<%= f.label :email_on_comment do %>
|
||||
<%= f.check_box :email_on_comment, title: t('account.show.email_on_comment_label'), label: false %>
|
||||
<span class="checkbox">
|
||||
<%= t("account.show.email_on_comment_label") %>
|
||||
</span>
|
||||
<% end %>
|
||||
</div>
|
||||
<div>
|
||||
<%= f.label :email_on_comment do %>
|
||||
<%= f.check_box :email_on_comment, title: t('account.show.email_on_comment_label'), label: false %>
|
||||
<span class="checkbox">
|
||||
<%= t("account.show.email_on_comment_label") %>
|
||||
</span>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= f.label :email_on_comment_reply do %>
|
||||
<%= f.check_box :email_on_comment_reply, title: t('account.show.email_on_comment_reply_label'), label: false %>
|
||||
<span class="checkbox">
|
||||
<%= t("account.show.email_on_comment_reply_label") %>
|
||||
</span>
|
||||
<% end %>
|
||||
</div>
|
||||
<div>
|
||||
<%= f.label :email_on_comment_reply do %>
|
||||
<%= f.check_box :email_on_comment_reply, title: t('account.show.email_on_comment_reply_label'), label: false %>
|
||||
<span class="checkbox">
|
||||
<%= t("account.show.email_on_comment_reply_label") %>
|
||||
</span>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= f.label :email_newsletter_subscribed do %>
|
||||
<%= f.check_box :newsletter, title: t('account.show.subscription_to_website_newsletter_label'), label: false %>
|
||||
<span class="checkbox">
|
||||
<%= t("account.show.subscription_to_website_newsletter_label") %>
|
||||
</span>
|
||||
<% end %>
|
||||
</div>
|
||||
<div>
|
||||
<%= f.label :email_newsletter_subscribed do %>
|
||||
<%= f.check_box :newsletter, title: t('account.show.subscription_to_website_newsletter_label'), label: false %>
|
||||
<span class="checkbox">
|
||||
<%= t("account.show.subscription_to_website_newsletter_label") %>
|
||||
</span>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= f.label :email_digest do %>
|
||||
<%= f.check_box :email_digest, title: t('account.show.email_digest_label'), label: false %>
|
||||
<span class="checkbox">
|
||||
<%= t("account.show.email_digest_label") %>
|
||||
</span>
|
||||
<% end %>
|
||||
</div>
|
||||
<div>
|
||||
<%= f.label :email_digest do %>
|
||||
<%= f.check_box :email_digest, title: t('account.show.email_digest_label'), label: false %>
|
||||
<span class="checkbox">
|
||||
<%= t("account.show.email_digest_label") %>
|
||||
</span>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= f.label :email_on_direct_message do %>
|
||||
<%= f.check_box :email_on_direct_message, title: t('account.show.email_on_direct_message_label'), label: false %>
|
||||
<span class="checkbox">
|
||||
<%= t("account.show.email_on_direct_message_label") %>
|
||||
</span>
|
||||
<% end %>
|
||||
</div>
|
||||
<div>
|
||||
<%= f.label :email_on_direct_message do %>
|
||||
<%= f.check_box :email_on_direct_message, title: t('account.show.email_on_direct_message_label'), label: false %>
|
||||
<span class="checkbox">
|
||||
<%= t("account.show.email_on_direct_message_label") %>
|
||||
</span>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if @account.official_level == 1 %>
|
||||
<div>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
label: t('management.username_label'),
|
||||
placeholder: t('management.username_label') %>
|
||||
<%= f.text_field :email,
|
||||
label: t('management.email_label'),
|
||||
label: t('management.users.email_optional_label'),
|
||||
placeholder: t('management.email_label') %>
|
||||
<div class="date-of-birth">
|
||||
<%= f.label t("management.date_of_birth") %>
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
<p><%= t("management.users.create_user_success_html", email: @user.email) %></p>
|
||||
<% if @user.email.blank? %>
|
||||
<p><%= t("management.users.autogenerated_password_html", password: @user.password) %></p>
|
||||
<% else %>
|
||||
<p><%= t("management.users.create_user_success_html", email: @user.email) %></p>
|
||||
<% end %>
|
||||
|
||||
<%= render 'management/user_permissions',
|
||||
message: t("management.document_verifications.in_census_has_following_permissions"),
|
||||
|
||||
Reference in New Issue
Block a user