mirror of
https://github.com/outline/outline.git
synced 2026-06-13 03:14:59 +03:00
adbffc0734
* chore: clear mechanical lint warnings Drops 44 oxlint warnings (559 → 515) by fixing easy mechanical rules across the codebase: no-useless-escape, no-duplicate-type-constituents, no-redundant-type-constituents, no-unused-expressions, no-meaningless-void-operator, require-array-sort-compare, await-thenable. * chore: drop callback parameter from useCallback deps The `open` argument is a parameter of the callback, not a closed-over variable, so it doesn't belong in the deps array. * chore: promote cleared lint rules to errors Promotes the rules cleared in this PR from warn to error so future violations fail the lint: - no-unused-expressions - typescript/await-thenable - typescript/no-duplicate-type-constituents - typescript/no-meaningless-void-operator - typescript/require-array-sort-compare Removes the override that suppressed no-useless-escape on source files (the global rule is already error) and fixes the 21 escape violations that this exposed in regex character classes and template literals. * chore: address PR review feedback - usePinnedDocuments: simplify UrlId to plain string instead of the intersection trick. - PlantUML embed: move - to end of character class so it's a literal hyphen rather than a range operator. - checkboxes: type token params as Token | undefined to match the actual call sites that pass tokens[index - 2] etc.
61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
import type { TFunction } from "i18next";
|
|
import capitalize from "lodash/capitalize";
|
|
import uniq from "lodash/uniq";
|
|
import { Scope } from "@shared/types";
|
|
|
|
export class OAuthScopeHelper {
|
|
public static normalizeScopes(scopes: string[], t: TFunction): string[] {
|
|
const methodToReadable = {
|
|
list: t("read"),
|
|
info: t("read"),
|
|
read: t("read"),
|
|
write: t("write"),
|
|
create: t("write"),
|
|
update: t("write"),
|
|
delete: t("write"),
|
|
"*": t("read and write"),
|
|
};
|
|
|
|
const translatedNamespaces = {
|
|
apiKeys: t("API keys"),
|
|
attachments: t("attachments"),
|
|
collections: t("collections"),
|
|
comments: t("comments"),
|
|
documents: t("documents"),
|
|
events: t("events"),
|
|
groups: t("groups"),
|
|
integrations: t("integrations"),
|
|
notifications: t("notifications"),
|
|
reactions: t("reactions"),
|
|
pins: t("pins"),
|
|
shares: t("shares"),
|
|
users: t("users"),
|
|
teams: t("teams"),
|
|
"*": t("workspace"),
|
|
};
|
|
|
|
const normalizedScopes = scopes.map((scope) => {
|
|
if (scope === Scope.Read) {
|
|
return t("Read all data");
|
|
}
|
|
if (scope === Scope.Write) {
|
|
return t("Write all data");
|
|
}
|
|
|
|
const [namespace, method] = scope.replace("/api/", "").split(/[:.]/g);
|
|
const readableMethod =
|
|
methodToReadable[method as keyof typeof methodToReadable] ?? method;
|
|
if (!readableMethod) {
|
|
return scope;
|
|
}
|
|
|
|
const translatedNamespace =
|
|
translatedNamespaces[namespace as keyof typeof translatedNamespaces] ??
|
|
namespace;
|
|
return capitalize(`${readableMethod} ${translatedNamespace}`);
|
|
});
|
|
|
|
return uniq(normalizedScopes);
|
|
}
|
|
}
|