mattermost/e2e-tests/playwright/lib/src/server/plugin.ts
Dylan Haussermann 8e7b3da702
Some checks are pending
API / build (push) Waiting to run
Server CI / Compute Go Version (push) Waiting to run
Server CI / Check mocks (push) Blocked by required conditions
Server CI / Check go mod tidy (push) Blocked by required conditions
Server CI / check-style (push) Blocked by required conditions
Server CI / Check serialization methods for hot structs (push) Blocked by required conditions
Server CI / Vet API (push) Blocked by required conditions
Server CI / Check migration files (push) Blocked by required conditions
Server CI / Generate email templates (push) Blocked by required conditions
Server CI / Check store layers (push) Blocked by required conditions
Server CI / Check mmctl docs (push) Blocked by required conditions
Server CI / Postgres with binary parameters (push) Blocked by required conditions
Server CI / Postgres (push) Blocked by required conditions
Server CI / Postgres (FIPS) (push) Blocked by required conditions
Server CI / Generate Test Coverage (push) Blocked by required conditions
Server CI / Run mmctl tests (push) Blocked by required conditions
Server CI / Run mmctl tests (FIPS) (push) Blocked by required conditions
Server CI / Build mattermost server app (push) Blocked by required conditions
Web App CI / check-lint (push) Waiting to run
Web App CI / check-i18n (push) Blocked by required conditions
Web App CI / check-types (push) Blocked by required conditions
Web App CI / test (platform) (push) Blocked by required conditions
Web App CI / test (mattermost-redux) (push) Blocked by required conditions
Web App CI / test (channels shard 1/4) (push) Blocked by required conditions
Web App CI / test (channels shard 2/4) (push) Blocked by required conditions
Web App CI / test (channels shard 3/4) (push) Blocked by required conditions
Web App CI / test (channels shard 4/4) (push) Blocked by required conditions
Web App CI / upload-coverage (push) Blocked by required conditions
Web App CI / build (push) Blocked by required conditions
Fixtures that allow install of a plugin from a target repo (#34520)
* Fixtures that allow install of a plugin from a target repo

* Fixed linting error and applied `prettier` formating.

* Implemeted feedback from code review

* Remove unused AdminConfig import

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
2026-01-27 21:41:49 +08:00

56 lines
1.7 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {Client4} from '@mattermost/client';
import {PluginManifest} from '@mattermost/types/plugins';
export async function isPluginActive(client: Client4, pluginId: string): Promise<boolean> {
const plugins = await client.getPlugins();
return plugins.active.some((plugin: PluginManifest) => plugin.id === pluginId);
}
export async function getPluginStatus(
client: Client4,
pluginId: string,
): Promise<{isInstalled: boolean; isActive: boolean}> {
const plugins = await client.getPlugins();
const isActive = plugins.active.some((plugin: PluginManifest) => plugin.id === pluginId);
const isInactive = plugins.inactive.some((plugin: PluginManifest) => plugin.id === pluginId);
return {
isInstalled: isActive || isInactive,
isActive,
};
}
/**
* Installs and enables a plugin with smart status checking
* - If already active: does nothing
* - If already installed: just enables it
* - Otherwise: installs from URL, then enables
*/
export async function installAndEnablePlugin(
client: Client4,
pluginUrl: string,
pluginId: string,
force = true,
): Promise<void> {
// Check current status
const status = await getPluginStatus(client, pluginId);
// If already active, nothing to do
if (status.isActive) {
return;
}
// If already installed but not active, just enable it
if (status.isInstalled) {
await client.enablePlugin(pluginId);
return;
}
// Not installed - install from URL then enable
await client.installPluginFromUrl(pluginUrl, force);
await client.enablePlugin(pluginId);
}