124 lines
3.6 KiB
Ruby
124 lines
3.6 KiB
Ruby
class RoomsController < ApplicationController
|
|
http_basic_authenticate_with name: Rails.application.config.admin_name,
|
|
password: Rails.application.config.admin_password
|
|
|
|
before_action :set_room, only: [:show, :edit, :update, :destroy, :voters, :export_for_mailing, :present]
|
|
|
|
# GET /rooms
|
|
# GET /rooms.json
|
|
def index
|
|
@rooms = Room.all
|
|
end
|
|
|
|
# GET /rooms/1
|
|
# GET /rooms/1.json
|
|
def show
|
|
end
|
|
|
|
# GET /rooms/new
|
|
def new
|
|
@room = Room.new
|
|
end
|
|
|
|
# GET /rooms/1/edit
|
|
def edit
|
|
end
|
|
|
|
# POST /rooms
|
|
# POST /rooms.json
|
|
def create
|
|
@room = Room.new(room_params)
|
|
|
|
respond_to do |format|
|
|
if @room.save
|
|
format.html { redirect_to rooms_url, notice: 'Room was successfully created.' }
|
|
format.json { render :show, status: :created, location: @room }
|
|
else
|
|
format.html { render :new }
|
|
format.json { render json: @room.errors, status: :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
|
|
# PATCH/PUT /rooms/1
|
|
# PATCH/PUT /rooms/1.json
|
|
def update
|
|
respond_to do |format|
|
|
if @room.update(room_params)
|
|
format.html { redirect_to rooms_url, notice: 'Room was successfully updated.' }
|
|
format.json { render :show, status: :ok, location: @room }
|
|
else
|
|
format.html { render :edit }
|
|
format.json { render json: @room.errors, status: :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
|
|
# DELETE /rooms/1
|
|
# DELETE /rooms/1.json
|
|
def destroy
|
|
@room.destroy
|
|
respond_to do |format|
|
|
format.html { redirect_to rooms_url, notice: 'Room was successfully destroyed.' }
|
|
format.json { head :no_content }
|
|
end
|
|
end
|
|
|
|
# GET /rooms/1/voters
|
|
# GET /rooms/1/voters.csv
|
|
def voters
|
|
require 'csv'
|
|
attendees = params[:user].present? ? User.where(room_id: @room.id, id: params[:user].to_i) : User.where(room_id: @room.id)
|
|
csv_data = CSV.generate do |csv|
|
|
attendees.each do |attendee|
|
|
if not attendee.proxy
|
|
if attendee.vote and voter = attendee
|
|
csv << ["password", voter.id, voter.email, voter.name]
|
|
end
|
|
User.where(email: attendee.email, vote: true, proxy: true, room_id: @room.id).each do |proxy|
|
|
csv << ["password", proxy.id, proxy.email, "gemachtigde voor #{proxy.name}"]
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
respond_to do |format|
|
|
format.csv { send_data csv_data, filename: "#{@room.name} #{Time.zone.now}.csv" }
|
|
end
|
|
end
|
|
|
|
# GET /rooms/1/mailing
|
|
# GET /rooms/1/mailing.csv
|
|
def export_for_mailing
|
|
require 'csv'
|
|
attendees = params[:user].present? ? User.where(room_id: @room.id, id: params[:user].to_i) : User.where(room_id: @room.id)
|
|
csv_data = CSV.generate do |csv|
|
|
attendees.each do |attendee|
|
|
if not attendee.proxy
|
|
if attendee.vote and voter = attendee
|
|
csv << [voter.email, voter.name, voter.token, "https://vergadering.bij1.org/ingang/#{voter.token}/"]
|
|
end
|
|
User.where(email: attendee.email, vote: true, proxy: true, room_id: @room.id).each do |proxy|
|
|
csv << [proxy.email, "gemachtigde voor #{proxy.name}", voter.token, "https://vergadering.bij1.org/ingang/#{voter.token}/"]
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
respond_to do |format|
|
|
format.csv { send_data csv_data, filename: "#{@room.name} #{Time.zone.now}.csv" }
|
|
end
|
|
end
|
|
|
|
private
|
|
# Use callbacks to share common setup or constraints between actions.
|
|
def set_room
|
|
@room = Room.find(params[:id])
|
|
end
|
|
|
|
# Only allow a list of trusted parameters through.
|
|
def room_params
|
|
params.require(:room).permit(:name, :meeting, :attendee_pw, :moderator_pw, :email_subject, :email_body)
|
|
end
|
|
end
|