Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

feature: read-only banner

goenning9c7e732e59eb
diff --git a/app/cmd/routes.go b/app/cmd/routes.go
index 2f4a5d5c1..79f00749f 100644
--- a/app/cmd/routes.go
+++ b/app/cmd/routes.go
@@ -102,9 +102,6 @@ func routes(r *web.Engine) *web.Engine {
r.Post("/_api/signin/complete", handlers.CompleteSignInProfile())
r.Post("/_api/signin", handlers.SignInByEmail())
- //Block if it's a locked tenant with a non-administrator user
- r.Use(middlewares.BlockLockedTenants())
-
//Block if it's private tenant with unauthenticated user
r.Use(middlewares.CheckTenantPrivacy())
diff --git a/app/handlers/signin.go b/app/handlers/signin.go
index 744b21647..48e1b7dab 100644
--- a/app/handlers/signin.go
+++ b/app/handlers/signin.go
@@ -22,7 +22,7 @@ import (
func SignInPage() web.HandlerFunc {
return func(c *web.Context) error {
- if c.Tenant().IsPrivate || c.Tenant().Status == enum.TenantLocked {
+ if c.Tenant().IsPrivate {
return c.Page(web.Props{
Title: "Sign in",
ChunkName: "SignIn.page",
diff --git a/app/middlewares/tenant.go b/app/middlewares/tenant.go
index 63803f547..38e2d3795 100644
--- a/app/middlewares/tenant.go
+++ b/app/middlewares/tenant.go
@@ -125,22 +125,3 @@ func CheckTenantPrivacy() web.MiddlewareFunc {
}
}
}
-
-// BlockLockedTenants blocks requests of non-administrator users on locked tenants
-func BlockLockedTenants() web.MiddlewareFunc {
- return func(next web.HandlerFunc) web.HandlerFunc {
- return func(c *web.Context) error {
- if c.Tenant().Status == enum.TenantLocked {
- if c.Request.IsAPI() {
- return c.JSON(http.StatusLocked, web.Map{})
- }
-
- isAdmin := c.IsAuthenticated() && c.User().Role == enum.RoleAdministrator
- if !isAdmin {
- return c.Redirect("/signin")
- }
- }
- return next(c)
- }
- }
-}
diff --git a/app/middlewares/tenant_test.go b/app/middlewares/tenant_test.go
index e0ec48746..2476770c9 100644
--- a/app/middlewares/tenant_test.go
+++ b/app/middlewares/tenant_test.go
@@ -422,52 +422,3 @@ func TestRequireTenant_SingleHostMode_ValidTenant(t *testing.T) {
Expect(status).Equals(http.StatusOK)
Expect(response.Body.String()).Equals("Demonstration")
}
-
-func TestBlockLockedTenants_ActiveTenant(t *testing.T) {
- RegisterT(t)
- server := mock.NewServer()
- server.Use(middlewares.BlockLockedTenants())
-
- status, response := server.
- WithURL("http://demo.test.fider.io").
- OnTenant(mock.DemoTenant).
- Execute(func(c *web.Context) error {
- return c.String(http.StatusOK, c.Tenant().Name)
- })
-
- Expect(status).Equals(http.StatusOK)
- Expect(response.Body.String()).Equals("Demonstration")
-}
-
-func TestBlockLockedTenants_LockedTenant(t *testing.T) {
- RegisterT(t)
- server := mock.NewServer()
- server.Use(middlewares.BlockLockedTenants())
- mock.DemoTenant.Status = enum.TenantLocked
-
- status, response := server.
- WithURL("http://demo.test.fider.io").
- OnTenant(mock.DemoTenant).
- Execute(func(c *web.Context) error {
- return c.String(http.StatusOK, c.Tenant().Name)
- })
-
- Expect(status).Equals(http.StatusTemporaryRedirect)
- Expect(response.Header().Get("Location")).Equals("/signin")
-}
-
-func TestBlockLockedTenants_LockedTenant_APICall(t *testing.T) {
- RegisterT(t)
- server := mock.NewServer()
- server.Use(middlewares.BlockLockedTenants())
- mock.DemoTenant.Status = enum.TenantLocked
-
- status, _ := server.
- WithURL("http://demo.test.fider.io/api/v1/posts").
- OnTenant(mock.DemoTenant).
- Execute(func(c *web.Context) error {
- return c.String(http.StatusOK, c.Tenant().Name)
- })
-
- Expect(status).Equals(http.StatusLocked)
-}
diff --git a/app/models/entity/tenant.go b/app/models/entity/tenant.go
index dcb89bc16..09a9e9883 100644
--- a/app/models/entity/tenant.go
+++ b/app/models/entity/tenant.go
@@ -19,11 +19,6 @@ type Tenant struct {
}
func (t *Tenant) IsDisabled() bool {
- //TODO: remove this when locked tenant status is implemented
- if t.Status == enum.TenantLocked {
- return true
- }
-
return t.Status == enum.TenantDisabled
}
diff --git a/public/assets/styles/utility/display.scss b/public/assets/styles/utility/display.scss
index b34ab3aa2..6c283adef 100644
--- a/public/assets/styles/utility/display.scss
+++ b/public/assets/styles/utility/display.scss
@@ -103,6 +103,10 @@
justify-content: space-evenly;
}
+.justify-center {
+ justify-content: center;
+}
+
.justify-full > * {
flex: 1 1 0;
}
diff --git a/public/components/Header.tsx b/public/components/Header.tsx
index ca88019e0..b4c754677 100644
--- a/public/components/Header.tsx
+++ b/public/components/Header.tsx
@@ -1,5 +1,5 @@
import React, { useState } from "react"
-import { SignInModal, TenantLogo, DevBanner, NotificationIndicator, UserMenu } from "@fider/components"
+import { SignInModal, TenantLogo, NotificationIndicator, UserMenu } from "@fider/components"
import { useFider } from "@fider/hooks"
import { HStack } from "./layout"
import { Trans } from "@lingui/macro"
@@ -16,32 +16,29 @@ export const Header = () => {
const hideModal = () => setIsSignInModalOpen(false)
return (
- <>
- <DevBanner />
- <div id="c-header">
- <SignInModal isOpen={isSignInModalOpen} onClose={hideModal} />
- <HStack className="c-menu shadow p-2 w-full">
- <div className="container">
- <HStack justify="between">
- <a href="/" className="flex flex-x flex-items-center flex--spacing-2 h-8">
- <TenantLogo size={100} />
- <h1 className="text-title">{fider.session.tenant.name}</h1>
+ <div id="c-header">
+ <SignInModal isOpen={isSignInModalOpen} onClose={hideModal} />
+ <HStack className="c-menu shadow p-2 w-full">
+ <div className="container">
+ <HStack justify="between">
+ <a href="/" className="flex flex-x flex-items-center flex--spacing-2 h-8">
+ <TenantLogo size={100} />
+ <h1 className="text-title">{fider.session.tenant.name}</h1>
+ </a>
+ {fider.session.isAuthenticated && (
+ <HStack spacing={2}>
+ <NotificationIndicator />
+ <UserMenu />
+ </HStack>
+ )}
+ {!fider.session.isAuthenticated && (
+ <a href="#" className="uppercase text-sm" onClick={showModal}>
+ <Trans id="action.signin">Sign in</Trans>
</a>
- {fider.session.isAuthenticated && (
- <HStack spacing={2}>
- <NotificationIndicator />
- <UserMenu />
- </HStack>
- )}
- {!fider.session.isAuthenticated && (
- <a href="#" className="uppercase text-sm" onClick={showModal}>
- <Trans id="action.signin">Sign in</Trans>
- </a>
- )}
- </HStack>
- </div>
- </HStack>
- </div>
- </>
+ )}
+ </HStack>
+ </div>
+ </HStack>
+ </div>
)
}
diff --git a/public/components/ReadOnlyNotice.tsx b/public/components/ReadOnlyNotice.tsx
new file mode 100644
index 000000000..0b254cd4e
--- /dev/null
+++ b/public/components/ReadOnlyNotice.tsx
@@ -0,0 +1,28 @@
+import React from "react"
+import { useFider } from "@fider/hooks"
+import { Message } from "./common"
+
+export const ReadOnlyNotice = () => {
+ const fider = useFider()
+ if (!fider.isReadOnly) {
+ return null
+ }
+
+ if (fider.session.isAuthenticated && fider.session.user.isAdministrator) {
+ return (
+ <Message alignment="center" type="warning">
+ This website is currently in read-only mode because there is no active subscription. Visit{" "}
+ <a className="text-link" href="/billing">
+ Billing
+ </a>{" "}
+ to subscribe.
+ </Message>
+ )
+ }
+
+ return (
+ <Message alignment="center" type="warning">
+ This website is currently in read-only mode.
+ </Message>
+ )
+}
diff --git a/public/components/common/Message.scss b/public/components/common/Message.scss
index c996d8d6e..2d0814620 100644
--- a/public/components/common/Message.scss
+++ b/public/components/common/Message.scss
@@ -4,21 +4,26 @@
padding: spacing(4);
margin-bottom: spacing(2);
+ &--icon {
+ border-left-width: 2px;
+ border-left-style: solid;
+ }
+
&--success {
color: get("colors.green.800");
- border-left: 2px solid get("colors.green.800");
+ border-color: get("colors.green.800");
background-color: get("colors.green.50");
}
&--warning {
color: get("colors.yellow.800");
- border-left: 2px solid get("colors.yellow.800");
+ border-color: get("colors.yellow.800");
background-color: get("colors.yellow.50");
}
&--error {
color: get("colors.red.800");
- border-left: 2px solid get("colors.red.800");
+ border-color: get("colors.red.800");
background-color: get("colors.red.50");
}
}
diff --git a/public/components/common/Message.tsx b/public/components/common/Message.tsx
index a814be1b6..1bfda9151 100644
--- a/public/components/common/Message.tsx
+++ b/public/components/common/Message.tsx
@@ -11,6 +11,7 @@ import { Icon } from "./Icon"
interface MessageProps {
type: "success" | "warning" | "error"
className?: string
+ alignment?: "center"
showIcon?: boolean
}
@@ -18,13 +19,14 @@ export const Message: React.FunctionComponent<MessageProps> = (props) => {
const className = classSet({
"c-message": true,
[`c-message--${props.type}`]: true,
+ [`c-message--icon`]: props.showIcon === true,
[`${props.className}`]: props.className,
})
const icon = props.type === "error" ? IconExclamation : props.type === "warning" ? IconExclamationCircle : IconCheckCircle
return (
- <HStack className={className} spacing={2}>
+ <HStack className={className} spacing={2} justify={props.alignment}>
{props.showIcon === true && <Icon className="h-5" sprite={icon} />}
<span>{props.children}</span>
</HStack>
diff --git a/public/components/index.tsx b/public/components/index.tsx
index ac679bb2c..c4fc4afce 100644
--- a/public/components/index.tsx
+++ b/public/components/index.tsx
@@ -7,4 +7,5 @@ export * from "./SignInModal"
export * from "./VoteCounter"
export * from "./NotificationIndicator"
export * from "./UserMenu"
+export * from "./ReadOnlyNotice"
export * from "./common"
diff --git a/public/components/layout/Stack.tsx b/public/components/layout/Stack.tsx
index af16c2778..b8357469a 100644
--- a/public/components/layout/Stack.tsx
+++ b/public/components/layout/Stack.tsx
@@ -7,7 +7,7 @@ interface StackProps {
onClick?: () => void
center?: boolean
divide?: boolean
- justify?: "between" | "evenly" | "full"
+ justify?: "between" | "evenly" | "full" | "center"
spacing?: 0 | 1 | 2 | 4 | 6 | 8
}
@@ -21,9 +21,7 @@ const Stack = (props: StackProps, dir: "x" | "y") => {
[`flex--spacing-${spacing}`]: spacing > 0 && !props.divide,
[`flex--divide-${spacing}`]: spacing > 0 && !!props.divide,
"flex-items-center": dir === "x" && props.center !== false,
- "justify-between": props.justify === "between",
- "justify-evenly": props.justify === "evenly",
- "justify-full": props.justify === "full",
+ [`justify-${props.justify}`]: props.justify,
})
return (
diff --git a/public/index.tsx b/public/index.tsx
index fc91b21ce..546dc59cb 100644
--- a/public/index.tsx
+++ b/public/index.tsx
@@ -3,7 +3,7 @@ import "@fider/assets/styles/index.scss"
import React, { Suspense } from "react"
import ReactDOM from "react-dom"
import { resolveRootComponent } from "@fider/router"
-import { Header, ErrorBoundary, Loader } from "@fider/components"
+import { Header, ErrorBoundary, Loader, ReadOnlyNotice, DevBanner } from "@fider/components"
import { classSet, Fider, FiderContext, actions, activateI18N } from "@fider/services"
import { I18n } from "@lingui/core"
@@ -47,7 +47,9 @@ const bootstrapApp = (i18n: I18n) => {
<ErrorBoundary onError={logProductionError}>
<I18nProvider i18n={i18n}>
<FiderContext.Provider value={fider}>
+ <DevBanner />
{config.showHeader && <Header />}
+ <ReadOnlyNotice />
<Suspense fallback={<Loading />}>{React.createElement(config.component, fider.session.props)}</Suspense>
</FiderContext.Provider>
</I18nProvider>
diff --git a/public/pages/Administration/pages/ManageBilling.page.tsx b/public/pages/Administration/pages/ManageBilling.page.tsx
index 5bfc72f4a..136fb85e9 100644
--- a/public/pages/Administration/pages/ManageBilling.page.tsx
+++ b/public/pages/Administration/pages/ManageBilling.page.tsx
@@ -72,15 +72,27 @@ const ActiveSubscriptionInformation = (props: ManageBillingPageProps) => {
const CancelledSubscriptionInformation = (props: ManageBillingPageProps) => {
const fider = useFider()
+ const isExpired = new Date(props.trialEndsAt) <= new Date()
+
return (
<>
- <p>
- Your Fider subscription is currently cancelled. This site will stay active until{" "}
- <strong>
- <Moment locale={fider.currentLocale} format="date" date={props.subscriptionEndsAt} />
- </strong>
- . <br /> Resubscribe to avoid a service interruption.
- </p>
+ {isExpired ? (
+ <p>
+ Your subscription expired on{" "}
+ <strong>
+ <Moment locale={fider.currentLocale} format="date" date={props.subscriptionEndsAt} />
+ </strong>
+ . Resubscribe to remove the read-only constraint from this site.
+ </p>
+ ) : (
+ <p>
+ Your subscription is currently cancelled. This site will stay active until{" "}
+ <strong>
+ <Moment locale={fider.currentLocale} format="date" date={props.subscriptionEndsAt} />
+ </strong>
+ . <br /> Resubscribe to avoid a service interruption.
+ </p>
+ )}
<Button variant="primary" onClick={subscribe}>
Resubscribe for $30/mo + Tax
@@ -92,16 +104,28 @@ const CancelledSubscriptionInformation = (props: ManageBillingPageProps) => {
const TrialInformation = (props: ManageBillingPageProps) => {
const fider = useFider()
+ const isExpired = new Date(props.trialEndsAt) <= new Date()
+
return (
<>
- <p>
- Your account is currently on a trial until{" "}
- <strong>
- <Moment locale={fider.currentLocale} format="date" date={props.trialEndsAt} />
- </strong>
- . <br />
- Subscribe before the end of your trial to avoid a service interruption.
- </p>
+ {isExpired ? (
+ <p>
+ Your trial expired on{" "}
+ <strong>
+ <Moment locale={fider.currentLocale} format="date" date={props.trialEndsAt} />
+ </strong>
+ . Subscribe to remove the read-only constraint from this site.
+ </p>
+ ) : (
+ <p>
+ Your account is currently on a trial until{" "}
+ <strong>
+ <Moment locale={fider.currentLocale} format="date" date={props.trialEndsAt} />
+ </strong>
+ . <br />
+ Subscribe before the end of your trial to avoid a service interruption.
+ </p>
+ )}
<Button variant="primary" onClick={subscribe}>
Subscribe for $30/mo + Tax
diff --git a/public/services/fider.ts b/public/services/fider.ts
index 344799811..315e5dd9a 100644
--- a/public/services/fider.ts
+++ b/public/services/fider.ts
@@ -1,5 +1,5 @@
import { createContext } from "react"
-import { CurrentUser, SystemSettings, Tenant } from "@fider/models"
+import { CurrentUser, SystemSettings, Tenant, TenantStatus } from "@fider/models"
export class FiderSession {
private pContextID: string
@@ -69,6 +69,10 @@ export class FiderImpl {
return this.pSettings
}
+ public get isReadOnly(): boolean {
+ return this.session.tenant && this.session.tenant.status === TenantStatus.Locked
+ }
+
public isProduction(): boolean {
return this.pSettings.environment === "production"
}
diff --git a/public/ssr.tsx b/public/ssr.tsx
index cb6b854cf..674620151 100644
--- a/public/ssr.tsx
+++ b/public/ssr.tsx
@@ -1,7 +1,7 @@
import React from "react"
import { renderToStaticMarkup } from "react-dom/server"
import { Fider, FiderContext } from "./services/fider"
-import { Header } from "./components"
+import { DevBanner, Header, ReadOnlyNotice } from "./components"
import { resolveRootComponent, route } from "./router"
import HomePage from "./pages/Home/Home.page"
@@ -47,7 +47,9 @@ function ssrRender(url: string, pathname: string, args: any) {
return renderToStaticMarkup(
<I18nProvider i18n={i18n}>
<FiderContext.Provider value={fider}>
+ <DevBanner />
{config.showHeader && <Header />}
+ <ReadOnlyNotice />
{React.createElement(config.component, args.props)}
</FiderContext.Provider>
</I18nProvider>