Make approved events confirmable

This commit is contained in:
Petko Bordjukov 2015-10-19 00:47:39 +03:00
parent 8c94bb3a87
commit 0296af92db
6 changed files with 28 additions and 3 deletions

View File

@ -40,6 +40,18 @@ module Public
end
end
def confirm
@event = current_user.events.approved.find(params[:id])
if @event.confirm!
flash[:notice] = I18n.t('views.events.successfully_confirmed', event_type: @event.event_type.name.mb_chars.downcase)
else
flash[:alert] = I18n.t('views.events.error_on_confirmation', event_type: @event.event_type.name.mb_chars.downcase)
end
after_save_redirect
end
private
def event_params

View File

@ -5,10 +5,11 @@ module Proposable
has_one :proposition, as: :proposable, dependent: :destroy
has_one :proposer, through: :proposition
delegate :email, to: :proposer, prefix: true
scope :confirmed, -> { joins(:proposition).where.not(propositions: {confirmed_at: nil}) }
delegate :confirm!, to: :proposition
scope :confirmed, -> { where.not(propositions: {confirmed_at: nil}) }
Proposition.defined_enums["status"].keys.each do |status|
scope status.to_sym, -> { joins(:proposition).where(propositions: {status: Proposition.defined_enums["status"][status]}) }
scope status.to_sym, -> { where(propositions: {status: Proposition.defined_enums["status"][status]}) }
end
end

View File

@ -7,6 +7,10 @@ class Proposition < ActiveRecord::Base
after_create :send_creation_notification
before_destroy :send_withdrawal_notification
def confirm!
update(confirmed_at: Time.now)
end
def send_creation_notification
PropositionMailer.new_proposition_notification(self).deliver_later
end

View File

@ -289,6 +289,8 @@ bg:
edit_event: "Редактиране на %{event_type} %{title}"
event_successfully_created: "Предложението Ви за %{event_type} беше създадено успешно"
event_successfully_updated: "Предложението Ви за %{event_type} беше обновено успешно"
successfully_confirmed: "Предложението Ви за %{event_type} беше потвърдено успешно"
error_on_confirmation: "Възникна грешка при потвърждението на предложението Ви за %{event_type}"
no_events: "Все още не сте предложили събитие"
submit_event: "Предлагане на %{event_type}"
navigation:

View File

@ -282,6 +282,8 @@ en:
edit_event: Editing %{event_type} %{title}
event_successfully_created: Your %{event_type} submission was successfully created
event_successfully_updated: Your %{event_type} submission was successfully updated
successfully_confirmed: Your %{event_type} submission was successfully confirmed
error_on_confirmation: There was an error during the confirmation of your %{event_type} submission
no_events: You are yet to submit an event
submit_event: Submit a %{event_type}
navigation:

View File

@ -4,7 +4,11 @@ Rails.application.routes.draw do
scope module: :public do
root to: 'home#index'
resource :personal_profile, path: 'profile'
resources :events
resources :events do
member do
get :confirm
end
end
resources :volunteerships, only: [:index, :destroy]
resources :volunteer_teams, only: [] do
resource :volunteership, only: :create