libertarian-party/partynest

View on GitHub
app/controllers/settings/contacts/public_switches_controller.rb

Summary

Maintainability
A
15 mins
Test Coverage
# frozen_string_literal: true

class Settings::Contacts::PublicSwitchesController < ApplicationController
  before_action :set_contact

  # POST /settings/contacts/:contact_id/public_switch
  def create
    authorize [:settings, ContactPublicSwitch.new(@contact)]

    @contact.show_in_public = !@contact.show_in_public
    @contact.save!

    redirect_to(
      settings_contacts_url,
      notice: translate_flash(
        @contact.show_in_public,
        value: @contact.value,
      ),
    )
  end

private

  def set_contact
    @contact = current_account&.contact_list&.contacts&.find params[:contact_id]
  end
end