mirror of
https://github.com/hanzoai/team.git
synced 2026-09-30 01:57:35 +00:00
* MM-69063 - Add team ABAC model and constants foundation * Add team ABAC store EXISTS, channel Type retrofit, policy count split, and index migration * Add team ABAC app layer: access gate, hydrators, assign/unassign, cleanup, and GetTeamMembersToRemove store * Enforce team membership ABAC on join and hide policy governed teams from non-qualifying users in the directory * Add team_ids to access policy assign/unassign, expose per-team policy GET, and support abac_match_only for not_in_team user listing * Add team ABAC client methods, websocket handler, per-team System Console policy UI, and hide policy-governed teams from non-qualifying users * Make team ABAC mode-aware: advisory on public teams, strict on private, and surface governed private teams to qualifying users in directory listings * Flag-gate team ABAC mutation/read APIs and fix policy-save error handling, member-removal limit, team-id validation, export, and audit cleanup * coderabbit feedback; Broadcast team policy enforcement updates on policy create/update and activation, not only on delete * Update team access control policy schema to allow nullable policies and enhance test cases with channel counts * Enhance access control policy tests to include team policy search alongside channel policy search * Add team membership access control feature flag to docker-compose generation * Implement team access control policy checks and refactor related components * MM-69100 - add team membership ABAC sync worker with mode-aware removal and auto-add * Add team ABAC removal/auto-add notifications, cascade audit, and team custom-rules save backend * Add Team Settings team membership tab with custom-rules editor, auto-add toggle, save confirmation, and mode-flip sync trigger * Add team access control policy panels, job details team list, and e2e coverage for membership tab and discoverability cards * ix save double-submit with loading state, team privacy via updateTeamPrivacy, mode-flip count accuracy, sync trigger logic, i18n keys, and e2e test cleanup * Add team membership policy notices to invite and add-to-team flows, team access control system messages, and a team policy attributes endpoint * Add team membership recommended tag for qualifying users and team requirements notice in the members modal * temp * adjust styling, add new e2e, fix team admin job permissions issues * e2e clean items created * fix directory and team integration e2e tests * Surface team sync results in the Sync Job Details modal via a Teams tab linked from the chained channel job * code clean up, adjust styling * Add access control attributes endpoint and enhance E2E tests for team membership * Enhance team access control by updating permission checks and syncing jobs * Add API-level enforcement gate tests for ABAC team membership * Fix formatting in team channel settings component by adding missing semicolon * Fix formatting in Client4 class by adjusting type annotations for clarity * revert unwanted changes in package-lock * Refactor job permission test and simplify error handling in team details component * Update test assertions and enhance auto-add functionality in team membership tab * Update onboarding tests to use 'Public Team' card for team access settings * Refactor AccessSettings and TeamPolicyEditor components to replace allowOpenInviteCheckbox with public and private team buttons, and update access control job dispatching logic. * Remove redundant state updates for channel assignments in access control policy reducer * Implement email suppression for team membership notifications and add related tests * Authorize ABAC team self-join by attribute match instead of the join_private_teams role * comments clean up * Gate team privacy type normalization behind active ABAC, keep legacy allow_open_invite-only path otherwise * adjust job details styles * Add team membership policy disconnect confirmation, fix linked-policy affected-member count, and polish job details modal * Combine custom rules with system policy expressions for accurate confirm counts * Implement child resource count stamping and deletion gating for access control policies * Enhance team sync job triggering logic for membership changes without auto-add * Refactor team privacy handling to align with open-directory model; update comments for clarity on allow_open_invite logic. * Deduplicate team ABAC sync jobs per policy to prevent concurrent runs emitting duplicate DMs and audit records on HA clusters * fix linter warnings * Add confirmation for policy removal in TeamDetails tests * Update delete policy message to include Teams in the warning * Add linked teams warning to policy deletion and update translations * Add Auto-add feature for policy selection and team management - Enhanced PolicySelectionModal to include an Auto-add checkbox for each policy. - Updated PolicyList to manage Auto-add state and reflect changes in the UI. - Modified TeamAccessControl to handle Auto-add functionality and persist changes. - Added tests to ensure Auto-add behavior works as expected in various scenarios. - Updated translations for Auto-add related strings. * Add team membership sync footer and enhance job fetching with policy ID * Refactor team membership policy handling and sync footer implementation * Add team sync channel cascade test for private channel membership --------- Co-authored-by: Mattermost Build <[email protected]>
111 lines
4.4 KiB
TypeScript
111 lines
4.4 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import type {Client4} from '@mattermost/client';
|
|
|
|
/**
|
|
* Enable team-membership ABAC end to end: the umbrella attribute-based access
|
|
* control setting plus the `TeamMembershipAccessControl` feature flag that gates
|
|
* the per-team System Console section. Both must be on for the team page to
|
|
* render the membership-policy toggle — mirroring the server enforcement gate.
|
|
*/
|
|
export async function enableTeamMembershipPolicies(client: Client4): Promise<void> {
|
|
await client.patchConfig({
|
|
AccessControlSettings: {
|
|
EnableAttributeBasedAccessControl: true,
|
|
EnableUserManagedAttributes: true,
|
|
},
|
|
FeatureFlags: {
|
|
TeamMembershipAccessControl: true,
|
|
},
|
|
} as any);
|
|
}
|
|
|
|
/**
|
|
* Create a parent membership policy that can be assigned to a TEAM.
|
|
*
|
|
* Team assignment runs `child.Inherit(parent)` with the child at v0.3, which
|
|
* requires the parent to also be v0.3 — so (unlike the channel-side
|
|
* createParentPolicy, which is v0.2) this helper stamps v0.3 and a membership
|
|
* action. Returns the created policy (carries `id` and `name`).
|
|
*/
|
|
export async function createTeamMembershipParentPolicy(
|
|
client: Client4,
|
|
name: string,
|
|
expression: string,
|
|
): Promise<{id: string; name: string}> {
|
|
return (client as any).doFetch(`${client.getBaseRoute()}/access_control_policies`, {
|
|
method: 'put',
|
|
body: JSON.stringify({
|
|
id: '',
|
|
name,
|
|
type: 'parent',
|
|
version: 'v0.3',
|
|
revision: 0,
|
|
rules: [{expression, actions: ['membership']}],
|
|
}),
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Trigger an access_control_team_sync job and poll that specific job until it
|
|
* finishes. Polling by ID (not list position) avoids a race where older jobs
|
|
* occupy jobs[0] and the newly created one is never checked.
|
|
*
|
|
* Both `success` and `warning` are terminal completions: the worker reports
|
|
* `warning` (not `success`) whenever the mass-removal guardrail trips — i.e. a
|
|
* sync that drops >50% of a team. The sync still ran to completion, so callers
|
|
* that exercise removals must accept it. The final status is returned so a
|
|
* caller can assert on it (e.g. expecting the warning state).
|
|
*/
|
|
export async function triggerSyncJobAndPoll(
|
|
client: Client4,
|
|
policyId = '',
|
|
timeoutMs = 90_000,
|
|
pollIntervalMs = 3_000,
|
|
): Promise<string> {
|
|
// Scope the sync to the team's policy (team policies are keyed by team id),
|
|
// mirroring the product trigger createAccessControlTeamSyncJob({policy_id}).
|
|
// A scoped sync also chains a scoped channel sync, so the chained job is
|
|
// created deterministically rather than skipped by the unscoped dedupe.
|
|
const body: {type: string; data?: {policy_id: string}} = {type: 'access_control_team_sync'};
|
|
if (policyId) {
|
|
body.data = {policy_id: policyId};
|
|
}
|
|
const job: any = await (client as any).doFetch(`${client.getBaseRoute()}/jobs`, {
|
|
method: 'POST',
|
|
body: JSON.stringify(body),
|
|
});
|
|
const jobId: string = job.id;
|
|
|
|
const deadline = Date.now() + timeoutMs;
|
|
while (Date.now() < deadline) {
|
|
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
|
|
const current: any = await (client as any).doFetch(`${client.getBaseRoute()}/jobs/${jobId}`, {method: 'GET'});
|
|
if (current.status === 'success' || current.status === 'warning') {
|
|
return current.status;
|
|
}
|
|
if (current.status === 'error') {
|
|
throw new Error(`access_control_team_sync job failed: ${JSON.stringify(current)}`);
|
|
}
|
|
}
|
|
throw new Error('Timed out waiting for access_control_team_sync job to finish');
|
|
}
|
|
|
|
/**
|
|
* Assign a parent policy to teams via the REST API (the `team_ids` field).
|
|
* Mirrors `assignChannelsToPolicy` from team_settings/helpers — same endpoint,
|
|
* different resource list.
|
|
*/
|
|
export async function assignTeamsToPolicy(client: Client4, policyId: string, teamIds: string[]): Promise<void> {
|
|
const url = `${client.getBaseRoute()}/access_control_policies/${policyId}/assign`;
|
|
const response = await fetch(url, {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'application/json', Authorization: `Bearer ${client.getToken()}`},
|
|
body: JSON.stringify({team_ids: teamIds}),
|
|
});
|
|
if (!response.ok) {
|
|
throw new Error(`assignTeamsToPolicy failed: ${response.status}`);
|
|
}
|
|
}
|