Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

2.0 KB
Raw Blame
import { HttpMethod } from '@activepieces/pieces-common';
import { createAction, Property } from '@activepieces/pieces-framework';

import { googleWorkspaceAuth } from '../auth';
import { googleWorkspaceClient } from '../common/client';
import { googleWorkspaceUtils } from '../common/utils';
import { suspendUserOutputSchema } from '../output-schemas';

export const suspendUser = createAction({
  name: 'suspendUser',
  classification: 'DESTRUCTIVE',
  displayName: 'Suspend User',
  description: 'Suspend a directory user (blocks sign-in, keeps data), or lift the suspension',
  audience: 'both',
  aiMetadata: {
    description:
      'Suspends a Google Workspace user (blocks sign-in and access while keeping the account and its data) or, with Suspended off, reactivates a suspended user. Prefer this over Delete Record when offboarding. Sets the user to the requested state, so retries are safe.',
    idempotent: true,
  },
  auth: googleWorkspaceAuth,
  props: {
    userKey: Property.ShortText({
      displayName: 'User',
      description: 'Primary e-mail, alias or id of the user.',
      required: true,
    }),
    suspended: Property.Checkbox({
      displayName: 'Suspended',
      description: 'On: suspend the user. Off: reactivate a suspended user.',
      required: false,
      defaultValue: true,
    }),
  },
  outputSchema: suspendUserOutputSchema,
  async run(context) {
    const { userKey, suspended } = context.propsValue;
    const auth = await googleWorkspaceClient.resolveAuth(context.auth);
    const value = suspended !== false;

    const user = await googleWorkspaceClient.request<Record<string, unknown>>({
      auth,
      method: HttpMethod.PATCH,
      path: googleWorkspaceUtils.resources.user.itemPath({ id: userKey }),
      body: { suspended: value },
    });

    return {
      id: user['id'] ?? null,
      primaryEmail: user['primaryEmail'] ?? null,
      suspended: typeof user['suspended'] === 'boolean' ? user['suspended'] : value,
      suspensionReason: user['suspensionReason'] ?? null,
      record: user,
    };
  },
});