2019-09-02 15:30:18 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Settings::ContactsController < ApplicationController
|
2020-01-04 13:51:32 -05:00
|
|
|
include PaginalController
|
|
|
|
|
2019-09-02 15:30:18 -04:00
|
|
|
before_action :skip_policy_scope, only: :index
|
|
|
|
|
2019-09-02 22:52:13 -04:00
|
|
|
before_action :set_contact_list
|
2019-09-03 01:24:33 -04:00
|
|
|
|
|
|
|
before_action :new_contact, only: :index
|
|
|
|
before_action :build_contact, only: :create
|
|
|
|
before_action :set_contact, only: :destroy
|
2019-09-02 15:30:18 -04:00
|
|
|
|
|
|
|
# GET /settings/contacts
|
|
|
|
def index
|
2019-09-03 01:24:33 -04:00
|
|
|
authorize [:settings, Contact]
|
|
|
|
|
2020-01-04 13:51:32 -05:00
|
|
|
@contacts = @contact_list.contacts.page(active_page)
|
2019-09-02 15:30:18 -04:00
|
|
|
end
|
|
|
|
|
2019-09-03 01:24:33 -04:00
|
|
|
# POST /settings/contacts
|
|
|
|
def create
|
|
|
|
authorize [:settings, @contact]
|
|
|
|
|
|
|
|
return render :index unless @contact.save
|
|
|
|
|
|
|
|
redirect_to settings_contacts_url
|
|
|
|
end
|
|
|
|
|
2019-09-02 23:14:33 -04:00
|
|
|
# DELETE /settings/contacts/:id
|
|
|
|
def destroy
|
|
|
|
authorize [:settings, @contact]
|
2019-09-03 01:24:33 -04:00
|
|
|
|
2019-09-02 23:14:33 -04:00
|
|
|
@contact.destroy!
|
2019-09-03 00:13:36 -04:00
|
|
|
|
|
|
|
redirect_to(
|
|
|
|
settings_contacts_url,
|
|
|
|
notice: translate_flash(
|
|
|
|
network_name: @contact.contact_network.name,
|
|
|
|
value: @contact.value,
|
|
|
|
),
|
|
|
|
)
|
2019-09-02 23:14:33 -04:00
|
|
|
end
|
|
|
|
|
2019-09-02 15:30:18 -04:00
|
|
|
private
|
|
|
|
|
2019-09-02 22:52:13 -04:00
|
|
|
def set_contact_list
|
|
|
|
@contact_list = current_account&.contact_list
|
2019-09-02 15:30:18 -04:00
|
|
|
end
|
2019-09-02 23:14:33 -04:00
|
|
|
|
2019-09-03 01:24:33 -04:00
|
|
|
def new_contact
|
|
|
|
@contact = Contact.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_contact
|
|
|
|
@contact = Contact.new permitted_attributes [:settings, Contact]
|
|
|
|
@contact.contact_list = @contact_list
|
|
|
|
end
|
|
|
|
|
2019-09-02 23:14:33 -04:00
|
|
|
def set_contact
|
|
|
|
@contact = Contact.find params[:id]
|
|
|
|
end
|
2019-09-02 15:30:18 -04:00
|
|
|
end
|