Account Labels API Controller (accounts/labels_controller.rb)

chatwoot · app/controllers/api/v1/accounts/labels_controller.rb · ruby · MIT
crm, integration, database, lang:ruby, fw:rails, tag:labels, tag:background-job

Provides JSON CRUD endpoints for managing account labels, with Pundit authorization and a background job to clean up related associations on delete.

# Source: https://github.com/chatwoot/chatwoot | License: MIT | Copyright 2017-2026 Chatwoot Inc
# Provided via justclaw.it.com; keep this notice with the code.
class Api::V1::Accounts::LabelsController < Api::V1::Accounts::BaseController
  before_action :fetch_label, except: [:index, :create]
  before_action :check_authorization

  def index
    @labels = policy_scope(Current.account.labels)
  end

  def show; end

  def create
    @label = Current.account.labels.create!(permitted_params)
  end

  def update
    @label.update!(permitted_params)
  end

  def destroy
    label_title = @label.title
    account_id = Current.account.id
    label_deleted_at = Time.current

    @label.destroy!
    Labels::RemoveAssociationsJob.perform_later(
      label_title: label_title,
      account_id: acco

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key