Move the suspended user logic to a transformer filter
Signed-off-by: Valério Valério <vdv100@gmail.com>
This commit is contained in:
@@ -5,5 +5,5 @@
|
||||
|
||||
Introduce new configuration option to exclude suspended users from GitHub Enterprise instances.
|
||||
|
||||
When it’s set to true, suspended users won’t be emitted by the default transform.
|
||||
When it’s set to true, suspended users won’t be returned when querying the organization users for GitHub Enterprise instances.
|
||||
Note that this option should be used only against GitHub Enterprise instances, the property does not exist in the github.com GraphQL schema, setting it will cause a schema validation error and the syncing of users will fail.
|
||||
|
||||
@@ -99,7 +99,6 @@ Directly under the `githubOrg` is a list of configurations, each entry is a stru
|
||||
- `githubUrl`: The target that this provider should consume
|
||||
- `orgs` (optional): The list of the GitHub orgs to consume. If you only list a single org the generated group entities will use the `default` namespace, otherwise they will use the org name as the namespace. By default the provider will consume all accessible orgs on the given GitHub instance (support for GitHub App integration only).
|
||||
- `schedule`: The refresh schedule to use, matches the structure of [`SchedulerServiceTaskScheduleDefinitionConfig`](https://backstage.io/docs/reference/backend-plugin-api.schedulerservicetaskscheduledefinitionconfig/)
|
||||
<<<<<<< HEAD
|
||||
- `pageSizes` (optional): Configure page sizes for GitHub GraphQL API queries to prevent `RESOURCE_LIMITS_EXCEEDED` errors. You can configure the following page sizes:
|
||||
|
||||
- `teams`: Number of teams to fetch per page when querying organization teams (default: 25)
|
||||
@@ -107,9 +106,8 @@ Directly under the `githubOrg` is a list of configurations, each entry is a stru
|
||||
- `organizationMembers`: Number of organization members to fetch per page (default: 50)
|
||||
|
||||
Reducing page sizes will result in more API calls and slightly longer sync times, but will prevent API resource limits for organizations with large number of teams and members.
|
||||
=======
|
||||
|
||||
- `excludeSuspendedUsers` (optional): Whether to exclude suspended users when querying organization users. Only for GitHub Enterprise instances. Will error if used against GitHub.com API.
|
||||
>>>>>>> 40785ff87c (Update documentation to list the new option 'excludeSuspendedUsers')
|
||||
|
||||
### Events Support
|
||||
|
||||
|
||||
@@ -266,7 +266,6 @@ export interface Config {
|
||||
|
||||
/**
|
||||
* (Optional) Only for GitHub Enterprise. Whether to exclude suspended users when querying organization users.
|
||||
* If true, the defaultTransformer will not return suspended users.
|
||||
* Default: `false`.
|
||||
*/
|
||||
excludeSuspendedUsers?: boolean;
|
||||
@@ -324,7 +323,6 @@ export interface Config {
|
||||
|
||||
/**
|
||||
* (Optional) Only for GitHub Enterprise. Whether to exclude suspended users when querying organization users.
|
||||
* If true, the defaultTransformer will not return suspended users.
|
||||
* Default: `false`.
|
||||
*/
|
||||
excludeSuspendedUsers?: boolean;
|
||||
|
||||
@@ -62,9 +62,6 @@ export const defaultUserTransformer = async (
|
||||
item: GithubUser,
|
||||
_ctx: TransformerContext,
|
||||
): Promise<UserEntity | undefined> => {
|
||||
if (item.suspendedAt) {
|
||||
return undefined;
|
||||
}
|
||||
const entity: UserEntity = {
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'User',
|
||||
|
||||
@@ -385,7 +385,7 @@ describe('github', () => {
|
||||
graphql,
|
||||
'a',
|
||||
'token',
|
||||
true,
|
||||
false,
|
||||
customUserTransformer,
|
||||
),
|
||||
).resolves.toEqual(output);
|
||||
|
||||
@@ -210,6 +210,17 @@ export async function getOrganizationUsers(
|
||||
}
|
||||
}`;
|
||||
|
||||
// Transformer to filter out suspended users, only for GitHub Enterprise instances.
|
||||
const suspendedUserFilteringTransformer = async (
|
||||
item: GithubUser,
|
||||
ctx: TransformerContext,
|
||||
): Promise<Entity | undefined> => {
|
||||
if (excludeSuspendedUsers && item.suspendedAt) {
|
||||
return undefined;
|
||||
}
|
||||
return userTransformer(item, ctx);
|
||||
};
|
||||
|
||||
// There is no user -> teams edge, so we leave the memberships empty for
|
||||
// now and let the team iteration handle it instead
|
||||
|
||||
@@ -218,7 +229,7 @@ export async function getOrganizationUsers(
|
||||
query,
|
||||
org,
|
||||
r => r.organization?.membersWithRole,
|
||||
userTransformer,
|
||||
suspendedUserFilteringTransformer,
|
||||
{
|
||||
org,
|
||||
email: tokenType === 'token',
|
||||
|
||||
Reference in New Issue
Block a user