Skip to content

Commit

Permalink
Merge remote-tracking branch 'gammelalf/jan++'
Browse files Browse the repository at this point in the history
  • Loading branch information
myOmikron committed Mar 26, 2024
2 parents ef7c985 + 99a3572 commit 28e1657
Show file tree
Hide file tree
Showing 83 changed files with 7,818 additions and 1,276 deletions.
12 changes: 7 additions & 5 deletions kraken_frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,22 @@
"format": "prettier --write ."
},
"dependencies": {
"react-markdown": "^9.0.1",
"remark-gfm": "^4.0.0",
"rehype-highlight": "^7.0.0",
"@monaco-editor/react": "^4.6.0",
"monaco-editor": "^0.45.0",
"d3": "^7.8.5",
"js-base64": "^3.7.5",
"monaco-editor": "^0.45.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-markdown": "^9.0.1",
"react-select": "^5.7.0",
"react-toastify": "^9.1.1",
"reactjs-popup": "^2.0.5"
"reactjs-popup": "^2.0.5",
"rehype-highlight": "^7.0.0",
"remark-gfm": "^4.0.0"
},
"devDependencies": {
"@openapitools/openapi-generator-cli": "^2.6.0",
"@types/d3": "^7.4.3",
"@types/react": "^18.0.27",
"@types/react-dom": "^18.0.10",
"@vitejs/plugin-react-swc": "^3.0.0",
Expand Down
48 changes: 48 additions & 0 deletions kraken_frontend/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
CreateWorkspaceRequest,
CreateWorkspaceTagRequest,
DomainsApi,
FilesApi,
FindingsApi,
GlobalTagsApi,
HostsApi,
Expand Down Expand Up @@ -54,6 +55,7 @@ import {
WorkspaceInvitationsApi,
WorkspaceTagsApi,
WorkspacesApi,
UpdateFindingDefinitionRequest,
} from "./generated";

/** Database id i.e. and u32 */
Expand All @@ -69,6 +71,7 @@ const userAdminManagement = new UserAdminManagementApi(configuration);
const adminWorkspaces = new AdminWorkspacesApi(configuration);
const attacks = new AttacksApi(configuration);
const findings = new FindingsApi(configuration);
const files = new FilesApi(configuration);
// const authentication = new generated.AuthenticationApi(configuration);
const leechManagement = new LeechManagementApi(configuration);
const userManagement = new UserManagementApi(configuration);
Expand Down Expand Up @@ -178,9 +181,43 @@ export const Api = {
delete: (uuid: UUID) => handleError(workspaces.deleteWorkspace({ uuid })),
transferOwnership: (uuid: UUID, user: UUID) =>
handleError(workspaces.transferOwnership({ uuid, transferWorkspaceRequest: { user } })),
archive: (uuid: UUID) => handleError(workspaces.archiveWorkspace({ uuid })),
unarchive: (uuid: UUID) => handleError(workspaces.unarchiveWorkspace({ uuid })),
attacks: {
all: (uuid: UUID) => handleError(attacks.getWorkspaceAttacks({ uuid })),
},
files: {
uploadFile: (workspace: UUID, filename: string, data: Blob) =>
handleError(
files.uploadFile({
uuid: workspace,
body: data,
filename: filename,
}),
),
uploadImage: (workspace: UUID, filename: string, data: Blob) =>
handleError(
files.uploadImage({
uuid: workspace,
body: data,
filename: filename,
}),
),
downloadFile: (workspace: UUID, file: UUID) =>
handleError(
files.downloadFile({
wUuid: workspace,
fUuid: file,
}),
),
downloadThumbnail: (workspace: UUID, file: UUID) =>
handleError(
files.downloadThumbnail({
wUuid: workspace,
fUuid: file,
}),
),
},
findings: {
all: (workspace: UUID) => handleError(findings.getAllFindings({ uuid: workspace })),
create: (workspace: UUID, options: CreateFindingRequest) =>
Expand Down Expand Up @@ -368,6 +405,17 @@ export const Api = {
handleError(knowledgeBase.getFindingDefinition({ uuid: findingDefinition })),
create: (createFindingDefinitionRequest: CreateFindingDefinitionRequest) =>
handleError(knowledgeBase.createFindingDefinition({ createFindingDefinitionRequest })),
update: (uuid: UUID, definition: UpdateFindingDefinitionRequest) =>
handleError(
knowledgeBase.updateFindingDefinition({
uuid,
updateFindingDefinitionRequest: definition,
}),
),
admin: {
delete: (findingDefinition: UUID) =>
handleError(knowledgeBase.deleteFindingDefinition({ uuid: findingDefinition })),
},
},
},
};
Expand Down
11 changes: 9 additions & 2 deletions kraken_frontend/src/components/admin-guard.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from "react";
import USER_CONTEXT from "../context/user";
import { ROUTES } from "../routes";
import { toast } from "react-toastify";
import { UserPermission } from "../api/generated";
import USER_CONTEXT from "../context/user";
import { ROUTES } from "../routes";

export type AdminGuardProps = {
children: React.ReactNode;
Expand All @@ -18,3 +18,10 @@ export default function AdminGuard(props: AdminGuardProps) {
return null;
}
}

/** Wrapper to show components only to admins */
export function AdminOnly(props: AdminGuardProps) {
const { user } = React.useContext(USER_CONTEXT);
if (user.permission === UserPermission.Admin) return <>{props.children}</>;
else return undefined;
}
Loading

0 comments on commit 28e1657

Please sign in to comment.