Chatwoot/app/controllers/api/v1/accounts/portals_controller.rb

54 lines
1.1 KiB
Ruby
Raw Normal View History

2022-05-16 08:29:59 +00:00
class Api::V1::Accounts::PortalsController < Api::V1::Accounts::BaseController
before_action :fetch_portal, except: [:index, :create]
before_action :check_authorization
def index
2022-05-16 08:29:59 +00:00
@portals = Current.account.portals
end
def add_members
agents = Current.account.agents.where(id: portal_member_params[:member_ids])
@portal.members << agents
end
def show; end
def create
2022-05-16 08:29:59 +00:00
@portal = Current.account.portals.create!(portal_params)
end
def update
@portal.update!(portal_params)
end
def destroy
@portal.destroy!
head :ok
end
def archive
@portal.update(archive: true)
head :ok
end
private
def fetch_portal
2022-05-16 08:29:59 +00:00
@portal = Current.account.portals.find_by(slug: permitted_params[:id])
end
def permitted_params
params.permit(:id)
end
def portal_params
params.require(:portal).permit(
2022-05-16 08:29:59 +00:00
:account_id, :color, :custom_domain, :header_text, :homepage_link, :name, :page_title, :slug, :archived
)
end
def portal_member_params
params.require(:portal).permit(:account_id, member_ids: [])
end
end