Verified Commit 65afa788 authored by Kaspar Vollenweider's avatar Kaspar Vollenweider 👻
Browse files

add submitted_by and setting it in all relevant controllers and views

parent 8b4382c3
......@@ -100,7 +100,7 @@ class AssignmentsController < ApplicationController
def update_submitted_at
@assignment.update(assignment_params.slice(:volunteer_attributes)
.merge(submitted_at: Time.zone.now))
.merge(submit_feedback: current_user))
redirect_to default_redirect || hours_and_feedbacks_submitted_assignments_path
end
......
......@@ -63,7 +63,7 @@ class GroupAssignmentsController < ApplicationController
def update_submitted_at
@group_assignment.update(group_assignment_params.slice(:volunteer_attributes)
.merge(submitted_at: Time.zone.now))
.merge(submit_feedback: current_user))
redirect_to default_redirect || hours_and_feedbacks_submitted_assignments_path
end
......
......@@ -17,6 +17,8 @@ module AssignmentCommon
inverse_of: 'assignment_terminations_submitted', optional: true
belongs_to :termination_verified_by, -> { with_deleted }, class_name: 'User',
inverse_of: 'assignment_terminations_verified', optional: true
belongs_to :submitted_by, -> { with_deleted }, class_name: 'User',
inverse_of: 'assignments_submitted', foreign_key: 'submitted_by_id', optional: true
scope :zurich, (-> { joins(:client).merge(Client.zurich) })
scope :not_zurich, (-> { joins(:client).merge(Client.not_zurich) })
......
......@@ -69,6 +69,11 @@ module GroupAssignmentAndAssignmentCommon
.where('reminder_mailings.kind != 1 OR reminder_mailing_volunteers.id IS NULL')
}
def submit_feedback=(submitter)
self.submitted_at = Time.zone.now
self.submitted_by = submitter
end
def termination_verifiable?
ended? && termination_submitted_by.present?
end
......
......@@ -19,6 +19,8 @@ module GroupAssignmentCommon
inverse_of: 'group_assignment_terminations_submitted', foreign_key: 'termination_submitted_by_id'
belongs_to :termination_verified_by, -> { with_deleted }, class_name: 'User', optional: true,
inverse_of: 'group_offer_terminations_verified'
belongs_to :submitted_by, -> { with_deleted }, class_name: 'User',
inverse_of: 'group_assignments_submitted', foreign_key: 'submitted_by_id', optional: true
def to_label
label_parts.compact.join(' - ')
......
......@@ -51,6 +51,8 @@ class User < ApplicationRecord
foreign_key: 'termination_submitted_by_id', inverse_of: 'termination_submitted_by'
has_many :assignment_terminations_verified, class_name: 'Assignment',
foreign_key: 'termination_verified_by_id', inverse_of: 'termination_verified_by'
has_many :assignments_submitted, class_name: 'Assignment',
foreign_key: 'submitted_by_id', inverse_of: 'submitted_by'
# GroupAssignment termination relations
has_many :group_assignment_period_ends_set, class_name: 'GroupAssignment',
......@@ -59,6 +61,8 @@ class User < ApplicationRecord
foreign_key: 'termination_submitted_by_id', inverse_of: 'termination_submitted_by'
has_many :group_assignment_terminations_verified, class_name: 'GroupAssignment',
foreign_key: 'termination_verified_by', inverse_of: 'termination_verified_by'
has_many :group_assignments_submitted, class_name: 'GroupAssignment',
foreign_key: 'submitted_by_id', inverse_of: 'submitted_by'
has_many :group_offer_period_ends_set, class_name: 'GroupOffer',
foreign_key: 'period_end_set_by_id', inverse_of: 'period_end_set_by'
......
......@@ -29,4 +29,7 @@
.submit-box
.col-xs-12
p Ich bestätige, dass ich alle meine Stunden und Halbjahres-Rapporte bis zum heutigen Datum erfasst habe.
= f.submit 'Bestätigen', class: 'btn btn-lg-accepted'
- if confirmable.submitted_at.present?
p.text-danger Bestätigt am #{l(confirmable.submitted_at.to_date)} durch #{profile_link(confirmable.submitted_by)}
- else
= f.submit 'Bestätigen', class: 'btn btn-lg-accepted'
class AddSubmittedByToAssignments < ActiveRecord::Migration[5.1]
def change
change_table :assignments do |t|
t.references :submitted_by, references: :users
end
change_table :assignment_logs do |t|
t.references :submitted_by, references: :users
end
change_table :group_assignments do |t|
t.references :submitted_by, references: :users
end
change_table :group_assignment_logs do |t|
t.references :submitted_by, references: :users
end
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180704073944) do
ActiveRecord::Schema.define(version: 20180709115633) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -54,6 +54,7 @@ ActiveRecord::Schema.define(version: 20180704073944) do
t.string "duration"
t.string "special_agreement"
t.text "agreement_text"
t.bigint "submitted_by_id"
t.index ["assignment_id"], name: "index_assignment_logs_on_assignment_id"
t.index ["client_id"], name: "index_assignment_logs_on_client_id"
t.index ["creator_id"], name: "index_assignment_logs_on_creator_id"
......@@ -62,6 +63,7 @@ ActiveRecord::Schema.define(version: 20180704073944) do
t.index ["period_end_set_by_id"], name: "index_assignment_logs_on_period_end_set_by_id"
t.index ["period_start"], name: "index_assignment_logs_on_period_start"
t.index ["submitted_at"], name: "index_assignment_logs_on_submitted_at"
t.index ["submitted_by_id"], name: "index_assignment_logs_on_submitted_by_id"
t.index ["termination_submitted_at"], name: "index_assignment_logs_on_termination_submitted_at"
t.index ["termination_submitted_by_id"], name: "index_assignment_logs_on_termination_submitted_by_id"
t.index ["termination_verified_at"], name: "index_assignment_logs_on_termination_verified_at"
......@@ -111,12 +113,14 @@ ActiveRecord::Schema.define(version: 20180704073944) do
t.string "pdf_content_type"
t.integer "pdf_file_size"
t.datetime "pdf_updated_at"
t.bigint "submitted_by_id"
t.index ["client_id"], name: "index_assignments_on_client_id"
t.index ["creator_id"], name: "index_assignments_on_creator_id"
t.index ["period_end"], name: "index_assignments_on_period_end"
t.index ["period_end_set_by_id"], name: "index_assignments_on_period_end_set_by_id"
t.index ["period_start"], name: "index_assignments_on_period_start"
t.index ["submitted_at"], name: "index_assignments_on_submitted_at"
t.index ["submitted_by_id"], name: "index_assignments_on_submitted_by_id"
t.index ["termination_submitted_at"], name: "index_assignments_on_termination_submitted_at"
t.index ["termination_submitted_by_id"], name: "index_assignments_on_termination_submitted_by_id"
t.index ["termination_verified_at"], name: "index_assignments_on_termination_verified_at"
......@@ -350,10 +354,12 @@ ActiveRecord::Schema.define(version: 20180704073944) do
t.string "frequency"
t.string "trial_period_end"
t.text "agreement_text"
t.bigint "submitted_by_id"
t.index ["deleted_at"], name: "index_group_assignment_logs_on_deleted_at"
t.index ["group_assignment_id"], name: "index_group_assignment_logs_on_group_assignment_id"
t.index ["group_offer_id"], name: "index_group_assignment_logs_on_group_offer_id"
t.index ["period_end_set_by_id"], name: "index_group_assignment_logs_on_period_end_set_by_id"
t.index ["submitted_by_id"], name: "index_group_assignment_logs_on_submitted_by_id"
t.index ["termination_submitted_by_id"], name: "index_group_assignment_logs_on_termination_submitted_by_id"
t.index ["termination_verified_by_id"], name: "index_group_assignment_logs_on_termination_verified_by_id"
t.index ["title"], name: "index_group_assignment_logs_on_title"
......@@ -391,12 +397,14 @@ ActiveRecord::Schema.define(version: 20180704073944) do
t.string "pdf_content_type"
t.integer "pdf_file_size"
t.datetime "pdf_updated_at"
t.bigint "submitted_by_id"
t.index ["deleted_at"], name: "index_group_assignments_on_deleted_at"
t.index ["group_offer_id"], name: "index_group_assignments_on_group_offer_id"
t.index ["period_end"], name: "index_group_assignments_on_period_end"
t.index ["period_end_set_by_id"], name: "index_group_assignments_on_period_end_set_by_id"
t.index ["period_start"], name: "index_group_assignments_on_period_start"
t.index ["submitted_at"], name: "index_group_assignments_on_submitted_at"
t.index ["submitted_by_id"], name: "index_group_assignments_on_submitted_by_id"
t.index ["termination_submitted_at"], name: "index_group_assignments_on_termination_submitted_at"
t.index ["termination_submitted_by_id"], name: "index_group_assignments_on_termination_submitted_by_id"
t.index ["termination_verified_at"], name: "index_group_assignments_on_termination_verified_at"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment