Remove Ransack from Exercise edit for tags

* Also improve Ransack usage of attributes and associations
This commit is contained in:
Sebastian Serth
2022-08-20 01:28:47 +02:00
parent 83feb67dd5
commit 166aa3cc6f
10 changed files with 46 additions and 3 deletions

View File

@ -461,8 +461,7 @@ class ExercisesController < ApplicationController
private :set_file_types
def collect_set_and_unset_exercise_tags
@search = policy_scope(Tag).ransack(params[:q])
@tags = @search.result.order(:name)
@tags = policy_scope(Tag)
checked_exercise_tags = @exercise.exercise_tags
checked_tags = checked_exercise_tags.collect(&:tag).to_set
unchecked_tags = Tag.all.to_set.subtract checked_tags

View File

@ -15,4 +15,12 @@ class ApplicationRecord < ActiveRecord::Base
end
end
end
def self.ransackable_associations(_auth_object = nil)
[]
end
def self.ransackable_attributes(_auth_object = nil)
[]
end
end

View File

@ -61,6 +61,10 @@ class ExecutionEnvironment < ApplicationRecord
exposed_ports.join(', ')
end
def self.ransackable_attributes(_auth_object = nil)
%w[id]
end
private
def set_default_values

View File

@ -597,4 +597,12 @@ cause: %w[submit assess remoteSubmit remoteAssess]}).distinct
WHERE exercise_id = #{id}
) AS t ON t.fv = submissions.id").distinct
end
def self.ransackable_attributes(_auth_object = nil)
%w[title]
end
def self.ransackable_associations(_auth_object = nil)
%w[execution_environment]
end
end

View File

@ -31,4 +31,8 @@ working_time: time_to_f(item.exercise.average_working_time)}
def to_s
"#{I18n.t('activerecord.models.exercise_collection.one')}: #{name} (#{id})"
end
def self.ransackable_attributes(_auth_object = nil)
%w[id]
end
end

View File

@ -246,4 +246,8 @@ class ProxyExercise < ApplicationRecord
def select_easiest_exercise(exercises)
exercises.order(:expected_difficulty).first
end
def self.ransackable_attributes(_auth_object = nil)
%w[title]
end
end

View File

@ -77,6 +77,14 @@ class RequestForComment < ApplicationRecord
# ugly, but necessary
end
def ransackable_associations(_auth_object = nil)
%w[exercise submission]
end
def ransackable_attributes(_auth_object = nil)
%w[solved]
end
private
def row_number_user_sql

View File

@ -191,6 +191,10 @@ class Submission < ApplicationRecord
result.merge(output)
end
def self.ransackable_attributes(_auth_object = nil)
%w[study_group_id]
end
private
def prepared_runner

View File

@ -41,4 +41,8 @@ class User < ApplicationRecord
def to_s
displayname
end
def self.ransackable_attributes(_auth_object = nil)
%w[name email external_id consumer_id role]
end
end

View File

@ -69,7 +69,7 @@
thead
tr
th = t('activerecord.attributes.exercise.selection')
th = sort_link(@search, :title, t('activerecord.attributes.tag.name'))
th = t('activerecord.attributes.tag.name')
th = t('activerecord.attributes.tag.difficulty')
= collection_check_boxes :exercise, :tag_ids, @exercise_tags, :tag_id, :id do |b|
tr