-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into M3-7772-vmpg-create-integration-tests
- Loading branch information
Showing
12 changed files
with
185 additions
and
82 deletions.
There are no files selected for viewing
This file contains 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,5 @@ | ||
--- | ||
"@linode/manager": Fixed | ||
--- | ||
|
||
Prevent Modification of Linode config 'interfaces' Array on No Changes ([#10423](https://github.com/linode/manager/pull/10423)) |
5 changes: 5 additions & 0 deletions
5
packages/manager/.changeset/pr-10435-tech-stories-1715021415506.md
This file contains 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,5 @@ | ||
--- | ||
"@linode/manager": Tech Stories | ||
--- | ||
|
||
Clean up Database feature flagging logic ([#10435](https://github.com/linode/manager/pull/10435)) |
This file contains 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,5 @@ | ||
--- | ||
"@linode/manager": Fixed | ||
--- | ||
|
||
Fix One-Click App test by using Ubuntu 22.04 image ([#10447](https://github.com/linode/manager/pull/10447)) |
This file contains 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 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 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 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 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 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,80 @@ | ||
import { renderHook, waitFor } from '@testing-library/react'; | ||
|
||
import { accountFactory } from 'src/factories'; | ||
import { makeResourcePage } from 'src/mocks/serverHandlers'; | ||
import { HttpResponse, http, server } from 'src/mocks/testServer'; | ||
import { wrapWithTheme } from 'src/utilities/testHelpers'; | ||
|
||
import { useIsDatabasesEnabled } from './utilities'; | ||
|
||
describe('useIsDatabasesEnabled', () => { | ||
it('should return true for an unrestricted user with the account capability', async () => { | ||
const account = accountFactory.build({ | ||
capabilities: ['Managed Databases'], | ||
}); | ||
|
||
server.use( | ||
http.get('*/v4/account', () => { | ||
return HttpResponse.json(account); | ||
}) | ||
); | ||
|
||
const { result } = renderHook(() => useIsDatabasesEnabled(), { | ||
wrapper: wrapWithTheme, | ||
}); | ||
|
||
await waitFor(() => expect(result.current.isDatabasesEnabled).toBe(true)); | ||
}); | ||
|
||
it('should return false for an unrestricted user without the account capability', async () => { | ||
const account = accountFactory.build({ | ||
capabilities: [], | ||
}); | ||
|
||
server.use( | ||
http.get('*/v4/account', () => { | ||
return HttpResponse.json(account); | ||
}) | ||
); | ||
|
||
const { result } = renderHook(() => useIsDatabasesEnabled(), { | ||
wrapper: wrapWithTheme, | ||
}); | ||
|
||
await waitFor(() => expect(result.current.isDatabasesEnabled).toBe(false)); | ||
}); | ||
|
||
it('should return true for a restricted user who can not load account but can load database engines', async () => { | ||
server.use( | ||
http.get('*/v4/account', () => { | ||
return HttpResponse.json({}, { status: 403 }); | ||
}), | ||
http.get('*/v4beta/databases/engines', () => { | ||
return HttpResponse.json(makeResourcePage([])); | ||
}), | ||
); | ||
|
||
const { result } = renderHook(() => useIsDatabasesEnabled(), { | ||
wrapper: wrapWithTheme, | ||
}); | ||
|
||
await waitFor(() => expect(result.current.isDatabasesEnabled).toBe(true)); | ||
}); | ||
|
||
it('should return false for a restricted user who can not load account and database engines', async () => { | ||
server.use( | ||
http.get('*/v4/account', () => { | ||
return HttpResponse.json({}, { status: 403 }); | ||
}), | ||
http.get('*/v4beta/databases/engines', () => { | ||
return HttpResponse.json({}, { status: 404 }); | ||
}) | ||
); | ||
|
||
const { result } = renderHook(() => useIsDatabasesEnabled(), { | ||
wrapper: wrapWithTheme, | ||
}); | ||
|
||
await waitFor(() => expect(result.current.isDatabasesEnabled).toBe(false)); | ||
}); | ||
}); |
This file contains 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,39 @@ | ||
import { useAccount } from 'src/queries/account/account'; | ||
import { useDatabaseEnginesQuery } from 'src/queries/databases'; | ||
|
||
/** | ||
* A hook to determine if Databases should be visible to the user. | ||
* | ||
* Because DBaaS is end of sale, we treat it differently than other products. | ||
* It should only be visible to customers with the account capability. | ||
* | ||
* For unrestricted users, databases will show when | ||
* The user has the `Managed Databases` account capability. | ||
* | ||
* For users who don't have permission to load /v4/account | ||
* (who are restricted users without account read access), | ||
* we must check if they can load Database Engines as a workaround. | ||
* If these users can successfully fetch database engines, we will | ||
* show databases. | ||
*/ | ||
export const useIsDatabasesEnabled = () => { | ||
const { data: account } = useAccount(); | ||
|
||
// If we don't have permission to GET /v4/account, | ||
// we need to try fetching Database engines to know if the user has databases enabled. | ||
const checkRestrictedUser = !account; | ||
|
||
const { data: engines } = useDatabaseEnginesQuery(checkRestrictedUser); | ||
|
||
if (account) { | ||
return { | ||
isDatabasesEnabled: account.capabilities.includes('Managed Databases'), | ||
}; | ||
} | ||
|
||
const userCouldLoadDatabaseEngines = engines !== undefined; | ||
|
||
return { | ||
isDatabasesEnabled: userCouldLoadDatabaseEngines, | ||
}; | ||
}; |
This file contains 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
Oops, something went wrong.