Skip to content

Commit

Permalink
Merge branch 'arb-ltip' into deployments/arbitrum
Browse files Browse the repository at this point in the history
  • Loading branch information
froid1911 committed Apr 19, 2024
2 parents ff204cf + 120a818 commit 1592177
Show file tree
Hide file tree
Showing 15 changed files with 2,427 additions and 3,531 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-deploy-makerdao-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ jobs:
email: ${{ secrets.HEROKU_EMAIL }}
heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
heroku_app_name: ${{ secrets.HEROKU_APP_NAME }}
docker_options: "--build-arg BASE_PATH=/makerdao/connect --build-arg VITE_BASE_HREF=/makerdao/connect/ --build-arg VITE_ROUTER_BASENAME=/makerdao/connect --build-arg VITE_SENTRY_DSN=${{ secrets.SENTRY_DSN }} --build-arg VITE_SENTRY_ENV=${{ secrets.SENTRY_ENV }}"
docker_options: "--build-arg BASE_PATH=/makerdao/connect --build-arg VITE_BASE_HREF=/makerdao/connect/ --build-arg VITE_ROUTER_BASENAME=/makerdao/connect --build-arg VITE_SENTRY_DSN=${{ secrets.SENTRY_DSN }} --build-arg VITE_SENTRY_ENV=${{ secrets.SENTRY_ENV }} --build-arg VITE_DEFAULT_DRIVE_URL=https://apps.powerhouse.io/makerdao/switchboard/d/monetalis"
process_type: web
2 changes: 1 addition & 1 deletion .github/workflows/build-and-deploy-makerdao-staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ jobs:
email: ${{ secrets.HEROKU_EMAIL }}
heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
heroku_app_name: ${{ secrets.HEROKU_APP_NAME }}
docker_options: "--build-arg BASE_PATH=/alpha/makerdao/connect --build-arg VITE_BASE_HREF=/alpha/makerdao/connect/ --build-arg VITE_ROUTER_BASENAME=/alpha/makerdao/connect --build-arg VITE_SENTRY_DSN=${{ secrets.SENTRY_DSN }} --build-arg VITE_SENTRY_ENV=${{ secrets.SENTRY_ENV }}"
docker_options: "--build-arg BASE_PATH=/alpha/makerdao/connect --build-arg VITE_BASE_HREF=/alpha/makerdao/connect/ --build-arg VITE_ROUTER_BASENAME=/alpha/makerdao/connect --build-arg VITE_SENTRY_DSN=${{ secrets.SENTRY_DSN }} --build-arg VITE_SENTRY_ENV=${{ secrets.SENTRY_ENV }} --build-arg VITE_DEFAULT_DRIVE_URL=https://apps.powerhouse.io/alpha/makerdao/switchboard/d/monetalis"
process_type: web
2 changes: 1 addition & 1 deletion .github/workflows/build-and-deploy-powerhouse-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ jobs:
email: ${{ secrets.HEROKU_EMAIL }}
heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
heroku_app_name: ${{ secrets.HEROKU_APP_NAME }}
docker_options: "--build-arg BASE_PATH=/powerhouse/connect --build-arg VITE_BASE_HREF=/powerhouse/connect/ --build-arg VITE_ROUTER_BASENAME=/powerhouse/connect --build-arg VITE_SENTRY_DSN=${{ secrets.SENTRY_DSN }} --build-arg VITE_SENTRY_ENV=${{ secrets.SENTRY_ENV }}"
docker_options: "--build-arg BASE_PATH=/powerhouse/connect --build-arg VITE_BASE_HREF=/powerhouse/connect/ --build-arg VITE_ROUTER_BASENAME=/powerhouse/connect --build-arg VITE_SENTRY_DSN=${{ secrets.SENTRY_DSN }} --build-arg VITE_SENTRY_ENV=${{ secrets.SENTRY_ENV }} VITE_DEFAULT_DRIVE_URL=https://apps.powerhouse.io/powerhouse/switchboard/d/powerhouse"
process_type: web
2 changes: 1 addition & 1 deletion .github/workflows/build-and-deploy-powerhouse-staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ jobs:
email: ${{ secrets.HEROKU_EMAIL }}
heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
heroku_app_name: ${{ secrets.HEROKU_APP_NAME }}
docker_options: "--build-arg BASE_PATH=/alpha/powerhouse/connect --build-arg VITE_BASE_HREF=/alpha/powerhouse/connect/ --build-arg VITE_ROUTER_BASENAME=/alpha/powerhouse/connect --build-arg VITE_SENTRY_DSN=${{ secrets.SENTRY_DSN }} --build-arg VITE_SENTRY_ENV=${{ secrets.SENTRY_ENV }}"
docker_options: "--build-arg BASE_PATH=/alpha/powerhouse/connect --build-arg VITE_BASE_HREF=/alpha/powerhouse/connect/ --build-arg VITE_ROUTER_BASENAME=/alpha/powerhouse/connect --build-arg VITE_SENTRY_DSN=${{ secrets.SENTRY_DSN }} --build-arg VITE_SENTRY_ENV=${{ secrets.SENTRY_ENV }} --build-arg VITE_DEFAULT_DRIVE_URL=https://apps.powerhouse.io/alpha/powerhouse/switchboard/d/powerhouse"
process_type: web
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,6 @@ out/
.vercel

# Generated assets
public/icons.svg
public/icons.svg

.env.local
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ENV VITE_SENTRY_DSN=${VITE_SENTRY_DSN}
ARG VITE_SENTRY_ENV="dev"
ENV VITE_SENTRY_ENV=${VITE_SENTRY_ENV}

ARG VITE_DEFAULT_DRIVE_URL=undefined
ARG VITE_DEFAULT_DRIVE_URL=""
ENV VITE_DEFAULT_DRIVE_URL=${VITE_DEFAULT_DRIVE_URL}

ARG VITE_ENABLED_EDITORS=undefined
Expand Down
5,773 changes: 2,285 additions & 3,488 deletions package-lock.json

Large diffs are not rendered by default.

17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
"format": "prettier --write \"**/*.+(js|ts|jsx|tsx|json)\"",
"dev:web": "vite -c vite.renderer.config.ts",
"build:web": "vite build -c vite.renderer.config.ts",
"prepare": "npm run prepare:scripts",
"release": "semantic-release",
"prepare": "npm run prepare:scripts",
"prepare:scripts": "node scripts/index.js",
"e2e": "playwright test"
},
Expand All @@ -48,7 +48,7 @@
"@semantic-release/github": "^9.2.4",
"@semantic-release/release-notes-generator": "^12.1.0",
"@total-typescript/ts-reset": "^0.5.1",
"@types/react": "^18.2.47",
"@types/react": "^18.2.79",
"@types/react-dom": "^18.2.18",
"@types/uuid": "^9.0.7",
"@types/wicg-file-system-access": "^2020.9.6",
Expand All @@ -57,8 +57,7 @@
"@vitejs/plugin-react": "^4.2.1",
"asar": "^3.2.0",
"autoprefixer": "^10.4.14",
"document-model-libs": "1.35.0-arbitrum.1",
"electron": "28.2.3",
"electron": "30.0.0",
"electron-playwright-helpers": "^1.7.1",
"eslint": "^8.56.0",
"eslint-config-prettier": "^8.8.0",
Expand Down Expand Up @@ -90,11 +89,12 @@
"xvfb-maybe": "^0.2.1"
},
"dependencies": {
"@powerhousedao/design-system": "^1.0.0-alpha.94",
"@powerhousedao/design-system": "1.0.0-alpha.97",
"@sentry/react": "^7.109.0",
"did-key-creator": "^1.2.0",
"document-drive": "1.0.0-alpha.39",
"document-model": "^1.0.43",
"document-drive": "1.0.0-alpha.41",
"document-model": "^1.0.51",
"document-model-libs": "^1.37.0-arbitrum.1",
"electron-is-dev": "^3.0.1",
"electron-squirrel-startup": "^1.0.0",
"electron-store": "^8.1.0",
Expand All @@ -115,5 +115,8 @@
"document-drive": {
"document-model-libs": "doc-arb-ltip"
}
},
"optionalDependencies": {
"@rollup/rollup-linux-x64-musl": "4.14.3"
}
}
3 changes: 3 additions & 0 deletions src/components/drive-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { useTranslation } from 'react-i18next';
import { useDocumentDriveServer } from 'src/hooks/useDocumentDriveServer';
import { useDrivesContainer } from 'src/hooks/useDrivesContainer';
import { useIsAllowedToCreateDocuments } from 'src/hooks/useIsAllowedToCreateDocuments';
import { useOnDropEvent } from 'src/hooks/useOnDropEvent';
import { driveSections } from 'src/utils/drive-sections';

Expand All @@ -31,6 +32,7 @@ export default function DriveContainer(props: DriveContainerProps) {
const { addDrive, addRemoteDrive } = useDocumentDriveServer();
const { onItemOptionsClick, onItemClick, onSubmitInput } =
useDrivesContainer();
const isAllowedToCreateDocuments = useIsAllowedToCreateDocuments();

const onDropEvent = useOnDropEvent();

Expand Down Expand Up @@ -149,6 +151,7 @@ export default function DriveContainer(props: DriveContainerProps) {
onDropActivate={onDropActivateHandler}
onCreateDrive={onCreateDriveHandler}
disableHighlightStyles={disableHoverStyles}
isAllowedToCreateDocuments={isAllowedToCreateDocuments}
/>
),
)}
Expand Down
8 changes: 4 additions & 4 deletions src/components/file-item/file-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import {
decodeID,
defaultDropdownMenuOptions,
} from '@powerhousedao/design-system';
import { FileNode } from 'document-model-libs/document-drive';
import { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useDocumentDriveById } from 'src/hooks/useDocumentDriveById';
import { useDrivesContainer } from 'src/hooks/useDrivesContainer';
import { useGetDocumentById } from 'src/hooks/useGetDocumentById';
import { useGetReadableItemPath } from 'src/hooks/useGetReadableItemPath';
import { useIsAllowedToCreateDocuments } from 'src/hooks/useIsAllowedToCreateDocuments';
import { useOpenSwitchboardLink } from 'src/hooks/useOpenSwitchboardLink';
import { useModal } from '../modal';

Expand All @@ -36,6 +36,7 @@ export const FileItem: React.FC<IProps> = ({ file, drive, onFileSelected }) => {
const getDocumentById = useGetDocumentById();
const { updateNodeName } = useDrivesContainer();
const { showModal } = useModal();
const isAllowedToCreateDocuments = useIsAllowedToCreateDocuments();

const decodedDriveID = decodeID(drive);
const openSwitchboardLink = useOpenSwitchboardLink(decodedDriveID);
Expand All @@ -56,9 +57,7 @@ export const FileItem: React.FC<IProps> = ({ file, drive, onFileSelected }) => {
}

if (optionId === 'switchboard-link') {
const document = getDocumentById(decodedDriveID, fileNode.id) as
| FileNode
| undefined;
const document = getDocumentById(decodedDriveID, fileNode.id);

await openSwitchboardLink(document);
}
Expand Down Expand Up @@ -100,6 +99,7 @@ export const FileItem: React.FC<IProps> = ({ file, drive, onFileSelected }) => {
onClick={() =>
!isWriteMode && onFileSelected(decodedDriveID, file.id)
}
isAllowedToCreateDocuments={isAllowedToCreateDocuments}
/>
);
};
Expand Down
3 changes: 3 additions & 0 deletions src/components/folder-item/folder-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import React, { useState } from 'react';
import { useModal } from 'src/components/modal';
import { useDrivesContainer } from 'src/hooks/useDrivesContainer';
import { useIsAllowedToCreateDocuments } from 'src/hooks/useIsAllowedToCreateDocuments';
import { useOnDropEvent } from 'src/hooks/useOnDropEvent';

const allowedItemOptions = ['delete', 'rename'];
Expand All @@ -22,6 +23,7 @@ export interface FolderItemProps {

export const FolderItem: React.FC<FolderItemProps> = props => {
const { folder, decodedDriveID, onFolderSelected } = props;
const isAllowedToCreateDocuments = useIsAllowedToCreateDocuments();

const { showModal } = useModal();
const { updateNodeName } = useDrivesContainer();
Expand Down Expand Up @@ -61,6 +63,7 @@ export const FolderItem: React.FC<FolderItemProps> = props => {
onOptionsClick={optionId => onFolderOptionsClick(optionId, folder)}
onDropEvent={onDropEvent}
item={folder}
isAllowedToCreateDocuments={isAllowedToCreateDocuments}
/>
);
};
1 change: 1 addition & 0 deletions src/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface ImportMetaEnv {
VITE_ROUTER_BASENAME: string;
VITE_SENTRY_DSN: string;
VITE_SENTRY_ENV: string;
VITE_CREATE_DOCUMENT_ALLOW_LIST: string | undefined;
}

interface ImportMeta {
Expand Down
49 changes: 49 additions & 0 deletions src/hooks/useDocumentDriveServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { useGetDocumentModel } from 'src/store/document-model';
import { DefaultDocumentDriveServer } from 'src/utils/document-drive-server';
import { loadFile } from 'src/utils/file';
import { useDocumentDrives } from './useDocumentDrives';
import { useIsAllowedToCreateDocuments } from './useIsAllowedToCreateDocuments';

// TODO this should be added to the document model
export interface SortOptions {
Expand All @@ -36,6 +37,8 @@ export interface SortOptions {
export function useDocumentDriveServer(
server: IDocumentDriveServer | undefined = DefaultDocumentDriveServer,
) {
const isAllowedToCreateDocuments = useIsAllowedToCreateDocuments();

if (!server) {
throw new Error('Invalid Document Drive Server');
}
Expand Down Expand Up @@ -105,6 +108,10 @@ export function useDocumentDriveServer(
parentFolder?: string,
document?: Document,
) {
if (!isAllowedToCreateDocuments) {
throw new Error('User is not allowed to create documents');
}

const id = utils.hashKey();

let drive = documentDrives.find(d => d.state.global.id === driveId);
Expand Down Expand Up @@ -141,6 +148,9 @@ export function useDocumentDriveServer(
name?: string,
parentFolder?: string,
) {
if (!isAllowedToCreateDocuments) {
throw new Error('User is not allowed to create files');
}
const document = await loadFile(file, getDocumentModel);
return addDocument(
drive,
Expand All @@ -158,6 +168,9 @@ export function useDocumentDriveServer(
name?: string,
parentFolder?: string,
) {
if (!isAllowedToCreateDocuments) {
throw new Error('User is not allowed to update files');
}
const drive = await _addDriveOperation(
driveId,
actions.updateFile({
Expand All @@ -180,6 +193,9 @@ export function useDocumentDriveServer(
name: string,
parentFolder?: string,
) {
if (!isAllowedToCreateDocuments) {
throw new Error('User is not allowed to create folders');
}
const id = utils.hashKey();
const drive = await _addDriveOperation(
driveId,
Expand All @@ -198,6 +214,9 @@ export function useDocumentDriveServer(
}

async function deleteNode(drive: string, id: string) {
if (!isAllowedToCreateDocuments) {
throw new Error('User is not allowed to delete documents');
}
await _addDriveOperation(
drive,
actions.deleteNode({
Expand All @@ -207,6 +226,9 @@ export function useDocumentDriveServer(
}

async function renameNode(driveId: string, id: string, name: string) {
if (!isAllowedToCreateDocuments) {
throw new Error('User is not allowed to rename documents');
}
const drive = await _addDriveOperation(
driveId,
actions.updateNode({
Expand All @@ -231,6 +253,9 @@ export function useDocumentDriveServer(
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- TODO: use this later for sorting
sortOptions?: SortOptions,
) {
if (!isAllowedToCreateDocuments) {
throw new Error('User is not allowed to copy or move nodes');
}
if (srcId === targetId) return;

const drive = documentDrives.find(
Expand Down Expand Up @@ -284,6 +309,9 @@ export function useDocumentDriveServer(
id: string,
operation: Operation,
) {
if (!isAllowedToCreateDocuments) {
throw new Error('User is not allowed to add operations');
}
if (!server) {
throw new Error('Server is not defined');
}
Expand All @@ -304,6 +332,9 @@ export function useDocumentDriveServer(
id: string,
operations: Operation[],
) {
if (!isAllowedToCreateDocuments) {
throw new Error('User is not allowed to add operations');
}
if (!server) {
throw new Error('Server is not defined');
}
Expand All @@ -320,6 +351,9 @@ export function useDocumentDriveServer(
}

async function addDrive(drive: DriveInput) {
if (!isAllowedToCreateDocuments) {
throw new Error('User is not allowed to create drives');
}
const id = drive.global.id || utils.hashKey();
drive = documentDriveUtils.createState(drive);
await server.addDrive({
Expand All @@ -330,11 +364,17 @@ export function useDocumentDriveServer(
}

async function addRemoteDrive(url: string, options: RemoteDriveOptions) {
if (!isAllowedToCreateDocuments) {
throw new Error('User is not allowed to create drives');
}
await server.addRemoteDrive(url, options);
await refreshDocumentDrives();
}

async function deleteDrive(id: string) {
if (!isAllowedToCreateDocuments) {
throw new Error('User is not allowed to delete drives');
}
if (!server) {
throw new Error('Server is not defined');
}
Expand All @@ -350,20 +390,29 @@ export function useDocumentDriveServer(
}

async function renameDrive(id: string, name: string) {
if (!isAllowedToCreateDocuments) {
throw new Error('User is not allowed to rename drives');
}
return _addDriveOperation(id, actions.setDriveName({ name }));
}

async function setDriveAvailableOffline(
id: string,
availableOffline: boolean,
) {
if (!isAllowedToCreateDocuments) {
throw new Error('User is not allowed to change drive availability');
}
return _addDriveOperation(
id,
actions.setAvailableOffline({ availableOffline }),
);
}

async function setDriveSharingType(id: string, sharingType: SharingType) {
if (!isAllowedToCreateDocuments) {
throw new Error('User is not allowed to change drive availability');
}
return _addDriveOperation(
id,
actions.setSharingType({ type: sharingType }),
Expand Down
29 changes: 29 additions & 0 deletions src/hooks/useIsAllowedToCreateDocuments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { useLogin } from './useLogin';

export function useIsAllowedToCreateDocuments() {
const { user, status } = useLogin();

const createDocumentAllowListEnvString = import.meta.env
.VITE_CREATE_DOCUMENT_ALLOW_LIST;

const createDocumentAllowList =
createDocumentAllowListEnvString?.split(',');
if (createDocumentAllowList === undefined) {
console.warn(`
WARNING: The VITE_CREATE_DOCUMENT_ALLOW_LIST environment variable is not set.
This means that _any_ users will be allowed to create documents.
`);

return true;
}

if (status !== 'authorized' || !user) return false;

const userAddressIsOnAllowList = createDocumentAllowList.includes(
user.address,
);

if (userAddressIsOnAllowList) return true;

return false;
}
Loading

0 comments on commit 1592177

Please sign in to comment.