New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add conference registration types CRUD + Public view #4408
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a9c8046
CRUD of registration types done, pending tests
f75205f
adding registration button to frontend
11a3d35
add registration type to conference registration [ci-skip]
de6090b
fix locale errors
126823e
fix invite join mailer
fb58f62
fix i18n locales
1ca8bf7
add tests for registration types, form, commands, system and model
a14a7f6
add changelog line
c9bbb11
fix changelog order on rebase
4d2524d
fix codeclimate erros
885012a
add trailing newline at the end of the file
93cb8c7
apply requested changes
ddca48b
Merge branch 'master' into conference_registration_types
oriolgual File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
4 changes: 2 additions & 2 deletions
4
...onference_button/registration_confirm.erb → ...egistration_type/registration_confirm.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
16 changes: 16 additions & 0 deletions
16
decidim-conferences/app/cells/decidim/conferences/registration_type/show.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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<div class="conference-registration card__block" id="registration-type-<%= model.id %>"> | ||
<div class="row flex--cc"> | ||
<div class="columns medium-8"> | ||
<div class="registration__text"> | ||
<strong><%= title %></strong> | ||
<span> <%= description %></span> | ||
</div> | ||
</div> | ||
<div class="columns medium-4"> | ||
<div class="registration__buttons"> | ||
<button type="button" class="small-5 small"><strong><%= price %></strong></button> | ||
<%= render :join_conference %> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
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
62 changes: 62 additions & 0 deletions
62
...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,62 @@ | ||
# 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, current_user) | ||
@conference_registration = conference_registration | ||
@current_user = current_user | ||
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 |
77 changes: 77 additions & 0 deletions
77
decidim-conferences/app/commands/decidim/conferences/admin/create_registration_type.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,77 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module Conferences | ||
module Admin | ||
# A command with all the business logic when creating a new registration type | ||
# in the system. | ||
class CreateRegistrationType < Rectify::Command | ||
# Public: Initializes the command. | ||
# | ||
# form - A form object with the params. | ||
# current_user - The current user hwo do the action of create | ||
# conference - The Conference that will hold the speaker | ||
def initialize(form, current_user, conference) | ||
@form = form | ||
@current_user = current_user | ||
@conference = conference | ||
end | ||
|
||
# Executes the command. Broadcasts these events: | ||
# | ||
# - :ok when everything is valid. | ||
# - :invalid if the form wasn't valid and we couldn't proceed. | ||
# | ||
# Returns nothing. | ||
def call | ||
return broadcast(:invalid) if form.invalid? | ||
|
||
transaction do | ||
create_registration_type! | ||
link_meetings(@registration_type) | ||
end | ||
|
||
broadcast(:ok) | ||
end | ||
|
||
private | ||
|
||
attr_reader :form, :conference, :current_user | ||
|
||
def create_registration_type! | ||
log_info = { | ||
resource: { | ||
title: form.title | ||
}, | ||
participatory_space: { | ||
title: conference.title | ||
} | ||
} | ||
|
||
@registration_type = Decidim.traceability.create!( | ||
Decidim::Conferences::RegistrationType, | ||
form.current_user, | ||
form.attributes.slice( | ||
:title, | ||
:description, | ||
:price, | ||
:weight | ||
).merge( | ||
conference: conference | ||
), | ||
log_info | ||
) | ||
end | ||
|
||
def conference_meetings(registration_type) | ||
meeting_components = registration_type.conference.components.where(manifest_name: "meetings") | ||
Decidim::ConferenceMeeting.where(component: meeting_components).where(id: @form.attributes[:conference_meeting_ids]) | ||
end | ||
|
||
def link_meetings(registration_type) | ||
registration_type.conference_meetings = conference_meetings(registration_type) | ||
end | ||
end | ||
end | ||
end | ||
end |
56 changes: 56 additions & 0 deletions
56
decidim-conferences/app/commands/decidim/conferences/admin/destroy_registration_type.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,56 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module Conferences | ||
module Admin | ||
# A command with all the business logic when destroying a conference | ||
# registration type in the system. | ||
class DestroyRegistrationType < Rectify::Command | ||
# Public: Initializes the command. | ||
# | ||
# registration_type - the Partner to destroy | ||
# current_user - the user performing this action | ||
def initialize(registration_type, current_user) | ||
@registration_type = registration_type | ||
@current_user = current_user | ||
end | ||
|
||
# Executes the command. Broadcasts these events: | ||
# | ||
# - :ok when everything is valid. | ||
# - :invalid if the form wasn't valid and we couldn't proceed. | ||
# | ||
# Returns nothing. | ||
def call | ||
destroy_registration_type! | ||
broadcast(:ok) | ||
end | ||
|
||
private | ||
|
||
attr_reader :registration_type, :current_user | ||
|
||
def destroy_registration_type! | ||
log_info = { | ||
resource: { | ||
title: registration_type.title | ||
}, | ||
participatory_space: { | ||
title: registration_type.conference.title | ||
} | ||
} | ||
|
||
Decidim.traceability.perform_action!( | ||
"delete", | ||
registration_type, | ||
current_user, | ||
log_info | ||
) do | ||
registration_type.destroy! | ||
registration_type | ||
end | ||
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's a
Decidim::ConferenceMeeting
? Shouldn't it be scoped toDecidim::Conferences
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe yes, but 'Decidim::ConferenceMeeting' is already in master. If 'ConferenceMeeting' should be scoped to 'Decidim::Conferences', in my opinion is out of this scope and it will be better to do in another PR.
What you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fair, let's do it in another PR!