Add Report Abuse dialog for public gallery notebooks (#265)

![image](https://user-images.githubusercontent.com/693092/95408825-3975a680-08d5-11eb-812b-80f922ab9fc8.png)
This commit is contained in:
Tanuj Mittal
2020-10-12 16:48:05 -07:00
committed by GitHub
parent daba1c4ed4
commit 3b64d75322
13 changed files with 317 additions and 105 deletions

View File

@@ -1,6 +1,5 @@
import ko from "knockout";
import { HttpStatusCodes } from "../Common/Constants";
import * as ViewModels from "../Contracts/ViewModels";
import { HttpHeaders, HttpStatusCodes } from "../Common/Constants";
import { IPinnedRepo, JunoClient, IGalleryItem } from "./JunoClient";
import { configContext } from "../ConfigContext";
import { getAuthorizationHeader } from "../Utils/AuthorizationUtils";
@@ -237,7 +236,7 @@ describe("Gallery", () => {
method: "PATCH",
headers: {
[authorizationHeader.header]: authorizationHeader.token,
"content-type": "application/json"
[HttpHeaders.contentType]: "application/json"
}
}
);
@@ -260,7 +259,7 @@ describe("Gallery", () => {
method: "PATCH",
headers: {
[authorizationHeader.header]: authorizationHeader.token,
"content-type": "application/json"
[HttpHeaders.contentType]: "application/json"
}
}
);
@@ -281,7 +280,7 @@ describe("Gallery", () => {
method: "PATCH",
headers: {
[authorizationHeader.header]: authorizationHeader.token,
"content-type": "application/json"
[HttpHeaders.contentType]: "application/json"
}
});
});
@@ -299,7 +298,7 @@ describe("Gallery", () => {
expect(window.fetch).toBeCalledWith(`${configContext.JUNO_ENDPOINT}/api/notebooks/gallery/favorites`, {
headers: {
[authorizationHeader.header]: authorizationHeader.token,
"content-type": "application/json"
[HttpHeaders.contentType]: "application/json"
}
});
});
@@ -317,7 +316,7 @@ describe("Gallery", () => {
expect(window.fetch).toBeCalledWith(`${configContext.JUNO_ENDPOINT}/api/notebooks/gallery/published`, {
headers: {
[authorizationHeader.header]: authorizationHeader.token,
"content-type": "application/json"
[HttpHeaders.contentType]: "application/json"
}
});
});
@@ -337,7 +336,7 @@ describe("Gallery", () => {
method: "DELETE",
headers: {
[authorizationHeader.header]: authorizationHeader.token,
"content-type": "application/json"
[HttpHeaders.contentType]: "application/json"
}
});
});
@@ -364,7 +363,7 @@ describe("Gallery", () => {
method: "PUT",
headers: {
[authorizationHeader.header]: authorizationHeader.token,
"content-type": "application/json"
[HttpHeaders.contentType]: "application/json"
},
body: JSON.stringify({
name,

View File

@@ -1,5 +1,5 @@
import ko from "knockout";
import { HttpStatusCodes } from "../Common/Constants";
import { HttpHeaders, HttpStatusCodes } from "../Common/Constants";
import { configContext } from "../ConfigContext";
import * as DataModels from "../Contracts/DataModels";
import { AuthorizeAccessComponent } from "../Explorer/Controls/GitHub/AuthorizeAccessComponent";
@@ -404,6 +404,30 @@ export class JunoClient {
return `${this.getNotebooksUrl()}/gallery/${id}`;
}
public async reportAbuse(notebookId: string, abuseCategory: string, notes: string): Promise<IJunoResponse<boolean>> {
const response = await window.fetch(`${this.getNotebooksUrl()}/avert/reportAbuse`, {
method: "POST",
body: JSON.stringify({
notebookId,
abuseCategory,
notes
}),
headers: {
[HttpHeaders.contentType]: "application/json"
}
});
let data: boolean;
if (response.status === HttpStatusCodes.OK) {
data = await response.json();
}
return {
status: response.status,
data
};
}
private async getNotebooks(input: RequestInfo, init?: RequestInit): Promise<IJunoResponse<IGalleryItem[]>> {
const response = await window.fetch(input, init);
@@ -430,7 +454,7 @@ export class JunoClient {
const authorizationHeader = getAuthorizationHeader();
return {
[authorizationHeader.header]: authorizationHeader.token,
"content-type": "application/json"
[HttpHeaders.contentType]: "application/json"
};
}