-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* OpenId implementation * Code rabbit auto generated code applied Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Code rabbit suggestions round 2 Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * fixes from code rabbit round 1 * fixes from code rabbit round 2 * change variable name * code review round 3 * Update VRT * small fix * Update VRT * linter * app.tsx * LoggedInUser * UserAccess * UserAccessHeader * UserAccessPage * UserAccessRow * UserDirectory * UserDirectoryHeader * UserDirectoryPage * UserDirectoryRow * BudgetList * Bootstrap * Login * OpenIdForm * CreateAccountModal * EditAccess * EditUser * GoCardlessInitialiseModal * OpenIDEnableModal * PasswordEnableModal * SimpleFinInitialiseModal * TransferOwnership * AuthSettings * fix hooks in EditUser * enable electron openid login * typecheck * linter and typecheck fixes * Update VRT * small fix * linter * small changes for file owner name and a fix for privacyfilter in the username * linter for merge * change the entra url and changing the electron loopback url when built * "logged in as" was showing when had no user * linter * linter² * code review --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: matt <matt@fiddaman.net>
- Loading branch information
1 parent
cde81da
commit 0b2c8cc
Showing
73 changed files
with
4,835 additions
and
391 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
Binary file modified
BIN
+150 Bytes
(100%)
...ettings.test.js-snapshots/Settings-checks-the-page-visuals-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+162 Bytes
(100%)
...ettings.test.js-snapshots/Settings-checks-the-page-visuals-3-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,48 @@ | ||
import React, { createContext, useContext, type ReactNode } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
|
||
import { type State } from 'loot-core/client/state-types'; | ||
|
||
import { useServerURL } from '../components/ServerContext'; | ||
|
||
import { type Permissions } from './types'; | ||
|
||
type AuthContextType = { | ||
hasPermission: (permission?: Permissions) => boolean; | ||
}; | ||
|
||
const AuthContext = createContext<AuthContextType | undefined>(undefined); | ||
|
||
type AuthProviderProps = { | ||
children?: ReactNode; | ||
}; | ||
|
||
export const AuthProvider = ({ children }: AuthProviderProps) => { | ||
const userData = useSelector((state: State) => state.user.data); | ||
const serverUrl = useServerURL(); | ||
|
||
const hasPermission = (permission?: Permissions) => { | ||
if (!permission) { | ||
return true; | ||
} | ||
|
||
return ( | ||
!serverUrl || | ||
userData?.permission?.toUpperCase() === permission?.toUpperCase() | ||
); | ||
}; | ||
|
||
return ( | ||
<AuthContext.Provider value={{ hasPermission }}> | ||
{children} | ||
</AuthContext.Provider> | ||
); | ||
}; | ||
|
||
export const useAuth = () => { | ||
const context = useContext(AuthContext); | ||
if (context === undefined) { | ||
throw new Error('useAuth must be used within an AuthProvider'); | ||
} | ||
return context; | ||
}; |
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,65 @@ | ||
import { useEffect, useState, type ReactElement } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
|
||
import { type RemoteFile, type SyncedLocalFile } from 'loot-core/types/file'; | ||
|
||
import { View } from '../components/common/View'; | ||
import { useMetadataPref } from '../hooks/useMetadataPref'; | ||
|
||
import { useAuth } from './AuthProvider'; | ||
import { type Permissions } from './types'; | ||
|
||
type ProtectedRouteProps = { | ||
permission: Permissions; | ||
element: ReactElement; | ||
validateOwner?: boolean; | ||
}; | ||
|
||
export const ProtectedRoute = ({ | ||
element, | ||
permission, | ||
validateOwner, | ||
}: ProtectedRouteProps) => { | ||
const { hasPermission } = useAuth(); | ||
const [permissionGranted, setPermissionGranted] = useState(false); | ||
const [cloudFileId] = useMetadataPref('cloudFileId'); | ||
const allFiles = useSelector(state => state.budgets.allFiles || []); | ||
const remoteFiles = allFiles.filter( | ||
(f): f is SyncedLocalFile | RemoteFile => | ||
f.state === 'remote' || f.state === 'synced' || f.state === 'detached', | ||
); | ||
const currentFile = remoteFiles.find(f => f.cloudFileId === cloudFileId); | ||
const userData = useSelector(state => state.user.data); | ||
|
||
useEffect(() => { | ||
const hasRequiredPermission = hasPermission(permission); | ||
setPermissionGranted(hasRequiredPermission); | ||
|
||
if (!hasRequiredPermission && validateOwner) { | ||
if (currentFile) { | ||
setPermissionGranted( | ||
currentFile.usersWithAccess.some(u => u.userId === userData?.userId), | ||
); | ||
} | ||
} | ||
}, [ | ||
cloudFileId, | ||
permission, | ||
validateOwner, | ||
hasPermission, | ||
currentFile, | ||
userData, | ||
]); | ||
|
||
return permissionGranted ? ( | ||
element | ||
) : ( | ||
<View | ||
style={{ | ||
margin: '50px', | ||
}} | ||
> | ||
<h3>You don't have permission to view this page</h3> | ||
</View> | ||
); | ||
}; |
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,3 @@ | ||
export enum Permissions { | ||
ADMINISTRATOR = 'ADMIN', | ||
} |
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
Oops, something went wrong.