Skip to content

Commit

Permalink
Make spaces plugin optional
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Feb 3, 2023
1 parent 7288b84 commit 175a625
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 49 deletions.
66 changes: 27 additions & 39 deletions x-pack/plugins/cases/kibana.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,31 @@
{
"configPath":[
"xpack",
"cases"
],
"description":"The Case management system in Kibana",
"extraPublicDirs":[
"common"
],
"id":"cases",
"kibanaVersion":"kibana",
"optionalPlugins":[
"home",
"taskManager",
"usageCollection"
],
"owner":{
"githubTeam":"response-ops",
"name":"ResponseOps"
"configPath": ["xpack", "cases"],
"description": "The Case management system in Kibana",
"extraPublicDirs": ["common"],
"id": "cases",
"kibanaVersion": "kibana",
"optionalPlugins": ["home", "taskManager", "usageCollection", "spaces"],
"owner": {
"githubTeam": "response-ops",
"name": "ResponseOps"
},
"requiredPlugins":[
"actions",
"data",
"embeddable",
"esUiShared",
"lens",
"licensing",
"features",
"kibanaReact",
"kibanaUtils",
"triggersActionsUi",
"management",
"spaces",
"security",
"notifications"
],
"requiredBundles": [
"savedObjects"
"requiredPlugins": [
"actions",
"data",
"embeddable",
"esUiShared",
"lens",
"licensing",
"features",
"kibanaReact",
"kibanaUtils",
"triggersActionsUi",
"management",
"security",
"notifications"
],
"server":true,
"ui":true,
"version":"8.0.0"
"requiredBundles": ["savedObjects"],
"server": true,
"ui": true,
"version": "8.0.0"
}
32 changes: 32 additions & 0 deletions x-pack/plugins/cases/server/authorization/authorization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,38 @@ describe('authorization', () => {
await expect(authPromise).resolves.not.toThrow();
});

it('creates an Authorization object without spaces', async () => {
expect.assertions(2);

const authPromise = Authorization.create({
request,
securityAuth: securityStart.authz,
features: featuresStart,
auditLogger: new AuthorizationAuditLogger(mockLogger),
logger: loggingSystemMock.createLogger(),
});

await expect(authPromise).resolves.toBeDefined();
await expect(authPromise).resolves.not.toThrow();
});

it('if spaces are disabled it does not filtered out disabled features', async () => {
(spacesStart.spacesService.getActiveSpace as jest.Mock).mockImplementation(() => {
return { disabledFeatures: ['1'] } as Space;
});

const auth = await Authorization.create({
request,
securityAuth: securityStart.authz,
features: featuresStart,
auditLogger: new AuthorizationAuditLogger(mockLogger),
logger: loggingSystemMock.createLogger(),
});

// @ts-expect-error
expect([...auth.featureCaseOwners.values()]).toEqual(['a']);
});

it('throws and error when a failure occurs', async () => {
expect.assertions(1);

Expand Down
10 changes: 6 additions & 4 deletions x-pack/plugins/cases/server/authorization/authorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,21 @@ export class Authorization {
}: {
request: KibanaRequest;
securityAuth?: SecurityPluginStart['authz'];
spaces: SpacesPluginStart;
spaces?: SpacesPluginStart;
features: FeaturesPluginStart;
auditLogger: AuthorizationAuditLogger;
logger: Logger;
}): Promise<Authorization> {
const getSpace = async (): Promise<Space> => {
return spaces.spacesService.getActiveSpace(request);
const getSpace = async (): Promise<Space | undefined> => {
return spaces?.spacesService.getActiveSpace(request);
};

// Since we need to do async operations, this static method handles that before creating the Auth class
let caseOwners: Set<string>;

try {
const disabledFeatures = new Set((await getSpace()).disabledFeatures ?? []);
const maybeSpace = await getSpace();
const disabledFeatures = new Set(maybeSpace?.disabledFeatures ?? []);

caseOwners = new Set(
features
Expand Down
9 changes: 6 additions & 3 deletions x-pack/plugins/cases/server/client/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import type { LensServerPluginSetup } from '@kbn/lens-plugin/server';
import type { SpacesPluginStart } from '@kbn/spaces-plugin/server';
import type { LicensingPluginStart } from '@kbn/licensing-plugin/server';
import type { NotificationsPluginStart } from '@kbn/notifications-plugin/server';
import { DEFAULT_SPACE_ID } from '@kbn/spaces-plugin/common';
import { SAVED_OBJECT_TYPES } from '../../common/constants';
import { Authorization } from '../authorization/authorization';
import {
Expand All @@ -49,7 +50,7 @@ import { EmailNotificationService } from '../services/notifications/email_notifi
interface CasesClientFactoryArgs {
securityPluginSetup: SecurityPluginSetup;
securityPluginStart: SecurityPluginStart;
spacesPluginStart: SpacesPluginStart;
spacesPluginStart?: SpacesPluginStart;
featuresPluginStart: FeaturesPluginStart;
actionsPluginStart: ActionsPluginStart;
licensingPluginStart: LicensingPluginStart;
Expand Down Expand Up @@ -144,7 +145,8 @@ export class CasesClientFactory {
externalReferenceAttachmentTypeRegistry: this.options.externalReferenceAttachmentTypeRegistry,
securityStartPlugin: this.options.securityPluginStart,
publicBaseUrl: this.options.publicBaseUrl,
spaceId: this.options.spacesPluginStart.spacesService.getSpaceId(request),
spaceId:
this.options.spacesPluginStart?.spacesService.getSpaceId(request) ?? DEFAULT_SPACE_ID,
savedObjectsSerializer,
});
}
Expand Down Expand Up @@ -197,7 +199,8 @@ export class CasesClientFactory {
notifications: this.options.notifications,
security: this.options.securityPluginStart,
publicBaseUrl: this.options.publicBaseUrl,
spaceId: this.options.spacesPluginStart.spacesService.getSpaceId(request),
spaceId:
this.options.spacesPluginStart?.spacesService.getSpaceId(request) ?? DEFAULT_SPACE_ID,
});

return {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export interface PluginsStart {
licensing: LicensingPluginStart;
taskManager?: TaskManagerStartContract;
security: SecurityPluginStart;
spaces: SpacesPluginStart;
spaces?: SpacesPluginStart;
notifications: NotificationsPluginStart;
}

Expand Down
5 changes: 3 additions & 2 deletions x-pack/plugins/cases/server/services/user_profiles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type { KibanaRequest, Logger } from '@kbn/core/server';
import type { SecurityPluginSetup, SecurityPluginStart } from '@kbn/security-plugin/server';
import type { UserProfile } from '@kbn/security-plugin/common';
import type { SpacesPluginStart } from '@kbn/spaces-plugin/server';
import { DEFAULT_SPACE_ID } from '@kbn/spaces-plugin/common';

import type { LicensingPluginStart } from '@kbn/licensing-plugin/server';
import { excess, SuggestUserProfilesRequestRt, throwErrors } from '../../../common/api';
Expand All @@ -28,7 +29,7 @@ const MIN_PROFILES_SIZE = 0;
interface UserProfileOptions {
securityPluginSetup: SecurityPluginSetup;
securityPluginStart: SecurityPluginStart;
spaces: SpacesPluginStart;
spaces?: SpacesPluginStart;
licensingPluginStart: LicensingPluginStart;
}

Expand Down Expand Up @@ -110,7 +111,7 @@ export class UserProfileService {
size,
owners,
securityPluginStart: this.options.securityPluginStart,
spaceId: spaces.spacesService.getSpaceId(request),
spaceId: spaces?.spacesService.getSpaceId(request) ?? DEFAULT_SPACE_ID,
});
} catch (error) {
throw createCaseError({
Expand Down

0 comments on commit 175a625

Please sign in to comment.