Skip to content

Commit 0f51a29

Browse files
agriyakhetarpalgithub-actions[bot]peytondmurray
authored
Make passwords non-editable (#40)
* Make passwords non-editable * Lint * Remove input rectangle around password * Lint again * Comment about TODO changes in notebook name * Lint yet again * Update Playwright Snapshots * Update Playwright Snapshots * Bump @playwright/test and dependencies * Fix location for password box * Update Playwright Snapshots * Simplify destructuring Co-Authored-By: Peyton Murray <[email protected]> * Drop redundant password generation * Remove TODO note --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Peyton Murray <[email protected]>
1 parent 312ccf5 commit 0f51a29

File tree

6 files changed

+44
-85
lines changed

6 files changed

+44
-85
lines changed

src/index.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ const plugin: JupyterFrontEndPlugin<void> = {
132132
});
133133

134134
if (result.button.accept) {
135-
const shareDialogData = result.value as IShareDialogData;
136-
const { notebookName, isViewOnly, password } = shareDialogData;
135+
const { notebookName, password } = result.value as IShareDialogData;
137136

138137
try {
139138
// Show loading indicator
@@ -154,16 +153,9 @@ const plugin: JupyterFrontEndPlugin<void> = {
154153

155154
let shareResponse;
156155
if (isNewShare) {
157-
shareResponse = await sharingService.share(
158-
notebookContent,
159-
isViewOnly ? password : undefined
160-
);
156+
shareResponse = await sharingService.share(notebookContent, password);
161157
} else if (notebookId) {
162-
shareResponse = await sharingService.update(
163-
notebookId,
164-
notebookContent,
165-
isViewOnly ? password : undefined
166-
);
158+
shareResponse = await sharingService.update(notebookId, notebookContent, password);
167159
}
168160

169161
if (shareResponse && shareResponse.notebook) {
@@ -176,7 +168,7 @@ const plugin: JupyterFrontEndPlugin<void> = {
176168
notebookContent.metadata.sharedId = shareResponse.notebook.id;
177169
notebookContent.metadata.readableId = shareResponse.notebook.readable_id;
178170
notebookContent.metadata.sharedName = notebookName;
179-
notebookContent.metadata.isPasswordProtected = isViewOnly;
171+
notebookContent.metadata.isPasswordProtected = true;
180172

181173
notebookPanel.context.model.fromJSON(notebookContent);
182174
}
@@ -195,9 +187,7 @@ const plugin: JupyterFrontEndPlugin<void> = {
195187
title: isNewShare
196188
? 'Notebook Shared Successfully'
197189
: 'Notebook Updated Successfully',
198-
body: ReactWidget.create(
199-
createSuccessDialog(shareableLink, isNewShare, isViewOnly)
200-
),
190+
body: ReactWidget.create(createSuccessDialog(shareableLink, isNewShare, true)),
201191
buttons: [
202192
Dialog.okButton({ label: 'Copy Link' }),
203193
Dialog.cancelButton({ label: 'Close' })

src/ui-components/share-dialog.tsx

Lines changed: 17 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import React from 'react';
77
*/
88
export interface IShareDialogData {
99
notebookName: string;
10-
isViewOnly: boolean;
1110
password: string;
1211
}
1312

@@ -31,22 +30,13 @@ const ShareDialogComponent = () => {
3130
return password;
3231
};
3332

34-
const [notebookName, setNotebookName] = React.useState(generateDefaultName());
35-
const [isViewOnly, setIsViewOnly] = React.useState(false);
36-
const [password, setPassword] = React.useState(generatePassword());
33+
const [notebookName, setNotebookName] = React.useState<string>(generateDefaultName());
34+
const [password] = React.useState<string>(generatePassword());
3735

3836
const handleNameChange = (e: React.ChangeEvent<HTMLInputElement>) => {
3937
setNotebookName(e.target.value);
4038
};
4139

42-
const handleViewOnlyChange = (e: React.ChangeEvent<HTMLInputElement>) => {
43-
setIsViewOnly(e.target.checked);
44-
};
45-
46-
const handlePasswordChange = (e: React.ChangeEvent<HTMLInputElement>) => {
47-
setPassword(e.target.value);
48-
};
49-
5040
return (
5141
<div>
5242
<label htmlFor="notebook-name">Notebook Name:</label>
@@ -64,73 +54,52 @@ const ShareDialogComponent = () => {
6454
/>
6555

6656
<div style={{ marginBottom: '15px' }}>
67-
<input
68-
id="view-only"
69-
type="checkbox"
70-
checked={isViewOnly}
71-
onChange={handleViewOnlyChange}
72-
style={{ marginRight: '5px' }}
73-
/>
74-
<label htmlFor="view-only">Share as view-only notebook (password-protected)</label>
75-
</div>
76-
77-
<div style={{ marginBottom: '15px' }}>
78-
<label htmlFor="password">Password:</label>
79-
<input
57+
<label htmlFor="password">
58+
Here's the code required to edit the original notebook. Make sure to save this code as it
59+
will not appear again:
60+
</label>
61+
<div
8062
id="password"
81-
type="text"
82-
value={password}
83-
onChange={handlePasswordChange}
84-
disabled={!isViewOnly}
8563
style={{
8664
width: '100%',
87-
padding: '5px'
65+
padding: '5px',
66+
fontFamily: 'monospace',
67+
fontSize: '14px'
8868
}}
89-
/>
69+
>
70+
{password}
71+
</div>
9072
</div>
9173
</div>
9274
);
9375
};
9476

9577
export class ShareDialog extends ReactWidget {
9678
private _notebookName: string;
97-
private _isViewOnly: boolean;
98-
private _password: string;
9979

10080
constructor() {
10181
super();
10282
// Generate default values
10383
const today = new Date();
10484
this._notebookName = `Notebook_${today.getFullYear()}-${(today.getMonth() + 1).toString().padStart(2, '0')}-${today.getDate().toString().padStart(2, '0')}`;
105-
this._isViewOnly = false;
106-
107-
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
108-
let password = '';
109-
for (let i = 0; i < 8; i++) {
110-
password += chars.charAt(Math.floor(Math.random() * chars.length));
111-
}
112-
this._password = password;
11385
}
11486

11587
getValue(): IShareDialogData {
11688
// Get current values from the DOM
11789
const nameInput = this.node.querySelector('#notebook-name') as HTMLInputElement;
118-
const viewOnlyCheckbox = this.node.querySelector('#view-only') as HTMLInputElement;
119-
const passwordInput = this.node.querySelector('#password') as HTMLInputElement;
90+
const passwordDiv = this.node.querySelector('#password') as HTMLDivElement;
12091

121-
if (nameInput && viewOnlyCheckbox && passwordInput) {
92+
if (nameInput && passwordDiv && passwordDiv.textContent) {
12293
return {
12394
notebookName: nameInput.value,
124-
isViewOnly: viewOnlyCheckbox.checked,
125-
password: passwordInput.value
95+
password: passwordDiv.textContent
12696
};
12797
}
12898

12999
// Fallback to stored values
130100
return {
131101
notebookName: this._notebookName,
132-
isViewOnly: this._isViewOnly,
133-
password: this._password
102+
password: '' // This shouldn't really happen since the component always renders a password
134103
};
135104
}
136105

ui-tests/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"test:update": "jlpm playwright test --update-snapshots"
1010
},
1111
"devDependencies": {
12-
"@playwright/test": "^1.37.0",
13-
"@jupyterlab/application": "^4.0.0"
12+
"@jupyterlab/application": "^4.0.0",
13+
"@playwright/test": "^1.52.0"
1414
}
1515
}

ui-tests/tests/jupytereverywhere.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ test.describe('Sharing', () => {
5555
const dialog = page.locator('.jp-Dialog-content');
5656
expect(
5757
await dialog.screenshot({
58-
mask: [dialog.locator('input#notebook-name'), dialog.locator('input#password')],
58+
mask: [dialog.locator('input#notebook-name'), dialog.locator('div#password')],
5959
maskColor: '#888888'
6060
})
6161
).toMatchSnapshot('share-dialog.png');
1.1 KB
Loading

ui-tests/yarn.lock

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ __metadata:
585585
languageName: node
586586
linkType: hard
587587

588-
"@playwright/test@npm:^1.37.0":
588+
"@playwright/test@npm:^1.52.0":
589589
version: 1.52.0
590590
resolution: "@playwright/test@npm:1.52.0"
591591
dependencies:
@@ -597,8 +597,8 @@ __metadata:
597597
linkType: hard
598598

599599
"@rjsf/core@npm:^5.13.4":
600-
version: 5.24.10
601-
resolution: "@rjsf/core@npm:5.24.10"
600+
version: 5.24.11
601+
resolution: "@rjsf/core@npm:5.24.11"
602602
dependencies:
603603
lodash: ^4.17.21
604604
lodash-es: ^4.17.21
@@ -608,13 +608,13 @@ __metadata:
608608
peerDependencies:
609609
"@rjsf/utils": ^5.24.x
610610
react: ^16.14.0 || >=17
611-
checksum: 90316d9dd90ae58805fc4f6fa2bb14dfd9a361abebb75bd3b1b7ed55b554e9a7d5145fc09ee5906bc91d362fc8f8c24619d4d4c432bae782da5cebb0a5b9cddf
611+
checksum: 7bceac697e7a289fb88c6e88e78a6fc50628ebb3064d63fa7e3244a1189c6a42c582a779c52b828e8b60fdc9ff81b5468c5e60a28392061fa2eab022e6a3c2d4
612612
languageName: node
613613
linkType: hard
614614

615615
"@rjsf/utils@npm:^5.13.4":
616-
version: 5.24.10
617-
resolution: "@rjsf/utils@npm:5.24.10"
616+
version: 5.24.11
617+
resolution: "@rjsf/utils@npm:5.24.11"
618618
dependencies:
619619
json-schema-merge-allof: ^0.8.1
620620
jsonpointer: ^5.0.1
@@ -623,7 +623,7 @@ __metadata:
623623
react-is: ^18.2.0
624624
peerDependencies:
625625
react: ^16.14.0 || >=17
626-
checksum: 64d9bcfea100c4b89128c20473982d316e960c01f9887fb3613bc0ecdaa9fdf8804f96ff99b0b415c2cbc7b4f7d5de941328a1a1a5d53148489d395a1f07a78e
626+
checksum: 81e716c5e34b5f194a384c75059aff2cb7c7f639f7998179c7648c280bf9c76b6e97ef22e3a99d4afaf8228f48acc499e39eca8574872ed75a97337c0e6072f6
627627
languageName: node
628628
linkType: hard
629629

@@ -635,12 +635,12 @@ __metadata:
635635
linkType: hard
636636

637637
"@types/react@npm:^18.0.26":
638-
version: 18.3.22
639-
resolution: "@types/react@npm:18.3.22"
638+
version: 18.3.23
639+
resolution: "@types/react@npm:18.3.23"
640640
dependencies:
641641
"@types/prop-types": "*"
642642
csstype: ^3.0.2
643-
checksum: e69bdec2df18397e0ecc48e0e858ba331e56130b0b2cd1561098dcdddf04a8aa1ae0b51a294d60d0ade13bfabe5670131a3bd82bedca3b323d51de2b9cd0debd
643+
checksum: d781257d42bf3c66f4bcd21e76a86cd9b6e21fbaf377fe0f840f1ff35049efa59491aa6a4dcf2b3db42af4ab085acebe185f0ae28b7c36d60be5e9094c707bdd
644644
languageName: node
645645
linkType: hard
646646

@@ -951,14 +951,14 @@ __metadata:
951951
linkType: hard
952952

953953
"fdir@npm:^6.4.4":
954-
version: 6.4.4
955-
resolution: "fdir@npm:6.4.4"
954+
version: 6.4.5
955+
resolution: "fdir@npm:6.4.5"
956956
peerDependencies:
957957
picomatch: ^3 || ^4
958958
peerDependenciesMeta:
959959
picomatch:
960960
optional: true
961-
checksum: 79043610236579ffbd0647c508b43bd030a2d034a17c43cf96813a00e8e92e51acdb115c6ddecef3b5812cc2692b976155b4f6413e51e3761f1e772fa019a321
961+
checksum: 14efd2d6617a6f9fb314916ccff64e00bdb96216f26542ec9dfa532ed60a7ebb45463f7009aa215c14071566bf43caeb8ba268ccb52a11e6b51e4aaa8cb58d81
962962
languageName: node
963963
linkType: hard
964964

@@ -1205,7 +1205,7 @@ __metadata:
12051205
resolution: "jupytereverywhere-ui-tests@workspace:."
12061206
dependencies:
12071207
"@jupyterlab/application": ^4.0.0
1208-
"@playwright/test": ^1.37.0
1208+
"@playwright/test": ^1.52.0
12091209
languageName: unknown
12101210
linkType: soft
12111211

@@ -1397,7 +1397,7 @@ __metadata:
13971397
languageName: node
13981398
linkType: hard
13991399

1400-
"nanoid@npm:^3.3.7, nanoid@npm:^3.3.8":
1400+
"nanoid@npm:^3.3.11, nanoid@npm:^3.3.7":
14011401
version: 3.3.11
14021402
resolution: "nanoid@npm:3.3.11"
14031403
bin:
@@ -1535,13 +1535,13 @@ __metadata:
15351535
linkType: hard
15361536

15371537
"postcss@npm:^8.3.11":
1538-
version: 8.5.3
1539-
resolution: "postcss@npm:8.5.3"
1538+
version: 8.5.4
1539+
resolution: "postcss@npm:8.5.4"
15401540
dependencies:
1541-
nanoid: ^3.3.8
1541+
nanoid: ^3.3.11
15421542
picocolors: ^1.1.1
15431543
source-map-js: ^1.2.1
1544-
checksum: da574620eb84ff60e65e1d8fc6bd5ad87a19101a23d0aba113c653434161543918229a0f673d89efb3b6d4906287eb04b957310dbcf4cbebacad9d1312711461
1544+
checksum: 7ede5eb54aa56767a61541f13ca9994ce56d93340bc3c99328c741e5cc6c0024510e31667be108e3d29e5189d434ae8476c820e8c0ce90cf942d8a2faf1eb876
15451545
languageName: node
15461546
linkType: hard
15471547

0 commit comments

Comments
 (0)