-
Notifications
You must be signed in to change notification settings - Fork 15
Audit log suspend #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d5eeb56
useGetUser hook
AlinaGoaga 4516da7
Add weave.works/suspended-by annotation when suspending resource
AlinaGoaga bf3f504
Add test for getUserInfo
AlinaGoaga 80d7faf
Update useToggleSuspendResource tests with user
AlinaGoaga 3f0613b
Add IdentifyApiMock to dev and tests
AlinaGoaga 9195927
Update tests to check for user data availability prior to running
AlinaGoaga d8f026b
Move user data retrieval to useToogleSuspend hook to ensure it's load…
AlinaGoaga 6c7537d
Uddate getUser types - WIP
AlinaGoaga 605c7f7
Uddate getUser types
AlinaGoaga 4fabd6b
Remove google from auth providers
AlinaGoaga 3d3afc4
Update dev mock
AlinaGoaga b62cac9
Simplify useGetUser hook and remove identity stub from table tests as…
AlinaGoaga 650f00e
Update toggleSuspend dependency list
AlinaGoaga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
plugins/backstage-plugin-flux/src/hooks/useGetUser.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { identityApiRef } from '@backstage/core-plugin-api'; | ||
import { getUserInfo } from './useGetUser'; | ||
|
||
function makeMockIdentityApi() { | ||
return { | ||
getObjectsByEntity: jest.fn(), | ||
getProfileInfo: jest.fn(), | ||
getBackstageIdentity: jest.fn(), | ||
getCredentials: jest.fn(), | ||
signOut: jest.fn(), | ||
} as jest.Mocked<typeof identityApiRef.T>; | ||
} | ||
|
||
function makeMockUserIdentityApi() { | ||
return { | ||
fromLegacy: jest.fn(), | ||
}; | ||
} | ||
|
||
describe('getUserInfo', () => { | ||
it('should get the user details', async () => { | ||
const userId = 'user:default/guest'; | ||
const profile = { | ||
displayName: 'Guest', | ||
picture: 'https://avatars.githubusercontent.com/u/35202557?v=4', | ||
}; | ||
|
||
const identityApi = makeMockIdentityApi(); | ||
const userIdentityApi = makeMockUserIdentityApi(); | ||
|
||
identityApi.getBackstageIdentity.mockImplementation(async () => { | ||
return { | ||
ownershipEntityRefs: [userId], | ||
type: 'user', | ||
userEntityRef: userId, | ||
}; | ||
}); | ||
|
||
identityApi.getProfileInfo.mockImplementation(async () => profile); | ||
|
||
userIdentityApi.fromLegacy.mockImplementation(async () => { | ||
return { | ||
result: { profile, userId }, | ||
}; | ||
}); | ||
|
||
const userDetails = await getUserInfo(identityApi); | ||
|
||
expect(userDetails).toEqual({ result: { profile, userId } }); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { | ||
IdentityApi, | ||
identityApiRef, | ||
useApi, | ||
} from '@backstage/core-plugin-api'; | ||
import { UserIdentity } from '@backstage/core-components'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
export async function getUserInfo(identityApi: IdentityApi) { | ||
const backstageIdentity = await identityApi.getBackstageIdentity(); | ||
const profile = await identityApi.getProfileInfo(); | ||
|
||
return await UserIdentity.fromLegacy({ | ||
AlinaGoaga marked this conversation as resolved.
Show resolved
Hide resolved
|
||
userId: backstageIdentity.userEntityRef, | ||
profile: profile, | ||
}); | ||
} | ||
|
||
/** | ||
* | ||
* @public | ||
*/ | ||
export function useGetUserInfo() { | ||
const identityApi = useApi(identityApiRef); | ||
AlinaGoaga marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const { isLoading, data, error } = useQuery<any, Error>({ | ||
AlinaGoaga marked this conversation as resolved.
Show resolved
Hide resolved
|
||
queryKey: ['user_info'], | ||
queryFn: () => getUserInfo(identityApi), | ||
}); | ||
|
||
return { isLoading, data, error }; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.