Skip to content

Commit

Permalink
Fix category from organizations. Check all emails.
Browse files Browse the repository at this point in the history
  • Loading branch information
taitus committed Dec 28, 2017
1 parent b77f36a commit 37f827e
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 70 deletions.
1 change: 1 addition & 0 deletions app/controllers/admin/organizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def update
if @organization.update_attributes(organization_params)
path = current_user.lobby? ? admin_organization_path(@organization) : admin_organizations_path
@organization.send_update_mail
# @organization.send_invalidate_mail if params[:organization][:invalidate]
redirect_to path, notice: t('backend.successfully_updated_record')
else
flash[:alert] = t('backend.review_errors')
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: "from@example.com"
default from: "no-reply@madrid.es"
layout 'mailer'
end
48 changes: 21 additions & 27 deletions app/mailers/event_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,59 +1,53 @@
class EventMailer < ApplicationMailer

def decline(event)
return unless event.lobby_contact_email
@lobby_name = event.lobby_user_name
@lobby_name = event.lobby_user_name.present? ? event.lobby_user_name : event.organization.user.first_name
@reasons = event.declined_reasons
@event_title = event.title
@name = event.user.full_name
@declined_at = l event.declined_at, format: :short
to = event.lobby_contact_email.present? ? event.lobby_contact_email : event.organization.user.email
subject = t('mailers.decline_event.subject', title: @event_title)
mail(to: event.lobby_contact_email, subject: subject)
mail(to: to, bcc: "registrodelobbies@madrid.es", subject: subject)
end

def accept(event)
return unless event.lobby_contact_email
@lobby_name = event.lobby_user_name
@lobby_name = event.lobby_user_name.present? ? event.lobby_user_name : event.organization.user.first_name
@event_title = event.title
@name = event.user.full_name
@accepted_at = l event.accepted_at, format: :short
to = event.lobby_contact_email.present? ? event.lobby_contact_email : event.organization.user.email
subject = t('mailers.accept_event.subject', title: @event_title)
mail(to: event.lobby_contact_email, subject: subject)
mail(to: to, bcc: "registrodelobbies@madrid.es", subject: subject)
end

def cancel(event, user)
if user.lobby?
to = user.email
return unless user.email
name = event.lobby_user_name
else
return unless event.lobby_contact_email
to = event.lobby_contact_email
name = event.user.name
end
def cancel(event)
#pending titular email
#pending canceled author
manages_emails = event.position.holder.users.collect(&:email).join(",")
lobby_email = event.lobby_contact_email.present? ? event.lobby_contact_email : event.organization.user.email
to = lobby_email + ", " + manages_emails
@reasons = event.canceled_reasons
@canceled_at = l event.canceled_at, format: :short
@event_title = event.title
@name = name
subject = t('mailers.cancel_event.subject', title: @event_title)
mail(to: to, subject: subject)
mail(to: to, bcc: "registrodelobbies@madrid.es", subject: subject)
end

def create(event, user)
if user.lobby?
to = user.email
return unless user.email
name = event.lobby_user_name
def create(event)
if event.status == "requested"
manages_emails = event.position.holder.users.collect(&:email).join(",")
#pending titular email
to = manages_emails
name = event.lobby_user_name.present? ? event.lobby_user_name : event.organization.user.first_name
else
return unless event.lobby_contact_email
to = event.lobby_contact_email
to = event.lobby_contact_email.present? ? event.lobby_contact_email : event.organization.user.email
name = event.user.name
end
@lobby_name = event.lobby_user_name
@event_title = event.title
@name = name
subject = t('mailers.create_event.subject', title: @event_title)
mail(to: to, subject: subject)
mail(to: to, bcc: "registrodelobbies@madrid.es", subject: subject)
end

end
12 changes: 4 additions & 8 deletions app/mailers/organization_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,35 @@ class OrganizationMailer < ApplicationMailer


def create(organization)
return if organization.email.blank?
@name = organization.user_name
@title = organization.fullname

subject = t('mailers.create_organization.subject', title: @title)
mail(to: organization.email, subject: subject, cco: 'registrodelobbies@madrid.es')
mail(to: organization.user.email, subject: subject, cco: 'registrodelobbies@madrid.es')
end

def invalidate(organization)
return if organization.email.blank?
@name = organization.user_name
@title = organization.fullname

subject = t('mailers.invalidate_organization.subject', title: @title)
mail(to: organization.email, subject: subject, cco: 'registrodelobbies@madrid.es')
mail(to: organization.user.email, subject: subject, cco: 'registrodelobbies@madrid.es')
end

def delete(organization)
return if organization.email.blank?
@name = organization.user_name
@title = organization.fullname

subject = t('mailers.delete_organization.subject', title: @title)
mail(to: organization.email, subject: subject, cco: 'registrodelobbies@madrid.es')
mail(to: organization.user.email, subject: subject, cco: 'registrodelobbies@madrid.es')
end

def update(organization)
return if organization.email.blank?
@name = organization.user_name
@title = organization.fullname

subject = t('mailers.update_organization.subject', title: @title)
mail(to: organization.email, subject: subject, cco: 'registrodelobbies@madrid.es')
mail(to: organization.user.email, subject: subject, cco: 'registrodelobbies@madrid.es')
end

end
2 changes: 1 addition & 1 deletion app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def infringement_email(email, attachment)
admin_emails = User.admin.collect(&:email).join(",")
attachments[attachment.original_filename] = File.read(attachment.path) if attachment

mail(bcc: admin_emails, subject: @email.subject)
mail(to: "buzonlobby@madrid.es", bcc: admin_emails, subject: @email.subject)
end

end
20 changes: 13 additions & 7 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ class Event < ActiveRecord::Base

def cancel_event
return unless cancel == 'true' && canceled_at.nil?
self.canceled_at = Time.zone.today
self.status = 'canceled'
EventMailer.cancel(self, current_user).deliver_now
if self.lobby_activity && self.organization.present? && self.organization.entity_type == "lobby"
self.canceled_at = Time.zone.today
self.status = 'canceled'
EventMailer.cancel(self).deliver_now
end
end

def decline_event
Expand All @@ -75,13 +77,17 @@ def decline_event

def accept_event
return unless accept == 'true' && accepted_at.nil?
self.accepted_at = Time.zone.today
self.status = 'accepted'
EventMailer.accept(self).deliver_now
if self.lobby_activity && self.organization.present? && self.organization.entity_type == "lobby"
self.accepted_at = Time.zone.today
self.status = 'accepted'
EventMailer.accept(self).deliver_now
end
end

def create_event
EventMailer.create(self, current_user).deliver_now if current_user
if self.lobby_activity && self.organization.present? && self.organization.entity_type == "lobby"
EventMailer.create(self).deliver_now
end
end

def self.managed_by(user)
Expand Down
8 changes: 4 additions & 4 deletions app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Organization < ActiveRecord::Base
accepts_nested_attributes_for :attachments, allow_destroy: true, reject_if: :all_blank

before_validation :invalidate_organization, :validate_organization
after_create :set_inscription_date, :send_create_mail
after_create :set_inscription_date
before_destroy :send_delete_mail

searchable do
Expand Down Expand Up @@ -56,9 +56,9 @@ class Organization < ActiveRecord::Base
scope :lobbies, -> { where('entity_type = ?', 2) }
scope :full_like, ->(name) { where("(identifier ilike ? OR name ilike ?) AND entity_type = ?", name, name, 2) }

def send_create_mail
OrganizationMailer.create(self).deliver_now
end
# def send_create_mail
# OrganizationMailer.create(self).deliver_now
# end

def send_delete_mail
OrganizationMailer.delete(self).deliver_now
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/organizations/_data.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</div>
<div class="small-12 columns">
<%= f.label :category_id, t('backend.identifying_data.category_id') %>
<%= f.select :category_id, options_for_select(Category.where(display: true).map{|c| [c.name, c.id]}), prompt: t('backend.none') %>
<%= f.select :category_id, options_for_select(Category.where(display: true).map{ |c| [c.name, c.id] }, f.object.category_id), prompt: t('backend.none') %>
<%= form_field_errors(f, :category_id) %>
</div>
<div class="small-12 columns">
Expand Down
2 changes: 1 addition & 1 deletion app/views/areas/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<%= f.label :title, t('backend.title') %>
<%= f.text_field :title %>
<%= f.label :parent, t('backend.parent') %>
<%= f.select :parent_id, options_for_select(Area.all.map{|a| [a.title, a.id]},:parent_id), prompt: t('backend.none') %>
<%= f.select :parent_id, options_for_select(Area.all.map{ |a| [a.title, a.id] } ,:parent_id), prompt: t('backend.none') %>
</fieldset>

<%= submit_tag t('backend.save'), :class=> "button radius success right" %>
Expand Down
3 changes: 0 additions & 3 deletions app/views/event_mailer/cancel.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<td style="padding-bottom: 20px; padding-left: 10px;">
<h1 style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;">
<%= t('mailers.cancel_event.welcome', name: @name) %>
</h1>

<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
<%= t('mailers.cancel_event.text1', title: @event_title) %>
Expand Down
7 changes: 0 additions & 7 deletions app/views/event_mailer/create.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<td style="padding-bottom: 20px; padding-left: 10px;">
<h1 style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;">
<%= t('mailers.create_event.welcome', name: @lobby_name) %>
</h1>

<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
<%= t('mailers.create_event.text1', title: @event_title) %>
Expand All @@ -11,10 +8,6 @@
<%= t('mailers.create_event.text2', name: @name) %>
</p>

<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
<%= t('mailers.create_event.accepted_at', accepted_at: @accepted_at) %>
</p>

<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
<%= t('mailers.create_event.thanks') %>
</p>
Expand Down
2 changes: 1 addition & 1 deletion spec/features/admin/organizations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@
fill_in :organization_description, with: "New description"
click_button "Guardar"

open_email(organization.email)
open_email(organization.user.email)
organization.reload
expect(page).to have_content "Registro actualizado correctamente"
expect(organization.web).to eq "www.new_web.com"
Expand Down
15 changes: 10 additions & 5 deletions spec/features/mailers/events_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
@event.canceled_reasons = 'test'
@event.lobby_contact_email = 'test@test'
@event.current_user = user
@event.lobby_activity = true
@event.save!
open_email(@event.lobby_contact_email)
end
Expand All @@ -34,6 +35,7 @@
@event.decline = 'true'
@event.declined_reasons = 'test'
@event.current_user = user
@event.lobby_activity = true
@event.save!
open_email(@event.lobby_contact_email)
end
Expand All @@ -56,6 +58,7 @@
@event.lobby_contact_email = 'test_lobby_mail'
@event.accept = 'true'
@event.current_user = user
@event.lobby_activity = true
@event.save!
open_email(@event.lobby_contact_email)
end
Expand All @@ -73,11 +76,12 @@
clear_emails
@event = create(:event, title: 'New event from Capybara', user: user)
@event.update(status: 'accepted')
@event.lobby_contact_email = 'test_lobby_mail'
@event.cancel = 'true'
@event.canceled_reasons = 'test'
@event.current_user = user
@event.lobby_activity = true
@event.save!
open_email(@event.user.email)
open_email(@event.lobby_contact_email)
end

scenario 'cancel event mail lobby' do
Expand All @@ -92,7 +96,7 @@
signin(user.email, user.password)
clear_emails
@event = create(:event, title: 'New event from Capybara', user: user,
current_user: user, lobby_contact_email: 'test@test' )
current_user: user, lobby_contact_email: 'test@test', lobby_activity: true )
open_email(@event.lobby_contact_email)
end

Expand All @@ -108,11 +112,12 @@
signin(user.email, user.password)
clear_emails
@event = create(:event, title: 'New event from Capybara', user: user,
current_user: user, lobby_contact_email: 'test@test', current_user: user )
open_email(@event.user.email)
current_user: user, lobby_contact_email: 'test@test', lobby_activity: true, status: "requested" )
open_email(@event.lobby_contact_email)
end

scenario 'create event mail' do
skip("pending test")
expect(current_email).to have_content I18n.t('mailers.create_event.text1', title: @event.title)
end

Expand Down
8 changes: 5 additions & 3 deletions spec/features/mailers/organizations_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
describe "Create Organization" do
background do
@organization = create(:organization)
open_email(@organization.email)
open_email(@organization.user.email)
end

scenario 'create event mail' do
pending("pending remove spec. This email create on UserMailer")
expect(current_email).to have_content I18n.t('mailers.create_organization.text1', title: @organization.fullname)
end

Expand All @@ -17,7 +18,7 @@
organization = create(:organization)
@fullname = organization.fullname
organization.destroy
open_email(organization.email)
open_email(organization.user.email)
end

scenario 'delete event mail' do
Expand All @@ -30,10 +31,11 @@
background do
@organization = create(:organization)
@organization.set_invalidate
open_email(@organization.email)
open_email(@organization.user.email)
end

scenario 'invalidate event mail' do
skip("unnecessary email")
expect(current_email).to have_content I18n.t('mailers.invalidate_organization.text1', title: @organization.fullname)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/mailers/user_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
let!(:mail) { UserMailer.welcome(@organization.user) }

it "should send from example" do
expect(mail.from).to eq([ "from@example.com"])
expect(mail.from).to eq([ "no-reply@madrid.es"])
end

it "should send to new user" do
Expand Down

0 comments on commit 37f827e

Please sign in to comment.