<commit_before>class Admin::CabinetMinistersController < Admin::BaseController
  before_action :enforce_permissions!

  def show
    @cabinet_minister_roles = MinisterialRole.includes(:translations).where(cabinet_member: true).order(:seniority)
    @also_attends_cabinet_roles = MinisterialRole.includes(:translations).also_attends_cabinet.order(:seniority)
    @whip_roles = MinisterialRole.includes(:translations).whip.order(:whip_ordering)
    @organisations = Organisation.ministerial_departments.excluding_govuk_status_closed.order(:ministerial_ordering)
  end

  def update
    update_ordering(:roles, :seniority)
    update_ordering(:whips, :whip_ordering)
    update_organisation_ordering

    redirect_to admin_cabinet_ministers_path
  end

private

  def enforce_permissions!
    enforce_permission!(:reorder_cabinet_ministers, MinisterialRole)
  end

  def update_ordering(key, column)
    return unless params.include?(key)
    params[key].each_key do |id|
      Role.where(id: id).update_all(
        column => params[key][id.to_s]["ordering"],
      )
    end
  end

  def update_organisation_ordering
    return unless params.include?(:organisation)
    params[:organisation].each_pair do |id, org_params|
      Organisation.find(id).update_attributes(
        ministerial_ordering: org_params["ordering"]
      )
    end
  end
end<commit_msg>Avoid calling `each_key` on params in cabinet ministers controller<commit_after>class Admin::CabinetMinistersController < Admin::BaseController
  before_action :enforce_permissions!

  def show
    @cabinet_minister_roles = MinisterialRole.includes(:translations).where(cabinet_member: true).order(:seniority)
    @also_attends_cabinet_roles = MinisterialRole.includes(:translations).also_attends_cabinet.order(:seniority)
    @whip_roles = MinisterialRole.includes(:translations).whip.order(:whip_ordering)
    @organisations = Organisation.ministerial_departments.excluding_govuk_status_closed.order(:ministerial_ordering)
  end

  def update
    update_ordering(:roles, :seniority)
    update_ordering(:whips, :whip_ordering)
    update_organisation_ordering

    redirect_to admin_cabinet_ministers_path
  end

private

  def enforce_permissions!
    enforce_permission!(:reorder_cabinet_ministers, MinisterialRole)
  end

  def update_ordering(key, column)
    return unless params.include?(key)
    params[key].keys.each do |id| # rubocop:disable Performance/HashEachMethods
      Role.where(id: id).update_all(
        column => params[key][id.to_s]["ordering"],
      )
    end
  end

  def update_organisation_ordering
    return unless params.include?(:organisation)
    params[:organisation].each_pair do |id, org_params|
      Organisation.find(id).update_attributes(
        ministerial_ordering: org_params["ordering"]
      )
    end
  end
end
{'fraction_non_alphanumeric': 0.09019886363636363, 'fraction_numerical': 0.0, 'mean_word_length': 5.204845814977974, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7244727', 'n_tokens_mistral': 910, 'n_tokens_neox': 876, 'n_words': 135}