Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Isaac Massot
committed
Oct 30, 2018
1 parent
06954a8
commit d196d1e
Showing
24 changed files
with
259 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...dim-conferences/app/commands/decidim/conferences/admin/confirm_conference_registration.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module Conferences | ||
module Admin | ||
# This command is executed when the user joins a conference. | ||
class ConfirmConferenceRegistration < Rectify::Command | ||
# Initializes a JoinConference Command. | ||
# | ||
# conference_registration - The registration to be confirmed | ||
def initialize(conference_registration) | ||
@conference_registration = conference_registration | ||
end | ||
|
||
# Creates a conference registration if the conference has registrations enabled | ||
# and there are available slots. | ||
# | ||
# Broadcasts :ok if successful, :invalid otherwise. | ||
def call | ||
conference_registration.with_lock do | ||
return broadcast(:invalid) unless can_join_conference? | ||
confirm_registration | ||
send_email_confirmation | ||
end | ||
broadcast(:ok) | ||
end | ||
|
||
private | ||
|
||
attr_reader :conference, :user | ||
|
||
def confirm_registration | ||
extra_info = { | ||
resource: { | ||
title: conference_registration.conference.title | ||
} | ||
} | ||
|
||
Decidim.traceability.perform_action!( | ||
"confirm", | ||
conference_registration, | ||
current_user, | ||
extra_info | ||
) do | ||
conference_registration.update!(confirmed_at: Time.current) | ||
conference_registration | ||
end | ||
end | ||
|
||
def can_join_conference? | ||
conference_registration.conference.registrations_enabled? && conference_registration.conference.has_available_slots? | ||
end | ||
|
||
def send_email_confirmation | ||
Decidim::Conferences::ConferenceRegistrationMailer.confirmation(conference_registration.user, | ||
conference_registration.conference, conference_registration.registration_type).deliver_later | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...erences/app/presenters/decidim/conferences/admin_log/conference_registration_presenter.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module Conferences | ||
module AdminLog | ||
# This class holds the logic to present a `Decidim::Conferences::ConferenceRegistration` | ||
# for the `AdminLog` log. | ||
# | ||
# Usage should be automatic and you shouldn't need to call this class | ||
# directly, but here's an example: | ||
# | ||
# action_log = Decidim::ActionLog.last | ||
# view_helpers # => this comes from the views | ||
# ConferenceRegistrationPresenter.new(action_log, view_helpers).present | ||
class ConferenceRegistrationPresenter < Decidim::Log::BasePresenter | ||
private | ||
|
||
def diff_fields_mapping | ||
{ | ||
confirmed_at: :date | ||
} | ||
end | ||
|
||
def i18n_labels_scope | ||
"activemodel.attributes.conferences.conference_registration" | ||
end | ||
|
||
def action_string | ||
case action | ||
when "confirm" | ||
"decidim.admin_log.conferences.conference_registration.#{action}" | ||
else | ||
super | ||
end | ||
end | ||
|
||
def has_diff? | ||
action == "delete" || super | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 9 additions & 1 deletion
10
...rences/app/views/decidim/conferences/conference_registration_mailer/confirmation.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
<p><%= t(".confirmed_html", title: translated_attribute(@conference.title), url: @locator.url) %></p> | ||
|
||
<p><%= t(".details") %></p> | ||
<p><%= t(".details_1", registration_type: translated_attribute(@registration_type.title), price: number_to_currency(@registration_type.price, locale: I18n.locale, unit: Decidim.currency_unit)) %></p> | ||
|
||
<ul> | ||
<% @registration_type.conference_meetings.each do |conference_meeting| %> | ||
<li><%= present(conference_meeting).title %> </li> | ||
<% end %> | ||
</ul> | ||
|
||
<p><%= t(".details_2") %></p> |
Oops, something went wrong.