Skip to content

Commit

Permalink
Enable storage for all (#906)
Browse files Browse the repository at this point in the history
  • Loading branch information
nezaj authored Feb 20, 2025
1 parent 5332248 commit 1e792cf
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 133 deletions.
60 changes: 0 additions & 60 deletions client/www/components/dash/Storage.tsx

This file was deleted.

8 changes: 1 addition & 7 deletions client/www/components/dash/explorer/Explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,9 @@ function SearchInput({
export function Explorer({
db,
appId,
isStorageEnabled,
}: {
db: InstantReactWebDatabase<any>;
appId: string;
isStorageEnabled: boolean;
}) {
// DEV
_dev(db);
Expand Down Expand Up @@ -452,11 +450,7 @@ export function Explorer({
}

// data
const { namespaces: _namespaces } = useSchemaQuery(db);
// (TODO): When fully launching storage we can remove this check
const namespaces = isStorageEnabled
? _namespaces
: _namespaces && _namespaces.filter((ns) => ns.name !== '$files');
const { namespaces } = useSchemaQuery(db);
const { selectedNamespace } = useMemo(
() => ({
selectedNamespace: namespaces?.find(
Expand Down
3 changes: 0 additions & 3 deletions client/www/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ export type DashResponse = {
email: string;
id: string;
};
flags: {
storage_enabled_apps?: string[];
};
};

export type AppError = { body: { message: string } | undefined };
Expand Down
13 changes: 1 addition & 12 deletions client/www/pages/_devtool/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,6 @@ function DevtoolWithData({
}
>({ state: 'pending' });

const isStorageEnabled = useMemo(() => {
const storageEnabledAppIds =
dashResponse.data?.flags?.storage_enabled_apps ?? [];

return storageEnabledAppIds.includes(appId);
}, [appId, dashResponse.data?.flags?.storage_enabled_apps]);

useEffect(() => {
function onKeyDown(e: KeyboardEvent) {
const isToggleShortcut = e.shiftKey && e.ctrlKey && e.key === '0';
Expand Down Expand Up @@ -345,11 +338,7 @@ function DevtoolWithData({
/>
<div className="flex w-full flex-1 overflow-auto">
{tab === 'explorer' ? (
<Explorer
db={connection.db}
appId={appId}
isStorageEnabled={isStorageEnabled}
/>
<Explorer db={connection.db} appId={appId} />
) : tab === 'sandbox' ? (
<div className="min-w-[960px] w-full">
<Sandbox app={app} />
Expand Down
40 changes: 3 additions & 37 deletions client/www/pages/dash/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import Billing from '@/components/dash/Billing';
import { useIsHydrated } from '@/lib/hooks/useIsHydrated';
import { QueryInspector } from '@/components/dash/explorer/QueryInspector';
import { Sandbox } from '@/components/dash/Sandbox';
import { StorageTab } from '@/components/dash/Storage';
import PersonalAccessTokensScreen from '@/components/dash/PersonalAccessTokensScreen';
import { useForm } from '@/lib/hooks/useForm';
import useLocalStorage from '@/lib/hooks/useLocalStorage';
Expand All @@ -79,7 +78,6 @@ type TabId =
| 'team'
| 'admin'
| 'billing'
| 'storage'
| 'docs';

interface Tab {
Expand All @@ -94,7 +92,6 @@ const tabs: Tab[] = [
{ id: 'explorer', title: 'Explorer' },
{ id: 'perms', title: 'Permissions' },
{ id: 'auth', title: 'Auth' },
{ id: 'storage', title: 'Storage' },
{ id: 'repl', title: 'Query Inspector' },
{ id: 'sandbox', title: 'Sandbox' },
{ id: 'admin', title: 'Admin', minRole: 'admin' },
Expand Down Expand Up @@ -279,14 +276,6 @@ function Dashboard() {
return apps;
}, [dashResponse.data?.apps]);
const app = apps?.find((a) => a.id === appId);
const isStorageEnabled = useMemo(() => {
if (!appId) return false;

const storageEnabledAppIds =
dashResponse.data?.flags?.storage_enabled_apps ?? [];

return storageEnabledAppIds.includes(appId);
}, [appId, dashResponse.data?.flags?.storage_enabled_apps]);

// ui
const availableTabs: TabBarTab[] = tabs
Expand Down Expand Up @@ -488,11 +477,7 @@ function Dashboard() {
{tab === 'home' ? (
<Home />
) : tab === 'explorer' ? (
<ExplorerTab
appId={appId}
db={connection.db}
isStorageEnabled={isStorageEnabled}
/>
<ExplorerTab appId={appId} db={connection.db} />
) : tab === 'repl' ? (
<QueryInspector
className="flex-1 w-full"
Expand All @@ -510,12 +495,6 @@ function Dashboard() {
dashResponse={dashResponse}
nav={nav}
/>
) : tab === 'storage' ? (
<StorageTab
key={app.id}
app={app}
isEnabled={isStorageEnabled}
/>
) : tab == 'admin' && isMinRole('admin', app.user_app_role) ? (
<Admin
dashResponse={dashResponse}
Expand Down Expand Up @@ -851,24 +830,11 @@ function Home() {
);
}

function ExplorerTab({
db,
appId,
isStorageEnabled,
}: {
db: InstantReactClient;
appId: string;
isStorageEnabled: boolean;
}) {
function ExplorerTab({ db, appId }: { db: InstantReactClient; appId: string }) {
return (
<div className="flex-1 overflow-hidden flex flex-col">
<div className="flex flex-1 flex-col overflow-hidden">
<Explorer
db={db}
appId={appId}
isStorageEnabled={isStorageEnabled}
key={db._core._reactor.config.appId}
/>
<Explorer db={db} appId={appId} key={db._core._reactor.config.appId} />
</div>
</div>
);
Expand Down
4 changes: 4 additions & 0 deletions server/flags-config/instant.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ const graph = i.graph(
"disableLegacy?": i.boolean(),
"useLocationId?": i.boolean(),
}),
"storage-block-list": i.entity({
appId: i.string().unique().indexed(),
isDisabled: i.boolean(),
}),
},
// You can define links here.
// For example, if `posts` should have many `comments`.
Expand Down
10 changes: 2 additions & 8 deletions server/src/instant/dash/routes.clj
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
[instant.lib.ring.websocket :as ws]
[instant.jdbc.aurora :as aurora]
[instant.stripe :as stripe]
[instant.storage.beta :as storage-beta]
[instant.model.instant-personal-access-token :as instant-personal-access-token-model]
[instant.model.schema :as schema-model]
[instant.intern.metrics :as metrics]
Expand Down Expand Up @@ -329,16 +328,11 @@
(let [{:keys [id email]} (req->auth-user! req)
apps (app-model/get-all-for-user {:user-id id})
profile (instant-profile-model/get-by-user-id {:user-id id})
invites (instant-app-member-invites-model/get-pending-for-invitee {:email email})
whitelist (storage-beta/whitelist)
storage-enabled-app-ids (->> apps
(map :id)
(filter #(contains? whitelist (str %))))]
invites (instant-app-member-invites-model/get-pending-for-invitee {:email email})]
(response/ok {:apps apps
:profile profile
:invites invites
:user {:id id :email email}
:flags {:storage_enabled_apps storage-enabled-app-ids}})))
:user {:id id :email email}})))

(comment
(def u (instant-user-model/get-by-email {:email "[email protected]"}))
Expand Down
16 changes: 14 additions & 2 deletions server/src/instant/flags.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
(def query {:friend-emails {}
:power-user-emails {}
:storage-whitelist {}
:storage-block-list {}
:storage-migration {}
:team-emails {}
:test-emails {}
Expand Down Expand Up @@ -49,6 +50,12 @@
(get o "appId")))
(get result "storage-whitelist")))

storage-block-list
(set (keep (fn [o]
(when (get o "isDisabled")
(get o "appId")))
(get result "storage-block-list")))

use-patch-presence (when-let [hz-flag (-> (get result "use-patch-presence")
first)]
(let [disabled-apps (-> hz-flag
Expand Down Expand Up @@ -97,6 +104,7 @@
storage-migration (-> result (get "storage-migration") first w/keywordize-keys)]
{:emails emails
:storage-enabled-whitelist storage-enabled-whitelist
:storage-block-list storage-block-list
:use-patch-presence use-patch-presence
:promo-code-emails promo-code-emails
:drop-refresh-spam drop-refresh-spam
Expand All @@ -118,9 +126,13 @@
(contains? (:team (get-emails))
email))

;; (TODO) After storage is public for awhile we can remove this
(defn storage-enabled-whitelist []
(get (query-result) :storage-enabled-whitelist))

(defn storage-block-list []
(get (query-result) :storage-block-list))

(defn promo-code-emails []
(get (query-result) :promo-code-emails))

Expand All @@ -134,9 +146,9 @@
(contains? (promo-code-emails)
email))

(defn storage-enabled? [app-id]
(defn storage-disabled? [app-id]
(let [app-id (str app-id)]
(contains? (storage-enabled-whitelist) app-id)))
(contains? (storage-block-list) app-id)))

(defn use-patch-presence? [app-id]
(let [flag (:use-patch-presence (query-result))
Expand Down
5 changes: 1 addition & 4 deletions server/src/instant/storage/beta.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
[instant.config :as config]
[instant.util.exception :as ex]))

(defn whitelist []
(flags/storage-enabled-whitelist))

(defn assert-storage-enabled! [app-id]
(if (= :prod (config/get-env))
(ex/assert-permitted! :storage-enabled? app-id (flags/storage-enabled? app-id))
(ex/assert-permitted! :storage-enabled? app-id (not (flags/storage-disabled? app-id)))
true))

0 comments on commit 1e792cf

Please sign in to comment.