Skip to content

Commit

Permalink
associate user info to directory (#301) (#305)
Browse files Browse the repository at this point in the history
* associate user info to directory (#301)

* associate user info to directory (#301)

* associate user info to directory (#301)
  • Loading branch information
xuwenyihust authored Aug 3, 2024
1 parent bc2efbf commit 7728c67
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 58 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
# Runs a set of commands using the runners shell
- name: Maven Package
run: |
cd examples/word-count
cd examples/[email protected]/word-count
mvn clean package
version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
Expand All @@ -50,7 +50,7 @@ jobs:

- name: Docker Build & Push
run: |
cd examples/word-count
cd examples/[email protected]/word-count
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/word-count:$VERSION_WITH_TIMESTAMP --build-arg VERSION=$VERSION .
docker push ${{ secrets.DOCKERHUB_USERNAME }}/word-count:$VERSION_WITH_TIMESTAMP
Expand Down
40 changes: 23 additions & 17 deletions docker/postgres/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ CREATE TABLE users (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
password_hash VARCHAR(255) NOT NULL,
email VARCHAR(100) NOT NULL
email VARCHAR(100) NOT NULL UNIQUE
);

CREATE TABLE notebooks (
Expand Down Expand Up @@ -43,22 +43,28 @@ GRANT ALL PRIVILEGES ON TABLE spark_apps TO server;


-- Add some initial data
-- 12345A
INSERT INTO users (name, password_hash, email) VALUES ('user_0', 'scrypt:32768:8:1$1k6HpQA8N58PkDz7$db383b0d69d7a2f6893116b1955da70cb217173dc44ce169acf57cfe6a79f63118ad7515563a0b4f8f39dda49510d061acdba26be8f7c8786c161dd54d7a91c1', '[email protected]');
INSERT INTO users (name, password_hash, email) VALUES ('user_1', 'pbkdf2:sha256:150000$3Z6Z6Z6Z$e3', '[email protected]');
-- user_0 -12345A
INSERT INTO users (name, password_hash, email) VALUES
('user_0', 'scrypt:32768:8:1$1k6HpQA8N58PkDz7$db383b0d69d7a2f6893116b1955da70cb217173dc44ce169acf57cfe6a79f63118ad7515563a0b4f8f39dda49510d061acdba26be8f7c8786c161dd54d7a91c1', '[email protected]'),
('user_1', 'pbkdf2:sha256:150000$3Z6Z6Z6Z$e3', '[email protected]');

INSERT INTO notebooks (name, path, user_id) VALUES ('demo.ipynb', 'work/demo.ipynb', 1);
INSERT INTO notebooks (name, path, user_id) VALUES ('notebook.ipynb', 'work/notebook.ipynb', 1);
INSERT INTO notebooks (name, path, user_id) VALUES ('quickstart.ipynb', 'work/quickstart.ipynb', 1);
INSERT INTO notebooks (name, path, user_id) VALUES ('sg-resale-flat-prices.ipynb', 'work/sg-resale-flat-prices/sg-resale-flat-prices.ipynb', 1);
INSERT INTO notebooks (name, path, user_id) VALUES
('demo.ipynb', 'work/[email protected]/demo.ipynb', 1),
('notebook.ipynb', 'work/[email protected]/notebook.ipynb', 1),
('quickstart.ipynb', 'work/[email protected]/quickstart.ipynb', 1),
('sg-resale-flat-prices.ipynb', 'work/[email protected]/sg-resale-flat-prices/sg-resale-flat-prices.ipynb', 1);

INSERT INTO directories (name, path, user_id) VALUES ('work', '/work', 1);
INSERT INTO directories (name, path, user_id) VALUES ('word-count', '/work/word-count', 1);
INSERT INTO directories (name, path, user_id) VALUES ('sg-resale-flat-prices', '/work/sg-resale-flat-prices', 1);
INSERT INTO directories (name, path, user_id) VALUES ('output', '/work/sg-resale-flat-prices/output', 1);
INSERT INTO directories (name, path, user_id) VALUES
-- ('work', '/work', 1),
('[email protected]', '/work/[email protected]', 1),
('word-count', '/work/[email protected]/word-count', 1),
('sg-resale-flat-prices', '/work/[email protected]/sg-resale-flat-prices', 1),
('output', '/work/[email protected]/sg-resale-flat-prices/output', 1),
('[email protected]', '/work/[email protected]', 1);

INSERT INTO spark_apps (spark_app_id, notebook_id) VALUES ('app-0000-0000', 1);
INSERT INTO spark_apps (spark_app_id, notebook_id) VALUES ('app-0000-0001', 1);
INSERT INTO spark_apps (spark_app_id, notebook_id) VALUES ('app-0000-0002', 1);
INSERT INTO spark_apps (spark_app_id, notebook_id) VALUES ('app-0000-0003', 2);
INSERT INTO spark_apps (spark_app_id, notebook_id) VALUES ('app-0000-0004', 2);
INSERT INTO spark_apps (spark_app_id, notebook_id) VALUES
('app-0000-0000', 1),
('app-0000-0001', 1),
('app-0000-0002', 1),
('app-0000-0003', 2),
('app-0000-0004', 2);
32 changes: 0 additions & 32 deletions examples/666

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions server/app/routes/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def login():
return Response(
response=json.dumps({
'message': 'Login successful',
'name': g.user.name,
'email': g.user.email,
'access_token': access_token
}),
status=200
Expand Down
14 changes: 12 additions & 2 deletions webapp/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const theme = createTheme({

const App = () => {
const [isLoggedIn, setIsLoggedIn] = useState(false);
const [username, setUsername] = useState('');
const [useremail, setUseremail] = useState('');

const [showHistoryServer, setShowHistoryServer] = useState(false);
const [showScheduler, setShowScheduler] = useState(false);
Expand All @@ -45,6 +47,7 @@ const App = () => {

const [openWorkspaceDrawer, setOpenWorkspaceDrawer] = useState(false);
const [currentPath, setCurrentPath] = useState('work');
const [rootPath, setRootPath] = useState('work');
const [workspaceFiles, setWorkspaceFiles] = useState([]);
const [refreshKey, setRefreshKey] = useState(0);

Expand Down Expand Up @@ -140,7 +143,13 @@ const App = () => {
};

if (!isLoggedIn) {
return <LoginForm onLogin={() => setIsLoggedIn(true)} />;
return <LoginForm onLogin={(username, useremail) => {
setUsername(username);
setUseremail(useremail);
setCurrentPath(`work/${useremail}`);
setRootPath(`work/${useremail}`);
setIsLoggedIn(true)}
} />;
}

return (
Expand All @@ -156,7 +165,8 @@ const App = () => {
currentPath={currentPath}
setCurrentPath={setCurrentPath}
setRefreshKey={setRefreshKey}
workspaceFiles={workspaceFiles}/>
workspaceFiles={workspaceFiles}
rootPath={rootPath}/>
<Notebook
showNotebook={showNotebook}
notebook={notebook}
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/components/auth/LoginForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ function LoginForm({ onLogin }) {
console.log('Logged in successfully');
const data = await response.json();
const token = data.access_token;
const useremail = data.email;
sessionStorage.setItem('token', token);
onLogin(username, password);
onLogin(username, useremail, password);
} else {
// The login failed
// You might want to show an error message here
Expand Down
6 changes: 4 additions & 2 deletions webapp/src/components/sidebar/Sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ function Sidebar({
currentPath,
setCurrentPath,
setRefreshKey,
workspaceFiles}) {
workspaceFiles,
rootPath}) {

const itemHeight = 35;

Expand Down Expand Up @@ -183,7 +184,8 @@ function Sidebar({
currentPath={currentPath}
setCurrentPath={setCurrentPath}
setRefreshKey={setRefreshKey}
workspaceFiles={workspaceFiles}/>
workspaceFiles={workspaceFiles}
rootPath={rootPath}/>
)}

{/* History Server */}
Expand Down
9 changes: 7 additions & 2 deletions webapp/src/components/sidebar/workspace/WorkspaceSidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ function WorkspaceSidebar({
currentPath,
setCurrentPath,
setRefreshKey,
workspaceFiles}) {
workspaceFiles,
rootPath}) {

const workspaceSidebarWidth = 300;

const handleBackClick = () => {
const parentPath = currentPath.split('/').slice(0, -1).join('/');
setCurrentPath(parentPath || 'work'); // Navigate to parent directory or root if at top level
if (parentPath === 'work') {
setCurrentPath(rootPath);
} else {
setCurrentPath(parentPath);
}
};

return (
Expand Down

0 comments on commit 7728c67

Please sign in to comment.