Commit f3064d41 authored by Tugce Nur Tas's avatar Tugce Nur Tas
Browse files

add take_responsibility function to semester process volunteer

parent 68db679b
class SemesterProcessVolunteersController < ApplicationController
before_action :prepare_review, :initialize_nested_objects, only: [:review_semester, :submit_review]
before_action :set_semester_process_volunteer, only: [:show, :edit, :update]
before_action :set_semester_process_volunteer, only: [:show, :edit, :update, :take_responsibility]
before_action :set_semester, only: [:index]
include SemesterProcessVolunteerHelper
......@@ -55,6 +55,21 @@ class SemesterProcessVolunteersController < ApplicationController
end
end
def take_responsibility
respond_to do |format|
if @spv.update(responsible: current_user)
format.html { redirect_to(@redirect_back_path, notice: 'Halbjahres-Rapport übernommen.') }
format.json do
render json: { link: url_for(@spv.responsible), at: I18n.l(@spv.responsibility_taken_at.to_date),
email: @spv.responsible.email }, status: :ok
end
else
format.html { redirect_to(@redirect_back_path, notice: 'Fehler: Übernehmen fehlgeschlagen.') }
format.json { render json: { errors: @spv.errors.messages }, status: :unprocessable_entity }
end
end
end
private
def prepare_review
......
......@@ -75,4 +75,9 @@ class SemesterProcessVolunteer < ApplicationRecord
def render_feedback(field)
semester_feedbacks.map(&field).join(', ')
end
def responsible=(responsible_user)
self.responsibility_taken_at = Time.zone.now
super(responsible_user)
end
end
......@@ -7,13 +7,14 @@ class SemesterProcessVolunteerPolicy < ApplicationPolicy
end
# Actions
alias_method :index?, :superadmin?
alias_method :review_semester?, :superadmin_or_volunteer_related?
alias_method :submit_review?, :superadmin_or_volunteer_related?
alias_method :new?, :superadmin?
alias_method :show?, :superadmin?
alias_method :edit?, :superadmin?
alias_method :create?, :superadmin?
alias_method :update?, :superadmin?
alias_method :destroy?, :superadmin?
alias_method :index?, :superadmin?
alias_method :review_semester?, :superadmin_or_volunteer_related?
alias_method :submit_review?, :superadmin_or_volunteer_related?
alias_method :new?, :superadmin?
alias_method :show?, :superadmin?
alias_method :edit?, :superadmin?
alias_method :create?, :superadmin?
alias_method :update?, :superadmin?
alias_method :destroy?, :superadmin?
alias_method :take_responsibility?, :superadmin?
end
......@@ -19,6 +19,7 @@ h1= t_title(:index)
th Bemerkungen
th= t_attr(:commited_by)
th Letzte Bestätigung
th Aktionen
tbody
- @spvs_sorted.each do |spv|
......@@ -39,6 +40,15 @@ h1= t_title(:index)
= td_truncate_content_modal(spv.render_feedback(:comments), 'Bemerkungen', shorten_size: 300)
td= spv.commited_by
td= spv.commited_at && l(spv.commited_at)
td.index-action-cell.hidden-print
- if spv.responsible.present?
= 'Übernommen durch '
= link_to spv.responsible.email, spv.responsible
= " am #{l(spv.responsibility_taken_at.to_date)}"
- else
= api_button('Übernehmen', subject: [spv],
action: :take_responsibility, extra_class: 'm-t-10',
template: 'Übernommen durch <a href="<%= data.link %>"><%= data.email %></a> am <%= data.at %>')
= bootstrap_paginate(@spvs)
......
......@@ -100,6 +100,7 @@ Rails.application.routes.draw do
resources :semester_process_volunteers do
get :review_semester, on: :member
patch :submit_review, on: :member
put :take_responsibility, on: :member
end
resources :semester_processes, except: [:destroy]
......
Markdown is supported
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