mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 09:57:23 +02:00
48 lines
985 B
Ruby
48 lines
985 B
Ruby
class Admin::ContactsController < AdminController
|
|
load_and_authorize_resource
|
|
before_action :set_contact, only: [:show]
|
|
|
|
def index
|
|
@q = Contact.includes(:registrar).search(params[:q])
|
|
@contacts = @q.result.page(params[:page])
|
|
end
|
|
|
|
def search
|
|
render json: Contact.search_by_query(params[:q])
|
|
end
|
|
|
|
def edit
|
|
end
|
|
|
|
def update
|
|
cp = ignore_empty_statuses
|
|
|
|
if @contact.update(cp)
|
|
flash[:notice] = I18n.t('contact_updated')
|
|
redirect_to [:admin, @contact]
|
|
else
|
|
flash.now[:alert] = I18n.t('failed_to_update_contact')
|
|
render 'edit'
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def set_contact
|
|
@contact = Contact.includes(domains: :registrar).find(params[:id])
|
|
end
|
|
|
|
def contact_params
|
|
if params[:contact]
|
|
params.require(:contact).permit({ statuses: [], status_notes_array: [] })
|
|
else
|
|
{ statuses: [] }
|
|
end
|
|
end
|
|
|
|
def ignore_empty_statuses
|
|
dp = contact_params
|
|
dp[:statuses].reject!(&:blank?)
|
|
dp
|
|
end
|
|
end
|