Manually registering users
This commit is contained in:
parent
4182608f39
commit
892b423eda
3 changed files with 78 additions and 0 deletions
|
|
@ -73,6 +73,43 @@ module Admin
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def register_user
|
||||||
|
conference = Conference.find(params[:conference_id])
|
||||||
|
|
||||||
|
if @user.registrations.exists?(conference: conference)
|
||||||
|
redirect_to edit_admin_user_path(@user),
|
||||||
|
error: "User is already registered to #{conference.title}."
|
||||||
|
else
|
||||||
|
registration = @user.registrations.build(conference: conference)
|
||||||
|
registration.accepted_code_of_conduct = true if conference.code_of_conduct.present?
|
||||||
|
|
||||||
|
if registration.save
|
||||||
|
redirect_to edit_admin_user_path(@user),
|
||||||
|
notice: "Successfully registered #{@user.name} to #{conference.title}."
|
||||||
|
else
|
||||||
|
redirect_to edit_admin_user_path(@user),
|
||||||
|
error: "Failed to register user: #{registration.errors.full_messages.join('. ')}."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
redirect_to edit_admin_user_path(@user), error: 'Conference not found.'
|
||||||
|
end
|
||||||
|
|
||||||
|
def unregister_user
|
||||||
|
registration = @user.registrations.find(params[:registration_id])
|
||||||
|
conference_title = registration.conference.title
|
||||||
|
|
||||||
|
if registration.destroy
|
||||||
|
redirect_to edit_admin_user_path(@user),
|
||||||
|
notice: "Successfully removed #{@user.name} from #{conference_title}."
|
||||||
|
else
|
||||||
|
redirect_to edit_admin_user_path(@user),
|
||||||
|
error: "Failed to remove registration: #{registration.errors.full_messages.join('. ')}."
|
||||||
|
end
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
redirect_to edit_admin_user_path(@user), error: 'Registration not found.'
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def user_params
|
def user_params
|
||||||
|
|
|
||||||
|
|
@ -42,3 +42,42 @@
|
||||||
= f.text_area :biography, rows: 10, data: { provide: 'markdown' }, class: 'form-control'
|
= f.text_area :biography, rows: 10, data: { provide: 'markdown' }, class: 'form-control'
|
||||||
%span.help-block= markdown_hint
|
%span.help-block= markdown_hint
|
||||||
= f.submit nil, class: 'btn btn-primary'
|
= f.submit nil, class: 'btn btn-primary'
|
||||||
|
|
||||||
|
- unless @user.new_record?
|
||||||
|
%hr
|
||||||
|
%h4 Conference Registration
|
||||||
|
.row
|
||||||
|
.col-md-6
|
||||||
|
%h5 Register to Conference
|
||||||
|
= form_with url: register_user_admin_user_path(@user), local: true, method: :post do |form|
|
||||||
|
.form-group
|
||||||
|
= form.label :conference_id, 'Select Conference'
|
||||||
|
= form.select :conference_id,
|
||||||
|
options_from_collection_for_select(Conference.all.order(:title), :id, :title),
|
||||||
|
{ prompt: 'Choose a conference...' },
|
||||||
|
{ class: 'form-control', required: true }
|
||||||
|
= form.submit 'Register User', class: 'btn btn-success'
|
||||||
|
|
||||||
|
.col-md-6
|
||||||
|
%h5 Current Registrations
|
||||||
|
- if @user.registrations.any?
|
||||||
|
.table-responsive
|
||||||
|
%table.table.table-condensed
|
||||||
|
%thead
|
||||||
|
%tr
|
||||||
|
%th Conference
|
||||||
|
%th Registered On
|
||||||
|
%th Actions
|
||||||
|
%tbody
|
||||||
|
- @user.registrations.includes(:conference).each do |registration|
|
||||||
|
%tr
|
||||||
|
%td= registration.conference.title
|
||||||
|
%td= registration.created_at.strftime('%B %d, %Y')
|
||||||
|
%td
|
||||||
|
= link_to 'Remove',
|
||||||
|
unregister_user_admin_user_path(@user, registration_id: registration.id),
|
||||||
|
method: :delete,
|
||||||
|
class: 'btn btn-xs btn-danger',
|
||||||
|
confirm: 'Are you sure you want to remove this registration?'
|
||||||
|
- else
|
||||||
|
%p.text-muted No current registrations
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,8 @@ Osem::Application.routes.draw do
|
||||||
resources :users do
|
resources :users do
|
||||||
member do
|
member do
|
||||||
patch :toggle_confirmation
|
patch :toggle_confirmation
|
||||||
|
post :register_user
|
||||||
|
delete :unregister_user
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
resource :ticket_scanning, only: [:create]
|
resource :ticket_scanning, only: [:create]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue