api key usage

main
alex 2023-07-04 23:19:29 +02:00
parent b1d41640f3
commit 7549290d15
5 changed files with 90 additions and 42 deletions

View File

@ -157,9 +157,9 @@
"userProfile.form.repeatNewPassword": "Neues Passwort wiederholen",
"userProfile.form.language": "Sprache",
"userProfile.header.yourSessions": "Ihre Sitzungen",
"userProfile.header.yourApiKeys": "Ihre API Schlüssel",
"userProfile.button.createApiKey": "Neuen API Schlüssel erstellen",
"userProfile.button.createApiKey.popconfirm.title": "Name für den neuen API Schlüssel",
"userProfile.header.yourApiKeys": "Ihre API-Schlüssel",
"userProfile.button.createApiKey": "Neuen API-Schlüssel erstellen",
"userProfile.button.createApiKey.popconfirm.title": "Name für den neuen API-Schlüssel",
"userProfile.button.createApiKey.popconfirm.okText": "Erstellen",
"userProfile.button.copyToClipboard.notification": "API Token in die Zwischenablage kopiert",
"scanners.column.name": "Name",

View File

@ -66,7 +66,7 @@ export default function LogCard({ type }) {
categoryGroup.category ===
webSocketContext.GroupTasks.find(
(groupTask) => groupTask.Id === groupTaskStep.GroupTasksId
).Category
)?.Category
)?.groups.find(
(groups) =>
groups.id ===

View File

@ -26,6 +26,7 @@ import {
MyAvatar,
getUserId,
GroupTasksStepsLockedAndUserUpdateInputValueRememberId,
hasXYPermission,
} from "../../../utils";
import {
CheckOutlined,
@ -56,20 +57,27 @@ export default function GroupTasksViewModal({ isOpen }) {
}
});
// invalid group task id in url specified
if (!currentGroupTask) {
// invalid group task id in url specified or no permissions
if (
!currentGroupTask ||
!hasXYPermission(
webSocketContext.User.Permissions,
Constants.PERMISSIONS.GROUP_TASKS.OVERVIEW.XYView,
currentGroupTask.Category
)
) {
return (
<Modal
open={isOpen}
width="70%"
maskClosable={true}
onCancel={handleCancel}
footer={<Button onClick={handleCancel}>Close</Button>}
footer={<Button onClick={handleCancel}>{t("buttonClose")}</Button>}
>
<Result
status="500"
title={t("groupTasks.groupTasksViewModal.groupTaskNotFound")}
/>{" "}
/>
</Modal>
);
}

View File

@ -23,6 +23,7 @@ import {
getConnectionStatusItem,
getUserSessionFromLocalStorage,
handleUnauthorizedStatus,
hasPermission,
isEmailValid,
} from "../../utils";
import { Link } from "react-router-dom";
@ -448,6 +449,12 @@ export default function UserProfile() {
dataSource={getSessionTableItems()}
/>
{hasPermission(
webSocketContext.User.Permissions,
Constants.PERMISSIONS.USER_PROFILE.API_KEYS
) && (
<>
{" "}
<div
style={{
display: "flex",
@ -478,11 +485,12 @@ export default function UserProfile() {
</Button>
</Popconfirm>
</div>
<Table
columns={getApiKeyTableColumns()}
dataSource={getApiKeyTableItems()}
/>
</>
)}
</>
);
}

View File

@ -73,6 +73,9 @@ export const Constants = {
},
LOGS: "admin_area.logs",
},
USER_PROFILE: {
API_KEYS: "user_profile.api_keys",
},
},
SYSTEM_LOG_TYPE: {
INFO: 0,
@ -193,6 +196,8 @@ const ReceivedMessagesCommands = {
AllUsersUserDeactivation: 28,
GroupTasksCategoryGroupChanges: 29,
NewUserApiKeyCreated: 30,
DeletedUserApiKey: 31,
NewApiKeyUsageCount: 32,
};
// commands sent to the backend server
@ -965,6 +970,33 @@ export function WebSocketProvider({
return updatedUser;
});
break;
case ReceivedMessagesCommands.DeletedUserApiKey:
setUser((user) => {
const updatedUser = { ...user };
updatedUser.ApiKeys = updatedUser.ApiKeys.filter(
(apiKey) => apiKey.Id !== body
);
return updatedUser;
});
break;
case ReceivedMessagesCommands.NewApiKeyUsageCount:
setUser((user) => {
const updatedUser = { ...user };
const foundIndex = updatedUser.ApiKeys.findIndex(
(apiKey) => apiKey.Id === body.Id
);
if (foundIndex !== -1) {
updatedUser.ApiKeys[foundIndex].UsageCount = body.UsageCount;
updatedUser.ApiKeys[foundIndex].LastUsed = body.LastUsed;
}
return updatedUser;
});
break;
default:
console.error("unknown command", cmd);