forked from decidim/decidim
-
Notifications
You must be signed in to change notification settings - Fork 0
Enable waiting lists in meetings registrations #86
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
antopalidi
wants to merge
14
commits into
develop
Choose a base branch
from
feature/waitlist-for-full-meetings
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
fab405a
add Waitlist enabled option
antopalidi 988a91a
add cell, migrations
antopalidi 89e69e6
leave waiting list button, move_from_waitlist!
antopalidi e4889d2
registration_modal
antopalidi 7fd3620
cancel waitlist modal
antopalidi 1672e51
add tests
antopalidi ed5d403
fix tests
antopalidi 4dfd971
fix cell, add tests
antopalidi 4ea9695
add tests, fix email notification
antopalidi 5a11501
fix locale
antopalidi e46deee
add text
antopalidi 1604f62
fix
antopalidi e7aad43
copy meeting
antopalidi 5989836
change text
antopalidi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
decidim-meetings/app/cells/decidim/meetings/join_waitlist_button/show.erb
This file contains hidden or 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,22 @@ | ||
| <% if model.registration_form_enabled? %> | ||
| <%= action_authorized_link_to( | ||
| :join_waitlist, | ||
| join_waitlist_meeting_registration_path(model), | ||
| class: button_classes | ||
| ) do %> | ||
| <%= icon(icon_name) %> | ||
| <%= i18n_join_waitlist_text %> | ||
| <% end %> | ||
| <% else %> | ||
| <% unless options[:hide_modal] %> | ||
| <%= render :registration_modal %> | ||
| <% end %> | ||
| <%= action_authorized_button_to( | ||
| :join_waitlist, | ||
| content_tag(:span, "#{icon(icon_name)} #{i18n_join_waitlist_text}".html_safe), | ||
| "#", | ||
| class: button_classes, | ||
| data: { "dialog-open": current_user.present? ? "meeting-registration-confirm-#{model.id}" : "loginModal" }, | ||
| resource: model | ||
| ) %> | ||
| <% end %> |
41 changes: 41 additions & 0 deletions
41
decidim-meetings/app/cells/decidim/meetings/join_waitlist_button_cell.rb
This file contains hidden or 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,41 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Decidim | ||
| module Meetings | ||
| # This cell renders the button to join a waitlist. | ||
| class JoinWaitlistButtonCell < Decidim::ViewModel | ||
| include MeetingCellsHelper | ||
|
|
||
| def show | ||
| return unless model.waitlist_enabled? && !model.has_available_slots? && model.can_be_joined_by?(current_user) | ||
| return if model.has_registration_for?(current_user) | ||
|
|
||
| render | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def current_component | ||
| model.component | ||
| end | ||
|
|
||
| def button_classes | ||
| "button button__sm button__transparent-secondary w-full" | ||
| end | ||
|
|
||
| def i18n_join_waitlist_text | ||
| return if !model.waitlist_enabled? && model.has_available_slots? | ||
|
|
||
| I18n.t("add_to_waitlist", scope: "decidim.meetings.meetings.show") | ||
| end | ||
|
|
||
| def icon_name | ||
| "list-ordered" | ||
| end | ||
|
|
||
| def registration_form | ||
| @registration_form ||= Decidim::Meetings::JoinMeetingForm.new | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or 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
57 changes: 57 additions & 0 deletions
57
decidim-meetings/app/commands/decidim/meetings/join_waitlist.rb
This file contains hidden or 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,57 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Decidim | ||
| module Meetings | ||
| # This command is executed when the user joins a meeting waitlist. | ||
| class JoinWaitlist < Decidim::Command | ||
| delegate :current_user, to: :form | ||
|
|
||
| def initialize(meeting, form) | ||
| @meeting = meeting | ||
| @user_group = Decidim::UserGroup.find_by(id: form.user_group_id) | ||
| @form = form | ||
| end | ||
|
|
||
| def call | ||
| return broadcast(:invalid) unless can_join_waitlist? | ||
| return broadcast(:invalid_form) unless form.valid? | ||
|
|
||
| meeting.with_lock do | ||
| create_waitlist_entry | ||
| send_waitlist_notification | ||
| end | ||
|
|
||
| broadcast(:ok) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| attr_reader :meeting, :user_group, :form | ||
|
|
||
| def can_join_waitlist? | ||
| meeting.waitlist_enabled? && | ||
| !meeting.registrations.exists?(user: current_user) && | ||
| !meeting.has_available_slots? | ||
| end | ||
|
|
||
| def create_waitlist_entry | ||
| @registration = Decidim::Meetings::Registration.create!( | ||
| meeting:, | ||
| user: current_user, | ||
| user_group:, | ||
| public_participation: form.public_participation, | ||
| status: :waiting_list | ||
| ) | ||
| end | ||
|
|
||
| def send_waitlist_notification | ||
| Decidim::EventsManager.publish( | ||
| event: "decidim.events.meetings.meeting_waitlist_added", | ||
| event_class: Decidim::Meetings::MeetingWaitlistNotificationEvent, | ||
| resource: meeting, | ||
| affected_users: [current_user] | ||
| ) | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
7 changes: 7 additions & 0 deletions
7
decidim-meetings/db/migrate/20250214110525_add_waitlist_enabled_to_decidim_meetings.rb
This file contains hidden or 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,7 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class AddWaitlistEnabledToDecidimMeetings < ActiveRecord::Migration[7.0] | ||
| def change | ||
| add_column :decidim_meetings_meetings, :waitlist_enabled, :boolean, default: false, null: false | ||
| end | ||
| end |
8 changes: 8 additions & 0 deletions
8
...b/migrate/20250214113208_add_status_to_registrations_to_decidim_meetings_registrations.rb
This file contains hidden or 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,8 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class AddStatusToRegistrationsToDecidimMeetingsRegistrations < ActiveRecord::Migration[7.0] | ||
| def change | ||
| add_column :decidim_meetings_registrations, :status, :string, default: "registered", null: false | ||
| add_index :decidim_meetings_registrations, :status | ||
| end | ||
| end |
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.