Skip to content

Commit

Permalink
Merge branch '339_3.29_EmailAddressProfile' of https://github.com/hpi…
Browse files Browse the repository at this point in the history
…-swt2/workshop-portal into 339_3.29_EmailAddressProfile

* '339_3.29_EmailAddressProfile' of https://github.com/hpi-swt2/workshop-portal:
  399: Remove infinity participants [#16] (#447)
  Randomize first_name of Profiles created by FactoryGirl (#461)
  Removed experience field from application letters (#451)
  387 Delete allergic field, layout improvements (#456)
  Rename "my application letters" to "my events" (#383) (#458)
  Hide register button to signed in users. (#457)
  431 remove button chaos on event creation page (#455)
  Fix missing ues
  Fix bug in test. Add test for apllication confirmation email.
  Add feature to send confirmation mail on application letter creation. Warning: No test added yet, as the corresponding dev did not know how to test.
  • Loading branch information
Baschdl committed Feb 1, 2017
2 parents 3f41989 + f071f97 commit 395d543
Show file tree
Hide file tree
Showing 42 changed files with 184 additions and 189 deletions.
1 change: 1 addition & 0 deletions .rbenv_version
@@ -0,0 +1 @@
2.2.2-x64
19 changes: 16 additions & 3 deletions app/controllers/application_letters_controller.rb
Expand Up @@ -30,7 +30,7 @@ def new
last_application_letter = ApplicationLetter.where(user: current_user).order("created_at").last
if last_application_letter
attrs_to_fill_in = last_application_letter.attributes
.slice("grade", "coding_skills", "emergency_number", "vegetarian", "vegan", "allergic", "allergies")
.slice("grade", "coding_skills", "emergency_number", "vegetarian", "vegan", "allergies")
@application_letter.attributes = attrs_to_fill_in
flash.now[:notice] = I18n.t('application_letters.fields_filled_in')
end
Expand All @@ -55,11 +55,24 @@ def edit
def create
@application_letter = ApplicationLetter.new(application_params)
#event must be param to new_application_letter_path
seminar_name = ''
if params[:event_id]
@application_letter.event_id = params[:event_id]
seminar_name = Event.find(params[:event_id]).name
end
@application_letter.user_id = current_user.id

# Send Confirmation E-Mail
email_params = {
:hide_recipients => true,
:recipients => [current_user.email],
:reply_to => I18n.t('controllers.application_letters.confirmation_mail.sender'),
:subject => I18n.t('controllers.application_letters.confirmation_mail.subject'),
:content => I18n.t('controllers.application_letters.confirmation_mail.content', :seminar_name => seminar_name)
}
@email = Email.new(email_params)
Mailer.send_generic_email(@email.hide_recipients, @email.recipients, @email.reply_to, @email.subject, @email.content)

if @application_letter.save
redirect_to check_application_letter_path(@application_letter), notice: I18n.t('application_letters.successful_creation')
else
Expand Down Expand Up @@ -110,8 +123,8 @@ 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, :organisation,
:vegetarian, :vegan, :allergic, :allergies, :annotation, :user_id, :event_id)
params.require(:application_letter).permit(:grade, :motivation, :coding_skills, :emergency_number, :organisation,
:vegetarian, :vegan, :allergies, :annotation, :user_id, :event_id)
.merge({:custom_application_fields => params[:custom_application_fields]})
end

Expand Down
3 changes: 1 addition & 2 deletions app/controllers/events_controller.rb
Expand Up @@ -252,8 +252,7 @@ def set_event
end

def event_params
params.require(:event).permit(:name, :description, :max_participants, :participants_are_unlimited, :kind, :organizer, :knowledge_level, :application_deadline, :published, :hidden, :custom_application_fields => [], date_ranges_attributes: [:start_date, :end_date, :id])

params.require(:event).permit(:name, :description, :max_participants, :organizer, :knowledge_level, :application_deadline, :published, :hidden, :custom_application_fields => [], date_ranges_attributes: [:start_date, :end_date, :id])
end

def add_event_query_conditions(query)
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Expand Up @@ -63,7 +63,7 @@ def dropdown_items
end
# pupils get their applications
if current_user.role == "pupil"
o << (menu_item t(:my_application_letters, scope: 'navbar'), application_letters_path)
o << (menu_item t(:my_events, scope: 'navbar'), application_letters_path)
end
# admins get user management
if current_user.role == "admin" || current_user.role == "organizer"
Expand Down
12 changes: 8 additions & 4 deletions app/models/application_letter.rb
Expand Up @@ -19,11 +19,11 @@ class ApplicationLetter < ActiveRecord::Base

VALID_GRADES = 5..13

validates :user, :event, :experience, :motivation, :coding_skills, :emergency_number,:organisation, presence: true
validates :user, :event, :motivation, :coding_skills, :emergency_number,:organisation, presence: true
validates :grade, presence: true, numericality: { only_integer: true }
validates_inclusion_of :grade, :in => VALID_GRADES
validates :vegetarian, :vegan, :allergic, inclusion: { in: [true, false] }
validates :vegetarian, :vegan, :allergic, exclusion: { in: [nil] }
validates :vegetarian, :vegan, inclusion: { in: [true, false] }
validates :vegetarian, :vegan, exclusion: { in: [nil] }
validate :deadline_cannot_be_in_the_past, :if => Proc.new { |letter| !(letter.status_changed?) }
validate :status_cannot_be_changed, :if => Proc.new { |letter| letter.status_changed?}

Expand Down Expand Up @@ -114,7 +114,11 @@ def eating_habits
habits = Array.new
habits.push(ApplicationLetter.human_attribute_name(:vegetarian)) if vegetarian
habits.push(ApplicationLetter.human_attribute_name(:vegan)) if vegan
habits.push(ApplicationLetter.human_attribute_name(:allergic)) if allergic
habits.push(ApplicationLetter.human_attribute_name(:allergies)) if allergic
habits
end

def allergic
not allergies.empty?
end
end
22 changes: 2 additions & 20 deletions app/models/event.rb
Expand Up @@ -31,25 +31,9 @@ class Event < ActiveRecord::Base
validate :application_deadline_before_start_of_event
validates :hidden, inclusion: { in: [true, false] }
validates :hidden, exclusion: { in: [nil] }
validates :published, inclusion: { in: [true, false] }
validates :published, exclusion: { in: [nil] }

# Setter for max_participants
# @param [Int Float] the max number of participants for the event or infinity if it is not limited
# @return none
def max_participants=(value)
if value == Float::INFINITY
self[:participants_are_unlimited] = true
else
self[:participants_are_unlimited] = false
self[:max_participants] = value
end
end

# Getter for max_participants
# @param none
# @return [Int Float] the max number of participants for the event or infinity if it is not limited
def max_participants
participants_are_unlimited ? Float::INFINITY : self[:max_participants]
end

# Returns all participants for this event in following order:
# 1. All participants that have to submit an letter of agreement but did not yet do so, ordered by name.
Expand Down Expand Up @@ -128,8 +112,6 @@ def agreement_letter_for(user)
self.agreement_letters.where(user: user).take
end

enum kind: [ :workshop, :camp ]

# Returns whether all application_letters are classified or not
#
# @param none
Expand Down
12 changes: 7 additions & 5 deletions app/views/application/index.html.erb
Expand Up @@ -23,11 +23,13 @@
<%= glyph 'calendar' %> <%= t "start_page.all_events" %>
</a>
</li>
<li>
<a class="btn btn-default" href="<%= new_user_registration_path %>">
<%= glyph 'user' %> <%= t 'start_page.register_now' %>
</a>
</li>
<% unless user_signed_in? %>
<li>
<a class="btn btn-default" href="<%= new_user_registration_path %>">
<%= glyph 'user' %> <%= t 'start_page.register_now' %>
</a>
</li>
<% end %>
</ul>
</div>
</div>
Expand Down
19 changes: 1 addition & 18 deletions app/views/application_letters/_form.html.erb
Expand Up @@ -15,12 +15,6 @@
</div>

</div>
<div class="form-group">
<%= f.label :experience, :class => 'control-label col-lg-2 required' %>
<div class="col-lg-10">
<%= f.text_area :experience, :class => 'form-control' %> <%=f.error_span(:experience) %>
</div>
</div>
<div class="form-group">
<%= f.label :motivation, :class => 'control-label col-lg-2 required' %>
<div class="col-lg-10">
Expand Down Expand Up @@ -53,23 +47,12 @@
<div class="col-sm-offset-2 col-sm-10">
<%= f.check_box :vegetarian%>
<%= f.label :vegetarian, :class => 'control-label' %>
<%=f.error_span(:vegetarian) %>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<%= f.check_box :vegan%>
<%= f.label :vegan, :class => 'control-label' %>
<%=f.error_span(:vegetarian) %>
<%=f.error_span(:vegan) %>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<%= f.check_box :allergic%>
<%= f.label :allergic, :class => 'control-label' %>
<%=f.error_span(:allergic) %>
</div>
</div>
<div class="form-group">
<%= f.label :allergies, :class => 'control-label col-lg-2' %>
<div class="col-lg-10">
Expand Down
2 changes: 0 additions & 2 deletions app/views/application_letters/check.html.erb
Expand Up @@ -23,8 +23,6 @@
<%= @application_letter.grade %><br/>
<strong><%= ApplicationLetter.human_attribute_name(:motivation) %>:</strong><br/>
<%= @application_letter.motivation %><br/>
<strong><%= ApplicationLetter.human_attribute_name(:experience) %>:</strong><br/>
<%= @application_letter.experience %><br/>
<strong><%= ApplicationLetter.human_attribute_name(:coding_skills) %>:</strong><br/>
<%= @application_letter.coding_skills %><br/>
<strong><%= ApplicationLetter.human_attribute_name(:emergency_number) %>:</strong>
Expand Down
7 changes: 2 additions & 5 deletions app/views/events/_applicants_overview.html.erb
@@ -1,10 +1,7 @@
<div class="container-fluid" id="applicants_overview">
<h3><%= t '.title', title: @event.name %></h3>
<% if @free_places == Float::INFINITY %>
<%= Event.human_attribute_name(:participants_are_unlimited) %>
<% else %>
<div id="free_places"><%= t '.free_places', count: @free_places %></div>
<% end %>

<div id="free_places"><%= t '.free_places', count: @free_places %></div>
<div id="occupied_places"><%= t '.occupied_places', count: @occupied_places %></div>

<table id="applicants" class="table table-striped">
Expand Down
58 changes: 26 additions & 32 deletions app/views/events/_form.html.erb
Expand Up @@ -2,24 +2,34 @@
<%= render partial: "shared/error_message", locals: {entity: @event} %>

<div class="form-group">
<div class="btn-group col-lg-10 col-lg-offset-2" data-toggle="buttons">
<% Event.kinds.keys.each do |key| %>
<label class="btn btn-default <%= 'active' if @event.kind == key %>">
<%= f.radio_button :kind, key %>
<%= I18n.t :"events.kinds.#{key}" %>
<div class="form-group">
<%= f.label :type, :class => 'control-label col-lg-2' %>
<div class="btn-group col-lg-10" data-toggle="buttons">
<label class="btn btn-default <%= 'active' if not @event.hidden %>">
<%= f.radio_button :hidden, false %>
<%= I18n.t :"events.type.public" %>
</label>
<% end %>
<%=f.error_span(:kind) %>
<label class="btn btn-default <%= 'active' if @event.hidden %>">
<%= f.radio_button :hidden, true %>
<%= I18n.t :"events.type.private" %>
</label>
<%= f.error_span(:hidden) %>
</div>
</div>
</div>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<%= f.check_box :hidden %>
<%= f.label :hidden, :class => 'control-label' %>
<%= f.error_span(:hidden) %>
<div class="form-group">
<%= f.label :published, :class => 'control-label col-lg-2' %>
<div class="btn-group col-lg-10" data-toggle="buttons">
<label class="btn btn-default <%= 'active' if not @event.published %>">
<%= f.radio_button :published, false %>
<%= I18n.t :"events.form.draft.save" %>
</label>
<label class="btn btn-default <%= 'active' if @event.published %>">
<%= f.radio_button :published, true %>
<%= I18n.t :"events.form.draft.publish" %>
</label>
<%= f.error_span(:published) %>
</div>
</div>
</div>
<div class="form-group">
<%= f.label :name, :class => 'control-label col-lg-2' %>
<div class="col-lg-10">
Expand All @@ -45,7 +55,7 @@
$("#description").blur(function(){
if($(this).val() ===''){
$(this).attr('placeholder', placeholder);
}
}
});
</script>
<%=f.error_span(:description) %>
Expand All @@ -58,8 +68,6 @@
<div class="col-lg-10">
<%= f.text_field :max_participants, :class => 'form-control' %>
<%=f.error_span(:max_participants) %>
<%= f.label :participants_are_unlimited %>
<%= f.check_box :participants_are_unlimited, :class => 'form_control' %>
</div>
</div>
<div class="form-group">
Expand Down Expand Up @@ -114,20 +122,6 @@
</div>
</div>
<%= (render 'custom_application_fields_input', form: f) if @event.new_record? %>
<div class="form-group">
<%= f.label :published, :class => 'control-label col-lg-2' %>
<div class="btn-group col-lg-10" data-toggle="buttons">
<label class="btn btn-default <%= 'active' if @event.published %>">
<%= f.radio_button :published, true %>
<%= I18n.t :"events.form.published.myon" %>
</label>
<label class="btn btn-default <%= 'active' if not @event.published %>">
<%= f.radio_button :published, false %>
<%= I18n.t :"events.form.published.myoff" %>
</label>
<%=f.error_span(:published) %>
</div>
</div>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<% if @event.new_record? %>
Expand Down
6 changes: 1 addition & 5 deletions app/views/events/_show_event.html.erb
Expand Up @@ -5,11 +5,7 @@
<dt><strong><%= model_class.human_attribute_name(:description) %>:</strong></dt>
<dd><%= markdown @event.description %></dd>
<dt><strong><%= model_class.human_attribute_name(:max_participants) %>:</strong></dt>
<%if @free_places == Float::INFINITY %>
<dd><%= model_class.human_attribute_name(:participants_are_unlimited) %></dd>
<%else%>
<dd><%= @event.max_participants %></dd>
<% end %>
<dd><%= @event.max_participants %></dd>
<dt><strong><%= model_class.human_attribute_name(:date_ranges, count: @event.date_ranges.count) %>:</strong></dt>
<dd>
<ul>
Expand Down
4 changes: 2 additions & 2 deletions app/views/events/participants.html.erb
@@ -1,6 +1,6 @@
<%- model_class = Event -%>
<div class="page-header">
<h1><%=t '.title', :default => model_class.model_name.human.titleize %> (<%= @event.kind.humanize %>)</h1>
<h1><%=t '.title', :default => model_class.model_name.human.titleize %> (<%= @event.hidden ? I18n.t("events.type.private") : I18n.t("events.type.public") %>)</h1>
</div>
<% if can? :view_participants, Event %>
<%= render :partial => 'participants_modal' %>
Expand All @@ -23,7 +23,7 @@
</th>
<% end %>
<% if can? :show_eatings_habits, Event %>
<th>
<th>7
<%= sort_caret(t('activerecord.methods.application_letter.eating_habits'), 'eating-habits') %>
</th>
<% end %>
Expand Down
10 changes: 8 additions & 2 deletions config/locales/de.application_letters.yml
Expand Up @@ -51,14 +51,12 @@ de:
attributes:
application_letter:
grade: "Klassenstufe"
experience: "Wie hast du von uns erfahren?"
motivation: "Motivationsschreiben"
coding_skills: "Mit welchen Programmiersprachen hast du bereits Erfahrungen gesammelt?"
emergency_number: "Telefonnummer für Notfälle"
organisation: "Schule/Organisation"
vegetarian: "Vegetarisch"
vegan: "Vegan"
allergic: "Allergien vorhanden"
allergies: "Falls Allergien vorhanden, welche?"
annotation: "Hast du weitere Anmerkungen oder Fragen?"
omnivorous: "Omnivor"
Expand All @@ -73,3 +71,11 @@ de:
pending_before_deadline: "Beworben"
pending_after_deadline: "In Bearbeitung"
alternative: "Nachrücker"


controllers:
application_letters:
confirmation_mail:
sender: "workshop@hpi.de"
subject: "Bewerbung erhalten"
content: "Hallo, \n\rDu hast dich erfolgreich für {{semimar_name}} beworben. Deine Bewerbung wird jetzt bearbeitet. Für weitere Information besuche das Workshop Portal. Viele Grüße, das HPI Workshop Team"

0 comments on commit 395d543

Please sign in to comment.