mirror of
https://github.com/outline/outline.git
synced 2026-11-25 15:15:15 +03:00
Authorize styling, scope conversion
This commit is contained in:
1 parent
b7425fefc6
commit
d13770ddf9
3 files changed
+73
-1177
No files matched your search
@@ -8,12 +8,14 @@ import { Avatar, AvatarSize } from "~/components/Avatar";
|
||||
import ButtonLarge from "~/components/ButtonLarge";
|
||||
import ChangeLanguage from "~/components/ChangeLanguage";
|
||||
import Heading from "~/components/Heading";
|
||||
import PageTitle from "~/components/PageTitle";
|
||||
import Text from "~/components/Text";
|
||||
import useCurrentTeam from "~/hooks/useCurrentTeam";
|
||||
import useQuery from "~/hooks/useQuery";
|
||||
import useRequest from "~/hooks/useRequest";
|
||||
import { client } from "~/utils/ApiClient";
|
||||
import { detectLanguage } from "~/utils/language";
|
||||
import { OAuthHelper } from "./OAuthHelper";
|
||||
import { Background } from "./components/Background";
|
||||
import { Centered } from "./components/Centered";
|
||||
|
||||
@@ -58,7 +60,7 @@ function Authorize() {
|
||||
<Background>
|
||||
<ChangeLanguage locale={detectLanguage()} />
|
||||
<Centered>
|
||||
<StyledHeading>{t("Error")}</StyledHeading>
|
||||
<StyledHeading>{t("An error occurred")}</StyledHeading>
|
||||
<Text as="p" type="secondary">
|
||||
{t("Required OAuth parameters are missing")}
|
||||
<Pre>
|
||||
@@ -80,8 +82,8 @@ function Authorize() {
|
||||
<Background>
|
||||
<ChangeLanguage locale={detectLanguage()} />
|
||||
<Centered>
|
||||
<StyledHeading>{t("Error")}</StyledHeading>
|
||||
<p>{t("Unable to load OAuth client")}</p>
|
||||
<StyledHeading>{t("An error occurred")}</StyledHeading>
|
||||
<p>{t("Unable to load details of OAuth client")}</p>
|
||||
</Centered>
|
||||
</Background>
|
||||
);
|
||||
@@ -94,6 +96,7 @@ function Authorize() {
|
||||
|
||||
return (
|
||||
<Background>
|
||||
<PageTitle title={t("Authorize")} />
|
||||
<ChangeLanguage locale={detectLanguage()} />
|
||||
|
||||
<Centered gap={12}>
|
||||
@@ -110,16 +113,26 @@ function Authorize() {
|
||||
<Logo model={team} size={AvatarSize.XXLarge} alt={t("Logo")} />
|
||||
</Flex>
|
||||
<StyledHeading>
|
||||
{response.data.name} wants to access {team.name}
|
||||
{t(`{{ appName }} wants to access {{ teamName }}`, {
|
||||
appName: response.data.name,
|
||||
teamName: team.name,
|
||||
})}
|
||||
</StyledHeading>
|
||||
<p>
|
||||
{scopes.map((item) => (
|
||||
<>
|
||||
{item}
|
||||
<br />
|
||||
</>
|
||||
<Text type="tertiary" as="p">
|
||||
{t(
|
||||
"{{ appName }} will be able to access your account and perform the following actions:",
|
||||
{
|
||||
appName: response.data.name,
|
||||
}
|
||||
)}
|
||||
</Text>
|
||||
<ul style={{ width: "100%", paddingLeft: "1em", marginTop: 0 }}>
|
||||
{OAuthHelper.normalizeScopes(scopes).map((item) => (
|
||||
<li key={item}>
|
||||
<Text type="secondary">{item}</Text>
|
||||
</li>
|
||||
))}
|
||||
</p>
|
||||
</ul>
|
||||
<form method="POST" action="/oauth/authorize" style={{ width: "100%" }}>
|
||||
<input type="hidden" name="client_id" value={clientId ?? ""} />
|
||||
<input
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import { t } from "i18next";
|
||||
import capitalize from "lodash/capitalize";
|
||||
import uniq from "lodash/uniq";
|
||||
|
||||
export class OAuthHelper {
|
||||
public static normalizeScopes(scopes: string[]): 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("manage"),
|
||||
};
|
||||
|
||||
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) => {
|
||||
const [namespace, method] = scope.replace("/api/", "").split(/[:\.]/g);
|
||||
const readableMethod =
|
||||
methodToReadable[method as keyof typeof methodToReadable] ?? method;
|
||||
const translatedNamespace =
|
||||
translatedNamespaces[namespace as keyof typeof translatedNamespaces] ??
|
||||
namespace;
|
||||
return capitalize(`${readableMethod} ${translatedNamespace}`);
|
||||
});
|
||||
|
||||
return uniq(normalizedScopes);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user