diff --git a/app/javascript/dashboard/components/layout/config/sidebarItems/settings.js b/app/javascript/dashboard/components/layout/config/sidebarItems/settings.js index 94997ac4b..c0d80932d 100644 --- a/app/javascript/dashboard/components/layout/config/sidebarItems/settings.js +++ b/app/javascript/dashboard/components/layout/config/sidebarItems/settings.js @@ -157,6 +157,7 @@ const settings = accountId => ({ hasSubMenu: false, toState: frontendURL(`accounts/${accountId}/settings/audit-log/list`), toStateName: 'auditlogs_list', + featureFlag: FEATURE_FLAGS.AUDIT_LOGS, beta: true, }, ], diff --git a/app/javascript/dashboard/featureFlags.js b/app/javascript/dashboard/featureFlags.js index 2358a2731..5f3a9ccbd 100644 --- a/app/javascript/dashboard/featureFlags.js +++ b/app/javascript/dashboard/featureFlags.js @@ -15,4 +15,5 @@ export const FEATURE_FLAGS = { REPORTS: 'reports', TEAM_MANAGEMENT: 'team_management', VOICE_RECORDER: 'voice_recorder', + AUDIT_LOGS: 'audit_logs', }; diff --git a/config/features.yml b/config/features.yml index adecba7b5..6132bda68 100644 --- a/config/features.yml +++ b/config/features.yml @@ -53,3 +53,5 @@ enabled: false - name: custom_reply_domain enabled: false +- name: audit_logs + enabled: false diff --git a/enterprise/app/controllers/api/v1/accounts/audit_logs_controller.rb b/enterprise/app/controllers/api/v1/accounts/audit_logs_controller.rb index 26a0d2c6e..d1e6b9287 100644 --- a/enterprise/app/controllers/api/v1/accounts/audit_logs_controller.rb +++ b/enterprise/app/controllers/api/v1/accounts/audit_logs_controller.rb @@ -21,6 +21,14 @@ class Api::V1::Accounts::AuditLogsController < Api::V1::Accounts::BaseController private 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 diff --git a/spec/enterprise/controllers/api/v1/accounts/audit_logs_controller_spec.rb b/spec/enterprise/controllers/api/v1/accounts/audit_logs_controller_spec.rb index 88ca5891e..53721c5c5 100644 --- a/spec/enterprise/controllers/api/v1/accounts/audit_logs_controller_spec.rb +++ b/spec/enterprise/controllers/api/v1/accounts/audit_logs_controller_spec.rb @@ -27,7 +27,20 @@ RSpec.describe 'Enterprise Audit API', type: :request do # check for response in parse 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 + account.enable_features(:audit_logs) + account.save! + get "/api/v1/accounts/#{account.id}/audit_logs", headers: admin.create_new_auth_token, as: :json