feat: Add a feature flag for Audit Log UI (#7035)

Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
Shivam Mishra
2023-05-09 01:14:15 +05:30
committed by GitHub
parent 683f259771
commit 2b88ecdfc4
5 changed files with 26 additions and 1 deletions

View File

@@ -157,6 +157,7 @@ const settings = accountId => ({
hasSubMenu: false, hasSubMenu: false,
toState: frontendURL(`accounts/${accountId}/settings/audit-log/list`), toState: frontendURL(`accounts/${accountId}/settings/audit-log/list`),
toStateName: 'auditlogs_list', toStateName: 'auditlogs_list',
featureFlag: FEATURE_FLAGS.AUDIT_LOGS,
beta: true, beta: true,
}, },
], ],

View File

@@ -15,4 +15,5 @@ export const FEATURE_FLAGS = {
REPORTS: 'reports', REPORTS: 'reports',
TEAM_MANAGEMENT: 'team_management', TEAM_MANAGEMENT: 'team_management',
VOICE_RECORDER: 'voice_recorder', VOICE_RECORDER: 'voice_recorder',
AUDIT_LOGS: 'audit_logs',
}; };

View File

@@ -53,3 +53,5 @@
enabled: false enabled: false
- name: custom_reply_domain - name: custom_reply_domain
enabled: false enabled: false
- name: audit_logs
enabled: false

View File

@@ -21,6 +21,14 @@ class Api::V1::Accounts::AuditLogsController < Api::V1::Accounts::BaseController
private private
def fetch_audit def fetch_audit
@audit_logs = Current.account.associated_audits.order(created_at: :desc) @audit_logs = if audit_logs_enabled?
Current.account.associated_audits.order(created_at: :desc)
else
Current.account.associated_audits.none
end
end
def audit_logs_enabled?
Current.account.feature_enabled?(:audit_logs)
end end
end end

View File

@@ -27,7 +27,20 @@ RSpec.describe 'Enterprise Audit API', type: :request do
# check for response in parse # check for response in parse
context 'when it is an authenticated admin user' do context 'when it is an authenticated admin user' do
it 'returns empty array if feature is not enabled' do
get "/api/v1/accounts/#{account.id}/audit_logs",
headers: admin.create_new_auth_token,
as: :json
expect(response).to have_http_status(:success)
json_response = JSON.parse(response.body)
expect(json_response['audit_logs']).to eql([])
end
it 'fetches audit logs associated with the account' do it 'fetches audit logs associated with the account' do
account.enable_features(:audit_logs)
account.save!
get "/api/v1/accounts/#{account.id}/audit_logs", get "/api/v1/accounts/#{account.id}/audit_logs",
headers: admin.create_new_auth_token, headers: admin.create_new_auth_token,
as: :json as: :json