diff --git a/app/controllers/entries_controller.rb b/app/controllers/entries_controller.rb index 38043a6..e1ee5f6 100644 --- a/app/controllers/entries_controller.rb +++ b/app/controllers/entries_controller.rb @@ -32,7 +32,7 @@ class EntriesController < ApplicationController @total_kilometer_costs_by_year = Entry.total_kilometer_cost_by_year(current_user) @fortbildungskosten_by_year = Entry.total_fortbildungskosten_by_year(current_user) - @selbstsupervision_by_year = Entry.total_selbsterfahrungskosten_by_year(current_user) + @selbstsupervision_by_year = Entry.total_supervision_by_year(current_user) @selbsterfahrungskosten_by_year = Entry.total_selbsterfahrungskosten_by_year(current_user) @allekosten_by_year = Entry.total_semesterkosten_by_year(current_user) @@ -91,7 +91,11 @@ class EntriesController < ApplicationController end def create - @entry = current_user.entries.build(entry_params) + @entry = current_user.entries.new(entry_params) + if current_user.praepedeutikum_abgeschlossen? && @entry.praktikums_typ == 'propädeutikum' + redirect_to entries_path, alert: "Propädeutikum ist bereits abgeschlossen – Neuer Eintrag dieses Typs ist nicht erlaubt." + return + end if @entry.save redirect_to entries_path, notice: "Eintrag gespeichert" else diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb index 7ee8bf6..fb7dc80 100644 --- a/app/controllers/users/registrations_controller.rb +++ b/app/controllers/users/registrations_controller.rb @@ -1,19 +1,20 @@ class Users::RegistrationsController < Devise::RegistrationsController - protected - - def update_resource(resource, params) - # Wenn kein Passwort gesetzt werden soll: - if params[:password].blank? && params[:password_confirmation].blank? - resource.update_without_password(params.except(:current_password)) - else - super - end - end - - def configure_permitted_parameters - devise_parameter_sanitizer.permit(:account_update, keys: [ - required_hours_matrix: {}, - weekly_target_matrix: {} - ]) - end + protected + + def update_resource(resource, params) + # Wenn kein Passwort gesetzt werden soll: + if params[:password].blank? && params[:password_confirmation].blank? + resource.update_without_password(params.except(:current_password)) + else + super + end + end + + def configure_permitted_parameters + devise_parameter_sanitizer.permit(:account_update, keys: [ + :praepedeutikum_done, + required_hours_matrix: {}, + weekly_target_matrix: {} + ]) + end end \ No newline at end of file diff --git a/app/models/entry.rb b/app/models/entry.rb index 128e41d..ef6abb6 100644 --- a/app/models/entry.rb +++ b/app/models/entry.rb @@ -112,6 +112,7 @@ class Entry < ApplicationRecord end end + def total_minutes_including_break return nil unless start_time && end_time diff --git a/app/models/user.rb b/app/models/user.rb index fbdfd80..ef3e081 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -10,8 +10,10 @@ class User < ApplicationRecord ENTRY_ARTEN = %w[Praktikum Selbsterfahrung Supervision] after_initialize :set_default, if: :new_record? - + def praepedeutikum_abgeschlossen? + praepedeutikum_done + end def is_admin? self.email =="christoph@marzell.net" end diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index 0432ec5..fdf69de 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -85,6 +85,11 @@ <%= f.password_field :current_password, autocomplete: "current-password", class: "form-control" %> +