[Cases] Notify assignment usage (#141243) (#141623)

* Notify assignement usage

* Change name

* PR feedback

* Fix types

(cherry picked from commit e9ca18247c)

Co-authored-by: Christos Nasikas <christos.nasikas@elastic.co>
This commit is contained in:
Kibana Machine 2022-09-23 08:06:37 -06:00 committed by GitHub
parent 0ef576b140
commit 172f7aa68a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 56 additions and 5 deletions

View file

@ -29,6 +29,7 @@ import { Operations } from '../../authorization';
import { createCaseError } from '../../common/error';
import { flattenCaseSavedObject, transformNewCase } from '../../common/utils';
import { CasesClientArgs } from '..';
import { LICENSING_CASE_ASSIGNMENT_FEATURE } from '../../common/constants';
/**
* Creates a new case.
@ -84,6 +85,8 @@ export const create = async (
'In order to assign users to cases, you must be subscribed to an Elastic Platinum license'
);
}
licensingService.notifyUsage(LICENSING_CASE_ASSIGNMENT_FEATURE);
}
if (areTotalAssigneesInvalid(query.assignees)) {

View file

@ -27,6 +27,7 @@ import { includeFieldsRequiredForAuthentication } from '../../authorization/util
import { Operations } from '../../authorization';
import { CasesClientArgs } from '..';
import { ConstructQueryParams } from '../types';
import { LICENSING_CASE_ASSIGNMENT_FEATURE } from '../../common/constants';
/**
* Retrieves a case and optionally its comments.
@ -66,6 +67,8 @@ export const find = async (
'In order to filter cases by assignees, you must be subscribed to an Elastic Platinum license'
);
}
licensingService.notifyUsage(LICENSING_CASE_ASSIGNMENT_FEATURE);
}
const queryArgs: ConstructQueryParams = {

View file

@ -49,6 +49,8 @@ import { UpdateAlertRequest } from '../alerts/types';
import { CasesClientArgs } from '..';
import { Operations, OwnerEntity } from '../../authorization';
import { dedupAssignees, getClosedInfoForUpdate, getDurationForUpdate } from './utils';
import { LICENSING_CASE_ASSIGNMENT_FEATURE } from '../../common/constants';
import { LicensingService } from '../../services/licensing';
/**
* Throws an error if any of the requests attempt to update the owner of a case.
@ -106,6 +108,19 @@ function throwIfUpdateAssigneesWithoutValidLicense(
}
}
function notifyPlatinumUsage(
licensingService: LicensingService,
requests: UpdateRequestWithOriginalCase[]
) {
const requestsUpdatingAssignees = requests.filter(
({ updateReq }) => updateReq.assignees !== undefined
);
if (requestsUpdatingAssignees.length > 0) {
licensingService.notifyUsage(LICENSING_CASE_ASSIGNMENT_FEATURE);
}
}
/**
* Throws an error if any of the requests attempt to add more than
* MAX_ASSIGNEES_PER_CASE to a case
@ -357,6 +372,8 @@ export const update = async (
throwIfUpdateAssigneesWithoutValidLicense(updateCases, hasPlatinumLicense);
throwIfTotalAssigneesAreInvalid(updateCases);
notifyPlatinumUsage(licensingService, updateCases);
const updatedCases = await patchCases({ caseService, user, casesToUpdate: updateCases });
// If a status update occurred and the case is synced then we need to update all alerts' status

View file

@ -155,7 +155,10 @@ export class CasesClientFactory {
attachmentService,
});
const licensingService = new LicensingService(this.options.licensingPluginStart.license$);
const licensingService = new LicensingService(
this.options.licensingPluginStart.license$,
this.options.licensingPluginStart.featureUsage.notifyUsage
);
return {
alertsService: new AlertService(esClient, this.logger),

View file

@ -32,3 +32,8 @@ export const COMMENT_REF_NAME = `associated-${CASE_COMMENT_SAVED_OBJECT}`;
* The name of the saved object reference indicating the externalReferenceId reference
*/
export const EXTERNAL_REFERENCE_REF_NAME = 'externalReferenceId';
/**
* The name of the licensing feature to notify for feature usage with the licensing plugin
*/
export const LICENSING_CASE_ASSIGNMENT_FEATURE = 'Cases user assignment';

View file

@ -30,7 +30,7 @@ import {
TaskManagerStartContract,
} from '@kbn/task-manager-plugin/server';
import { UsageCollectionSetup } from '@kbn/usage-collection-plugin/server';
import { LicensingPluginStart } from '@kbn/licensing-plugin/server';
import { LicensingPluginSetup, LicensingPluginStart } from '@kbn/licensing-plugin/server';
import { APP_ID } from '../common/constants';
import {
@ -53,12 +53,14 @@ import { getInternalRoutes } from './routes/api/get_internal_routes';
import { PersistableStateAttachmentTypeRegistry } from './attachment_framework/persistable_state_registry';
import { ExternalReferenceAttachmentTypeRegistry } from './attachment_framework/external_reference_registry';
import { UserProfileService } from './services';
import { LICENSING_CASE_ASSIGNMENT_FEATURE } from './common/constants';
export interface PluginsSetup {
actions: ActionsPluginSetup;
lens: LensServerPluginSetup;
features: FeaturesPluginSetup;
security: SecurityPluginSetup;
licensing: LicensingPluginSetup;
taskManager?: TaskManagerSetupContract;
usageCollection?: UsageCollectionSetup;
}
@ -149,6 +151,8 @@ export class CasePlugin {
telemetryUsageCounter,
});
plugins.licensing.featureUsage.register(LICENSING_CASE_ASSIGNMENT_FEATURE, 'platinum');
return {
attachmentFramework: {
registerExternalReference: (externalReferenceAttachmentType) => {

View file

@ -6,13 +6,22 @@
*/
import { firstValueFrom, Observable } from 'rxjs';
import { ILicense, LicenseType } from '@kbn/licensing-plugin/server';
import { ILicense, LicenseType, LicensingPluginStart } from '@kbn/licensing-plugin/server';
export class LicensingService {
private readonly license$: Observable<ILicense>;
private readonly _notifyUsage: LicensingPluginStart['featureUsage']['notifyUsage'];
constructor(license$: Observable<ILicense>) {
constructor(
license$: Observable<ILicense>,
notifyUsage: LicensingPluginStart['featureUsage']['notifyUsage']
) {
this.license$ = license$;
this._notifyUsage = notifyUsage;
}
public notifyUsage(featureName: string) {
this._notifyUsage(featureName);
}
public async getLicenseInformation(): Promise<ILicense> {

View file

@ -20,6 +20,7 @@ import { excess, SuggestUserProfilesRequestRt, throwErrors } from '../../../comm
import { Operations } from '../../authorization';
import { createCaseError } from '../../common/error';
import { LicensingService } from '../licensing';
import { LICENSING_CASE_ASSIGNMENT_FEATURE } from '../../common/constants';
const MAX_PROFILES_SIZE = 100;
const MIN_PROFILES_SIZE = 0;
@ -81,7 +82,11 @@ export class UserProfileService {
try {
this.validateInitialization();
const licensingService = new LicensingService(this.options.licensingPluginStart.license$);
const licensingService = new LicensingService(
this.options.licensingPluginStart.license$,
this.options.licensingPluginStart.featureUsage.notifyUsage
);
const hasPlatinumLicenseOrGreater = await licensingService.isAtLeastPlatinum();
if (!hasPlatinumLicenseOrGreater) {
@ -90,6 +95,8 @@ export class UserProfileService {
);
}
licensingService.notifyUsage(LICENSING_CASE_ASSIGNMENT_FEATURE);
const { spaces } = this.options;
UserProfileService.validateSizeParam(size);