From dc967be4fc1ab336720350bdc8e4b7e0e4c12bc9 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Wed, 10 Mar 2021 14:56:34 -0800 Subject: [PATCH] chore: Syncs changes that were erroneously made in enterprise repo (#1949) --- app/components/Checkbox.js | 3 ++- app/components/Input.js | 11 +++++++---- app/scenes/Document/components/Document.js | 4 +++- app/scenes/Settings/components/SlackButton.js | 4 ++-- app/stores/AuthStore.js | 2 +- server/middlewares/validation.js | 6 ++++++ server/models/Document.js | 2 ++ server/models/User.js | 3 ++- server/utils/jwt.js | 10 +++++++++- 9 files changed, 34 insertions(+), 11 deletions(-) diff --git a/app/components/Checkbox.js b/app/components/Checkbox.js index 73068677f..281e5764f 100644 --- a/app/components/Checkbox.js +++ b/app/components/Checkbox.js @@ -6,7 +6,7 @@ import HelpText from "components/HelpText"; export type Props = {| checked?: boolean, - label?: string, + label?: React.Node, labelHidden?: boolean, className?: string, name?: string, @@ -26,6 +26,7 @@ const LabelText = styled.span` const Wrapper = styled.div` padding-bottom: 8px; ${(props) => (props.small ? "font-size: 14px" : "")}; + width: 100%; `; const Label = styled.label` diff --git a/app/components/Input.js b/app/components/Input.js index 8ca02b24c..f279af693 100644 --- a/app/components/Input.js +++ b/app/components/Input.js @@ -42,6 +42,7 @@ const RealInput = styled.input` const Wrapper = styled.div` flex: ${(props) => (props.flex ? "1" : "0")}; + width: ${(props) => (props.short ? "49%" : "auto")}; max-width: ${(props) => (props.short ? "350px" : "100%")}; min-height: ${({ minHeight }) => (minHeight ? `${minHeight}px` : "0")}; max-height: ${({ maxHeight }) => (maxHeight ? `${maxHeight}px` : "initial")}; @@ -55,7 +56,6 @@ const IconWrapper = styled.span` `; export const Outline = styled(Flex)` - display: flex; flex: 1; margin: ${(props) => props.margin !== undefined ? props.margin : "0 0 16px"}; @@ -64,7 +64,7 @@ export const Outline = styled(Flex)` border-style: solid; border-color: ${(props) => props.hasError - ? "red" + ? props.theme.danger : props.focused ? props.theme.inputBorderFocused : props.theme.inputBorder}; @@ -81,7 +81,7 @@ export const LabelText = styled.div` `; export type Props = {| - type?: "text" | "email" | "checkbox" | "search", + type?: "text" | "email" | "checkbox" | "search" | "textarea", value?: string, label?: string, className?: string, @@ -97,8 +97,11 @@ export type Props = {| autoComplete?: boolean | string, readOnly?: boolean, required?: boolean, + disabled?: boolean, placeholder?: string, - onChange?: (ev: SyntheticInputEvent) => mixed, + onChange?: ( + ev: SyntheticInputEvent + ) => mixed, onFocus?: (ev: SyntheticEvent<>) => void, onBlur?: (ev: SyntheticEvent<>) => void, |}; diff --git a/app/scenes/Document/components/Document.js b/app/scenes/Document/components/Document.js index f52105c98..b396bb29a 100644 --- a/app/scenes/Document/components/Document.js +++ b/app/scenes/Document/components/Document.js @@ -452,7 +452,9 @@ class DocumentScene extends React.Component { - {isShare && !isCustomDomain() && } + {isShare && !isCustomDomain() && ( + + )} {!isShare && } ); diff --git a/app/scenes/Settings/components/SlackButton.js b/app/scenes/Settings/components/SlackButton.js index 240d47189..fec74ee7b 100644 --- a/app/scenes/Settings/components/SlackButton.js +++ b/app/scenes/Settings/components/SlackButton.js @@ -9,11 +9,11 @@ import env from "env"; type Props = { scopes?: string[], redirectUri: string, - state: string, + state?: string, label?: string, }; -function SlackButton({ state, scopes, redirectUri, label }: Props) { +function SlackButton({ state = "", scopes, redirectUri, label }: Props) { const handleClick = () => (window.location.href = slackAuth( state, diff --git a/app/stores/AuthStore.js b/app/stores/AuthStore.js index 95b0e2992..48f01972e 100644 --- a/app/stores/AuthStore.js +++ b/app/stores/AuthStore.js @@ -174,7 +174,7 @@ export default class AuthStore { runInAction("AuthStore#updateUser", () => { this.addPolicies(res.policies); - this.user = res.data; + this.user = new User(res.data); }); } finally { this.isSaving = false; diff --git a/server/middlewares/validation.js b/server/middlewares/validation.js index 78795ae44..d7cc3e3b4 100644 --- a/server/middlewares/validation.js +++ b/server/middlewares/validation.js @@ -48,6 +48,12 @@ export default function validation() { } }; + ctx.assertValueInArray = (value, values, message) => { + if (!values.includes(value)) { + throw new ValidationError(message); + } + }; + return next(); }; } diff --git a/server/models/Document.js b/server/models/Document.js index 0ec336332..d0b165f49 100644 --- a/server/models/Document.js +++ b/server/models/Document.js @@ -95,6 +95,8 @@ const Document = sequelize.define( }, getterMethods: { url: function () { + if (!this.title) return `/doc/untitled-${this.urlId}`; + const slugifiedTitle = slugify(this.title); return `/doc/${slugifiedTitle}-${this.urlId}`; }, diff --git a/server/models/User.js b/server/models/User.js index fc179767a..02a4ab01c 100644 --- a/server/models/User.js +++ b/server/models/User.js @@ -60,11 +60,12 @@ const User = sequelize.define( return original; } + const initial = this.name ? this.name[0] : "?"; const hash = crypto .createHash("md5") .update(this.email || "") .digest("hex"); - return `${DEFAULT_AVATAR_HOST}/avatar/${hash}/${this.name[0]}.png`; + return `${DEFAULT_AVATAR_HOST}/avatar/${hash}/${initial}.png`; }, }, } diff --git a/server/utils/jwt.js b/server/utils/jwt.js index a71ce4d23..b372339c6 100644 --- a/server/utils/jwt.js +++ b/server/utils/jwt.js @@ -69,7 +69,15 @@ export async function getUserForEmailSigninToken(token: string): Promise { } } - const user = await User.findByPk(payload.id); + const user = await User.findByPk(payload.id, { + include: [ + { + model: Team, + as: "team", + required: true, + }, + ], + }); // if user has signed in at all since the token was created then // it's no longer valid, they'll need a new one.