Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit304e9c9

Browse files
committed
Add user settings page for revoking OAuth2 apps
1 parent72c8ab7 commit304e9c9

File tree

5 files changed

+203
-0
lines changed

5 files changed

+203
-0
lines changed

‎site/src/AppRouter.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ const ExternalAuthPage = lazy(
156156
constUserExternalAuthSettingsPage=lazy(
157157
()=>import("./pages/UserSettingsPage/ExternalAuthPage/ExternalAuthPage"),
158158
);
159+
constUserOAuth2ProviderSettingsPage=lazy(
160+
()=>
161+
import("./pages/UserSettingsPage/OAuth2ProviderPage/OAuth2ProviderPage"),
162+
);
159163
constTemplateVersionPage=lazy(
160164
()=>import("./pages/TemplateVersionPage/TemplateVersionPage"),
161165
);
@@ -362,6 +366,10 @@ export const AppRouter: FC = () => {
362366
path="external-auth"
363367
element={<UserExternalAuthSettingsPage/>}
364368
/>
369+
<Route
370+
path="oauth2-provider"
371+
element={<UserOAuth2ProviderSettingsPage/>}
372+
/>
365373
<Routepath="tokens">
366374
<Routeindexelement={<TokensPage/>}/>
367375
<Routepath="new"element={<CreateTokenPage/>}/>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import{typeFC,useState}from"react";
2+
import{useMutation,useQuery,useQueryClient}from"react-query";
3+
import{getErrorMessage}from"api/errors";
4+
import{getApps,revokeApp}from"api/queries/oauth2";
5+
importtype*asTypesGenfrom"api/typesGenerated";
6+
import{DeleteDialog}from"components/Dialogs/DeleteDialog/DeleteDialog";
7+
import{displayError,displaySuccess}from"components/GlobalSnackbar/utils";
8+
import{useMe}from"hooks";
9+
import{Section}from"../Section";
10+
importOAuth2ProviderPageViewfrom"./OAuth2ProviderPageView";
11+
12+
constOAuth2ProviderPage:FC=()=>{
13+
constme=useMe();
14+
constqueryClient=useQueryClient();
15+
constuserOAuth2AppsQuery=useQuery(getApps(me.id));
16+
constrevokeAppMutation=useMutation(revokeApp(queryClient,me.id));
17+
const[appToRevoke,setAppToRevoke]=useState<TypesGen.OAuth2ProviderApp>();
18+
19+
return(
20+
<Sectiontitle="OAuth2 Applications"layout="fluid">
21+
<OAuth2ProviderPageView
22+
isLoading={userOAuth2AppsQuery.isLoading}
23+
error={userOAuth2AppsQuery.error}
24+
apps={userOAuth2AppsQuery.data}
25+
revoke={(app)=>{
26+
setAppToRevoke(app);
27+
}}
28+
/>
29+
{appToRevoke!==undefined&&(
30+
<DeleteDialog
31+
title="Revoke Application"
32+
verb="Revoking"
33+
info={`This will invalidate any tokens created by the OAuth2 application "${appToRevoke.name}".`}
34+
label="Name of the application to revoke"
35+
isOpen
36+
confirmLoading={revokeAppMutation.isLoading}
37+
name={appToRevoke.name}
38+
entity="application"
39+
onCancel={()=>setAppToRevoke(undefined)}
40+
onConfirm={async()=>{
41+
try{
42+
awaitrevokeAppMutation.mutateAsync(appToRevoke.id);
43+
displaySuccess(
44+
`You have successfully revoked the OAuth2 application "${appToRevoke.name}"`,
45+
);
46+
setAppToRevoke(undefined);
47+
}catch(error){
48+
displayError(
49+
getErrorMessage(error,"Failed to revoke application."),
50+
);
51+
}
52+
}}
53+
/>
54+
)}
55+
</Section>
56+
);
57+
};
58+
59+
exportdefaultOAuth2ProviderPage;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
importtype{Meta,StoryObj}from"@storybook/react";
2+
import{MockOAuth2ProviderApps}from"testHelpers/entities";
3+
importOAuth2ProviderPageViewfrom"./OAuth2ProviderPageView";
4+
5+
constmeta:Meta<typeofOAuth2ProviderPageView>={
6+
title:"pages/UserSettingsPage/OAuth2ProviderPageView",
7+
component:OAuth2ProviderPageView,
8+
};
9+
10+
exportdefaultmeta;
11+
typeStory=StoryObj<typeofOAuth2ProviderPageView>;
12+
13+
exportconstLoading:Story={
14+
args:{
15+
isLoading:true,
16+
revoke:()=>undefined,
17+
},
18+
};
19+
20+
exportconstError:Story={
21+
args:{
22+
isLoading:false,
23+
error:"some error",
24+
revoke:()=>undefined,
25+
},
26+
};
27+
28+
exportconstApps:Story={
29+
args:{
30+
isLoading:false,
31+
apps:MockOAuth2ProviderApps,
32+
revoke:()=>undefined,
33+
},
34+
};
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
importButtonfrom"@mui/material/Button";
2+
importTablefrom"@mui/material/Table";
3+
importTableBodyfrom"@mui/material/TableBody";
4+
importTableCellfrom"@mui/material/TableCell";
5+
importTableContainerfrom"@mui/material/TableContainer";
6+
importTableHeadfrom"@mui/material/TableHead";
7+
importTableRowfrom"@mui/material/TableRow";
8+
import{typeFC}from"react";
9+
importtype*asTypesGenfrom"api/typesGenerated";
10+
import{AvatarData}from"components/AvatarData/AvatarData";
11+
import{Avatar}from"components/Avatar/Avatar";
12+
import{ErrorAlert}from"components/Alert/ErrorAlert";
13+
import{TableLoader}from"components/TableLoader/TableLoader";
14+
15+
exporttypeOAuth2ProviderPageViewProps={
16+
isLoading:boolean;
17+
error?:unknown;
18+
apps?:TypesGen.OAuth2ProviderApp[];
19+
revoke:(app:TypesGen.OAuth2ProviderApp)=>void;
20+
};
21+
22+
constOAuth2ProviderPageView:FC<OAuth2ProviderPageViewProps>=({
23+
isLoading,
24+
error,
25+
apps,
26+
revoke,
27+
})=>{
28+
return(
29+
<TableContainer>
30+
<Table>
31+
<TableHead>
32+
<TableRow>
33+
<TableCellwidth="100%">Name</TableCell>
34+
<TableCellwidth="1%"/>
35+
</TableRow>
36+
</TableHead>
37+
<TableBody>
38+
{isLoading&&<TableLoader/>}
39+
{!isLoading&&
40+
apps?.map((app)=>(
41+
<OAuth2AppRowkey={app.id}app={app}revoke={revoke}/>
42+
))}
43+
{!isLoading&&(!apps||apps?.length===0)&&(
44+
<TableRow>
45+
<TableCellcolSpan={999}>
46+
{error ?(
47+
<ErrorAlerterror={error}/>
48+
) :(
49+
<divcss={{textAlign:"center"}}>
50+
No OAuth2 applications have been authorized.
51+
</div>
52+
)}
53+
</TableCell>
54+
</TableRow>
55+
)}
56+
</TableBody>
57+
</Table>
58+
</TableContainer>
59+
);
60+
};
61+
62+
typeOAuth2AppRowProps={
63+
app:TypesGen.OAuth2ProviderApp;
64+
revoke:(app:TypesGen.OAuth2ProviderApp)=>void;
65+
};
66+
67+
constOAuth2AppRow:FC<OAuth2AppRowProps>=({ app, revoke})=>{
68+
return(
69+
<TableRowkey={app.id}data-testid={`app-${app.id}`}>
70+
<TableCell>
71+
<AvatarData
72+
title={app.name}
73+
avatar={
74+
Boolean(app.icon)&&(
75+
<Avatarsrc={app.icon}variant="square"fitImage/>
76+
)
77+
}
78+
/>
79+
</TableCell>
80+
81+
<TableCell>
82+
<Button
83+
variant="contained"
84+
size="small"
85+
color="error"
86+
onClick={()=>revoke(app)}
87+
>
88+
Revoke&hellip;
89+
</Button>
90+
</TableCell>
91+
</TableRow>
92+
);
93+
};
94+
95+
exportdefaultOAuth2ProviderPageView;

‎site/src/pages/UserSettingsPage/Sidebar.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import AccountIcon from "@mui/icons-material/Person";
55
importAppearanceIconfrom"@mui/icons-material/Brush";
66
importScheduleIconfrom"@mui/icons-material/EditCalendarOutlined";
77
importSecurityIconfrom"@mui/icons-material/LockOutlined";
8+
importTokenfrom"@mui/icons-material/Token";
89
importtype{User}from"api/typesGenerated";
910
import{UserAvatar}from"components/UserAvatar/UserAvatar";
1011
import{
@@ -23,6 +24,7 @@ export const Sidebar: FC<SidebarProps> = ({ user }) => {
2324
const{ entitlements}=useDashboard();
2425
constshowSchedulePage=
2526
entitlements.features.advanced_template_scheduling.enabled;
27+
constshowOAuth2Page=entitlements.features.oauth2_provider.enabled;
2628

2729
return(
2830
<BaseSidebar>
@@ -53,6 +55,11 @@ export const Sidebar: FC<SidebarProps> = ({ user }) => {
5355
<SidebarNavItemhref="external-auth"icon={GitIcon}>
5456
External Authentication
5557
</SidebarNavItem>
58+
{showOAuth2Page&&(
59+
<SidebarNavItemhref="oauth2-provider"icon={Token}>
60+
OAuth2 Applications
61+
</SidebarNavItem>
62+
)}
5663
<SidebarNavItemhref="tokens"icon={VpnKeyOutlined}>
5764
Tokens
5865
</SidebarNavItem>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp