Move the suspended user logic to a transformer filter
Signed-off-by: Valério Valério <vdv100@gmail.com>
This commit is contained in:
@@ -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