Skip to content

Commit a0ac9b1

Browse files
author
Arvid Paeglit
committed
refactored user approval for file upload using configuration layer and added possibility to say "Always yes"
1 parent fd01941 commit a0ac9b1

7 files changed

Lines changed: 60 additions & 4 deletions

File tree

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@
5858
"default": "",
5959
"description": "API key",
6060
"scope": "application"
61+
},
62+
"deepcode.uploadApproved": {
63+
"type": "boolean",
64+
"default": false,
65+
"markdownDescription": "User consent for code upload to `#deepcode.url#`",
66+
"scope": "window"
6167
}
6268
}
6369
}

src/deepcode/DeepCodeExtension.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ class DeepCodeExtension extends DeepCodeLib implements DeepCode.ExtensionInterfa
2828
context.subscriptions.push(
2929
{ dispose: this.startExtension() },
3030
);
31+
32+
this.runMigration();
33+
}
34+
35+
private runMigration() {
36+
// TODO: remove it after 01.06.2020
37+
// Move 'deepcode.api.cloudBackend' to 'deepcode.url' configuration
38+
const config = vscode.workspace.getConfiguration('deepcode');
39+
const oldBaseURL = config.get('api.cloudBackend');
40+
if (!config.get('url') && oldBaseURL) {
41+
config.update('url', oldBaseURL, true);
42+
}
3143
}
3244

3345
public startExtension(): any {

src/deepcode/lib/modules/BaseDeepCodeModule.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default class BaseDeepCodeModule implements DeepCode.BaseDeepCodeModuleIn
2828
public staticToken = '';
2929
public staticBaseURL = '';
3030
public defaultBaseURL = 'https://www.deepcode.ai';
31+
public staticuUploadApproved = false;
3132

3233
constructor() {
3334
this.store = new DeepCodeStore();
@@ -51,7 +52,7 @@ export default class BaseDeepCodeModule implements DeepCode.BaseDeepCodeModuleIn
5152
}
5253

5354
public get termsConditionsUrl(): string {
54-
return `${this.baseURL}tc?utm_source=vsc`;
55+
return `${this.baseURL}/tc?utm_source=vsc`;
5556
}
5657

5758
public get token(): string {
@@ -63,4 +64,13 @@ export default class BaseDeepCodeModule implements DeepCode.BaseDeepCodeModuleIn
6364
this.staticToken = '';
6465
vscode.workspace.getConfiguration('deepcode').update('token', value, true);
6566
}
67+
68+
public get uploadApproved(): boolean {
69+
return this.staticuUploadApproved || !!(vscode.workspace.getConfiguration('deepcode').get('uploadApproved'));
70+
}
71+
72+
public async approveUpload(isGlobal: boolean = false): Promise<void> {
73+
await vscode.workspace.getConfiguration('deepcode').update('uploadApproved', true, isGlobal);
74+
}
75+
6676
}

src/deepcode/lib/modules/BundlesModule.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ class BundlesModule extends LoginModule
8585
throw error;
8686
}
8787

88+
public async askUploadApproval(): Promise<void> {
89+
const { uploadApproval } = deepCodeMessages;
90+
let pressedButton: string | undefined;
91+
92+
pressedButton = await vscode.window.showInformationMessage(uploadApproval.msg(this.termsConditionsUrl), uploadApproval.workspace, uploadApproval.global);
93+
if (pressedButton) {
94+
await this.approveUpload(pressedButton === uploadApproval.global);
95+
}
96+
}
97+
8898
// processing workspaces
8999
public updateCurrentWorkspacePath(newWorkspacePath: string): void {
90100
this.currentWorkspacePath = newWorkspacePath;

src/deepcode/lib/modules/DeepCodeLib.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,25 @@ export default class DeepCodeLib extends BundlesModule implements DeepCode.DeepC
5555

5656
await this.updateHashesBundles();
5757

58+
// First, check logged in or not
5859
let loggedIn = await this.checkSession();
5960
if (!loggedIn) {
6061
await this.initiateLogin();
6162
loggedIn = await this.checkSession();
63+
if (!loggedIn) {
64+
return;
65+
}
6266
}
6367

64-
if (!loggedIn) {
65-
return;
68+
// Second, check user consent on sending files to server
69+
if (!this.uploadApproved) {
70+
await this.askUploadApproval();
71+
if (!this.uploadApproved) {
72+
return;
73+
}
6674
}
67-
75+
76+
// Third, initiate analysis
6877
try {
6978
// Main entry point to
7079
for await (const path of this.workspacesPaths) {

src/deepcode/messages/deepCodeMessages.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ export const deepCodeMessages = {
33
msg: "Login to your account to obtain your API key and start analysing the code with DeepCode.",
44
button: "Proceed"
55
},
6+
uploadApproval: {
7+
msg: (termsConditionsUrl: string): string =>
8+
`You are almost set 🤗. Let's confirm and start the remote analysis of this workspace ([DeepCode's Terms & Conditions](${termsConditionsUrl}))`,
9+
workspace: "Yes",
10+
global: "Always yes"
11+
},
612
error: {
713
msg: "DeepCode encountered a problem.",
814
button: "Restart"

src/interfaces/DeepCodeInterfaces.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ namespace DeepCode {
190190
baseURL: string;
191191
termsConditionsUrl: string;
192192
token: string;
193+
uploadApproved: boolean;
194+
approveUpload(): Promise<void>;
193195
analyzer: DeepCode.AnalyzerInterface;
194196
statusBarItem: StatusBarItemInterface;
195197
filesWatcher: DeepCodeWatcherInterface;
@@ -204,6 +206,7 @@ namespace DeepCode {
204206
}
205207

206208
export interface BundlesModuleInterface {
209+
askUploadApproval(): Promise<void>;
207210
createFilesFilterList(): Promise<void>;
208211
createWorkspacesList(workspaces: WorkspaceFolder[]): void;
209212
changeWorkspaceList(workspacePath: string, deleteAddFlag?: boolean): void;

0 commit comments

Comments
 (0)