Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

refactor: use self hosted geo service

goenningef6436c65c08
diff --git a/app/middlewares/security_test.go b/app/middlewares/security_test.go
index 47bac3a59..4c159a50b 100644
--- a/app/middlewares/security_test.go
+++ b/app/middlewares/security_test.go
@@ -37,7 +37,7 @@ func TestSecureWithoutCDN(t *testing.T) {
return c.NoContent(http.StatusOK)
})
- expectedPolicy := "base-uri 'self'; default-src 'self'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com ; script-src 'self' 'nonce-" + ctxID + "' https://www.google-analytics.com ; img-src 'self' https: data: ; font-src 'self' https://fonts.gstatic.com data: ; object-src 'none'; media-src 'none'; connect-src 'self' https://ipinfo.io https://www.google-analytics.com ; frame-src 'self'"
+ expectedPolicy := "base-uri 'self'; default-src 'self'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com ; script-src 'self' 'nonce-" + ctxID + "' https://www.google-analytics.com ; img-src 'self' https: data: ; font-src 'self' https://fonts.gstatic.com data: ; object-src 'none'; media-src 'none'; connect-src 'self' https://mygeo.vercel.app https://www.google-analytics.com ; frame-src 'self'"
Expect(status).Equals(http.StatusOK)
Expect(response.Header().Get("Content-Security-Policy")).Equals(expectedPolicy)
@@ -60,7 +60,7 @@ func TestSecureWithCDN(t *testing.T) {
return c.NoContent(http.StatusOK)
})
- expectedPolicy := "base-uri 'self'; default-src 'self'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com *.test.fider.io; script-src 'self' 'nonce-" + ctxID + "' https://www.google-analytics.com *.test.fider.io; img-src 'self' https: data: *.test.fider.io; font-src 'self' https://fonts.gstatic.com data: *.test.fider.io; object-src 'none'; media-src 'none'; connect-src 'self' https://ipinfo.io https://www.google-analytics.com *.test.fider.io; frame-src 'self'"
+ expectedPolicy := "base-uri 'self'; default-src 'self'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com *.test.fider.io; script-src 'self' 'nonce-" + ctxID + "' https://www.google-analytics.com *.test.fider.io; img-src 'self' https: data: *.test.fider.io; font-src 'self' https://fonts.gstatic.com data: *.test.fider.io; object-src 'none'; media-src 'none'; connect-src 'self' https://mygeo.vercel.app https://www.google-analytics.com *.test.fider.io; frame-src 'self'"
Expect(status).Equals(http.StatusOK)
Expect(response.Header().Get("Content-Security-Policy")).Equals(expectedPolicy)
@@ -83,7 +83,7 @@ func TestSecureWithCDN_SingleHost(t *testing.T) {
return c.NoContent(http.StatusOK)
})
- expectedPolicy := "base-uri 'self'; default-src 'self'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com test.fider.io; script-src 'self' 'nonce-" + ctxID + "' https://www.google-analytics.com test.fider.io; img-src 'self' https: data: test.fider.io; font-src 'self' https://fonts.gstatic.com data: test.fider.io; object-src 'none'; media-src 'none'; connect-src 'self' https://ipinfo.io https://www.google-analytics.com test.fider.io; frame-src 'self'"
+ expectedPolicy := "base-uri 'self'; default-src 'self'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com test.fider.io; script-src 'self' 'nonce-" + ctxID + "' https://www.google-analytics.com test.fider.io; img-src 'self' https: data: test.fider.io; font-src 'self' https://fonts.gstatic.com data: test.fider.io; object-src 'none'; media-src 'none'; connect-src 'self' https://mygeo.vercel.app https://www.google-analytics.com test.fider.io; frame-src 'self'"
Expect(status).Equals(http.StatusOK)
Expect(response.Header().Get("Content-Security-Policy")).Equals(expectedPolicy)
diff --git a/app/pkg/web/engine.go b/app/pkg/web/engine.go
index 70c902781..fdaa918b8 100644
--- a/app/pkg/web/engine.go
+++ b/app/pkg/web/engine.go
@@ -35,7 +35,7 @@ var (
cspObject = "object-src 'none'"
cspFrame = "frame-src 'self'"
cspMedia = "media-src 'none'"
- cspConnect = "connect-src 'self' https://ipinfo.io https://www.google-analytics.com %[2]s"
+ cspConnect = "connect-src 'self' https://mygeo.vercel.app https://www.google-analytics.com %[2]s"
//CspPolicyTemplate is the template used to generate the policy
CspPolicyTemplate = fmt.Sprintf("%s; %s; %s; %s; %s; %s; %s; %s; %s; %s", cspBase, cspDefault, cspStyle, cspScript, cspImage, cspFont, cspObject, cspMedia, cspConnect, cspFrame)
diff --git a/app/services/sqlstore/postgres/oauth.go b/app/services/sqlstore/postgres/oauth.go
index 44c12dfb9..d9c66b134 100644
--- a/app/services/sqlstore/postgres/oauth.go
+++ b/app/services/sqlstore/postgres/oauth.go
@@ -74,6 +74,10 @@ func getCustomOAuthConfigByProvider(ctx context.Context, q *query.GetCustomOAuth
func listCustomOAuthConfig(ctx context.Context, q *query.ListCustomOAuthConfig) error {
return using(ctx, func(trx *dbx.Trx, tenant *entity.Tenant, user *entity.User) error {
+ if trx == nil || tenant == nil {
+ return nil
+ }
+
configs := []*dbOAuthConfig{}
if tenant != nil {
err := trx.Select(&configs, `
diff --git a/app/services/sqlstore/postgres/postgres.go b/app/services/sqlstore/postgres/postgres.go
index 38be8f6f3..0f64e4709 100644
--- a/app/services/sqlstore/postgres/postgres.go
+++ b/app/services/sqlstore/postgres/postgres.go
@@ -139,7 +139,7 @@ func (s Service) Init() {
type SqlHandler func(trx *dbx.Trx, tenant *entity.Tenant, user *entity.User) error
func using(ctx context.Context, handler SqlHandler) error {
- trx := ctx.Value(app.TransactionCtxKey).(*dbx.Trx)
+ trx, _ := ctx.Value(app.TransactionCtxKey).(*dbx.Trx)
tenant, _ := ctx.Value(app.TenantCtxKey).(*entity.Tenant)
user, _ := ctx.Value(app.UserCtxKey).(*entity.User)
return handler(trx, tenant, user)
diff --git a/public/pages/Administration/components/billing/SubscribeButton.tsx b/public/pages/Administration/components/billing/SubscribeButton.tsx
index 53cb5e5b7..f0ab565a5 100644
--- a/public/pages/Administration/components/billing/SubscribeButton.tsx
+++ b/public/pages/Administration/components/billing/SubscribeButton.tsx
@@ -1,49 +1,28 @@
import React, { useEffect, useState } from "react"
import { Button } from "@fider/components"
-import { getCountryCode } from "@fider/services"
+import { getCurrencyCode } from "@fider/services"
interface SubscribeButtonProps {
onClick: () => void
}
-interface SubscriptionPrice {
- currency: string
- symbol: string
- countries: string[]
- amount: number
-}
-
-const prices = [
- { currency: "USD", symbol: "$", amount: 30, countries: ["US"] },
- {
- currency: "EUR",
- symbol: "€",
- amount: 28,
- countries: ["AD", "AT", "BE", "FI", "FR", "GF", "TF", "DE", "GR", "GP", "VA", "IE", "IT", "LU", "MQ", "YT", "MC", "NL", "PT", "RE", "PM", "SM", "CS", "ES"],
- },
- { currency: "GBP", symbol: "£", amount: 26, countries: ["GB", "UK"] },
-]
-
-const getPrice = async (): Promise<SubscriptionPrice> => {
- const countryCode = await getCountryCode()
-
- if (countryCode) {
- for (const price of prices) {
- if (price.countries.includes(countryCode)) {
- return price
- }
- }
+const usePricing = (): string | undefined => {
+ const prices: { [code: string]: string } = {
+ USD: "$30",
+ EUR: "€28",
+ GBP: "£26",
}
- return prices[0]
+ const [price, setPrice] = useState<string>()
+ useEffect(() => {
+ getCurrencyCode().then((currencyCode) => setPrice(prices[currencyCode]))
+ }, [])
+
+ return price
}
export const SubscribeButton = (props: SubscribeButtonProps) => {
- const [price, setPrice] = useState<SubscriptionPrice | undefined>()
-
- useEffect(() => {
- getPrice().then(setPrice)
- }, [])
+ const price = usePricing()
if (!price) {
return null
@@ -52,8 +31,9 @@ export const SubscribeButton = (props: SubscribeButtonProps) => {
return (
<p>
<Button variant="primary" onClick={props.onClick}>
- Resubscribe for {price.symbol} {price.amount}/mo
+ Subscribe for {price}/mo
</Button>
+
<span className="block text-muted">Taxes may be added during checkout.</span>
</p>
)
diff --git a/public/services/geo.ts b/public/services/geo.ts
index fdb8f05d7..8de4b3336 100644
--- a/public/services/geo.ts
+++ b/public/services/geo.ts
@@ -1,21 +1,23 @@
import { cache } from "./cache"
-const CACHE_COUNTRYCODE_KEY = "CountryCode"
+const CACHE_CURRENCYCODE_KEY = "CurrencyCode"
-export const getCountryCode = async (): Promise<string | undefined> => {
- const countryCode = cache.session.get(CACHE_COUNTRYCODE_KEY)
- if (countryCode) {
- return countryCode
+export const getCurrencyCode = async (): Promise<string> => {
+ const currencyCode = cache.session.get(CACHE_CURRENCYCODE_KEY)
+ if (currencyCode) {
+ return currencyCode
}
try {
- const response = await fetch("https://ipinfo.io/json")
+ const response = await fetch("https://mygeo.vercel.app")
if (response.status === 200) {
const data = await response.json()
- cache.session.set(CACHE_COUNTRYCODE_KEY, data.country)
- return data.country
+ cache.session.set(CACHE_CURRENCYCODE_KEY, data.currencyCode)
+ return data.currencyCode
}
} catch (err) {
console.error(err)
}
+
+ return "USD"
}