feat: SLA CRUD APIs (EE) (#7027)
Fixes: https://linear.app/chatwoot/issue/CW-1613/sla-api Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
@@ -1,16 +1,9 @@
|
||||
# module Enterprise::Api::V1::Accounts::AuditLogsController < Api::V1::Accounts::BaseController
|
||||
class Api::V1::Accounts::AuditLogsController < Api::V1::Accounts::BaseController
|
||||
class Api::V1::Accounts::AuditLogsController < Api::V1::Accounts::EnterpriseAccountsController
|
||||
before_action :check_admin_authorization?
|
||||
before_action :fetch_audit
|
||||
before_action :prepend_view_paths
|
||||
|
||||
RESULTS_PER_PAGE = 15
|
||||
|
||||
# Prepend the view path to the enterprise/app/views won't be available by default
|
||||
def prepend_view_paths
|
||||
prepend_view_path 'enterprise/app/views/'
|
||||
end
|
||||
|
||||
def show
|
||||
@audit_logs = @audit_logs.page(params[:page]).per(RESULTS_PER_PAGE)
|
||||
@current_page = @audit_logs.current_page
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
class Api::V1::Accounts::EnterpriseAccountsController < Api::V1::Accounts::BaseController
|
||||
before_action :prepend_view_paths
|
||||
|
||||
# Prepend the view path to the enterprise/app/views won't be available by default
|
||||
def prepend_view_paths
|
||||
prepend_view_path 'enterprise/app/views/'
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,31 @@
|
||||
class Api::V1::Accounts::SlaPoliciesController < Api::V1::Accounts::EnterpriseAccountsController
|
||||
before_action :fetch_sla, only: [:show, :update, :destroy]
|
||||
before_action :check_authorization
|
||||
|
||||
def index
|
||||
@sla_policies = Current.account.sla_policies
|
||||
end
|
||||
|
||||
def create
|
||||
@sla_policy = Current.account.sla_policies.create!(permitted_params)
|
||||
end
|
||||
|
||||
def show; end
|
||||
|
||||
def update
|
||||
@sla_policy.update!(permitted_params)
|
||||
end
|
||||
|
||||
def destroy
|
||||
@sla_policy.destroy!
|
||||
head :ok
|
||||
end
|
||||
|
||||
def permitted_params
|
||||
params.require(:sla_policy).permit(:name, :rt_threshold, :frt_threshold, :only_during_business_hours)
|
||||
end
|
||||
|
||||
def fetch_sla
|
||||
@sla_policy = Current.account.sla_policies.find_by(id: params[:id])
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
module Enterprise::EnterpriseAccountConcern
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
has_many :sla_policies, dependent: :destroy_async
|
||||
end
|
||||
end
|
||||
21
enterprise/app/models/sla_policy.rb
Normal file
21
enterprise/app/models/sla_policy.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: sla_policies
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# frt_threshold :float
|
||||
# name :string not null
|
||||
# only_during_business_hours :boolean default(FALSE)
|
||||
# rt_threshold :float
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# account_id :bigint not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_sla_policies_on_account_id (account_id)
|
||||
#
|
||||
class SlaPolicy < ApplicationRecord
|
||||
belongs_to :account
|
||||
validates :name, presence: true
|
||||
end
|
||||
21
enterprise/app/policies/sla_policy_policy.rb
Normal file
21
enterprise/app/policies/sla_policy_policy.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
class SlaPolicyPolicy < ApplicationPolicy
|
||||
def index?
|
||||
@account_user.administrator? || @account_user.agent?
|
||||
end
|
||||
|
||||
def update?
|
||||
@account_user.administrator?
|
||||
end
|
||||
|
||||
def show?
|
||||
@account_user.administrator? || @account_user.agent?
|
||||
end
|
||||
|
||||
def create?
|
||||
@account_user.administrator?
|
||||
end
|
||||
|
||||
def destroy?
|
||||
@account_user.administrator?
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,3 @@
|
||||
json.payload do
|
||||
json.partial! 'api/v1/models/sla_policy', formats: [:json], sla_policy: @sla_policy
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
json.payload do
|
||||
json.array! @sla_policies do |sla_policy|
|
||||
json.partial! 'api/v1/models/sla_policy', formats: [:json], sla_policy: sla_policy
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,3 @@
|
||||
json.payload do
|
||||
json.partial! 'api/v1/models/sla_policy', formats: [:json], sla_policy: @sla_policy
|
||||
end
|
||||
@@ -0,0 +1,3 @@
|
||||
json.payload do
|
||||
json.partial! 'api/v1/models/sla_policy', formats: [:json], sla_policy: @sla_policy
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
json.id sla_policy.id
|
||||
json.name sla_policy.name
|
||||
json.frt_threshold sla_policy.frt_threshold
|
||||
json.rt_threshold sla_policy.rt_threshold
|
||||
json.only_during_business_hours sla_policy.only_during_business_hours
|
||||
Reference in New Issue
Block a user