aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/apis/HypothesisAuthenticationManager.tsx164
-rw-r--r--src/client/apis/hypothesis/HypothesisUtils.ts18
-rw-r--r--src/client/util/CurrentUserUtils.ts1
-rw-r--r--src/client/util/SettingsManager.tsx6
-rw-r--r--src/client/views/GlobalKeyHandler.ts2
-rw-r--r--src/client/views/linking/LinkMenuItem.tsx2
-rw-r--r--src/server/ApiManagers/HypothesisManager.ts40
-rw-r--r--src/server/ApiManagers/UploadManager.ts1
-rw-r--r--src/server/apis/google/GoogleApiServerUtils.ts1
-rw-r--r--src/server/database.ts38
-rw-r--r--src/server/index.ts2
11 files changed, 4 insertions, 271 deletions
diff --git a/src/client/apis/HypothesisAuthenticationManager.tsx b/src/client/apis/HypothesisAuthenticationManager.tsx
deleted file mode 100644
index 653f21a7a..000000000
--- a/src/client/apis/HypothesisAuthenticationManager.tsx
+++ /dev/null
@@ -1,164 +0,0 @@
-import { observable, action, reaction, runInAction, IReactionDisposer } from "mobx";
-import { observer } from "mobx-react";
-import * as React from "react";
-import MainViewModal from "../views/MainViewModal";
-import { Opt } from "../../fields/Doc";
-import { Networking } from "../Network";
-import "./HypothesisAuthenticationManager.scss";
-import { Scripting } from "../util/Scripting";
-import { Hypothesis } from "./hypothesis/HypothesisUtils";
-
-const prompt = "Paste authorization code here...";
-
-@observer
-export default class HypothesisAuthenticationManager extends React.Component<{}> {
- public static Instance: HypothesisAuthenticationManager;
- private authenticationLink: Opt<string> = undefined;
- @observable private openState = false;
- @observable private authenticationCode: Opt<string> = undefined;
- @observable private showPasteTargetState = false;
- @observable private success: Opt<boolean> = undefined;
- @observable private displayLauncher = true;
- @observable private credentials: { username: string, apiKey: string } | undefined;
- private disposer: Opt<IReactionDisposer>;
-
- private set isOpen(value: boolean) {
- runInAction(() => this.openState = value);
- }
-
- private set shouldShowPasteTarget(value: boolean) {
- runInAction(() => this.showPasteTargetState = value);
- }
-
- public cancel() {
- this.openState && this.resetState(0, 0);
- }
-
- public fetchAccessToken = async (displayIfFound = false) => {
- const jsonResponse = await Networking.FetchFromServer("/readHypothesisAccessToken");
- const response = jsonResponse !== "" ? JSON.parse(jsonResponse) : undefined;
- // if this is an authentication url, activate the UI to register the new access token
- if (!response) {
- this.isOpen = true;
- this.authenticationLink = response;
- return new Promise<string>(async resolve => {
- this.disposer?.();
- this.disposer = reaction(
- () => this.authenticationCode,
- async authenticationCode => {
- const userProfile = authenticationCode && await Hypothesis.fetchUser(authenticationCode);
- if (userProfile && userProfile.userid !== null) {
- this.disposer?.();
- const hypothesisUsername = Hypothesis.extractUsername(userProfile.userid); // extract username from profile
- Networking.PostToServer("/writeHypothesisAccessToken", { authenticationCode, hypothesisUsername });
- runInAction(() => {
- this.success = true;
- this.credentials = { username: hypothesisUsername, apiKey: authenticationCode! };
- });
- this.resetState();
- resolve(authenticationCode);
- }
- }
- );
- });
- }
-
- if (displayIfFound) {
- runInAction(() => {
- this.success = true;
- this.credentials = response;
- });
- this.resetState(-1, -1);
- this.isOpen = true;
- }
- return response;
- }
-
- resetState = action((visibleForMS: number = 3000, fadesOutInMS: number = 500) => {
- if (!visibleForMS && !fadesOutInMS) {
- runInAction(() => {
- this.isOpen = false;
- this.success = undefined;
- this.displayLauncher = true;
- this.credentials = undefined;
- this.shouldShowPasteTarget = false;
- this.authenticationCode = undefined;
- });
- return;
- }
- this.authenticationCode = undefined;
- this.displayLauncher = false;
- this.shouldShowPasteTarget = false;
- if (visibleForMS > 0 && fadesOutInMS > 0) {
- setTimeout(action(() => {
- this.isOpen = false;
- setTimeout(action(() => {
- this.success = undefined;
- this.displayLauncher = true;
- this.credentials = undefined;
- }), fadesOutInMS);
- }), visibleForMS);
- }
- });
-
- constructor(props: {}) {
- super(props);
- HypothesisAuthenticationManager.Instance = this;
- }
-
- private get renderPrompt() {
- return (
- <div className={'authorize-container'}>
-
- {this.displayLauncher ? <button
- className={"dispatch"}
- onClick={() => {
- this.shouldShowPasteTarget = true;
- }}
- style={{ marginBottom: this.showPasteTargetState ? 15 : 0 }}
- >Authorize a Hypothesis account...</button> : (null)}
- {this.showPasteTargetState ? <input
- className={'paste-target'}
- onChange={action(e => this.authenticationCode = e.currentTarget.value)}
- placeholder={prompt}
- /> : (null)}
- {this.credentials ?
- <>
- <span
- className={'welcome'}
- >Welcome to Dash, {this.credentials.username}
- </span>
- <div
- className={'disconnect'}
- onClick={async () => {
- await Networking.FetchFromServer("/revokeHypothesisAccessToken");
- this.resetState(0, 0);
- }}
- >Disconnect Account</div>
- </> : (null)}
- </div>
- );
- }
-
- private get dialogueBoxStyle() {
- const borderColor = this.success === undefined ? "black" : this.success ? "green" : "red";
- return { borderColor, transition: "0.2s borderColor ease", zIndex: 1002 };
- }
-
- render() {
- return (
- <MainViewModal
- isDisplayed={this.openState}
- interactive={true}
- contents={this.renderPrompt}
- // overlayDisplayedOpacity={0.9}
- dialogueBoxStyle={this.dialogueBoxStyle}
- overlayStyle={{ zIndex: 1001 }}
- closeOnExternalClick={action(() => this.isOpen = false)}
- />
- );
- }
-
-}
-
-Scripting.addGlobal("HypothesisAuthenticationManager", HypothesisAuthenticationManager); \ No newline at end of file
diff --git a/src/client/apis/hypothesis/HypothesisUtils.ts b/src/client/apis/hypothesis/HypothesisUtils.ts
index 8eaad2905..a9d807976 100644
--- a/src/client/apis/hypothesis/HypothesisUtils.ts
+++ b/src/client/apis/hypothesis/HypothesisUtils.ts
@@ -1,5 +1,4 @@
import { StrCast, Cast } from "../../../fields/Types";
-import HypothesisAuthenticationManager from "../HypothesisAuthenticationManager";
import { SearchUtil } from "../../util/SearchUtil";
import { action } from "mobx";
import { Doc } from "../../../fields/Doc";
@@ -8,18 +7,6 @@ import { WebField } from "../../../fields/URLField";
import { DocumentManager } from "../../util/DocumentManager";
export namespace Hypothesis {
- export const fetchUser = async (apiKey: string) => {
- const response = await fetch('https://api.hypothes.is/api/profile', {
- headers: {
- 'Authorization': `Bearer ${apiKey}`,
- },
- });
- if (response.ok) {
- return response.json();
- } else {
- throw new Error('DASH: Error in fetchUser GET request');
- }
- };
// Send Hypothes.is client request to edit an annotation to add a Dash hyperlink
export const makeLink = async (title: string, url: string, annotationId: string) => {
@@ -40,6 +27,7 @@ export namespace Hypothesis {
// Construct an URL which will automatically scroll the web page to a specific annotation's position
export const makeAnnotationUrl = (annotationId: string, baseUrl: string) => {
+ console.log("baseUrl", baseUrl, annotationId);
return `${baseUrl}#annotations:${annotationId}`;
};
@@ -58,8 +46,8 @@ export namespace Hypothesis {
doc.type === DocumentType.WEB && doc.data
);
filteredDocs.forEach(doc => {
- console.log(Cast(doc.data, WebField)?.url.href);
- if (uri === Cast(doc.data, WebField)?.url.href) results.push(doc); // TODO check history? imperfect matches?
+ console.log(uri, Cast(doc.data, WebField)?.url.href, uri === Cast(doc.data, WebField)?.url.href);
+ (uri === Cast(doc.data, WebField)?.url.href) && results.push(doc); // TODO check history? imperfect matches?
});
}));
diff --git a/src/client/util/CurrentUserUtils.ts b/src/client/util/CurrentUserUtils.ts
index ff33d35e0..1fe611b12 100644
--- a/src/client/util/CurrentUserUtils.ts
+++ b/src/client/util/CurrentUserUtils.ts
@@ -441,7 +441,6 @@ export class CurrentUserUtils {
{ toolTip: "Drag a document previewer", title: "Prev", icon: "expand", click: 'openOnRight(getCopy(this.dragFactory, true))', drag: 'getCopy(this.dragFactory,true)', dragFactory: doc.emptyDocHolder as Doc },
{ toolTip: "Toggle a Calculator REPL", title: "repl", icon: "calculator", click: 'addOverlayWindow("ScriptingRepl", { x: 300, y: 100, width: 200, height: 200, title: "Scripting REPL" })' },
{ toolTip: "Connect a Google Account", title: "Google Account", icon: "external-link-alt", click: 'GoogleAuthenticationManager.Instance.fetchOrGenerateAccessToken(true)' },
- { toolTip: "Connect a Hypothesis Account", title: "Hypothesis Account", icon: "heading", click: 'HypothesisAuthenticationManager.Instance.fetchAccessToken(true)' },
];
}
diff --git a/src/client/util/SettingsManager.tsx b/src/client/util/SettingsManager.tsx
index 90d59aa51..a9c2d5e15 100644
--- a/src/client/util/SettingsManager.tsx
+++ b/src/client/util/SettingsManager.tsx
@@ -12,7 +12,6 @@ import { CurrentUserUtils } from "./CurrentUserUtils";
import { Utils } from "../../Utils";
import { Doc } from "../../fields/Doc";
import GroupManager from "./GroupManager";
-import HypothesisAuthenticationManager from "../apis/HypothesisAuthenticationManager";
import GoogleAuthenticationManager from "../apis/GoogleAuthenticationManager";
import { togglePlaygroundMode } from "../../fields/util";
@@ -92,10 +91,6 @@ export default class SettingsManager extends React.Component<{}> {
googleAuthorize = (event: any) => {
GoogleAuthenticationManager.Instance.fetchOrGenerateAccessToken(true);
}
- @action
- hypothesisAuthorize = (event: any) => {
- HypothesisAuthenticationManager.Instance.fetchAccessToken(true);
- }
@action
togglePlaygroundMode = () => {
@@ -118,7 +113,6 @@ export default class SettingsManager extends React.Component<{}> {
<button onClick={this.noviceToggle} value="data">{`Set ${Doc.UserDoc().noviceMode ? "developer" : "novice"} mode`}</button>
<button onClick={this.togglePlaygroundMode}>{`${this.playgroundMode ? "Disable" : "Enable"} playground mode`}</button>
<button onClick={this.googleAuthorize} value="data">{`Link to Google`}</button>
- <button onClick={this.hypothesisAuthorize} value="data">{`Link to Hypothes.is`}</button>
<button onClick={() => GroupManager.Instance.open()}>Manage groups</button>
<button onClick={() => window.location.assign(Utils.prepend("/logout"))}>
{CurrentUserUtils.GuestWorkspace ? "Exit" : "Log Out"}
diff --git a/src/client/views/GlobalKeyHandler.ts b/src/client/views/GlobalKeyHandler.ts
index 086085db5..e1232e6f8 100644
--- a/src/client/views/GlobalKeyHandler.ts
+++ b/src/client/views/GlobalKeyHandler.ts
@@ -7,7 +7,6 @@ import { List } from "../../fields/List";
import { ScriptField } from "../../fields/ScriptField";
import { Cast, PromiseValue } from "../../fields/Types";
import GoogleAuthenticationManager from "../apis/GoogleAuthenticationManager";
-import HypothesisAuthenticationManager from "../apis/HypothesisAuthenticationManager";
import { DocServer } from "../DocServer";
import { DocumentType } from "../documents/DocumentTypes";
import { DictationManager } from "../util/DictationManager";
@@ -107,7 +106,6 @@ export default class KeyManager {
DictationManager.Controls.stop();
// RecommendationsBox.Instance.closeMenu();
GoogleAuthenticationManager.Instance.cancel();
- HypothesisAuthenticationManager.Instance.cancel();
SharingManager.Instance.close();
GroupManager.Instance.close();
CollectionFreeFormViewChrome.Instance.clearKeep();
diff --git a/src/client/views/linking/LinkMenuItem.tsx b/src/client/views/linking/LinkMenuItem.tsx
index 079e130ea..8503bcbeb 100644
--- a/src/client/views/linking/LinkMenuItem.tsx
+++ b/src/client/views/linking/LinkMenuItem.tsx
@@ -156,7 +156,7 @@ export class LinkMenuItem extends React.Component<LinkMenuItemProps> {
const linkDoc = this.props.linkDoc;
if (linkDoc.followLinkLocation === "openExternal" && this.props.destinationDoc.type === DocumentType.WEB) {
- window.open(Hypothesis.makeAnnotationUrl(StrCast(this.props.linkDoc.annotationId), '_blank'));
+ window.open(Hypothesis.makeAnnotationUrl(StrCast(linkDoc.annotationId), StrCast(linkDoc.annotationUri)), '_blank');
return;
}
diff --git a/src/server/ApiManagers/HypothesisManager.ts b/src/server/ApiManagers/HypothesisManager.ts
deleted file mode 100644
index 370d02a49..000000000
--- a/src/server/ApiManagers/HypothesisManager.ts
+++ /dev/null
@@ -1,40 +0,0 @@
-import ApiManager, { Registration } from "./ApiManager";
-import { Method, _permission_denied } from "../RouteManager";
-import { GoogleApiServerUtils } from "../apis/google/GoogleApiServerUtils";
-import { Database } from "../database";
-import { writeFile, readFile, readFileSync, existsSync } from "fs";
-import { serverPathToFile, Directory } from "./UploadManager";
-
-export default class HypothesisManager extends ApiManager {
-
- protected initialize(register: Registration): void {
-
- register({
- method: Method.GET,
- subscription: "/readHypothesisAccessToken",
- secureHandler: async ({ user, res }) => {
- const credentials = await Database.Auxiliary.HypothesisAccessToken.Fetch(user.id);
- res.send(credentials ? { username: credentials.hypothesisUsername, apiKey: credentials.hypothesisApiKey } : "");
- }
- });
-
- register({
- method: Method.POST,
- subscription: "/writeHypothesisAccessToken",
- secureHandler: async ({ user, req, res }) => {
- await Database.Auxiliary.HypothesisAccessToken.Write(user.id, req.body.authenticationCode, req.body.hypothesisUsername);
- res.send();
- }
- });
-
- register({
- method: Method.GET,
- subscription: "/revokeHypothesisAccessToken",
- secureHandler: async ({ user, res }) => {
- await Database.Auxiliary.HypothesisAccessToken.Revoke(user.id);
- res.send();
- }
- });
-
- }
-} \ No newline at end of file
diff --git a/src/server/ApiManagers/UploadManager.ts b/src/server/ApiManagers/UploadManager.ts
index 4455d11eb..bd242db5e 100644
--- a/src/server/ApiManagers/UploadManager.ts
+++ b/src/server/ApiManagers/UploadManager.ts
@@ -26,7 +26,6 @@ export enum Directory {
text = "text",
pdf_thumbnails = "pdf_thumbnails",
audio = "audio",
- hypothesis = "hypothesis"
}
export function serverPathToFile(directory: Directory, filename: string) {
diff --git a/src/server/apis/google/GoogleApiServerUtils.ts b/src/server/apis/google/GoogleApiServerUtils.ts
index b0157a85f..64bafe7fb 100644
--- a/src/server/apis/google/GoogleApiServerUtils.ts
+++ b/src/server/apis/google/GoogleApiServerUtils.ts
@@ -40,7 +40,6 @@ export namespace GoogleApiServerUtils {
export enum Service {
Documents = "Documents",
Slides = "Slides",
- Hypothesis = "Hypothesis"
}
/**
diff --git a/src/server/database.ts b/src/server/database.ts
index 456c1c254..64c5b7e4b 100644
--- a/src/server/database.ts
+++ b/src/server/database.ts
@@ -305,7 +305,6 @@ export namespace Database {
export enum AuxiliaryCollections {
GooglePhotosUploadHistory = "uploadedFromGooglePhotos",
GoogleAccess = "googleAuthentication",
- HypothesisAccess = "hypothesisAuthentication"
}
/**
@@ -406,43 +405,6 @@ export namespace Database {
}
- export namespace HypothesisAccessToken {
- /**
- * Format stored in database.
- */
- interface StoredCredentials {
- userId: string;
- hypothesisApiKey: string;
- hypothesisUsername: string;
- _id?: string;
- }
-
- /**
- * Writes the @param hypothesisApiKey to the database, associated
- * with @param userId for later retrieval and updating.
- */
- export const Write = async (userId: string, hypothesisApiKey: string, hypothesisUsername: string) => {
- return Instance.insert({ userId, hypothesisApiKey, hypothesisUsername }, AuxiliaryCollections.HypothesisAccess);
- };
-
- /**
- * Retrieves the credentials associaed with @param userId
- * and optionally removes their database id according to @param removeId.
- */
- export const Fetch = async (userId: string, removeId = true): Promise<Opt<StoredCredentials>> => {
- return SanitizedSingletonQuery<StoredCredentials>({ userId }, AuxiliaryCollections.HypothesisAccess, removeId);
- };
-
- /**
- * Revokes the credentials associated with @param userId.
- */
- export const Revoke = async (userId: string) => {
- const entry = await Fetch(userId, false);
- if (entry) {
- Instance.delete({ _id: entry._id }, AuxiliaryCollections.HypothesisAccess);
- }
- };
- }
}
}
diff --git a/src/server/index.ts b/src/server/index.ts
index 9af4b00bc..5c313654c 100644
--- a/src/server/index.ts
+++ b/src/server/index.ts
@@ -18,7 +18,6 @@ import PDFManager from "./ApiManagers/PDFManager";
import UploadManager from "./ApiManagers/UploadManager";
import { log_execution } from "./ActionUtilities";
import GeneralGoogleManager from "./ApiManagers/GeneralGoogleManager";
-import HypothesisManager from "./ApiManagers/HypothesisManager";
import GooglePhotosManager from "./ApiManagers/GooglePhotosManager";
import { Logger } from "./ProcessFactory";
import { yellow } from "colors";
@@ -72,7 +71,6 @@ function routeSetter({ isRelease, addSupervisedRoute, logRegistrationOutcome }:
new DeleteManager(),
new UtilManager(),
new GeneralGoogleManager(),
- new HypothesisManager(),
new GooglePhotosManager(),
];