Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Add staff token entry and session controls

Neeraj Guptac0cc984b9e36
diff --git a/infra/staff/src/App.css b/infra/staff/src/App.css
index 060b652b81..ce33fda593 100644
--- a/infra/staff/src/App.css
+++ b/infra/staff/src/App.css
@@ -9,6 +9,33 @@
margin: 0 auto;
}
+.token-entry {
+ width: 408px;
+ max-width: 100vw;
+ justify-content: center;
+ padding: 24px;
+ box-sizing: border-box;
+}
+
+.token-entry p {
+ margin-top: 0;
+}
+
+.token-form {
+ display: flex;
+ flex-direction: column;
+ gap: 16px;
+ width: 100%;
+ max-width: 360px;
+ margin: 8px auto;
+}
+
+.token-form-actions {
+ display: flex;
+ justify-content: flex-end;
+ gap: 8px;
+}
+
.input-form {
display: flex;
flex-direction: column;
diff --git a/infra/staff/src/App.tsx b/infra/staff/src/App.tsx
index 4ed0350991..e4bd047793 100644
--- a/infra/staff/src/App.tsx
+++ b/infra/staff/src/App.tsx
@@ -1,7 +1,14 @@
+import MoreVertIcon from "@mui/icons-material/MoreVert";
import {
Box,
Button,
CircularProgress,
+ Dialog,
+ DialogContent,
+ DialogTitle,
+ IconButton,
+ Menu,
+ MenuItem,
Tab,
Tabs,
TextField,
@@ -40,6 +47,11 @@ export const App: React.FC = () => {
const [authToken] = useState(
() => urlCredentials.token ?? localStorage.getItem("token") ?? "",
);
+ const [tokenInput, setTokenInput] = useState("");
+ const [tokenDialogOpen, setTokenDialogOpen] = useState(false);
+ const [tokenMenuAnchor, setTokenMenuAnchor] = useState<HTMLElement | null>(
+ null,
+ );
const [selectedUserEmail, setSelectedUserEmail] = useState(
urlCredentials.email ?? "",
);
@@ -65,8 +77,24 @@ export const App: React.FC = () => {
} else {
localStorage.removeItem("token");
}
+ removeTokenFromUrl();
}, [authToken]);
+ const handleTokenSubmit = (event: React.SubmitEvent<HTMLFormElement>) => {
+ event.preventDefault();
+ const token = tokenInput.trim();
+ if (!token) return;
+ localStorage.setItem("token", token);
+ removeTokenFromUrl();
+ window.location.reload();
+ };
+
+ const handleLogout = () => {
+ localStorage.removeItem("token");
+ removeTokenFromUrl();
+ window.location.reload();
+ };
+
const fetchData = useCallback(async (input: string, authToken: string) => {
const requestID = ++searchRequestID.current;
setLoading(true);
@@ -196,6 +224,41 @@ export const App: React.FC = () => {
}
};
+ const tokenForm = (
+ <form className="token-form" onSubmit={handleTokenSubmit}>
+ <TextField
+ label="Staff token"
+ type="password"
+ value={tokenInput}
+ onChange={(event) => setTokenInput(event.target.value)}
+ autoComplete="off"
+ autoFocus
+ required
+ fullWidth
+ />
+ <div className="token-form-actions">
+ {authToken && (
+ <Button onClick={() => setTokenDialogOpen(false)}>
+ Cancel
+ </Button>
+ )}
+ <Button type="submit" variant="contained">
+ {authToken ? "Update token" : "Continue"}
+ </Button>
+ </div>
+ </form>
+ );
+
+ if (!authToken) {
+ return (
+ <div className="container token-entry">
+ <h1>Ente Staff</h1>
+ <p>Enter your staff token to continue.</p>
+ {tokenForm}
+ </div>
+ );
+ }
+
return (
<StaffSessionProvider session={session}>
<div className="container">
@@ -244,6 +307,33 @@ export const App: React.FC = () => {
fetchData(selectedUserEmail, authToken)
}
/>
+ <IconButton
+ aria-label="Staff session options"
+ color="inherit"
+ onClick={(event) =>
+ setTokenMenuAnchor(event.currentTarget)
+ }
+ >
+ <MoreVertIcon />
+ </IconButton>
+ <Menu
+ anchorEl={tokenMenuAnchor}
+ open={Boolean(tokenMenuAnchor)}
+ onClose={() => setTokenMenuAnchor(null)}
+ >
+ <MenuItem
+ onClick={() => {
+ setTokenMenuAnchor(null);
+ setTokenInput("");
+ setTokenDialogOpen(true);
+ }}
+ >
+ Update token
+ </MenuItem>
+ <MenuItem onClick={handleLogout}>
+ Log out
+ </MenuItem>
+ </Menu>
</div>
</div>
</form>
@@ -335,6 +425,15 @@ export const App: React.FC = () => {
/>
)}
</div>
+ <Dialog
+ open={tokenDialogOpen}
+ onClose={() => setTokenDialogOpen(false)}
+ fullWidth
+ maxWidth="xs"
+ >
+ <DialogTitle>Update staff token</DialogTitle>
+ <DialogContent>{tokenForm}</DialogContent>
+ </Dialog>
</div>
</StaffSessionProvider>
);
@@ -345,6 +444,13 @@ const readUrlCredentials = () => {
return { email: urlParams.get("email"), token: urlParams.get("token") };
};
+const removeTokenFromUrl = () => {
+ const url = new URL(window.location.href);
+ if (!url.searchParams.has("token")) return;
+ url.searchParams.delete("token");
+ window.history.replaceState(window.history.state, "", url);
+};
+
const noSearchableAccountMessage =
"No active account or searchable scheduled deletion found. For older deletions, find the user ID in logs and use the existing recovery flow.";