From 972df7c167f5a5857975c84c46cabb5c7e9ca322 Mon Sep 17 00:00:00 2001 From: yoan <536464346@qq.com> Date: Sun, 24 Nov 2024 20:16:55 +0800 Subject: [PATCH] migration --- migrations/1732450576_collections_snapshot.go | 1236 +++++++++++++++++ .../components/certimate/AccessLocalForm.tsx | 4 +- ui/src/components/certimate/AccessSSHForm.tsx | 24 +- ui/src/domain/version.ts | 2 +- ui/src/providers/config/index.tsx | 27 +- ui/src/providers/config/reducer.ts | 10 +- ui/src/repository/access_group.ts | 45 - 7 files changed, 1241 insertions(+), 107 deletions(-) create mode 100644 migrations/1732450576_collections_snapshot.go delete mode 100644 ui/src/repository/access_group.ts diff --git a/migrations/1732450576_collections_snapshot.go b/migrations/1732450576_collections_snapshot.go new file mode 100644 index 00000000..01aa2d29 --- /dev/null +++ b/migrations/1732450576_collections_snapshot.go @@ -0,0 +1,1236 @@ +package migrations + +import ( + "encoding/json" + + "github.com/pocketbase/dbx" + "github.com/pocketbase/pocketbase/daos" + m "github.com/pocketbase/pocketbase/migrations" + "github.com/pocketbase/pocketbase/models" +) + +func init() { + m.Register(func(db dbx.Builder) error { + jsonData := `[ + { + "id": "z3p974ainxjqlvs", + "created": "2024-07-29 10:02:48.334Z", + "updated": "2024-11-05 12:57:58.246Z", + "name": "domains", + "type": "base", + "system": false, + "schema": [ + { + "system": false, + "id": "iuaerpl2", + "name": "domain", + "type": "text", + "required": false, + "presentable": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "ukkhuw85", + "name": "email", + "type": "email", + "required": false, + "presentable": false, + "unique": false, + "options": { + "exceptDomains": null, + "onlyDomains": null + } + }, + { + "system": false, + "id": "v98eebqq", + "name": "crontab", + "type": "text", + "required": false, + "presentable": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "alc8e9ow", + "name": "access", + "type": "relation", + "required": false, + "presentable": false, + "unique": false, + "options": { + "collectionId": "4yzbv8urny5ja1e", + "cascadeDelete": false, + "minSelect": null, + "maxSelect": 1, + "displayFields": null + } + }, + { + "system": false, + "id": "topsc9bj", + "name": "certUrl", + "type": "text", + "required": false, + "presentable": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "vixgq072", + "name": "certStableUrl", + "type": "text", + "required": false, + "presentable": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "g3a3sza5", + "name": "privateKey", + "type": "text", + "required": false, + "presentable": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "gr6iouny", + "name": "certificate", + "type": "text", + "required": false, + "presentable": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "tk6vnrmn", + "name": "issuerCertificate", + "type": "text", + "required": false, + "presentable": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "sjo6ibse", + "name": "csr", + "type": "text", + "required": false, + "presentable": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "x03n1bkj", + "name": "expiredAt", + "type": "date", + "required": false, + "presentable": false, + "unique": false, + "options": { + "min": "", + "max": "" + } + }, + { + "system": false, + "id": "srybpixz", + "name": "targetType", + "type": "select", + "required": false, + "presentable": false, + "unique": false, + "options": { + "maxSelect": 1, + "values": [ + "aliyun-oss", + "aliyun-cdn", + "aliyun-dcdn", + "ssh", + "webhook", + "tencent-cdn", + "qiniu-cdn", + "local" + ] + } + }, + { + "system": false, + "id": "xy7yk0mb", + "name": "targetAccess", + "type": "relation", + "required": false, + "presentable": false, + "unique": false, + "options": { + "collectionId": "4yzbv8urny5ja1e", + "cascadeDelete": false, + "minSelect": null, + "maxSelect": 1, + "displayFields": null + } + }, + { + "system": false, + "id": "6jqeyggw", + "name": "enabled", + "type": "bool", + "required": false, + "presentable": false, + "unique": false, + "options": {} + }, + { + "system": false, + "id": "hdsjcchf", + "name": "deployed", + "type": "bool", + "required": false, + "presentable": false, + "unique": false, + "options": {} + }, + { + "system": false, + "id": "aiya3rev", + "name": "rightnow", + "type": "bool", + "required": false, + "presentable": false, + "unique": false, + "options": {} + }, + { + "system": false, + "id": "ixznmhzc", + "name": "lastDeployedAt", + "type": "date", + "required": false, + "presentable": false, + "unique": false, + "options": { + "min": "", + "max": "" + } + }, + { + "system": false, + "id": "ghtlkn5j", + "name": "lastDeployment", + "type": "relation", + "required": false, + "presentable": false, + "unique": false, + "options": { + "collectionId": "0a1o4e6sstp694f", + "cascadeDelete": false, + "minSelect": null, + "maxSelect": 1, + "displayFields": null + } + }, + { + "system": false, + "id": "zfnyj9he", + "name": "variables", + "type": "text", + "required": false, + "presentable": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "1bspzuku", + "name": "group", + "type": "relation", + "required": false, + "presentable": false, + "unique": false, + "options": { + "collectionId": "teolp9pl72dxlxq", + "cascadeDelete": false, + "minSelect": null, + "maxSelect": 1, + "displayFields": null + } + }, + { + "system": false, + "id": "g65gfh7a", + "name": "nameservers", + "type": "text", + "required": false, + "presentable": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "wwrzc3jo", + "name": "applyConfig", + "type": "json", + "required": false, + "presentable": false, + "unique": false, + "options": { + "maxSize": 2000000 + } + }, + { + "system": false, + "id": "474iwy8r", + "name": "deployConfig", + "type": "json", + "required": false, + "presentable": false, + "unique": false, + "options": { + "maxSize": 2000000 + } + } + ], + "indexes": [ + "CREATE UNIQUE INDEX ` + "`" + `idx_4ABO6EQ` + "`" + ` ON ` + "`" + `domains` + "`" + ` (` + "`" + `domain` + "`" + `)" + ], + "listRule": null, + "viewRule": null, + "createRule": null, + "updateRule": null, + "deleteRule": null, + "options": {} + }, + { + "id": "4yzbv8urny5ja1e", + "created": "2024-07-29 10:04:39.685Z", + "updated": "2024-11-18 11:43:01.059Z", + "name": "access", + "type": "base", + "system": false, + "schema": [ + { + "system": false, + "id": "geeur58v", + "name": "name", + "type": "text", + "required": false, + "presentable": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "iql7jpwx", + "name": "config", + "type": "json", + "required": false, + "presentable": false, + "unique": false, + "options": { + "maxSize": 2000000 + } + }, + { + "system": false, + "id": "hwy7m03o", + "name": "configType", + "type": "select", + "required": false, + "presentable": false, + "unique": false, + "options": { + "maxSelect": 1, + "values": [ + "aliyun", + "tencent", + "huaweicloud", + "qiniu", + "aws", + "cloudflare", + "namesilo", + "godaddy", + "pdns", + "httpreq", + "local", + "ssh", + "webhook", + "k8s", + "baiducloud", + "dogecloud", + "volcengine", + "byteplus" + ] + } + }, + { + "system": false, + "id": "lr33hiwg", + "name": "deleted", + "type": "date", + "required": false, + "presentable": false, + "unique": false, + "options": { + "min": "", + "max": "" + } + }, + { + "system": false, + "id": "hsxcnlvd", + "name": "usage", + "type": "select", + "required": false, + "presentable": false, + "unique": false, + "options": { + "maxSelect": 1, + "values": [ + "apply", + "deploy", + "all" + ] + } + }, + { + "system": false, + "id": "c8egzzwj", + "name": "group", + "type": "relation", + "required": false, + "presentable": false, + "unique": false, + "options": { + "collectionId": "teolp9pl72dxlxq", + "cascadeDelete": false, + "minSelect": null, + "maxSelect": 1, + "displayFields": null + } + } + ], + "indexes": [ + "CREATE UNIQUE INDEX ` + "`" + `idx_wkoST0j` + "`" + ` ON ` + "`" + `access` + "`" + ` (` + "`" + `name` + "`" + `)" + ], + "listRule": null, + "viewRule": null, + "createRule": null, + "updateRule": null, + "deleteRule": null, + "options": {} + }, + { + "id": "0a1o4e6sstp694f", + "created": "2024-07-30 06:30:27.801Z", + "updated": "2024-11-05 12:57:58.247Z", + "name": "deployments", + "type": "base", + "system": false, + "schema": [ + { + "system": false, + "id": "farvlzk7", + "name": "domain", + "type": "relation", + "required": false, + "presentable": false, + "unique": false, + "options": { + "collectionId": "z3p974ainxjqlvs", + "cascadeDelete": false, + "minSelect": null, + "maxSelect": 1, + "displayFields": null + } + }, + { + "system": false, + "id": "jx5f69i3", + "name": "log", + "type": "json", + "required": false, + "presentable": false, + "unique": false, + "options": { + "maxSize": 2000000 + } + }, + { + "system": false, + "id": "qbxdtg9q", + "name": "phase", + "type": "select", + "required": false, + "presentable": false, + "unique": false, + "options": { + "maxSelect": 1, + "values": [ + "check", + "apply", + "deploy" + ] + } + }, + { + "system": false, + "id": "rglrp1hz", + "name": "phaseSuccess", + "type": "bool", + "required": false, + "presentable": false, + "unique": false, + "options": {} + }, + { + "system": false, + "id": "lt1g1blu", + "name": "deployedAt", + "type": "date", + "required": false, + "presentable": false, + "unique": false, + "options": { + "min": "", + "max": "" + } + }, + { + "system": false, + "id": "wledpzgb", + "name": "wholeSuccess", + "type": "bool", + "required": false, + "presentable": false, + "unique": false, + "options": {} + } + ], + "indexes": [], + "listRule": null, + "viewRule": null, + "createRule": null, + "updateRule": null, + "deleteRule": null, + "options": {} + }, + { + "id": "_pb_users_auth_", + "created": "2024-09-12 13:09:54.234Z", + "updated": "2024-11-05 12:57:58.247Z", + "name": "users", + "type": "auth", + "system": false, + "schema": [ + { + "system": false, + "id": "users_name", + "name": "name", + "type": "text", + "required": false, + "presentable": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "users_avatar", + "name": "avatar", + "type": "file", + "required": false, + "presentable": false, + "unique": false, + "options": { + "mimeTypes": [ + "image/jpeg", + "image/png", + "image/svg+xml", + "image/gif", + "image/webp" + ], + "thumbs": null, + "maxSelect": 1, + "maxSize": 5242880, + "protected": false + } + } + ], + "indexes": [], + "listRule": "id = @request.auth.id", + "viewRule": "id = @request.auth.id", + "createRule": "", + "updateRule": "id = @request.auth.id", + "deleteRule": "id = @request.auth.id", + "options": { + "allowEmailAuth": true, + "allowOAuth2Auth": true, + "allowUsernameAuth": true, + "exceptEmailDomains": null, + "manageRule": null, + "minPasswordLength": 8, + "onlyEmailDomains": null, + "onlyVerified": false, + "requireEmail": false + } + }, + { + "id": "dy6ccjb60spfy6p", + "created": "2024-09-12 23:12:21.677Z", + "updated": "2024-11-05 12:57:58.247Z", + "name": "settings", + "type": "base", + "system": false, + "schema": [ + { + "system": false, + "id": "1tcmdsdf", + "name": "name", + "type": "text", + "required": false, + "presentable": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "f9wyhypi", + "name": "content", + "type": "json", + "required": false, + "presentable": false, + "unique": false, + "options": { + "maxSize": 2000000 + } + } + ], + "indexes": [ + "CREATE UNIQUE INDEX ` + "`" + `idx_RO7X9Vw` + "`" + ` ON ` + "`" + `settings` + "`" + ` (` + "`" + `name` + "`" + `)" + ], + "listRule": null, + "viewRule": null, + "createRule": null, + "updateRule": null, + "deleteRule": null, + "options": {} + }, + { + "id": "teolp9pl72dxlxq", + "created": "2024-09-13 12:51:05.611Z", + "updated": "2024-11-05 12:57:58.247Z", + "name": "access_groups", + "type": "base", + "system": false, + "schema": [ + { + "system": false, + "id": "7sajiv6i", + "name": "name", + "type": "text", + "required": false, + "presentable": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "xp8admif", + "name": "access", + "type": "relation", + "required": false, + "presentable": false, + "unique": false, + "options": { + "collectionId": "4yzbv8urny5ja1e", + "cascadeDelete": false, + "minSelect": null, + "maxSelect": null, + "displayFields": null + } + } + ], + "indexes": [ + "CREATE UNIQUE INDEX ` + "`" + `idx_RgRXp0R` + "`" + ` ON ` + "`" + `access_groups` + "`" + ` (` + "`" + `name` + "`" + `)" + ], + "listRule": null, + "viewRule": null, + "createRule": null, + "updateRule": null, + "deleteRule": null, + "options": {} + }, + { + "id": "012d7abbod1hwvr", + "created": "2024-10-23 06:37:13.155Z", + "updated": "2024-11-05 12:57:58.247Z", + "name": "acme_accounts", + "type": "base", + "system": false, + "schema": [ + { + "system": false, + "id": "fmjfn0yw", + "name": "ca", + "type": "text", + "required": false, + "presentable": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "qqwijqzt", + "name": "email", + "type": "email", + "required": false, + "presentable": false, + "unique": false, + "options": { + "exceptDomains": null, + "onlyDomains": null + } + }, + { + "system": false, + "id": "genxqtii", + "name": "key", + "type": "text", + "required": false, + "presentable": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "1aoia909", + "name": "resource", + "type": "json", + "required": false, + "presentable": false, + "unique": false, + "options": { + "maxSize": 2000000 + } + } + ], + "indexes": [], + "listRule": null, + "viewRule": null, + "createRule": null, + "updateRule": null, + "deleteRule": null, + "options": {} + }, + { + "id": "tovyif5ax6j62ur", + "created": "2024-11-12 01:09:03.542Z", + "updated": "2024-11-18 02:36:33.502Z", + "name": "workflow", + "type": "base", + "system": false, + "schema": [ + { + "system": false, + "id": "8yydhv1h", + "name": "name", + "type": "text", + "required": false, + "presentable": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "1buzebwz", + "name": "description", + "type": "text", + "required": false, + "presentable": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "vqoajwjq", + "name": "type", + "type": "select", + "required": false, + "presentable": false, + "unique": false, + "options": { + "maxSelect": 1, + "values": [ + "auto", + "manual" + ] + } + }, + { + "system": false, + "id": "8ho247wh", + "name": "crontab", + "type": "text", + "required": false, + "presentable": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "awlphkfe", + "name": "content", + "type": "json", + "required": false, + "presentable": false, + "unique": false, + "options": { + "maxSize": 2000000 + } + }, + { + "system": false, + "id": "g9ohkk5o", + "name": "draft", + "type": "json", + "required": false, + "presentable": false, + "unique": false, + "options": { + "maxSize": 2000000 + } + }, + { + "system": false, + "id": "nq7kfdzi", + "name": "enabled", + "type": "bool", + "required": false, + "presentable": false, + "unique": false, + "options": {} + }, + { + "system": false, + "id": "2rpfz9t3", + "name": "hasDraft", + "type": "bool", + "required": false, + "presentable": false, + "unique": false, + "options": {} + } + ], + "indexes": [], + "listRule": null, + "viewRule": null, + "createRule": null, + "updateRule": null, + "deleteRule": null, + "options": {} + }, + { + "id": "bqnxb95f2cooowp", + "created": "2024-11-18 01:35:35.222Z", + "updated": "2024-11-18 08:27:41.125Z", + "name": "workflow_output", + "type": "base", + "system": false, + "schema": [ + { + "system": false, + "id": "jka88auc", + "name": "workflow", + "type": "relation", + "required": false, + "presentable": false, + "unique": false, + "options": { + "collectionId": "tovyif5ax6j62ur", + "cascadeDelete": false, + "minSelect": null, + "maxSelect": 1, + "displayFields": null + } + }, + { + "system": false, + "id": "z9fgvqkz", + "name": "nodeId", + "type": "text", + "required": false, + "presentable": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "c2rm9omj", + "name": "node", + "type": "json", + "required": false, + "presentable": false, + "unique": false, + "options": { + "maxSize": 2000000 + } + }, + { + "system": false, + "id": "he4cceqb", + "name": "output", + "type": "json", + "required": false, + "presentable": false, + "unique": false, + "options": { + "maxSize": 2000000 + } + }, + { + "system": false, + "id": "2yfxbxuf", + "name": "succeed", + "type": "bool", + "required": false, + "presentable": false, + "unique": false, + "options": {} + } + ], + "indexes": [], + "listRule": null, + "viewRule": null, + "createRule": null, + "updateRule": null, + "deleteRule": null, + "options": {} + }, + { + "id": "4szxr9x43tpj6np", + "created": "2024-11-18 01:36:34.011Z", + "updated": "2024-11-19 06:50:53.806Z", + "name": "certificate", + "type": "base", + "system": false, + "schema": [ + { + "system": false, + "id": "fugxf58p", + "name": "san", + "type": "text", + "required": false, + "presentable": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "plmambpz", + "name": "certificate", + "type": "text", + "required": false, + "presentable": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "49qvwxcg", + "name": "privateKey", + "type": "text", + "required": false, + "presentable": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "agt7n5bb", + "name": "issuerCertificate", + "type": "text", + "required": false, + "presentable": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "ayyjy5ve", + "name": "certUrl", + "type": "url", + "required": false, + "presentable": false, + "unique": false, + "options": { + "exceptDomains": null, + "onlyDomains": null + } + }, + { + "system": false, + "id": "3x5heo8e", + "name": "certStableUrl", + "type": "url", + "required": false, + "presentable": false, + "unique": false, + "options": { + "exceptDomains": null, + "onlyDomains": null + } + }, + { + "system": false, + "id": "2ohlr0yd", + "name": "output", + "type": "relation", + "required": false, + "presentable": false, + "unique": false, + "options": { + "collectionId": "bqnxb95f2cooowp", + "cascadeDelete": false, + "minSelect": null, + "maxSelect": 1, + "displayFields": null + } + }, + { + "system": false, + "id": "zgpdby2k", + "name": "expireAt", + "type": "date", + "required": false, + "presentable": false, + "unique": false, + "options": { + "min": "", + "max": "" + } + }, + { + "system": false, + "id": "uvqfamb1", + "name": "workflow", + "type": "relation", + "required": false, + "presentable": false, + "unique": false, + "options": { + "collectionId": "tovyif5ax6j62ur", + "cascadeDelete": false, + "minSelect": null, + "maxSelect": 1, + "displayFields": null + } + }, + { + "system": false, + "id": "uqldzldw", + "name": "nodeId", + "type": "text", + "required": false, + "presentable": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + } + ], + "indexes": [], + "listRule": null, + "viewRule": null, + "createRule": null, + "updateRule": null, + "deleteRule": null, + "options": {} + }, + { + "id": "qjp8lygssgwyqyz", + "created": "2024-11-19 07:58:21.573Z", + "updated": "2024-11-19 07:59:50.658Z", + "name": "workflow_run_log", + "type": "base", + "system": false, + "schema": [ + { + "system": false, + "id": "m8xfsyyy", + "name": "workflow", + "type": "relation", + "required": false, + "presentable": false, + "unique": false, + "options": { + "collectionId": "tovyif5ax6j62ur", + "cascadeDelete": false, + "minSelect": null, + "maxSelect": 1, + "displayFields": null + } + }, + { + "system": false, + "id": "2m9byaa9", + "name": "log", + "type": "json", + "required": false, + "presentable": false, + "unique": false, + "options": { + "maxSize": 2000000 + } + }, + { + "system": false, + "id": "cht6kqw9", + "name": "succeed", + "type": "bool", + "required": false, + "presentable": false, + "unique": false, + "options": {} + }, + { + "system": false, + "id": "hvebkuxw", + "name": "error", + "type": "text", + "required": false, + "presentable": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + } + ], + "indexes": [], + "listRule": null, + "viewRule": null, + "createRule": null, + "updateRule": null, + "deleteRule": null, + "options": {} + } + ]` + + collections := []*models.Collection{} + if err := json.Unmarshal([]byte(jsonData), &collections); err != nil { + return err + } + + return daos.New(db).ImportCollections(collections, true, nil) + }, func(db dbx.Builder) error { + return nil + }) +} diff --git a/ui/src/components/certimate/AccessLocalForm.tsx b/ui/src/components/certimate/AccessLocalForm.tsx index 23184b66..ba5611a2 100644 --- a/ui/src/components/certimate/AccessLocalForm.tsx +++ b/ui/src/components/certimate/AccessLocalForm.tsx @@ -19,7 +19,7 @@ type AccessLocalFormProps = { }; const AccessLocalForm = ({ data, op, onAfterReq }: AccessLocalFormProps) => { - const { addAccess, updateAccess, reloadAccessGroups } = useConfigContext(); + const { addAccess, updateAccess } = useConfigContext(); const { t } = useTranslation(); const formSchema = z.object({ @@ -64,8 +64,6 @@ const AccessLocalForm = ({ data, op, onAfterReq }: AccessLocalFormProps) => { } else { addAccess(req); } - - reloadAccessGroups(); } catch (e) { const err = e as ClientResponseError; diff --git a/ui/src/components/certimate/AccessSSHForm.tsx b/ui/src/components/certimate/AccessSSHForm.tsx index 797538b0..ed9f3cb3 100644 --- a/ui/src/components/certimate/AccessSSHForm.tsx +++ b/ui/src/components/certimate/AccessSSHForm.tsx @@ -12,7 +12,6 @@ import { readFileContent } from "@/lib/file"; import { PbErrorData } from "@/domain/base"; import { accessProvidersMap, accessTypeFormSchema, type Access, type SSHConfig } from "@/domain/access"; import { save } from "@/repository/access"; -import { updateById } from "@/repository/access_group"; import { useConfigContext } from "@/providers/config"; type AccessSSHFormProps = { @@ -22,15 +21,13 @@ type AccessSSHFormProps = { }; const AccessSSHForm = ({ data, op, onAfterReq }: AccessSSHFormProps) => { - const { addAccess, updateAccess, reloadAccessGroups } = useConfigContext(); + const { addAccess, updateAccess } = useConfigContext(); const fileInputRef = useRef(null); const [fileName, setFileName] = useState(""); const { t } = useTranslation(); - const originGroup = data ? (data.group ? data.group : "") : ""; - const domainReg = /^(?:\*\.)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$/; const ipReg = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/; @@ -136,25 +133,6 @@ const AccessSSHForm = ({ data, op, onAfterReq }: AccessSSHFormProps) => { } else { addAccess(req); } - - // 同步更新授权组 - if (group != originGroup) { - if (originGroup) { - await updateById({ - id: originGroup, - "access-": req.id, - }); - } - - if (group) { - await updateById({ - id: group, - "access+": req.id, - }); - } - } - - reloadAccessGroups(); } catch (e) { const err = e as ClientResponseError; diff --git a/ui/src/domain/version.ts b/ui/src/domain/version.ts index d0c90d4e..d925c9c3 100644 --- a/ui/src/domain/version.ts +++ b/ui/src/domain/version.ts @@ -1 +1 @@ -export const version = "Certimate v0.3.0-alpha.2"; +export const version = "Certimate v0.3.0-alpha.3"; diff --git a/ui/src/providers/config/index.tsx b/ui/src/providers/config/index.tsx index d484859c..511a3d4c 100644 --- a/ui/src/providers/config/index.tsx +++ b/ui/src/providers/config/index.tsx @@ -1,17 +1,15 @@ import { createContext, ReactNode, useCallback, useContext, useEffect, useReducer } from "react"; import { Access } from "@/domain/access"; -import { AccessGroup } from "@/domain/access_groups"; import { EmailsSetting, Setting } from "@/domain/settings"; import { list } from "@/repository/access"; -import { list as getAccessGroups } from "@/repository/access_group"; + import { getEmails } from "@/repository/settings"; import { configReducer } from "./reducer"; export type ConfigData = { accesses: Access[]; emails: Setting; - accessGroups: AccessGroup[]; }; export type ConfigContext = { @@ -20,8 +18,6 @@ export type ConfigContext = { addAccess: (access: Access) => void; updateAccess: (access: Access) => void; deleteAccess: (id: string) => void; - setAccessGroups: (accessGroups: AccessGroup[]) => void; - reloadAccessGroups: () => void; }; const Context = createContext({} as ConfigContext); @@ -36,7 +32,6 @@ export const ConfigProvider = ({ children }: ConfigProviderProps) => { const [config, dispatchConfig] = useReducer(configReducer, { accesses: [], emails: { content: { emails: [] } }, - accessGroups: [], }); useEffect(() => { @@ -55,19 +50,6 @@ export const ConfigProvider = ({ children }: ConfigProviderProps) => { featchEmails(); }, []); - useEffect(() => { - const featchAccessGroups = async () => { - const accessGroups = await getAccessGroups(); - dispatchConfig({ type: "SET_ACCESS_GROUPS", payload: accessGroups }); - }; - featchAccessGroups(); - }, []); - - const reloadAccessGroups = useCallback(async () => { - const accessGroups = await getAccessGroups(); - dispatchConfig({ type: "SET_ACCESS_GROUPS", payload: accessGroups }); - }, []); - const setEmails = useCallback((emails: Setting) => { dispatchConfig({ type: "SET_EMAILS", payload: emails }); }, []); @@ -84,24 +66,17 @@ export const ConfigProvider = ({ children }: ConfigProviderProps) => { dispatchConfig({ type: "UPDATE_ACCESS", payload: access }); }, []); - const setAccessGroups = useCallback((accessGroups: AccessGroup[]) => { - dispatchConfig({ type: "SET_ACCESS_GROUPS", payload: accessGroups }); - }, []); - return ( {children && children} diff --git a/ui/src/providers/config/reducer.ts b/ui/src/providers/config/reducer.ts index fd45386c..9586f9bb 100644 --- a/ui/src/providers/config/reducer.ts +++ b/ui/src/providers/config/reducer.ts @@ -1,5 +1,4 @@ import { Access } from "@/domain/access"; -import { AccessGroup } from "@/domain/access_groups"; import { EmailsSetting, Setting } from "@/domain/settings"; import { ConfigData } from "./"; @@ -9,8 +8,7 @@ type Action = | { type: "UPDATE_ACCESS"; payload: Access } | { type: "SET_ACCESSES"; payload: Access[] } | { type: "SET_EMAILS"; payload: Setting } - | { type: "ADD_EMAIL"; payload: string } - | { type: "SET_ACCESS_GROUPS"; payload: AccessGroup[] }; + | { type: "ADD_EMAIL"; payload: string }; export const configReducer = (state: ConfigData, action: Action): ConfigData => { switch (action.type) { @@ -55,12 +53,6 @@ export const configReducer = (state: ConfigData, action: Action): ConfigData => }, }; } - case "SET_ACCESS_GROUPS": { - return { - ...state, - accessGroups: action.payload, - }; - } default: return state; } diff --git a/ui/src/repository/access_group.ts b/ui/src/repository/access_group.ts deleted file mode 100644 index 41080f8c..00000000 --- a/ui/src/repository/access_group.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { Access } from "@/domain/access"; -import { AccessGroup } from "@/domain/access_groups"; -import { getPb } from "./api"; - -export const list = async () => { - const resp = await getPb().collection("access_groups").getFullList({ - sort: "-created", - expand: "access", - }); - - return resp; -}; - -export const remove = async (id: string) => { - const pb = getPb(); - - // 查询有没有关联的access - const accessGroup = await pb.collection("access").getList(1, 1, { - filter: `group='${id}' && deleted=null`, - }); - - if (accessGroup.items.length > 0) { - throw new Error("该分组下有授权配置,无法删除"); - } - - await pb.collection("access_groups").delete(id); -}; - -export const update = async (accessGroup: AccessGroup) => { - const pb = getPb(); - if (accessGroup.id) { - return await pb.collection("access_groups").update(accessGroup.id, accessGroup); - } - return await pb.collection("access_groups").create(accessGroup); -}; - -type UpdateByIdReq = { - id: string; - [key: string]: string | string[]; -}; - -export const updateById = async (req: UpdateByIdReq) => { - const pb = getPb(); - return await pb.collection("access_groups").update(req.id, req); -};