revokeUser static method

Future<void> revokeUser(
  1. Client cloudApiClient, {
  2. required CommandLogger logger,
  3. required String projectId,
  4. required String email,
  5. List<String> unassignRoleNames = const [],
  6. bool unassignAllRoles = false,
})

Implementation

static Future<void> revokeUser(
  final Client cloudApiClient, {
  required final CommandLogger logger,
  required final String projectId,
  required final String email,
  final List<String> unassignRoleNames = const [],
  final bool unassignAllRoles = false,
}) async {
  final List<String> actuallyUnassigned;
  try {
    actuallyUnassigned = await cloudApiClient.projects.revokeUser(
      cloudProjectId: projectId,
      email: email,
      unassignRoleNames: unassignRoleNames,
      unassignAllRoles: unassignAllRoles,
    );
  } on NotFoundException catch (e) {
    throw FailureException(error: e.message);
  } on Exception catch (e, s) {
    throw FailureException.nested(e, s, 'Failed to revoke user from project');
  }

  if (actuallyUnassigned.isEmpty) {
    logger.info(
      unassignAllRoles
          ? 'The user has no access roles to revoke on the project.'
          : 'The user does not have any of the specified project roles.',
    );
  } else {
    logger.success(
      unassignAllRoles
          ? 'Revoked all access roles of the user from the project: ${actuallyUnassigned.join(', ')}'
          : 'Revoked access roles of the user from the project: ${actuallyUnassigned.join(', ')}',
      newParagraph: true,
    );
  }
}