Commit 666ebb6c authored by Jiri Strojil's avatar Jiri Strojil

Merge remote-tracking branch 'origin/develop' into chores/remove-old-halfyear-feedback

parents 343408e9 5c98cf5a
Pipeline #33585 passed with stage
in 33 minutes and 49 seconds
# this is obsolete, only used for the index action. we should move the action and the view to semester_feedbacks
class FeedbacksController < ApplicationController
before_action :set_feedback,
only: [:show, :edit, :update, :destroy, :mark_as_done, :take_responsibility]
before_action :set_feedbackable, except: [:index]
before_action :set_volunteer
before_action :set_list_response_feedback_redirect_back_path,
only: [:mark_as_done, :take_responsibility]
def index
authorize Feedback
@feedbacks = if params[:assignment_id]
SemesterFeedback.where(assignment_id: params[:assignment_id])
elsif params[:group_offer_id]
......@@ -15,117 +8,7 @@ class FeedbacksController < ApplicationController
else
[]
end
end
def show; end
def new
@feedback = SemesterFeedback.new(feedbackable: @feedbackable, volunteer: @volunteer,
author: current_user)
authorize @feedback
simple_form_params
end
def edit
simple_form_params
end
def create
@feedback = Feedback.new(feedback_params.merge(author_id: current_user.id,
volunteer_id: @volunteer.id))
@feedback.feedbackable = @feedbackable
authorize @feedback
simple_form_params
if @feedback.save
redirect_to default_redirect || @volunteer, make_notice
else
render :new
end
end
def update
if @feedback.update(feedback_params)
redirect_to params[:redirect_to] || @feedback.volunteer, make_notice
else
render :edit
end
end
def destroy
@feedback.destroy
redirect_back(fallback_location: url_for(@feedbackable))
end
def mark_as_done
respond_to do |format|
if @feedback.update(reviewer: current_user)
format.html { redirect_to(@redirect_back_path, notice: 'Halbjahres-Rapport quittiert.') }
format.json { render json: { link: polymorphic_path([@feedback.volunteer, @feedback.feedbackable, @feedback]) }, status: :ok }
else
format.html { redirect_to(@redirect_back_path, notice: 'Fehler: Quittieren fehlgeschlagen.') }
format.json { render json: { errors: @feedback.errors.messages }, status: :unprocessable_entity }
end
end
end
def take_responsibility
respond_to do |format|
if @feedback.update(responsible: current_user)
format.html { redirect_to(@redirect_back_path, notice: 'Halbjahres-Rapport übernommen.') }
format.json do
render json: { link: url_for(@feedback.responsible), at: I18n.l(@feedback.responsible_at.to_date),
email: @feedback.responsible.email }, status: :ok
end
else
format.html { redirect_to(@redirect_back_path, notice: 'Fehler: Übernehmen fehlgeschlagen.') }
format.json { render json: { errors: @feedback.errors.messages }, status: :unprocessable_entity }
end
end
end
private
def set_list_response_feedback_redirect_back_path
@redirect_back_path = list_responses_feedbacks_path(
params.to_unsafe_hash.slice(:q, :page)
)
end
def simple_form_params
@simple_form_for_params = [
[@volunteer, @feedbackable, @feedback], {
url: polymorphic_path(
[@volunteer, @feedbackable, @feedback],
redirect_to: params[:redirect_back] || default_redirect,
group_assignment: params[:group_assignment]
)
}
]
end
def set_feedbackable
@feedbackable = Assignment.find_by(id: params[:assignment_id]) ||
GroupOffer.find_by(id: params[:group_offer_id])
end
def find_feedbackable_submit_form
return @feedbackable if @feedbackable.assignment?
GroupAssignment.find_by(id: params[:group_assignment])
end
def set_volunteer
@volunteer = Volunteer.find(params[:volunteer_id]) if params[:volunteer_id]
end
def set_feedback
@feedback = Feedback.find(params[:id])
@feedbackable = @feedback.feedbackable
@volunteer = @feedback.volunteer
authorize @feedback
end
def feedback_params
params.require(:feedback).permit(:goals, :achievements, :future, :comments, :conversation,
:volunteer_id, :group_offer_id, :assignment_id)
authorize @feedbacks
@feedbacks = policy_scope(@feedbacks)
end
end
......@@ -11,7 +11,6 @@ class JournalsController < ApplicationController
def new
@journal = @journaled.journals.new
handle_feedback_quote
handle_semester_feedback_quote
authorize @journal
end
......@@ -58,17 +57,6 @@ class JournalsController < ApplicationController
@journaled = Volunteer.find(params[:volunteer_id])
end
def handle_feedback_quote
return unless params[:feedback_id]
@feedback = Feedback.find_by(id: params[:feedback_id])
return unless @feedback
@journal.category = :feedback
@journal.title = "Feedback vom #{I18n.l(@feedback.created_at.to_date)}: "
@journal.body = @feedback.slice(:goals, :achievements, :future, :comments).map do |key, fb_quote|
"#{I18n.t("activerecord.attributes.feedback.#{key}")}:\n«#{fb_quote}»" if fb_quote.present?
end.compact.join("\n\n")
end
def handle_semester_feedback_quote
return unless params[:semester_feedback_id]
@semester_feedback = SemesterFeedback.find_by(id: params[:semester_feedback_id])
......
class ListResponsesController < ApplicationController
before_action { set_default_filter(author_volunteer: 'true', reviewer_id_null: 'true') }
def feedbacks
authorize :list_response
@q = Feedback.created_asc.author_volunteer(params[:q]).ransack(params[:q])
@q.sorts = ['updated_at asc'] if @q.sorts.empty?
@feedbacks = @q.result.paginate(page: params[:page])
set_responsibles
end
def trial_feedbacks
authorize :list_response
@q = TrialFeedback.created_asc.author_volunteer(params[:q]).ransack(params[:q])
@q.sorts = ['updated_at asc'] if @q.sorts.empty?
@trial_feedbacks = @q.result.paginate(page: params[:page])
end
private
def set_responsibles
@responsibles = Feedback.joins(responsible: [profile: [:contact]])
.distinct
.select('users.id, contacts.full_name')
.map do |responsible|
{
q: :responsible_id_eq,
text: "Übernommen von #{responsible.full_name}",
value: responsible.id
}
end
end
end
class Feedback < ApplicationRecord
include FeedbackTrialFeedbackCommon
attr_reader :feedbackable_id_and_type
belongs_to :volunteer
belongs_to :author, class_name: 'User', inverse_of: 'feedbacks'
belongs_to :reviewer, class_name: 'User', foreign_key: 'reviewer_id',
inverse_of: 'reviewed_feedbacks', optional: true
belongs_to :responsible, class_name: 'User', foreign_key: 'responsible_id',
inverse_of: 'responsible_feedbacks', optional: true
belongs_to :feedbackable, polymorphic: true, optional: true
scope :assignment, (-> { where(feedbackable_type: 'Assignment') })
scope :group_offer, (-> { where(feedbackable_type: 'GroupOffer') })
scope :from_assignments, lambda { |assignment_ids|
assignment.where(feedbackable_id: assignment_ids)
}
scope :from_group_offers, lambda { |group_offer_ids|
group_offer.where(feedbackable_id: group_offer_ids)
}
# READ ONLY MODEL
before_save { false }
def responsible=(responsible_user)
self.responsible_at = Time.zone.now
super(responsible_user)
end
def assignment?
feedbackable_type == 'Assignment'
end
def group_offer?
feedbackable_type == 'GroupOffer'
end
def feedbackable_id_and_type=(id_and_type)
self.feedbackable_id, self.feedbackable_type = id_and_type.split(',', 2)
end
def feedbackable_id_and_type
"#{feedbackable_id},#{feedbackable_type}"
end
end
# obsolete, currently only used for Policy and Polymorphic link
class Feedback < ApplicationRecord; end
......@@ -7,7 +7,6 @@ class GroupAssignment < ApplicationRecord
has_many :group_assignment_logs
has_many :hours, ->(object) { where(volunteer: object.volunteer) }, through: :group_offer
has_many :feedbacks, ->(object) { where(volunteer: object.volunteer) }, through: :group_offer
delegate :title, to: :group_offer
......@@ -45,10 +44,6 @@ class GroupAssignment < ApplicationRecord
hours.since_last_submitted(submitted_at)
end
def feedbacks_since_last_submitted
feedbacks.since_last_submitted(submitted_at)
end
def polymorph_url_object
group_offer
end
......
......@@ -22,7 +22,6 @@ class GroupOffer < ApplicationRecord
has_many :group_assignment_logs
has_many :hours, as: :hourable, dependent: :destroy, inverse_of: :hourable
has_many :feedbacks, as: :feedbackable, dependent: :destroy, inverse_of: :feedbackable
has_many :trial_feedbacks, as: :trial_feedbackable, inverse_of: :trial_feedbackable,
dependent: :destroy
......
......@@ -41,7 +41,7 @@ class PerformanceReport < ApplicationRecord
only_assignment_active = assignment_active - active_both
active_total = assignment_active + group_active
hours = Hour.date_between(:meeting_date, *periods).where(volunteer_id: volunteers.ids)
feedbacks = Feedback.created_between(*periods).where(volunteer_id: volunteers.ids)
feedbacks = SemesterFeedback.created_between(*periods).joins(:semester_process_volunteer, :volunteer).where(volunteers: {id: volunteers.ids})
trial_feedbacks = TrialFeedback.created_between(*periods).where(volunteer_id: volunteers.ids)
event_volunteers = EventVolunteer
......@@ -65,9 +65,9 @@ class PerformanceReport < ApplicationRecord
group_offer_hour_records: hours.group_offer.count,
group_offer_hours: hours.group_offer.total_hours,
total_hours: hours.total_hours,
assignment_feedbacks: feedbacks.assignment.count,
group_offer_feedbacks: feedbacks.group_offer.count,
total_feedbacks: feedbacks.count,
assignment_feedbacks: feedbacks.where(group_assignment: nil).count,
group_offer_feedbacks: feedbacks.where(assignment: nil).count,
assignment_trial_feedbacks: trial_feedbacks.assignment.count,
group_offer_trial_feedbacks: trial_feedbacks.group_offer.count,
total_trial_feedbacks: trial_feedbacks.count,
......@@ -136,7 +136,7 @@ class PerformanceReport < ApplicationRecord
started_ga = group_assignments.start_within(*periods)
ended_ga = group_assignments.end_within(*periods)
created_ga = group_assignments.created_between(*periods)
feedbacks = Feedback.created_between(*periods).from_group_offers(group_offers.ids)
feedbacks = SemesterFeedback.created_between(*periods).where.not(group_assignment: nil)
{
all: group_offers.count,
created: group_offers.created_after(periods.first).count,
......
......@@ -35,7 +35,6 @@ class Volunteer < ApplicationRecord
has_many :departments, through: :group_offers
has_many :hours, dependent: :destroy
has_many :feedbacks, dependent: :destroy
has_many :certificates
......
class FeedbackPolicy < ApplicationPolicy
class Scope < ApplicationScope
def resolve
return all if superadmin?
scope.where(volunteer: user.volunteer, author: user) if volunteer?
end
class Scope < ApplicationScope
def resolve
return all if superadmin?
scope.joins(:semester_process_volunteer, :volunteer).where(volunteers: {id: user.volunteer}) if volunteer?
end
end
alias_method :index?, :superadmin_or_volunteer?
end
alias_method :index?, :superadmin_or_volunteer?
alias_method :show?, :superadmin_or_feedback_about_volunteer?
alias_method :edit?, :superadmin_or_feedback_about_volunteer?
alias_method :update?, :superadmin_or_feedback_about_volunteer?
alias_method :new?, :superadmin_or_volunteers_feedback?
alias_method :create?, :superadmin_or_volunteers_feedback?
alias_method :destroy?, :superadmin_or_volunteers_feedback?
alias_method :mark_as_done?, :superadmin?
alias_method :take_responsibility?, :superadmin?
end
\ No newline at end of file
class ListResponsePolicy < ApplicationPolicy
alias_method :feedbacks?, :superadmin?
alias_method :trial_feedbacks?, :superadmin?
end
class SemesterFeedbackPolicy < ApplicationPolicy
class Scope < ApplicationScope
def resolve
return all if superadmin?
scope.joins(:semester_process_volunteer, :volunteer).where(volunteers: {id: user.volunteer}) if volunteer?
end
end
# Actions
alias_method :review_semester?, :superadmin_or_volunteer?
alias_method :submit_review?, :superadmin_or_volunteer?
alias_method :index?, :superadmin_or_volunteer?
end
\ No newline at end of file
h1= t_title(:edit)
= render 'form'
= bootstrap_row_col { button_link icon_span(:back), @volunteer }
h1= t_title(:new)
= render 'form'
= bootstrap_row_col { button_link icon_span(:back), default_redirect || @volunteer || :back }
= render 'reminder_mailings/section_navigation'
h1 Eingereichte Halbjahres-Rapporte
nav.navbar.section-navigation.hidden-print
ul.list-inline
li= clear_filter_button
= custom_filter_dropdown('Geprüft',
{ q: :reviewer_id_not_null, text: 'Quittiert', value: 'true' },
{ q: :reviewer_id_null, text: 'Unquittiert', value: 'true' })
= custom_filter_dropdown('Übernommen',
{ q: :responsible_id_null, text: 'Offen', value: 'true' },
{ q: :responsible_id_not_null, text: 'Übernommen', value: 'true' },
*@responsibles)
= custom_filter_dropdown('Autor',
{ q: :author_volunteer, text: 'Freiwillige/r', value: 'true' },
{ q: :author_volunteer, text: 'AOZ', value: 'false' })
= bootstrap_paginate(@feedbacks)
table.table.table-striped.list-responses-table
thead
tr
th.limit-width Journal / Stunden
th.limit-width= sort_link @q, :volunteer_contact_full_name, 'Freiwillige/r'
th.limit-width Einsatz
th= sort_link @q, :author_profile_contact_full_name, 'Autor/in'
th Ziele
th Erfolge
th Zukunft
th= t_attr(:comments, Feedback)
th.limit-width= sort_link @q, :conversation, 'Gespräch'
th= sort_link @q, :created_at, 'Datum'
th= sort_link @q, :responsible, 'Übernommen'
th.limit-width
tbody
- @feedbacks.each do |record|
tr*{ data: { feedback_id: record.id } }
td.index-action-cell
= button_link icon_span(:journal), volunteer_journals_path(record.volunteer), title: 'Journal'
= button_link icon_span(:journal_new), new_volunteer_journal_path(record.volunteer, feedback_id: record.id),
title: 'Neuen Journal eintrag mit Zitat erstellen'
= button_link icon_span(:hours), volunteer_hours_path(record.volunteer), title: 'Stunden'
td.index-action-cell
a href="#{url_for(record.feedbackable)}" title="#{record.feedbackable.to_label}"
- record.feedbackable.label_parts.reject(&:blank?).each do |label_part|
span= label_part.truncate(30)
td
- if record.author.volunteer?
= link_to record.volunteer.contact.full_name, record.volunteer
- else
= link_to record.author.profile.contact.natural_name, record.author.profile
td= record.goals
= td_truncate_content_modal(record.achievements, 'Erfolge', shorten_size: 300)
= td_truncate_content_modal(record.future, 'Zukunft', shorten_size: 300)
= td_truncate_content_modal(record.comments, t_attr(:comments, Feedback), shorten_size: 300)
td= t(record.conversation)
td.index-action-cell
span= I18n.l record.created_at.to_date
- if record.reviewer.present?
span Quittiert von: #{link_to(record.reviewer.email, record.reviewer)}
td.index-action-cell.hidden-print
- if record.responsible.present?
= 'Übernommen durch '
= link_to record.responsible.email, record.responsible
= " am #{l(record.responsible_at.to_date)}"
- else
= api_button('Übernehmen', subject: [record.volunteer, record.feedbackable, record],
action: :take_responsibility, extra_class: 'm-t-10',
template: 'Übernommen durch <a href="<%= data.link %>"><%= data.email %></a> am <%= data.at %>')
td.index-action-cell.hidden-print
- if record.reviewer.present?
= link_to 'Anzeigen', polymorphic_path([record.volunteer, record.feedbackable, record])
- else
= api_button 'Quittieren', subject: [record.volunteer, record.feedbackable, record],
action: :mark_as_done, extra_class: 'm-t-10',
template: '<a href="<%= data.link %>">Anzeigen</a>'
= bootstrap_paginate(@feedbacks)
nav.navbar.section-navigation.hidden-print
ul.section-nav-ul.list-unstyled
li= section_nav_button 'Probezeit Feedback Eingang', list_responses_trial_feedbacks_path
li= section_nav_button 'Halbjahres-Rapport Eingang', list_responses_feedbacks_path
li= section_nav_button 'Halbjahres-Rapport Eingang', semester_process_volunteers_path
li= section_nav_button 'Probezeit Erinnerung erstellen', new_trial_period_reminder_mailings_path
li= section_nav_button 'Versandte Erinnerungen', reminder_mailings_path
li= section_nav_button 'E-Mailvorlagen', email_templates_path
......@@ -67,8 +67,6 @@ Rails.application.routes.draw do
resources :event_volunteers, only: [:create, :destroy]
end
resources :feedbacks, only: [:new, :create]
resources :group_assignments, only: [:show, :create, :edit, :update],
concerns: [:submit_feedback, :termination_actions] do
put :set_end_today, on: :member
......@@ -84,7 +82,6 @@ Rails.application.routes.draw do
get :search_volunteer, on: :member
end
get 'list_responses/feedbacks', to: 'list_responses#feedbacks'
get 'list_responses/trial_feedbacks', to: 'list_responses#trial_feedbacks'
resources :profiles, except: [:destroy, :index]
......
class RemoveOldFeedbacks < ActiveRecord::Migration[5.1]
def change
drop_table :feedbacks
end
end
......@@ -301,30 +301,6 @@ ActiveRecord::Schema.define(version: 20181218094649) do
t.index ["department_id"], name: "index_events_on_department_id"
end
create_table "feedbacks", force: :cascade do |t|
t.text "goals"
t.text "achievements"
t.text "future"
t.text "comments"
t.boolean "conversation"
t.datetime "deleted_at"
t.bigint "volunteer_id"
t.bigint "author_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "feedbackable_type"
t.bigint "feedbackable_id"
t.bigint "reviewer_id"
t.bigint "responsible_id"
t.datetime "responsible_at"
t.index ["author_id"], name: "index_feedbacks_on_author_id"
t.index ["deleted_at"], name: "index_feedbacks_on_deleted_at"
t.index ["feedbackable_type", "feedbackable_id"], name: "index_feedbacks_on_feedbackable_type_and_feedbackable_id"
t.index ["responsible_id"], name: "index_feedbacks_on_responsible_id"
t.index ["reviewer_id"], name: "index_feedbacks_on_reviewer_id"
t.index ["volunteer_id"], name: "index_feedbacks_on_volunteer_id"
end
create_table "group_assignment_logs", force: :cascade do |t|
t.bigint "group_offer_id"
t.bigint "volunteer_id"
......@@ -849,7 +825,6 @@ ActiveRecord::Schema.define(version: 20181218094649) do
add_foreign_key "client_notifications", "users"
add_foreign_key "clients", "users"
add_foreign_key "events", "departments"
add_foreign_key "feedbacks", "users", column: "author_id"
add_foreign_key "group_offers", "departments"
add_foreign_key "group_offers", "group_offer_categories"
add_foreign_key "hours", "billing_expenses"
......
......@@ -50,9 +50,6 @@ def generate_feedback_and_hours(hourable, start_date, end_date = nil, volunteer:
meeting_date = FFaker::Time.between(start_date + 1.day, end_date)
hour = FactoryBot.create(:hour, volunteer: volunteer, hourable: hourable, meeting_date: meeting_date)
hour.update(created_at: meeting_date + 1.day)
feedback = FactoryBot.create(:feedback, volunteer: volunteer, feedbackable: hourable,
author: volunteer.user)
feedback.update(created_at: FFaker::Time.between(start_date + 1.day, end_date - 1.day))
trial_feedback = FactoryBot.create(:trial_feedback, volunteer: volunteer, author: volunteer.user,
trial_feedbackable: hourable)
trial_feedback.update(created_at: FFaker::Time.between(start_date + 6.weeks, start_date + 8.weeks))
......
......@@ -6,21 +6,9 @@ class JournalsControllerTest < ActionDispatch::IntegrationTest
@reminder_mailing = create :reminder_mailing, :trial_period
@assignment = @reminder_mailing.reminder_mailing_volunteers.first.reminder_mailable
@volunteer = @assignment.volunteer
@feedback = create :feedback, feedbackable: @assignment, volunteer: @volunteer, author: @volunteer.user
login_as @superadmin
end
test '#new prefilles with feedback quote if feedback_id param is passed for trial period' do
get new_volunteer_journal_path(@volunteer, feedback_id: @feedback.id)
@journal = @controller.instance_variable_get(:@journal)
assert_equal @journal.category, 'feedback'
assert_equal @journal.title, "Feedback vom #{I18n.l(@feedback.created_at.to_date)}: "
assert @journal.body.include? @feedback.goals
assert @journal.body.include? @feedback.achievements
assert @journal.body.include? @feedback.future
assert @journal.body.include? @feedback.comments
end
test '#new prefilling for semester feedback quote if semester_feedback_id param is passed works also' do
@spv = create(:semester_process_volunteer, volunteer: @volunteer)
@semester_feedback = create(:semester_feedback, :no_mission, semester_process_volunteer: @spv, volunteer: @volunteer)
......
FactoryBot.define do
factory :feedback do
association :feedbackable, factory: :assignment
volunteer
association :author, factory: :user
goals { FFaker::Lorem.words(4).join(', ') }
achievements { FFaker::Lorem.sentence }
future { FFaker::Lorem.sentence }
comments { FFaker::Lorem.paragraph }
conversation false
after(:build) do |feedback|
if feedback.volunteer.present? && feedback.feedbackable.blank?
feedback.volunteer.user = create(:user_volunteer) if feedback.volunteer.user.blank?
feedback.feedbackable = create(:assignment, volunteer: feedback.volunteer)
elsif feedback.volunteer.blank? && feedback.feedbackable.present?
feedback.volunteer = feedback.feedbackable.volunteer
elsif feedback.volunteer.blank? && feedback.feedbackable.blank?
feedback.volunteer = create(:volunteer)
feedback.feedbackable = create(:assignment, volunteer: feedback.volunteer)
end
feedback.author ||= feedback.volunteer&.user || create(:user)
end
end
end
require 'test_helper'
class FeedbackTest < ActiveSupport::TestCase
test 'since_last_submitted_scope' do
volunteer = create :volunteer
assignment = create :assignment, volunteer: volunteer
feedback = create :feedback, feedbackable: assignment, volunteer: volunteer,
author: volunteer.user
feedback_by_superadmin = create :feedback, feedbackable: assignment, volunteer: volunteer,
author: create(:user)
assignment_last_submitted = create :assignment, volunteer: volunteer,
submitted_at: 6.months.ago
before_last_submitted_feedback = create :feedback, volunteer: volunteer, author: volunteer.user,
feedbackable: assignment_last_submitted
before_last_submitted_feedback.update(created_at: 8.months.ago, updated_at: 8.months.ago)
after_last_submitted_feedback = create :feedback, volunteer: volunteer, author: volunteer.user,
feedbackable: assignment_last_submitted
after_last_submitted_feedback.update(created_at: 2.months.ago, updated_at: 2.months.ago)
before_last_submitted_feedback_superadmin = create :feedback, volunteer: volunteer,
author: create(:user), feedbackable: assignment_last_submitted
before_last_submitted_feedback_superadmin.update(created_at: 8.months.ago,
updated_at: 8.months.ago)
after_last_submitted_feedback_superadmin = create :feedback, volunteer: volunteer,
author: create(:user), feedbackable: assignment_last_submitted
after_last_submitted_feedback_superadmin.update(created_at: 2.months.ago,
updated_at: 2.months.ago)
assignment.reload
assignment_last_submitted.reload
query_via_assignment = assignment.feedbacks_since_last_submitted
query_via_feedback = Feedback.where(feedbackable: assignment).since_last_submitted(nil)
assert query_via_assignment.include? feedback
assert query_via_assignment.include? feedback_by_superadmin
assert query_via_feedback.include? feedback
assert query_via_feedback.include? feedback_by_superadmin
query_via_assignment = assignment_last_submitted.feedbacks_since_last_submitted
query_via_feedback = Feedback.where(feedbackable: assignment_last_submitted)
.since_last_submitted(assignment_last_submitted.submitted_at)
assert query_via_feedback.include? after_last_submitted_feedback
assert query_via_assignment.include? after_last_submitted_feedback
refute query_via_assignment.include? before_last_submitted_feedback
refute query_via_assignment.include? before_last_submitted_feedback_superadmin
assert query_via_assignment.include? after_last_submitted_feedback_superadmin
refute query_via_feedback.include? before_last_submitted_feedback
refute query_via_feedback.include? before_last_submitted_feedback_superadmin
assert query_via_feedback.include? after_last_submitted_feedback_superadmin
end
test 'set_responsible_also_sets_responsible_at' do
feedback = create :feedback
feedback.update(responsible: create(:user))
assert feedback.responsible_at.present?
end
end
......@@ -9,53 +9,11 @@ class FeedbackPolicyTest < PolicyAssertions::Test
end
test 'superadmin can use all actions' do
assert_permit(create(:user), Feedback, 'new?', 'create?', 'index?', 'show?', 'edit?',
'update?', 'destroy?')
assert_permit(create(:user), Feedback, 'index?')
end
test 'social worker and department manager have no access' do
refute_permit(create(:social_worker), Feedback, 'new?', 'create?', 'index?', 'show?',
'edit?', 'update?', 'destroy?')
refute_permit(create(:department_manager), Feedback, 'new?', 'create?', 'index?',
'show?', 'edit?', 'update?', 'destroy?')
end
test 'volunteer has limited access to assignment feedbacks' do
assignment = create :assignment, volunteer: @volunteer
other_assignment = create :assignment, volunteer: @other_volunteer
superadmin_feedback = create :feedback, volunteer: @volunteer, author: @superadmin,
feedbackable: assignment
feedback_volunteer = create :feedback, volunteer: @volunteer, author: @user_volunteer,
feedbackable: assignment
foreign_feedback = create :feedback, feedbackable: other_assignment,
volunteer: @other_volunteer, author: @other_volunteer.user
refute_permit(@user_volunteer, superadmin_feedback, 'destroy?')
assert_permit(@user_volunteer, superadmin_feedback, 'show?', 'edit?', 'update?')
refute_permit(@user_volunteer, foreign_feedback, 'show?', 'edit?', 'update?', 'destroy?',
'new?', 'create?')
assert_permit(@user_volunteer, feedback_volunteer, 'index?', 'show?', 'edit?', 'update?',
'destroy?', 'new?', 'create?')
end
test 'volunteer_has_limited_access_to_group_offer_feedbacks' do
group_offer = create :group_offer
create :group_assignment, volunteer: @volunteer, group_offer: group_offer
create :group_assignment, volunteer: @other_volunteer, group_offer: group_offer
other_group_offer = create :group_offer
create :group_assignment, volunteer: create(:volunteer), group_offer: other_group_offer
create :group_assignment, volunteer: @other_volunteer, group_offer: other_group_offer
superadmin_feedback = create :feedback, volunteer: @volunteer, author: @superadmin,
feedbackable: group_offer
feedback_volunteer = create :feedback, volunteer: @volunteer, author: @user_volunteer,
feedbackable: group_offer
foreign_feedback = create :feedback, volunteer: @other_volunteer, author: @other_volunteer.user,
feedbackable: other_group_offer
refute_permit(@user_volunteer, superadmin_feedback, 'destroy?')