Skip to content

Commit

Permalink
Merge branch 'dev' into 272_button_removal_party
Browse files Browse the repository at this point in the history
  • Loading branch information
LeaGe committed Jan 24, 2017
2 parents c602349 + e43d478 commit a4dd22a
Show file tree
Hide file tree
Showing 17 changed files with 83 additions and 22 deletions.
9 changes: 7 additions & 2 deletions app/controllers/events_controller.rb
Expand Up @@ -7,11 +7,16 @@ class EventsController < ApplicationController

# GET /events
def index
@events = Event.sorted_by_start_date(!can?(:view_unpublished, Event))
@events = Event.sorted_by_start_date(false)
@events = @events.select{|event| event.hidden == false} unless can? :view_hidden, Event
@events = @events.select{|event| event.published == true} unless can? :view_unpublished, Event
end

# GET /events/1
def show
if @event.hidden and !can? :view_hidden, Event
redirect_to new_application_letter_path(:event_id => @event.id)
end
@free_places = @event.compute_free_places
@occupied_places = @event.compute_occupied_places
@application_letters = filter_application_letters(@event.application_letters)
Expand Down Expand Up @@ -227,7 +232,7 @@ def set_event

# Only allow a trusted parameter "white list" through.
def event_params
params.require(:event).permit(:name, :description, :max_participants, :participants_are_unlimited, :kind, :organizer, :knowledge_level, :application_deadline, :published, :custom_application_fields => [], date_ranges_attributes: [:start_date, :end_date, :id])
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])
end

# Generate all names to print from the query-params
Expand Down
2 changes: 1 addition & 1 deletion app/models/ability.rb
Expand Up @@ -57,7 +57,7 @@ def initialize(user)
can [:index, :show], Profile
can [:index, :show, :view_and_add_notes, :update_status], ApplicationLetter
cannot :update, ApplicationLetter
can [:view_applicants, :edit_applicants, :view_participants, :print_applications, :manage, :view_material, :upload_material, :print_agreement_letters, :download_material, :view_unpublished], Event
can [:view_applicants, :edit_applicants, :view_participants, :print_applications, :manage, :view_material, :upload_material, :print_agreement_letters, :download_material, :view_unpublished, :view_hidden], Event
can :send_email, Email
can :manage, Request
can [:update], ParticipantGroup
Expand Down
15 changes: 9 additions & 6 deletions app/models/event.rb
Expand Up @@ -11,6 +11,7 @@
# created_at :datetime not null
# updated_at :datetime not null
# application_status_locked :boolean
# hidden :boolean
#

class Event < ActiveRecord::Base
Expand All @@ -24,6 +25,12 @@ class Event < ActiveRecord::Base
has_many :participant_groups
has_many :date_ranges
accepts_nested_attributes_for :date_ranges
validates :max_participants, numericality: { only_integer: true, greater_than: 0 }
validate :has_date_ranges
validates_presence_of :application_deadline
validate :application_deadline_before_start_of_event
validates :hidden, inclusion: { in: [true, false] }
validates :hidden, 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
Expand Down Expand Up @@ -56,10 +63,6 @@ def participants_by_agreement_letter
@participants.sort { |x, y| self.compare_participants_by_agreement(x,y) }
end

validates :max_participants, numericality: { only_integer: true, greater_than: 0 }
validate :has_date_ranges
validates_presence_of :application_deadline
validate :application_deadline_before_start_of_event


# @return the minimum start_date over all date ranges
Expand Down Expand Up @@ -273,10 +276,10 @@ def material_path
# if requested
#
# @param limit Maximum number of events to return
# @param only_public Set to true to not include drafts
# @param only_public Set to true to not include drafts and hidden events
# @return List of events
def self.sorted_by_start_date(only_public)
(only_public ? Event.draft_is(false) : Event.all)
(only_public ? Event.draft_is(false).where(hidden: false) : Event.all)
.sort_by(&:start_date)
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/application_letters/check.html.erb
Expand Up @@ -12,7 +12,7 @@
</div>

<%# Be careful: user.requires_agreement_letter_for_event? behaves exactly the way you wouldn't expect it do behave: If the user requires an agreement letter for the event, it returns false... But fuck me if I'm the one to refactor it%>
<% if (not @application_letter.user.requires_agreement_letter_for_event?(@application_letter.event)) and (not @application_deadline_exceeded)%>
<% if not @application_letter.user.requires_agreement_letter_for_event?(@application_letter.event)%>
<h3 id="agreement_header"><%= t('agreement_letters.please_upload', event: @application_letter.event.name)%></h3>
<%= render('upload_form', event_id: @application_letter.event.id, agreement_letter: @application_letter.event.agreement_letter_for(@application_letter.user)) %>
<% end %>
Expand Down
1 change: 1 addition & 0 deletions app/views/events/_event.html.erb
Expand Up @@ -10,6 +10,7 @@
<%= event.name %>
<small>
<%= tag_label t('activerecord.attributes.event.draft'), :default if not event.published and can? :view_unpublished, Event %>
<%= tag_label t('activerecord.attributes.event.hidden'), :default if event.hidden and can? :view_hidden, Event %>
<%= tag_label t('events.notices.past_event'), :default if event.is_past %>
</small>
</h3>
Expand Down
8 changes: 7 additions & 1 deletion app/views/events/_form.html.erb
Expand Up @@ -13,7 +13,13 @@
<%=f.error_span(:kind) %>
</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>
</div>
<div class="form-group">
<%= f.label :name, :class => 'control-label col-lg-2' %>
<div class="col-lg-10">
Expand Down
1 change: 1 addition & 0 deletions config/locales/de.events.yml
Expand Up @@ -135,6 +135,7 @@ de:
other: "Zeitspannen"
application_deadline: "Bewerbungsschluss"
published: "Öffentlich"
hidden: "Versteckt"
helpers:
submit:
event:
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20170123161527_add_hidden_to_event.rb
@@ -0,0 +1,5 @@
class AddHiddenToEvent < ActiveRecord::Migration
def change
add_column :events, :hidden, :boolean
end
end
6 changes: 6 additions & 0 deletions db/sample_data/events.rb
Expand Up @@ -14,6 +14,7 @@ def event_programmierkurs
application_deadline: Date.tomorrow,
application_status_locked: false,
published: true,
hidden: true,
custom_application_fields: ['Lieblingsapp']
)
end
Expand All @@ -33,6 +34,7 @@ def event_mintcamp
date_ranges: [date_range_mint_camp],
application_deadline: Date.tomorrow,
application_status_locked: false,
hidden: false,
published: true
)
end
Expand All @@ -52,6 +54,7 @@ def event_bechersaeuberungsevent
application_deadline: Date.tomorrow,
application_status_locked: false,
published: true,
hidden: false,
custom_application_fields: ['Lieblings-Becherart', 'Kannst du eine eigene Spülmaschine mitbringen?']
)
end
Expand All @@ -69,6 +72,7 @@ def event_gongakrobatik
date_ranges: [date_range_long],
application_deadline: Date.tomorrow,
application_status_locked: false,
hidden: false,
published: true
)
end
Expand All @@ -92,6 +96,7 @@ def event_batterie_akustik
application_deadline: Date.tomorrow,
application_status_locked: false,
published: false,
hidden: false,
custom_application_fields: ['Spielst du gerne in deiner Freizeit mit Batterien?']
)
end
Expand All @@ -116,6 +121,7 @@ def event_bachlorpodium
date_ranges: [date_range_singleday1, date_range_singleday2, date_range_singleday3],
application_deadline: Date.tomorrow,
application_status_locked: false ,
hidden: true,
published: true
)
end
3 changes: 2 additions & 1 deletion db/schema.rb
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20170122191752) do
ActiveRecord::Schema.define(version: 20170123161527) do

create_table "agreement_letters", force: :cascade do |t|
t.integer "user_id", null: false
Expand Down Expand Up @@ -85,6 +85,7 @@
t.boolean "application_status_locked"
t.boolean "participants_are_unlimited", default: false
t.text "custom_application_fields"
t.boolean "hidden"
end

create_table "participant_groups", force: :cascade do |t|
Expand Down
6 changes: 2 additions & 4 deletions spec/controllers/agreement_letters_controller_spec.rb
Expand Up @@ -4,8 +4,7 @@

describe "POST #create" do
before :each do
@user = FactoryGirl.create(:user, role: :pupil)
@user.profile ||= FactoryGirl.create(:profile)
@user = FactoryGirl.create(:user_with_profile, role: :pupil)
@event = FactoryGirl.create(:event)
@application = FactoryGirl.create(:application_letter, user: @user, event: @event)
filepath = Rails.root.join('spec/testfiles/actual.pdf')
Expand All @@ -31,8 +30,7 @@

describe "POST #create when file was already created" do
before :each do
@user = FactoryGirl.create(:user, role: :pupil)
@user.profile ||= FactoryGirl.create(:profile)
@user = FactoryGirl.create(:user_with_profile, role: :pupil)
@event = FactoryGirl.create(:event)
filepath = Rails.root.join('spec/testfiles/actual.pdf')
@file = fixture_file_upload(filepath, 'application/pdf')
Expand Down
13 changes: 11 additions & 2 deletions spec/controllers/events_controller_spec.rb
Expand Up @@ -165,6 +165,16 @@
end
end

describe "GET #show for hidden event as pupil"
it "should redirect to new application letter page" do
@event = FactoryGirl.create(:event, hidden: true)
@user = FactoryGirl.create(:user_with_profile, role: :pupil)
sign_in @user

get :show, id: @event.to_param, session: valid_session
expect(response).to redirect_to(new_application_letter_path(:event_id => @event.id))
end

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

Expand Down Expand Up @@ -259,8 +269,7 @@

describe "POST #download_material" do
before :each do
@user = FactoryGirl.create(:user, role: :coach)
@user.profile ||= FactoryGirl.create(:profile)
@user = FactoryGirl.create(:user_with_profile, role: :coach)
sign_in @user

filepath = Rails.root.join('spec/testfiles/actual.pdf')
Expand Down
3 changes: 3 additions & 0 deletions spec/factories/events.rb
Expand Up @@ -10,6 +10,7 @@
# published :boolean
# created_at :datetime not null
# updated_at :datetime not null
# hidden :boolean
#

FactoryGirl.define do
Expand All @@ -24,6 +25,7 @@
application_deadline Date.tomorrow
custom_application_fields ["Field 1", "Field 2", "Field 3"]
date_ranges { build_list :date_range, 1 }
hidden false

trait :with_two_date_ranges do
after(:build) do |event|
Expand Down Expand Up @@ -120,6 +122,7 @@
description "Event-Description"
max_participants 20
date_ranges { build_list :date_range, 1 }
hidden false
transient do
accepted_application_letters_count 5
rejected_application_letters_count 5
Expand Down
18 changes: 18 additions & 0 deletions spec/features/event_spec.rb
Expand Up @@ -17,6 +17,14 @@
expect(page).to have_css(".label", text: I18n.t(".activerecord.attributes.event.draft"))
end

it "should mark an event as hidden by showing a label" do
login_as(FactoryGirl.create(:user, role: :organizer), :scope => :user)

FactoryGirl.create :event, hidden: true
visit events_path
expect(page).to have_css(".label", text: I18n.t(".activerecord.attributes.event.hidden"))
end

it "should not show drafts to pupils or coaches" do
%i[coach pupil].each do |role|
login_as(FactoryGirl.create(:user, role: role), :scope => :user)
Expand All @@ -27,6 +35,16 @@
end
end

it "should not show hidden events to pupils or coaches" do
%i[coach pupil].each do |role|
login_as(FactoryGirl.create(:user, role: role), :scope => :user)

FactoryGirl.create :event, hidden: true, name: "Verstecktes Event"
visit events_path
expect(page).to_not have_text("Verstecktes Event")
end
end

it "should display the duration of the event" do
FactoryGirl.create :event, :over_six_days
visit events_path
Expand Down
8 changes: 8 additions & 0 deletions spec/models/event_spec.rb
Expand Up @@ -17,6 +17,14 @@

let(:event) { FactoryGirl.create :event, :with_two_date_ranges }


it "can't be created without mandatory fields" do
[:hidden, :application_deadline].each do |attr|
event = FactoryGirl.build(:event, attr => nil)
expect(event).to_not be_valid
end
end

it "is created by event factory" do
expect(event).to be_valid
end
Expand Down
4 changes: 0 additions & 4 deletions spec/models/profile_spec.rb
Expand Up @@ -40,10 +40,6 @@
profile = FactoryGirl.build(:profile)
adult_profile = FactoryGirl.build(:adult_profile)


puts "FUCK #{profile.birth_date}: #{profile.birth_date >= 18.years.ago}"
puts "FUCK #{adult_profile.birth_date}: #{adult_profile.birth_date >= 18.years.ago}"

expect(profile.adult?).to be false
expect(adult_profile.adult?).to be true
end
Expand Down
1 change: 1 addition & 0 deletions spec/views/events/new.html.erb_spec.rb
Expand Up @@ -14,6 +14,7 @@
assert_select "input#event_max_participants[name=?]", "event[max_participants]"
assert_select "input#event_organizer[name=?]", "event[organizer]"
assert_select "input#event_knowledge_level[name=?]", "event[knowledge_level]"
assert_select "input#event_hidden[name=?]", "event[hidden]"
end
end
end

0 comments on commit a4dd22a

Please sign in to comment.