Skip to content

Commit

Permalink
Merge branch 'dev' into 55_3.14_sendEmailsUI
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Basel committed Jan 4, 2017
2 parents 12d467c + 126a100 commit fce6ad4
Show file tree
Hide file tree
Showing 46 changed files with 1,167 additions and 204 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -21,4 +21,5 @@ deploy:
run:
- rake db:schema:load
- rake db:seed
- rake db:populate_sample_data
- restart
8 changes: 5 additions & 3 deletions Gemfile
Expand Up @@ -80,6 +80,7 @@ gem 'coveralls', require: false

# pdf generation
gem 'prawn'
gem 'prawn-table'

# Simple, Heroku-friendly Rails app configuration using ENV and a single YAML file
gem 'figaro'
Expand Down Expand Up @@ -119,7 +120,7 @@ group :development do
# Add a comment summarizing the current schema for models and others
# usage: annotate
gem 'annotate'

# opens sent emails in a new browser tab
# gem "letter_opener"
end
Expand All @@ -134,8 +135,9 @@ group :test do
gem 'parser', '~> 2.2.2.5'
# Stubbing external calls by blocking traffic with WebMock.disable_net_connect! or allow:
# gem 'webmock'
gem 'pdf-inspector', require: "pdf/inspector"
end

# PDF testing
gem 'pdf-inspector', require: "pdf/inspector"end

group :production do
# Use Puma web server
Expand Down
30 changes: 18 additions & 12 deletions Gemfile.lock
Expand Up @@ -40,7 +40,8 @@ GEM
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.4.0)
addressable (2.5.0)
public_suffix (~> 2.0, >= 2.0.2)
afm (0.2.2)
airbrake (5.6.1)
airbrake-ruby (~> 1.6)
Expand All @@ -65,22 +66,23 @@ GEM
builder (3.2.2)
byebug (9.0.6)
cancancan (1.15.0)
capybara (2.10.1)
capybara (2.11.0)
addressable
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
cliver (0.3.2)
codeclimate-test-reporter (1.0.1)
codeclimate-test-reporter (1.0.3)
simplecov
coderay (1.1.1)
commonjs (0.2.7)
concurrent-ruby (1.0.2)
coveralls (0.8.15)
coveralls (0.8.16)
json (>= 1.8, < 3)
simplecov (~> 0.12.0)
term-ansicolor (~> 1.3)
term-ansicolor (~> 1.3.0)
thor (~> 0.19.1)
tins (>= 1.6.0, < 2)
database_cleaner (1.5.3)
Expand Down Expand Up @@ -122,7 +124,7 @@ GEM
jquery-turbolinks (2.1.0)
railties (>= 3.1.0)
turbolinks
jquery-ui-rails (5.0.5)
jquery-ui-rails (6.0.1)
railties (>= 3.2.16)
json (1.8.3)
less (2.6.0)
Expand All @@ -141,7 +143,7 @@ GEM
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mini_portile2 (2.1.0)
minitest (5.9.1)
minitest (5.10.1)
nokogiri (1.6.8.1)
mini_portile2 (~> 2.1.0)
orm_adapter (0.5.0)
Expand All @@ -165,14 +167,17 @@ GEM
prawn (2.1.0)
pdf-core (~> 0.6.1)
ttfunk (~> 1.4.0)
prawn-table (0.2.2)
prawn (>= 1.3.0, < 3.0.0)
pry (0.10.4)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
pry-rails (0.3.4)
pry (>= 0.9.10)
puma (3.6.0)
rack (1.6.4)
public_suffix (2.0.4)
puma (3.6.2)
rack (1.6.5)
rack-openid (1.4.2)
rack (>= 1.1.0)
ruby-openid (>= 2.1.8)
Expand Down Expand Up @@ -253,12 +258,12 @@ GEM
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.3.12)
term-ansicolor (1.4.0)
term-ansicolor (1.3.2)
tins (~> 1.0)
thor (0.19.1)
thor (0.19.4)
thread_safe (0.3.5)
tilt (2.0.5)
tins (1.12.0)
tins (1.13.0)
ttfunk (1.4.0)
turbolinks (5.0.1)
turbolinks-source (~> 5)
Expand Down Expand Up @@ -315,6 +320,7 @@ DEPENDENCIES
pg
poltergeist
prawn
prawn-table
pry
pry-rails
puma
Expand Down
24 changes: 19 additions & 5 deletions app/controllers/application_letters_controller.rb
Expand Up @@ -6,7 +6,7 @@ class ApplicationLettersController < ApplicationController

# GET /applications
def index
@application_letters = ApplicationLetter.all
@application_letters = ApplicationLetter.where(user_id: current_user.id)
end

# GET /applications/1
Expand Down Expand Up @@ -43,7 +43,7 @@ def create
@application_letter.user_id = current_user.id

if @application_letter.save
redirect_to @application_letter, notice: 'Application was successfully created.'
redirect_to @application_letter, notice: I18n.t('application_letters.successful_creation')
else
render :new
end
Expand All @@ -52,7 +52,16 @@ def create
# PATCH/PUT /applications/1
def update
if @application_letter.update_attributes(application_params)
redirect_to :back, notice: 'Application was successfully updated.' rescue ActionController::RedirectBackError redirect_to root_path
redirect_to :back, notice: I18n.t('application_letters.successful_update') rescue ActionController::RedirectBackError redirect_to root_path
else
render :edit
end
end

# PATCH/PUT /applications/1/status
def update_status
if @application_letter.update_attributes(application_status_param)
redirect_to :back, notice: I18n.t('application_letters.successful_update') rescue ActionController::RedirectBackError redirect_to root_path
else
render :edit
end
Expand All @@ -61,7 +70,7 @@ def update
# DELETE /applications/1
def destroy
@application_letter.destroy
redirect_to application_letters_url, notice: 'Application was successfully destroyed.'
redirect_to application_letters_url, notice: I18n.t('application_letters.successful_deletion')
end

private
Expand All @@ -73,6 +82,11 @@ def set_application
# Only allow a trusted parameter "white list" through.
# Don't allow user_id as you shouldn't be able to set the user from outside of create/update.
def application_params
params.require(:application_letter).permit(:grade, :experience, :motivation, :coding_skills, :emergency_number, :vegeterian, :vegan, :allergic, :allergies, :user_id, :event_id, :status)
params.require(:application_letter).permit(:grade, :experience, :motivation, :coding_skills, :emergency_number, :vegeterian, :vegan, :allergic, :allergies, :user_id, :event_id)
end

# Only allow to update the status
def application_status_param
params.require(:application_letter).permit(:status)
end
end
10 changes: 9 additions & 1 deletion app/controllers/events_controller.rb
@@ -1,5 +1,7 @@
require 'pdf_generation/applications_pdf'

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

# GET /events
def index
Expand Down Expand Up @@ -84,6 +86,12 @@ def participants
@participants = @event.participants_by_agreement_letter
end

# GET /events/1/print_applications
def print_applications
authorize! :print_applications, @event
pdf = ApplicationsPDF.generate(@event)
send_data pdf, filename: "applications_#{@event.name}_#{Date.today}.pdf", type: "application/pdf", disposition: "inline"
end
# GET /events/1/send-acceptances-email
def send_acceptance_emails
event = Event.find(params[:id])
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/profiles_controller.rb
Expand Up @@ -29,9 +29,9 @@ def create

if @profile.save
if flash[:event_id]
redirect_to new_application_letter_path(:event_id => flash[:event_id])
redirect_to new_application_letter_path(:event_id => flash[:event_id]), notice: I18n.t('profiles.successful_creation')
else
redirect_to @profile
redirect_to @profile, notice: I18n.t('profiles.successful_creation')
end
else
render :new
Expand All @@ -41,7 +41,7 @@ def create
# PATCH/PUT /profiles/1
def update
if @profile.update(profile_params)
redirect_to @profile, notice: 'Profile was successfully updated.'
redirect_to @profile, notice: I18n.t('profiles.successful_update')
else
render :edit
end
Expand All @@ -50,7 +50,7 @@ def update
# DELETE /profiles/1
def destroy
@profile.destroy
redirect_to profiles_url, notice: 'Profile was successfully destroyed.'
redirect_to profiles_url, notice: I18n.t('profiles.successful_deletion')
end

private
Expand Down
10 changes: 7 additions & 3 deletions app/models/ability.rb
Expand Up @@ -42,17 +42,21 @@ def initialize(user)
can [:index, :show, :edit, :update, :destroy], ApplicationLetter, user: { id: user.id }
# Pupils can upload their letters of agreement
can [:create], AgreementLetter
can [:new, :create], Request
end
if user.role? :coach
# Coaches can view Applications and participants for Event
can [:view_applicants, :view_participants], Event
can [:view_and_add_notes, :show], ApplicationLetter
can [:print_applications], Event
end
if user.role? :organizer
can [:index, :show], Profile
can [:index, :show, :view_and_add_notes], ApplicationLetter
# Organizers can view and edit Applications and view participants for Events
can [:view_applicants, :edit_applicants, :view_participants], Event
can [:index, :show, :view_and_add_notes, :update_status], ApplicationLetter
cannot :update, ApplicationLetter
# Organizers can view, edit and print Applications, view participants for and manage Events
can [:view_applicants, :edit_applicants, :view_participants, :print_applications, :manage], Event
can :manage, Request
end
if user.role? :admin
can :manage, :all
Expand Down
24 changes: 23 additions & 1 deletion app/models/application_letter.rb
Expand Up @@ -27,10 +27,11 @@ class ApplicationLetter < ActiveRecord::Base
validate :status_cannot_be_changed, :if => Proc.new { |letter| letter.status_changed?}

enum status: {accepted: 1, rejected: 0, pending: 2, alternative: 3}
validates :status, inclusion: { in: statuses.keys }


# Checks if the deadline is over
# additionally only return if event and event.application_deadline is present
# TODO: 'event.application_deadline' should never be nil, when #18 is finished. Please remove this in #18.
#
# @param none
# @return [Boolean] true if deadline is over
Expand All @@ -54,6 +55,27 @@ def deadline_cannot_be_in_the_past
end
end

# Chooses right status based on status and event deadline
#
# @param none
# @return [String] to display on the website
def status_type
case ApplicationLetter.statuses[status]
when ApplicationLetter.statuses[:accepted]
return I18n.t("application_status.accepted")
when ApplicationLetter.statuses[:rejected]
return I18n.t("application_status.rejected")
when ApplicationLetter.statuses[:pending]
if after_deadline?
return I18n.t("application_status.pending_after_deadline")
else
return I18n.t("application_status.pending_before_deadline")
end
else
return I18n.t("application_status.alternative")
end
end

# Validator for status_change_allowed?
# Adds error
def status_cannot_be_changed
Expand Down
2 changes: 1 addition & 1 deletion app/models/event.rb
Expand Up @@ -167,7 +167,7 @@ def date_ranges_attributes=(*args)
event.date_ranges.each do |date_range|
next if date_range.valid?
date_range.errors.full_messages.each do |msg|
errors.add :date_ranges, msg
errors.add :date_ranges, msg unless errors[:date_ranges].include? msg
end
end
end
Expand Down
@@ -1,5 +1,5 @@
<% if can? :edit_applicants, Event and not (application_letter.event.application_status_locked == true) %>
<%= form_for :application_letter, url: application_letter_path(application_letter), html: {method: :put} do |f| %>
<%= form_for :application_letter, url: update_application_letter_status_path(application_letter), html: {method: :put} do |f| %>
<div class="form-group">
<div class="btn-group">
<% ApplicationLetter.statuses.keys.each do |key| %>
Expand Down
52 changes: 23 additions & 29 deletions app/views/application_letters/index.html.erb
@@ -1,38 +1,32 @@
<%- model_class = ApplicationLetter -%>
<div class="page-header">
<h1><%=t '.title', :default => model_class.model_name.human(:count => model_class.count).titleize %></h1>
<h1><%= t '.title', :default => model_class.model_name.human(:count => model_class.count).titleize %></h1>
</div>
<table class="table table-striped">
<thead>
<tr>
<th><%= model_class.human_attribute_name(:id) %></th>
<th><%= model_class.human_attribute_name(:motivation) %></th>
<th><%= model_class.human_attribute_name(:user_id) %></th>
<th><%= model_class.human_attribute_name(:event_id) %></th>
<th><%= model_class.human_attribute_name(:created_at) %></th>
<th><%=t '.actions', :default => t("helpers.actions") %></th>
</tr>
<tr>
<th><%= Event.model_name.human(:count => model_class.count).titleize %></th>
<th><%= model_class.human_attribute_name(:status) %></th>
<th><%= t '.actions', :default => t("helpers.actions") %></th>
</tr>
</thead>
<tbody>
<% @application_letters.each do |application| %>
<% if can? :destroy, application %>
<tr>
<td><%= link_to application.id, application_letter_path(application) %></td>
<td><%= application.motivation %></td>
<td><%= application.user_id %></td>
<td><%= application.event_id %></td>
<td><%=l application.created_at %></td>
<td>
<%= link_to t('.edit', :default => t("helpers.links.edit")),
edit_application_letter_path(application), :class => 'btn btn-default btn-xs' %>
<%= link_to t('.destroy', :default => t("helpers.links.destroy")),
application_letter_path(application),
:method => :delete,
:data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
:class => 'btn btn-xs btn-danger' %>
</td>
</tr>
<% end %>
<% end %>
<% @application_letters.each do |application| %>
<tr>
<td><%= link_to application.event.name, event_path(application.event) %></td>
<td><%= application.status_type %></td>
<td>
<% if not application.after_deadline? %>
<%= link_to t('.edit', :default => t("helpers.links.edit")),
edit_application_letter_path(application), :class => 'btn btn-default btn-xs' %>
<%= link_to t('.destroy', :default => t("helpers.links.destroy")),
application_letter_path(application),
:method => :delete,
:data => {:confirm => t('.confirm', :default => t("application_letters.confirm_deletion", :default => 'Are you sure?'))},
:class => 'btn btn-xs btn-danger' %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
2 changes: 1 addition & 1 deletion app/views/application_letters/show.html.erb
Expand Up @@ -25,7 +25,7 @@
<%= link_to t('.destroy', :default => t("helpers.links.destroy")),
application_letter_path(@application_letter),
:method => 'delete',
:data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
:data => { :confirm => t('.confirm', :default => t("application_letters.confirm_deletion", :default => 'Are you sure?')) },
:class => 'btn btn-danger' %>

<h3><%= t('.application_title', title: @application_letter.event.name) %></h3>
Expand Down

0 comments on commit fce6ad4

Please sign in to comment.