Skip to content
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

Openid #2945

Open
wants to merge 160 commits into
base: master
Choose a base branch
from
Open

Openid #2945

Show file tree
Hide file tree
Changes from 131 commits
Commits
Show all changes
160 commits
Select commit Hold shift + click to select a range
e3a1cd6
OpenId implementation
apilat Jun 21, 2023
cb75f63
Fix bootstrap (doesn't include OpenID yet)
apilat Jun 21, 2023
03acb3b
Add frontend for OpenID bootstrap
apilat Jun 22, 2023
2e13fed
Address code review
apilat Jun 23, 2023
28c323e
Fix typecheck and add release notes
apilat Jun 27, 2023
e3ed86a
Merge branch 'master' into openid
apilat Sep 28, 2023
8696956
Changing the autocomplete search to accept text without accents to ma…
lelemm Jun 5, 2024
29bd12f
lint fix
lelemm Jun 5, 2024
0c35c91
Added upcoming-release-notes
lelemm Jun 5, 2024
4fb4424
Release note authors should be a list.
lelemm Jun 5, 2024
a31861a
Release note file upcoming-release-notes/2842.md body should contain …
lelemm Jun 5, 2024
e4e37a5
smaller 2842.md
lelemm Jun 10, 2024
850865b
Merge branch 'actualbudget:master' into master
lelemm Jun 13, 2024
27aeb09
Merge branch 'actualbudget:master' into master
lelemm Jun 14, 2024
914106e
Merge branch 'actualbudget:master' into master
lelemm Jun 17, 2024
b1d02bf
create schedules from csv import
lelemm Jun 17, 2024
9e4f185
lint
lelemm Jun 17, 2024
939b870
Merge pull request #1 from lelemm/DetectInstallments
lelemm Jun 17, 2024
a86b7a3
merge
lelemm Jun 20, 2024
f2344c0
Merge branch 'actualbudget:master' into master
lelemm Jun 20, 2024
9031ede
Merge branch 'master' into openid
lelemm Jun 20, 2024
cf1b485
working example
lelemm Jun 26, 2024
08a2d32
removed not related files from the original branch
lelemm Jun 26, 2024
262a4ff
REMOVED UNRELATED CUSTOM
lelemm Jun 26, 2024
8cbcc3f
old merge cleanup
lelemm Jun 26, 2024
d921631
Merge branch 'actualbudget:master' into openid
lelemm Jun 26, 2024
ee43263
added me to the md
lelemm Jun 26, 2024
e3118d8
Merge branch 'openid' of https://github.com/lelemm/actual into openid
lelemm Jun 26, 2024
3213048
lint
lelemm Jun 26, 2024
963f11c
cleanup
lelemm Jun 27, 2024
403c73f
cleanup
lelemm Jun 27, 2024
55ff88d
reverting
lelemm Jun 27, 2024
919bc5b
typecheck
lelemm Jun 27, 2024
5a7ef59
lint
lelemm Jun 27, 2024
db47c22
fixes on lint, typecheck and tests
lelemm Jul 11, 2024
4beabb5
Merge branch 'master' into openid
lelemm Jul 11, 2024
9b53173
lint after merge
lelemm Jul 11, 2024
e5feddd
moving to another pc
lelemm Jul 15, 2024
d56e1f2
Removing out of scope features
lelemm Jul 15, 2024
ad1d774
fixes and lint
lelemm Jul 15, 2024
0aa1f74
features
lelemm Jul 23, 2024
eba7af7
more features
lelemm Jul 24, 2024
e5ea5b6
changed from isOpenId to multiuserEnabled
lelemm Jul 24, 2024
637fa93
bug fixes and linter
lelemm Jul 25, 2024
5214fce
Merge remote-tracking branch 'org/master' into openid
lelemm Jul 26, 2024
899494a
merge fixes and linter
lelemm Jul 26, 2024
da7b0d6
Merge remote-tracking branch 'org/master' into openid
lelemm Jul 29, 2024
8389cee
fix for Modal2
lelemm Jul 29, 2024
6eb64df
merge fix
lelemm Jul 29, 2024
7deb883
linter
lelemm Jul 29, 2024
e633c8c
fix to launch demo
lelemm Jul 29, 2024
db82dba
lint
lelemm Jul 29, 2024
618202a
typecheck fixes
lelemm Jul 29, 2024
f8da704
lint
lelemm Jul 29, 2024
ccbabe5
changing error location
lelemm Jul 29, 2024
04369bc
lint
lelemm Jul 29, 2024
57dcb89
change ref
lelemm Jul 29, 2024
b6e7c48
ops, missing errors here
lelemm Jul 29, 2024
c7c1f4a
more typecheck fixes
lelemm Jul 29, 2024
e5ce252
typecheck and lint
lelemm Jul 29, 2024
6522800
lint and typecheck, once again Oo
lelemm Jul 30, 2024
4b72a00
Merge branch 'master' into openid
lelemm Jul 30, 2024
cd6c283
fix for visual regression
lelemm Jul 30, 2024
0c67d72
now typecheck
lelemm Jul 30, 2024
1d06652
why did I deleted this?
lelemm Jul 30, 2024
1226f5b
type-o
lelemm Jul 30, 2024
c4f37c0
looprole
lelemm Jul 30, 2024
cc39152
looprole
lelemm Jul 30, 2024
2c6d71d
deleted the file wrongly
lelemm Jul 30, 2024
12ae11c
revert gitignore changes
lelemm Jul 30, 2024
6a5e520
reverting the only test change
lelemm Jul 30, 2024
c4995f7
fixes
lelemm Jul 30, 2024
2d80c1d
fixes
lelemm Jul 30, 2024
1e04f3a
Merge branch 'openid' of https://github.com/lelemm/actual into openid
lelemm Jul 30, 2024
9a9aeb8
typecheck and test fixes
lelemm Jul 30, 2024
7cc9c30
lint fix
lelemm Jul 30, 2024
e8cfa79
added authentication method to visual regression
lelemm Jul 30, 2024
bd66917
change location of component
lelemm Jul 30, 2024
46301c4
lint again
lelemm Jul 30, 2024
187e841
fixes and QOL improvements
lelemm Jul 30, 2024
e76d74c
fix
lelemm Jul 31, 2024
7a77f86
redirect on login was not working
lelemm Aug 1, 2024
20e8864
fix on login layout
lelemm Aug 1, 2024
1c4e858
QOL changes
lelemm Aug 1, 2024
d3b9659
more fixes
lelemm Aug 1, 2024
e7ae31c
fixes
lelemm Aug 1, 2024
3893b22
missing condition
lelemm Aug 1, 2024
de9664c
more providers
lelemm Aug 1, 2024
9cec67c
linter
lelemm Aug 1, 2024
a134bdc
added keycloak
lelemm Aug 1, 2024
9d70014
typecheck
lelemm Aug 1, 2024
25e4694
more typecheck
lelemm Aug 1, 2024
2ad5123
typecheck
lelemm Aug 1, 2024
2dffea4
linter
lelemm Aug 1, 2024
0bfc25a
typecheck again
lelemm Aug 1, 2024
fc87021
added Authentik
lelemm Aug 2, 2024
817c3a6
Merge branch 'master' into openid
lelemm Aug 2, 2024
0048608
Merge branch 'master' into openid
lelemm Aug 6, 2024
b2ab60a
Merge branch 'master' into openid
lelemm Aug 6, 2024
622b195
typecheck and lint
lelemm Aug 6, 2024
7b14b89
Merge branch 'master' into openid
lelemm Aug 6, 2024
7f405b1
Merge branch 'master' into openid
lelemm Aug 12, 2024
6ce0a93
merge fixes
lelemm Aug 12, 2024
7f10bf2
more merge fixes
lelemm Aug 12, 2024
55246f9
linter
lelemm Aug 13, 2024
cabf174
Merge branch 'master' into openid
lelemm Sep 4, 2024
b2fd2e2
linter
lelemm Sep 4, 2024
780a3d6
Merge branch 'openid' of https://github.com/lelemm/actual into openid
lelemm Sep 4, 2024
75db9a4
Merge branch 'master' into openid
lelemm Sep 4, 2024
ce5ee9b
fixes
lelemm Sep 5, 2024
ea1b56f
linter
lelemm Sep 5, 2024
6a78649
fixes
lelemm Sep 5, 2024
29b87ab
linter
lelemm Sep 5, 2024
8d4745a
linter and typecheck
lelemm Sep 5, 2024
8056d43
PR review suggestion
lelemm Sep 5, 2024
2b20ba1
code review fixes
lelemm Sep 5, 2024
e7c6d79
linter + typecheck
lelemm Sep 5, 2024
d2b8dd6
master user -> server owner
lelemm Sep 5, 2024
12af985
change to link to types of permissions
lelemm Sep 5, 2024
f4cd173
removed debugger
lelemm Sep 5, 2024
25687b2
changes based on feedback
lelemm Sep 5, 2024
c81841f
typecheck
lelemm Sep 5, 2024
c6f66c5
typecheck
lelemm Sep 5, 2024
ffbfd97
vrt
lelemm Sep 5, 2024
3f4b287
linter
lelemm Sep 5, 2024
521b8d2
Merge branch 'master' into openid
lelemm Sep 5, 2024
7cb7918
vrt
lelemm Sep 5, 2024
925337f
Merge branch 'openid' of https://github.com/lelemm/actual into openid
lelemm Sep 5, 2024
9de7cc0
Merge branch 'master' into openid
lelemm Sep 6, 2024
a057f68
vrt
lelemm Sep 6, 2024
01b1273
vrt
lelemm Sep 6, 2024
c37c74d
code review suggestion
lelemm Oct 3, 2024
e5025ca
Merge remote-tracking branch 'org/master' into openid
lelemm Oct 3, 2024
d2ec0c2
typecheck and linter
lelemm Oct 3, 2024
ff992ab
wrong file
lelemm Oct 3, 2024
9c88bc1
Merge remote-tracking branch 'org/master' into openid_rescue
lelemm Oct 3, 2024
59ac6ee
fixes on merge
lelemm Oct 3, 2024
ce1b8b7
Merge branch 'openid' of https://github.com/lelemm/actual into openid
lelemm Oct 3, 2024
76c3fac
linter + typecheck
lelemm Oct 3, 2024
226282e
Update packages/desktop-client/src/components/common/Button2.tsx
lelemm Oct 3, 2024
4750516
Update packages/desktop-client/src/components/LoggedInUser.tsx
lelemm Oct 3, 2024
ddfe646
Update packages/desktop-client/src/components/admin/UserAccess/UserAc…
lelemm Oct 3, 2024
bfc4b5d
ai code review suggestions
lelemm Oct 3, 2024
f789f30
Merge branch 'openid' of https://github.com/lelemm/actual into openid
lelemm Oct 3, 2024
2c13abc
refactors
lelemm Oct 3, 2024
5a23f3f
fixes
lelemm Oct 3, 2024
4d522e5
changed masterCreated to ownerCreated
lelemm Oct 4, 2024
6626f83
changed routes
lelemm Oct 7, 2024
051b29a
WPA adjustment
lelemm Oct 7, 2024
6553314
WPA adjustment
lelemm Oct 7, 2024
5cb9613
fixes
lelemm Oct 7, 2024
97ebff9
fixes and refactories based on actual-server changes
lelemm Oct 8, 2024
43b49e2
more code review
lelemm Oct 8, 2024
7bdff09
linter
lelemm Oct 9, 2024
4453145
trigger actions
lelemm Oct 9, 2024
3ec6cc1
fixes and code enhancement
lelemm Oct 9, 2024
906ed5e
Merge remote-tracking branch 'org/master' into openid
lelemm Nov 8, 2024
d4b0e49
merge fixes
lelemm Nov 8, 2024
30afb0e
fixes after actual-server reviews and fixes from merge
lelemm Nov 8, 2024
ae2506f
fix
lelemm Nov 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/api/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ export function addTransactions(
}

export function importTransactions(accountId, transactions) {
return send('api/transactions-import', { accountId, transactions });
return send('api/transactions-import', {
accountId,
transactions,
});
}

export function getTransactions(accountId, startDate, endDate) {
Expand Down
MikesGlitch marked this conversation as resolved.
Show resolved Hide resolved
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions packages/desktop-client/src/auth/AuthProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React, { createContext, useContext, type ReactNode } from 'react';
import { useSelector } from 'react-redux';

import { type State } from 'loot-core/client/state-types';

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 hasPermission = (permission?: Permissions) => {
if (!permission) {
return true;
}

return (
(userData?.offline ?? false) ||
(userData?.permissions?.includes(permission?.toUpperCase()) ?? false)
);
};

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;
};
59 changes: 59 additions & 0 deletions packages/desktop-client/src/auth/ProtectedRoute.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { useEffect, useState, type ReactElement } from 'react';

import { send } from 'loot-core/platform/client/fetch';

import { View } from '../components/common/View';
import { useLocalPref } from '../hooks/useLocalPref';

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] = useLocalPref('cloudFileId');

useEffect(() => {
if (permissionGranted) {
return;
}

setPermissionGranted(hasPermission(permission));

if (!permissionGranted && validateOwner) {
send('check-file-access', cloudFileId).then(
({ granted }: { granted: boolean }) => {
setPermissionGranted(granted);
},
);
}
}, [
cloudFileId,
permission,
validateOwner,
hasPermission,
permissionGranted,
]);
lelemm marked this conversation as resolved.
Show resolved Hide resolved

return permissionGranted ? (
element
) : (
<View
style={{
margin: '50px',
}}
>
<h3>You don&apos;t have permission to view this page</h3>
</View>
);
};
3 changes: 3 additions & 0 deletions packages/desktop-client/src/auth/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export enum Permissions {
ADMINISTRATOR = 'ADMINISTRATOR',
}
21 changes: 21 additions & 0 deletions packages/desktop-client/src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
send,
} from 'loot-core/src/platform/client/fetch';

import { useActions } from '../hooks/useActions';
import { useMetadataPref } from '../hooks/useMetadataPref';
import { installPolyfills } from '../polyfills';
import { ResponsiveProvider } from '../ResponsiveProvider';
Expand All @@ -47,6 +48,8 @@ function AppInner({ budgetId, cloudFileId }: AppInnerProps) {
const { showBoundary: showErrorBoundary } = useErrorBoundary();
const loadingText = useSelector((state: State) => state.app.loadingText);
const dispatch = useDispatch();
const userData = useSelector((state: State) => state.user.data);
const { signOut, addNotification } = useActions();

async function init() {
const socketName = await global.Actual.getServerSocket();
Expand Down Expand Up @@ -114,6 +117,24 @@ function AppInner({ budgetId, cloudFileId }: AppInnerProps) {
global.Actual.updateAppMenu(budgetId);
}, [budgetId]);

useEffect(() => {
if (userData?.tokenExpired) {
addNotification({
type: 'error',
id: 'login-expired',
title: 'Login expired',
sticky: true,
message: 'Login expired, please login again.',
button: {
title: 'Go to login',
action: () => {
signOut();
},
},
});
}
}, [userData, userData?.tokenExpired]);
Comment on lines +131 to +147
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove duplicate useEffect hooks to eliminate redundancy

The useEffect hooks starting at lines 117 and 135 are identical, resulting in redundant execution of the same code. This can lead to unintended side effects, such as multiple notifications for a single token expiration event. Please remove one of the duplicate useEffect blocks to avoid redundancy.

Apply this diff to remove the duplicate useEffect hook:

-      useEffect(() => {
-        if (userData?.tokenExpired) {
-          addNotification({
-            type: 'error',
-            id: 'login-expired',
-            title: 'Login expired',
-            sticky: true,
-            message: 'Login expired, please login again.',
-            button: {
-              title: 'Go to login',
-              action: () => {
-                signOut();
-              },
-            },
-          });
-        }
-      }, [userData, userData?.tokenExpired]);

Also applies to: 135-151


return (
<>
{(initializing || !budgetId) && (
Expand Down
32 changes: 31 additions & 1 deletion packages/desktop-client/src/components/FinancesApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { type State } from 'loot-core/src/client/state-types';
import { checkForUpdateNotification } from 'loot-core/src/client/update-notification';
import * as undo from 'loot-core/src/platform/client/undo';

import { ProtectedRoute } from '../auth/ProtectedRoute';
import { Permissions } from '../auth/types';
import { useAccounts } from '../hooks/useAccounts';
import { useActions } from '../hooks/useActions';
import { useNavigate } from '../hooks/useNavigate';
Expand All @@ -25,6 +27,7 @@ import { theme } from '../style';
import { ExposeNavigate } from '../util/router-tools';
import { getIsOutdated, getLatestVersion } from '../util/versions';

import { UserAccessPage } from './admin/UserAccess/UserAccessPage';
import { BankSyncStatus } from './BankSyncStatus';
import { BudgetMonthCountProvider } from './budget/BudgetMonthCountContext';
import { View } from './common/View';
Expand All @@ -38,7 +41,9 @@ import { Notifications } from './Notifications';
import { ManagePayeesPage } from './payees/ManagePayeesPage';
import { Reports } from './reports';
import { NarrowAlternate, WideComponent } from './responsive';
import { UserDirectoryPage } from './responsive/wide';
import { ScrollProvider } from './ScrollProvider';
import { useMultiuserEnabled } from './ServerContext';
import { Settings } from './settings';
import { FloatableSidebar } from './sidebar';
import { SidebarProvider } from './sidebar/SidebarProvider';
Expand Down Expand Up @@ -78,6 +83,7 @@ function RouterBehaviors() {
const accountsLoaded = useSelector(
(state: State) => state.queries.accountsLoaded,
);

useEffect(() => {
// If there are no accounts, we want to redirect the user to
// the All Accounts screen which will prompt them to add an account
Expand All @@ -97,6 +103,8 @@ function RouterBehaviors() {

function FinancesAppWithoutContext() {
const actions = useActions();
const multiuserEnabled = useMultiuserEnabled();

useEffect(() => {
// Wait a little bit to make sure the sync button will get the
// sync start event. This can be improved later.
Expand Down Expand Up @@ -219,7 +227,29 @@ function FinancesAppWithoutContext() {
</WideNotSupported>
}
/>

{multiuserEnabled && (
<Route
path="/user-directory"
element={
<ProtectedRoute
permission={Permissions.ADMINISTRATOR}
element={<UserDirectoryPage />}
/>
}
/>
)}
{multiuserEnabled && (
<Route
path="/user-access"
element={
<ProtectedRoute
permission={Permissions.ADMINISTRATOR}
validateOwner={true}
element={<UserAccessPage />}
/>
}
/>
)}
{/* redirect all other traffic to the budget page */}
<Route path="/*" element={<Navigate to="/budget" replace />} />
</Routes>
Expand Down
Loading
Loading