Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
Conflicts:
	db/schema.rb
	spec/features/event_spec.rb
  • Loading branch information
MasterCarl committed Jan 18, 2017
2 parents 5ff1c4d + cc61490 commit e2c6d59
Show file tree
Hide file tree
Showing 52 changed files with 243 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ group :test do
gem 'parser', '~> 2.2.2.5'
# Stubbing external calls by blocking traffic with WebMock.disable_net_connect! or allow:
# gem 'webmock'

end


Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions app/assets/images/sample_images/copyright.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#Disclaimer

All pictures in this directory were downloaded from Pixabay.com in January 2017under CC0 Public Domain License.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 35 additions & 3 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'zip'

class EventsController < ApplicationController
before_action :set_event, only: [:show, :edit, :update, :destroy, :print_applications]
before_action :set_event, only: [:show, :edit, :update, :destroy, :participants, :participants_pdf, :print_applications]

# GET /events
def index
Expand Down Expand Up @@ -85,7 +85,6 @@ def print_badges

# GET /events/1/participants
def participants
@event = Event.find(params[:id])
@participants = @event.participants_by_agreement_letter
@has_agreement_letters = @event.agreement_letters.any?
end
Expand Down Expand Up @@ -164,7 +163,7 @@ def download_agreement_letters
params[:selected_participants].each do |participant_id|
agreement_letter = User.find(participant_id).agreement_letter_for_event(@event)
unless agreement_letter.nil?
pdf << CombinePDF.load(agreement_letter.path)
pdf << CombinePDF.load(agreement_letter.path)
empty = false
end
end
Expand Down Expand Up @@ -195,6 +194,39 @@ def upload_material
redirect_to event_path(event), notice: I18n.t("events.material_area.success_message")
end

# GET /event/1/participants_pdf
def participants_pdf
default = {:order_by => 'email', :order_direction => 'asc'}
default = default.merge(params)

@application_letters = @event.application_letters_ordered(default[:order_by], default[:order_direction])
.where(:status => ApplicationLetter.statuses[:accepted])

data = @application_letters.collect do |application_letter|
[
application_letter.user.profile.first_name,
application_letter.user.profile.last_name,
application_letter.user.profile.birth_date,
application_letter.allergies
]
end

data.unshift([
I18n.t('controllers.events.participants_pdf.first_name'),
I18n.t('controllers.events.participants_pdf.last_name'),
I18n.t('controllers.events.participants_pdf.first_name'),
I18n.t('controllers.events.participants_pdf.allergies')
])

name = @event.name
doc = Prawn::Document.new(:page_size => 'A4') do
text "Teilnehmerliste - " + name
table(data, width: bounds.width)
end

send_data doc.render, :filename => "participants.pdf", :type => "application/pdf", disposition: "inline"
end

# POST /events/1/download_material
def download_material
event = Event.find(params[:event_id])
Expand Down
3 changes: 2 additions & 1 deletion app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ def initialize(user)
# Pupils can upload their letters of agreement
can [:create], AgreementLetter
can [:new, :create], Request
cannot :view_personal_details, ApplicationLetter, user: { id: !user.id }
end
if user.role? :coach
# Coaches can view Applications and participants for and view, upload and download materials for Event
can [:view_applicants, :view_participants, :view_material, :upload_material, :print_applications, :download_material], Event
can [:view_and_add_notes, :show], ApplicationLetter
can [:print_applications], Event
can :manage, Request
cannot [:check], ApplicationLetter
cannot :check, ApplicationLetter
end
if user.role? :organizer
can [:index, :show], Profile
Expand Down
19 changes: 19 additions & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,25 @@ def duration_label
end
end

# Returns the application letters ordered by either "email", "first_name", "last_name", "birth_date"
# either "asc" (ascending) or "desc" (descending).
#
# @param field [String] the field that should be used to order
# @param order_by [String] the order that should be used
# @return [ApplicationLetter] the application letters found
def application_letters_ordered(field, order_by)
field = case field
when "email"
"users.email"
when "birth_date", "first_name", "last_name"
"profiles." + field
else
"users.email"
end
order_by = 'asc' unless order_by == 'asc' || order_by == 'desc'
application_letters.joins(user: :profile).order(field + ' ' + order_by)
end

# Make sure any assignment coming from the controller
# replaces all date ranges instead of adding new ones
def date_ranges_attributes=(*args)
Expand Down
12 changes: 9 additions & 3 deletions app/views/application_letters/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@
<h1><%=t '.title', :default => model_class.model_name.human.titleize %></h1>
</div>

<h3><%= @application_letter.user.profile.name %></h3>
<% if can? :show, @application_letter.user.profile %>
<h3><%= link_to @application_letter.user.profile.name, profile_path(@application_letter.user.profile) %></h3>
<% else %>
<h3><%= @application_letter.user.profile.name %></h3>
<% end %>

<dl class="dl-horizontal" id="applicant_details">
<dt><strong><%= Profile.human_attribute_name(:gender) %>:</strong></dt>
<dd><%= @application_letter.user.profile.gender %></dd>
<dt><strong><%= t('.age_when_event_starts') %>:</strong></dt>
<dd><%= @application_letter.user.profile.age_at_time(@application_letter.event.start_date) %></dd>
<dt><strong><%= Profile.human_attribute_name(:address) %>:</strong></dt>
<dd><%= @application_letter.user.profile.address %></dd>
<% if can? :view_personal_details, ApplicationLetter %>
<dt><strong><%= Profile.human_attribute_name(:address) %>:</strong></dt>
<dd><%= @application_letter.user.profile.address %></dd>
<% end %>
<dt><strong><%= User.human_attribute_name(:accepted_application_count) %>:</strong></dt>
<dd><%= @application_letter.user.accepted_applications_count(@application_letter.event) %></dd>
<dt><strong><%= User.human_attribute_name(:rejected_application_count) %>:</strong></dt>
Expand Down
31 changes: 31 additions & 0 deletions app/views/events/_participants_modal.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<div class="modal fade" id="print_participant_modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<%= form_tag(participants_pdf_event_path(@event), method: :get, class:'form') do %>
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title"><%= t('.print_names') %></h4>
</div>
<div class="modal-body">
<div class="form-group">
<%= label_tag(:order_by, t('.order_by')) %>
<%= select_tag(:order_by, options_for_select([
[t('.email'),'email'],
[t('.date_of_birth'),'birth_date'],
[t('.first_name'),'first_name'],
[t('.last_name'),'last_name']
]), class:'form-control') %>
</div>
<div class="form-group">
<%= label_tag(:order_direction, t('.order_direction')) %>
<%= select_tag(:order_direction, options_for_select([[t('.order_ascending'),'asc'],[t('.order_descending'),'desc']]), class:'form-control') %>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal"><%= t('.close_modal') %></button>
<%= submit_tag(t('.create_pdf'), class: 'btn btn-default', id:'print_participant_list' ) %>
</div>
</div><!-- /.modal-content -->
<% end %>
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
17 changes: 10 additions & 7 deletions app/views/events/participants.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
<h1><%=t '.title', :default => model_class.model_name.human.titleize %> (<%= @event.kind.humanize %>)</h1>
</div>
<% if can? :view_participants, Event %>
<%= render :partial => 'participants_modal' %>
<%= render :partial => 'show_event' %>

<h1><%= t '.participants' %></h1>
<%= form_tag(event_path(@event) + "/participants/agreement_letters") do %>
<table class="table table-striped">
<tr>
<th><%= t 'activerecord.attributes.profile.name' %></th>
<th><%= t 'activerecord.attributes.profile.email' %></th>
<th><%= t 'agreement_letters.agreement_letter' %></th>
<th><%= t 'agreement_letters.agreement_letter' %></th>
<% if can? :print_agreement_letters, Event and @has_agreement_letters %>
<th>
<label>
Expand All @@ -20,11 +21,11 @@
</label>
</th>
<% end %>
</tr>
</tr>

<% @participants.each do |participant| %>
<tr>

<td>
<%= participant.name %>
</td>
Expand All @@ -48,14 +49,16 @@
</tr>
<% end %>
</table>

<button class="btn btn-default" type="button" data-toggle="modal" data-target="#print_participant_modal" id="open_print_modal">Teilnehmerliste (PDF)</button>
<% if can? :print_agreement_letters, Event and @has_agreement_letters %>
<div id="participants_download_submit_button">
<%= submit_tag t('events.agreement_letters_download.download_all_as'), name: "download_all" %>
<%= submit_tag t('events.agreement_letters_download.download_all_as'), name: "download_all", class: "btn btn-default" %>
<%= select_tag :download_type, options_for_select([['pdf'], ['zip']]) %>
</div>
<% end %>
<% end %>
<br>
<%= link_to t('.back', :default => t('helpers.links.back')),
event_path(@event), :class => 'btn btn-default' %>
<% end %>
<% end %>
22 changes: 21 additions & 1 deletion config/locales/de.events.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,25 @@ de:
no_participants_selected: "Keine Teilnehmer ausgewählt"
no_agreement_letters: "Keiner der gewählten Teilnehmer hat eine Einverständniserklärung"
select_all: "Alle auswählen"
download_all_as: "Alle herunterladen als"
download_all_as: "Einverständniserklärungen herunterladen als"
kinds:
workshop: "Workshop"
camp: "Camp"
list:
more: "Mehr dazu"
read_on: "Weiterlesen"
participants_modal:
print_names: 'Teilnehmerliste drucken'
order_by: 'Sortieren nach'
email: 'E-Mail'
date_of_birth: 'Geburtsdatum'
first_name: 'Vorname'
last_name: 'Nachname'
order_direction: 'Sortierung'
order_ascending: 'Aufsteigend'
order_descending: 'Absteigend'
close_modal: 'Schließen'
create_pdf: 'Erstellen'

notices:
created: "Event wurde erstellt."
Expand Down Expand Up @@ -123,3 +135,11 @@ de:
submit:
event:
create: "Veröffentlichen"

controllers:
events:
participants_pdf:
first_name: 'Vorname'
last_name: 'Nachname'
date_of_birth: 'Geburtsdatum'
allergies: 'Allergien'
5 changes: 4 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
end
resources :events do
resources :agreement_letters, only: [:create], shallow: true
get 'print_applications', on: :member
get 'badges'
post 'badges' => 'events#print_badges', as: :print_badges
post 'upload_material' => 'events#upload_material', as: :upload_material
member do
get 'participants_pdf'
get 'print_applications'
end
post 'download_material' => 'events#download_material', as: :download_material
end
resources :profiles, except: [:index, :destroy]
Expand Down
10 changes: 5 additions & 5 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20170116093536) do
ActiveRecord::Schema.define(version: 20170118132170) do

create_table "agreement_letters", force: :cascade do |t|
t.integer "user_id", null: false
Expand Down Expand Up @@ -68,15 +68,15 @@
t.string "name"
t.string "description"
t.integer "max_participants"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "kind", default: 0
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "kind", default: 0
t.boolean "draft"
t.string "organizer"
t.string "knowledge_level"
t.date "application_deadline"
t.boolean "application_status_locked"
t.boolean "participants_are_unlimited"
t.boolean "participants_are_unlimited", default: false
t.text "custom_application_fields"
end

Expand Down
25 changes: 25 additions & 0 deletions spec/controllers/events_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,30 @@
end
end

describe "GET #participants_pdf" do
let(:valid_attributes) { FactoryGirl.attributes_for(:event_with_accepted_applications) }

it "should return an pdf" do
event = Event.create! valid_attributes
get :participants_pdf, id: event.to_param, session: valid_session
expect(response.content_type).to eq('application/pdf')
end

it "should return an pdf with the name of the user" do
event = Event.create! valid_attributes
profile = FactoryGirl.create(:profile)
user = FactoryGirl.create(:user, profile: profile)
application_letter = FactoryGirl.create(:application_letter, status: ApplicationLetter.statuses[:accepted], event: event, user: user)
response = get :participants_pdf, id: event.to_param, session: valid_session
expect(response.content_type).to eq('application/pdf')

pdf = PDF::Inspector::Text.analyze(response.body)
expect(pdf.strings).to include("Vorname")
expect(pdf.strings).to include("Nachname")
expect(pdf.strings).to include(application_letter.user.profile.first_name)
end
end

describe "GET #badges" do
let(:valid_attributes) { FactoryGirl.attributes_for(:event_with_accepted_applications) }

Expand Down Expand Up @@ -207,6 +231,7 @@
"1243_print" => "Max Mustermann",
"1244_print" => "Max Mustermann",
"1245_print" => "Max Mustermann"

pdf = PDF::Inspector::Text.analyze(rendered_pdf.body)
expect(pdf.strings).to include("Max Mustermann")
expect(pdf.strings).to include("John Doe")
Expand Down
25 changes: 25 additions & 0 deletions spec/features/application_letters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,31 @@
expect(page).to have_text('Bewerbung erstellen')
end

%i[coach organizer].each do |role|
it "logged in as #{role} I cannot see personal details" do
login(role)
expect(page).to_not have_text(@application_letter.user.profile.address)
expect(page).to_not have_text(@application_letter.user.profile.school)
end
end

it "logged in as admin I can see personal details" do
login(:admin)
expect(page).to have_text(@application_letter.user.profile.address)
end

it "logged in as admin I cannot see the school of an applicant" do
login(:admin)
expect(page).to_not have_text(@application_letter.user.profile.school)
end

%i[organizer admin].each do |role|
it "logged in as #{role} I can click on the applicants name" do
login(role)
expect(page).to have_link(@application_letter.user.profile.name, :href => profile_path(@application_letter.user.profile))
end
end

def login(role)
@event = FactoryGirl.create(:event)
@profile = FactoryGirl.create(:profile)
Expand Down
Loading

0 comments on commit e2c6d59

Please sign in to comment.