Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Author block #1172

Merged
merged 31 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
59d0781
WIP
george-misan Aug 20, 2023
f0798d5
Add Author InnerBlock
george-misan Aug 21, 2023
fed8491
Add Author InnerBlock
george-misan Aug 21, 2023
fbf9825
update AuthorBlock
george-misan Aug 22, 2023
748f3a8
+ responsiveness to AUthorBlock
george-misan Aug 23, 2023
393b16a
resolve merge conflicts
george-misan Aug 23, 2023
7443364
remove unused import
george-misan Aug 23, 2023
00b3b18
update AuthorEditor style
george-misan Aug 24, 2023
52baf86
update AuthorEditor style
george-misan Aug 24, 2023
6595038
add page containing AuthorBlock to seed_courses.rs
george-misan Aug 25, 2023
26df370
+ test for Author block
george-misan Aug 25, 2023
964592c
add test
george-misan Aug 25, 2023
28417c5
add missing comma
george-misan Aug 25, 2023
a553432
update snapshot
george-misan Aug 25, 2023
6e6312c
update snapshot
george-misan Aug 26, 2023
e4663d2
WIP
george-misan Aug 29, 2023
096ff30
WIP
george-misan Aug 29, 2023
81e4bc3
Add broken example code
nygrenh Aug 29, 2023
bc3716e
update author in seed_course
george-misan Aug 30, 2023
8f54965
remove unused import
george-misan Aug 30, 2023
d9c52d4
add assets
george-misan Aug 30, 2023
00d8e6f
remove unused code
george-misan Aug 30, 2023
cf172f2
update seed_courses
george-misan Aug 30, 2023
090c3ab
Show block name in the default block
nygrenh Aug 30, 2023
bb43158
update seed_courses
george-misan Aug 30, 2023
9d5f4bc
fetch from upstream
george-misan Aug 30, 2023
22f5238
update snapshots
george-misan Aug 30, 2023
a622496
run cargo-fmt
george-misan Aug 30, 2023
5216ba2
Close browser contexts
nygrenh Aug 31, 2023
de772ad
update snapshot
george-misan Aug 31, 2023
161b80b
Misc fixes
nygrenh Aug 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions services/cms/src/blocks/Author/AuthorEditor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { css } from "@emotion/css"
import { InnerBlocks } from "@wordpress/block-editor"
import { BlockEditProps, Template } from "@wordpress/blocks"
import React from "react"
import { useTranslation } from "react-i18next"

import { baseTheme, headingFont } from "../../shared-module/styles"
import BlockWrapper from "../BlockWrapper"

const ALLOWED_NESTED_BLOCKS = ["moocfi/author-inner-block"]
const AUTHOR_BLOCK_TEMPLATE: Template[] = [["moocfi/author-inner-block"]]
const AuthorEditor: React.FC<React.PropsWithChildren<BlockEditProps<Record<string, never>>>> = ({
clientId,
}) => {
const { t } = useTranslation()
return (
<BlockWrapper id={clientId}>
<div>
<div
className={css`
padding: 1rem;
background: ${baseTheme.colors.clear[100]};
text-align: center;
font-family: ${headingFont};
`}
>
<h4>{t("authors-block")}</h4>
<span
className={css`
color: ${baseTheme.colors.gray[600]};
text-align: center;
font-weight: 500;
display: inline-block;
margin-bottom: 1.4rem;
font-family: ${headingFont};
`}
>
{t("authors-block-description")}
</span>

<div>
<InnerBlocks allowedBlocks={ALLOWED_NESTED_BLOCKS} template={AUTHOR_BLOCK_TEMPLATE} />
</div>
</div>
</div>
</BlockWrapper>
)
}

export default AuthorEditor
11 changes: 11 additions & 0 deletions services/cms/src/blocks/Author/AuthorSave.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { InnerBlocks } from "@wordpress/block-editor"

const AuthorSave: React.FC<unknown> = () => {
return (
<div>
<InnerBlocks.Content />
</div>
)
}

export default AuthorSave
18 changes: 18 additions & 0 deletions services/cms/src/blocks/Author/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* eslint-disable i18next/no-literal-string */
import { BlockConfiguration } from "@wordpress/blocks"

import { MOOCFI_CATEGORY_SLUG } from "../../utils/Gutenberg/modifyGutenbergCategories"

import AuthorEditor from "./AuthorEditor"
import AuthorSave from "./AuthorSave"

const AuthorConfiguration: BlockConfiguration = {
title: "Authors",
description: "Author Section",
category: MOOCFI_CATEGORY_SLUG,
attributes: {},
edit: AuthorEditor,
save: AuthorSave,
}

export default AuthorConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { InnerBlocks } from "@wordpress/block-editor"
import { BlockEditProps, Template } from "@wordpress/blocks"
import React from "react"

import BlockWrapper from "../BlockWrapper"

const ALLOWED_NESTED_BLOCKS = ["core/image", "core/paragraph"]
const AUTHOR_BLOCK_TEMPLATE: Template[] = [
[
"core/columns",
{ isStackedOnMobile: true },
[
[
"core/column",
{},
[
[
"core/image",
{
level: 2,
textAlign: "left",
anchor: "author-photo",
},
],
],
],
[
"core/column",
{},
[
[
"core/paragraph",
{
content: "Insert author's bio text...",
placeholder: "Insert author's bio text...",
align: "left",
},
],
],
],
],
],
]

const AuthorEditor: React.FC<React.PropsWithChildren<BlockEditProps<Record<string, never>>>> = ({
clientId,
}) => {
return (
<BlockWrapper id={clientId}>
<div>
<InnerBlocks allowedBlocks={ALLOWED_NESTED_BLOCKS} template={AUTHOR_BLOCK_TEMPLATE} />
</div>
</BlockWrapper>
)
}

export default AuthorEditor
11 changes: 11 additions & 0 deletions services/cms/src/blocks/AuthorInnerBlock/AuthorInnerBlockSave.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { InnerBlocks } from "@wordpress/block-editor"

const AuthorInnerBlockSave: React.FC<unknown> = () => {
return (
<div>
<InnerBlocks.Content />
</div>
)
}

export default AuthorInnerBlockSave
18 changes: 18 additions & 0 deletions services/cms/src/blocks/AuthorInnerBlock/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* eslint-disable i18next/no-literal-string */
import { BlockConfiguration } from "@wordpress/blocks"

import { MOOCFI_CATEGORY_SLUG } from "../../utils/Gutenberg/modifyGutenbergCategories"

import AuthorInnerBlockEditor from "./AuthorInnerBlockEditor"
import AuthorInnerBlockSave from "./AuthorInnerBlockSave"

const AuthorInnerBlockConfiguration: BlockConfiguration = {
title: "AuthorInnerBlock",
description: "Author InnerBlock",
category: MOOCFI_CATEGORY_SLUG,
attributes: {},
edit: AuthorInnerBlockEditor,
save: AuthorInnerBlockSave,
}

export default AuthorInnerBlockConfiguration
4 changes: 4 additions & 0 deletions services/cms/src/blocks/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import { BlockConfiguration } from "@wordpress/blocks"

import Aside from "./Aside"
import Author from "./Author"
import AuthorInnerBlock from "./AuthorInnerBlock"
import ChapterProgress from "./ChapterProgress"
import Congratulations from "./Congratulations"
import CourseChapterGrid from "./CourseChapterGrid"
Expand Down Expand Up @@ -54,6 +56,8 @@ export const blockTypeMapForPages = [
["moocfi/tablebox", TableBox],
["moocfi/iframe", Iframe],
["moocfi/map", Map],
["moocfi/author", Author],
["moocfi/author-inner-block", AuthorInnerBlock],
// eslint-disable-next-line @typescript-eslint/no-explicit-any
] as Array<[string, BlockConfiguration<Record<string, any>>]>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
import { css } from "@emotion/css"

import { BlockAttributes } from "../../../types/GutenbergBlockAttributes"
import { baseTheme } from "../../shared-module/styles"
import withErrorBoundary from "../../shared-module/utils/withErrorBoundary"

import { BlockRendererProps } from "."

const DefaultBlock: React.FC<React.PropsWithChildren<BlockRendererProps<BlockAttributes>>> = ({
data,
}) => {
return <pre>{JSON.stringify(data, undefined, 2)}</pre>
return (
<div
className={css`
padding: 1rem;
border: 1px solid ${baseTheme.colors.gray[400]};
`}
>
<b>{data.name}</b>
<pre>{JSON.stringify(data, undefined, 2)}</pre>
</div>
)
}

export default withErrorBoundary(DefaultBlock)
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import SeparatorBlock from "./core/layout/Separator"
import SpacerBlock from "./core/layout/SpacerBlock"
import AsideBlock from "./moocfi/AsideBlock"
import AudioPlayer from "./moocfi/AudioPlayer/index"
import AuthorBlock from "./moocfi/AuthorBlock"
import AuthorInnerBlock from "./moocfi/AuthorInnerBlock"
import ChapterProgressBlock from "./moocfi/ChapterProgressBlock"
import CongratulationsBlock from "./moocfi/CongratulationsBlock"
import CourseChapterGridBlock from "./moocfi/CourseChapterGridBlock"
Expand Down Expand Up @@ -144,6 +146,8 @@ export const blockToRendererMap: { [blockName: string]: any } = {
"moocfi/iframe": IframeBlock,
"moocfi/audio-upload": AudioPlayer,
"moocfi/map": Map,
"moocfi/author": AuthorBlock,
"moocfi/author-inner-block": AuthorInnerBlock,
"moocfi/research-consent-checkbox": ResearchFormCheckBoxBlock,
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import styled from "@emotion/styled"
import { t } from "i18next"
import React from "react"

import { BlockRendererProps } from ".."
import { baseTheme } from "../../../shared-module/styles"
import withErrorBoundary from "../../../shared-module/utils/withErrorBoundary"
import InnerBlocks from "../util/InnerBlocks"

interface InfoBoxBlockAttributes {
backgroundColor: string
}

const Wrapper = styled.div`
background: #f7f8f9;
padding: 2rem 2rem 1rem 2rem;
margin-bottom: 1rem;

h3 {
color: ${baseTheme.colors.gray[700]};
padding-bottom: 0.5rem;
border-bottom: 2px solid #edf0f2;
font-weight: 600;
font-size: 22px;
margin-bottom: 1.4rem;
}

/*Overwrite InnerBlock Component styles*/

figure {
margin: 0;
img {
margin: 0;
width: 250px;
height: 223px;
object-fit: cover;
}
}

div {
margin-left: 0;
}

div.course-material-block > div > div:nth-child(2) {
margin-bottom: 1.4rem !important;
}

div.course-material-block > div > div > div > div:nth-child(1) {
max-width: 250px !important;
}

p {
margin: 0;
font-size: 16px;
font-weight: 400;
color: ${baseTheme.colors.gray[600]};
}
`

const AuthorBlock: React.FC<React.PropsWithChildren<BlockRendererProps<InfoBoxBlockAttributes>>> = (
props,
) => {
return (
<Wrapper>
<h3>{t("author")}</h3>
<div>
<InnerBlocks parentBlockProps={props} />
</div>
</Wrapper>
)
}

export default withErrorBoundary(AuthorBlock)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from "react"

import { BlockRendererProps } from ".."
import withErrorBoundary from "../../../shared-module/utils/withErrorBoundary"
import InnerBlocks from "../util/InnerBlocks"

interface InfoBoxBlockAttributes {
backgroundColor: string
}

const AuthorInnerBlock: React.FC<
React.PropsWithChildren<BlockRendererProps<InfoBoxBlockAttributes>>
> = (props) => {
return (
<div>
<InnerBlocks parentBlockProps={props} />
</div>
)
}

export default withErrorBoundary(AuthorInnerBlock)
52 changes: 30 additions & 22 deletions services/headless-lms/server/src/domain/langs/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,32 +51,40 @@ impl FromRequest for AuthToken {
.and_then(|h| h.strip_prefix("Bearer ").map(str::to_string));
async move {
let Some(token) = auth_header else {
return Err(ControllerError::new(ControllerErrorType::Unauthorized, "Missing bearer token".to_string(), None));
return Err(ControllerError::new(
ControllerErrorType::Unauthorized,
"Missing bearer token".to_string(),
None,
));
};
let mut conn = pool.acquire().await?;


let user = if app_conf.test_mode {
warn!("Using test credentials. Normal accounts won't work.");
authorization::authenticate_test_token(&mut conn, &token, &app_conf)
.await.map_err(|err|
ControllerError::new(ControllerErrorType::Unauthorized, "Could not find user".to_string(), Some(err)))?
} else {
match load_user(&cache, &token).await {
Some(user) => user,
None => {
let token = LoginToken::new(
oauth2::AccessToken::new(token),
oauth2::basic::BasicTokenType::Bearer,
oauth2::EmptyExtraTokenFields {},
);
let user = authorization::get_user_from_moocfi(&token, &mut conn).await?;
cache_user(&cache, &token, &user)
.await;
user
let user = if app_conf.test_mode {
warn!("Using test credentials. Normal accounts won't work.");
authorization::authenticate_test_token(&mut conn, &token, &app_conf)
.await
.map_err(|err| {
ControllerError::new(
ControllerErrorType::Unauthorized,
"Could not find user".to_string(),
Some(err),
)
})?
} else {
match load_user(&cache, &token).await {
Some(user) => user,
None => {
let token = LoginToken::new(
oauth2::AccessToken::new(token),
oauth2::basic::BasicTokenType::Bearer,
oauth2::EmptyExtraTokenFields {},
);
let user = authorization::get_user_from_moocfi(&token, &mut conn).await?;
cache_user(&cache, &token, &user).await;
user
}
}
}
};
};

Ok(Self(user))
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading