Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide has_many associations in rails admin #403

Merged
merged 3 commits into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/channels/api_channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ def finish data
dispatch_all 'comments/load', Comment.includes(:user).where(task_id:)
dispatch_all 'app/finish'

dispatch_self 'notifications/push', kind: 'info', message: 'Calculating results …'

users_without_result = []
begin
result_multiplier = Rational task.result_multiplier
Expand All @@ -171,6 +173,8 @@ def finish data
task.update_column :scoring_open, true
dispatch_self 'app/ready', ready_info
raise e
else
dispatch_self 'notifications/push', kind: 'success', message: 'Results calculated'
end
end

Expand Down
3 changes: 2 additions & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def collection
end

def resource_params
params.require(:user).permit(PERMITTED_PARAMS).merge(registration_ips: ip_addresses, device_id: @device_id)
params.require(:user).permit(PERMITTED_PARAMS)
.merge(registration_ips: ip_addresses, device_id: @device_id, registration_secret_required: true)
end

def initialize_resource
Expand Down
9 changes: 6 additions & 3 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
class User < ApplicationRecord
attr_accessor :registration_secret
attr_accessor :registration_secret, :registration_secret_required

validates :name, :email, :city, :institution, :contest_site, :grade, presence: true
validates :name, :secret, :judge_secret, uniqueness: { scope: :contest }
validates :registration_secret, presence: true, on: :create
validate :registration_secret_must_be_valid, on: :create

with_options if: :registration_secret_required, on: :create do
validates :registration_secret, presence: true
validate :registration_secret_must_be_valid
end

belongs_to :contest, inverse_of: :users
has_many :solutions, inverse_of: :user, dependent: :destroy
Expand Down
15 changes: 15 additions & 0 deletions config/initializers/rails_admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,18 @@
config.model 'Task' do |_config|
configure :file_names, :pg_string_array
configure :judges, :pg_string_array
configure(:solutions) { hide }
configure(:results) { hide }
configure(:criterions) { hide }
configure(:comments) { hide }
end

config.model 'User' do |_config|
configure :registration_ips, :pg_inet_array
configure(:solutions) { hide }
configure(:results) { hide }
configure(:comments) { hide }
configure(:criterion_user_results) { hide }
end

config.model 'Solution' do |_config|
Expand All @@ -92,5 +100,12 @@
configure :cities, :pg_string_array
configure :institutions, :pg_string_array
configure :contest_sites, :pg_string_array
configure(:tasks) { hide }
configure(:users) { hide }
configure(:solutions) { hide }
end

config.model 'Criterion' do |_config|
configure(:criterion_user_results) { hide }
end
end