Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

Make patchPrincipal be consistent with other patchXXX

天舟908778b4135c
diff --git a/frontend/src/miragejs/models/index.js b/frontend/src/miragejs/models/index.js
index 1a42c6ad22..802c91ab45 100644
--- a/frontend/src/miragejs/models/index.js
+++ b/frontend/src/miragejs/models/index.js
@@ -16,6 +16,8 @@ export default {
userNew: Model,
+ userPatch: Model,
+
workspace: Model.extend({
roleMapping: hasMany(),
activity: hasMany(),
diff --git a/frontend/src/miragejs/routes/user.js b/frontend/src/miragejs/routes/user.js
index 17709af1db..e5574a44e9 100644
--- a/frontend/src/miragejs/routes/user.js
+++ b/frontend/src/miragejs/routes/user.js
@@ -6,7 +6,7 @@ export default function configureUser(route) {
route.get("/user");
route.post("/user", function (schema, request) {
- const attrs = this.normalizedRequestAttrs("user");
+ const attrs = this.normalizedRequestAttrs("user-new");
const user = schema.users.findBy({ email: attrs.email });
if (user) {
return user;
@@ -15,11 +15,35 @@ export default function configureUser(route) {
});
route.patch("/user/:userId", function (schema, request) {
- const attrs = this.normalizedRequestAttrs("user");
- return schema.users.find(request.params.userId).update(attrs);
+ const attrs = this.normalizedRequestAttrs("user-patch");
+ const user = schema.users.find(request.params.userId);
+
+ if (!user) {
+ return new Response(
+ 404,
+ {},
+ {
+ errors: "User id " + request.params.userId + " not found",
+ }
+ );
+ }
+
+ return user.update(attrs);
});
route.get("/user/:userId/database", function (schema, request) {
+ const user = schema.users.find(request.params.userId);
+
+ if (!user) {
+ return new Response(
+ 404,
+ {},
+ {
+ errors: "User id " + request.params.userId + " not found",
+ }
+ );
+ }
+
return schema.databases.where((database) => {
const dataSourceList = schema.dataSources.where({
workspaceId: WORKSPACE_ID,
diff --git a/frontend/src/store/modules/principal.ts b/frontend/src/store/modules/principal.ts
index d7a5d4c050..244dac7ac8 100644
--- a/frontend/src/store/modules/principal.ts
+++ b/frontend/src/store/modules/principal.ts
@@ -8,6 +8,7 @@ import {
PrincipalState,
PrincipalStatus,
ResourceObject,
+ UserPatch,
unknown,
} from "../../types";
import { isDevOrDemo, randomString } from "../../utils";
@@ -106,15 +107,23 @@ const actions = {
async patchPrincipal(
{ commit, rootGetters }: any,
- principal: PrincipalPatch
+ {
+ principalId,
+ principalPatch,
+ }: {
+ principalId: PrincipalId;
+ principalPatch: PrincipalPatch;
+ }
) {
- const { id, ...attrs } = principal;
+ const userPatch: UserPatch = {
+ name: principalPatch.name,
+ };
const updatedPrincipal = convert(
(
- await axios.patch(`/api/user/${principal.id}`, {
+ await axios.patch(`/api/user/${principalId}`, {
data: {
- type: "user",
- attributes: attrs,
+ type: "userpatch",
+ attributes: userPatch,
},
})
).data.data,
diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.ts
index ef1f62ac3f..2fc9585ea9 100644
--- a/frontend/src/types/bytebase.ts
+++ b/frontend/src/types/bytebase.ts
@@ -281,7 +281,6 @@ export type PrincipalNew = {
};
export type PrincipalPatch = {
- id: PrincipalId;
name?: string;
};
@@ -292,11 +291,8 @@ export type User = {
email: string;
};
-export type NewUser = {
- status: PrincipalStatus;
- name: string;
- email: string;
- password: string;
+export type UserPatch = {
+ name?: string;
};
// Bookmark
diff --git a/frontend/src/views/ProfileDashboard.vue b/frontend/src/views/ProfileDashboard.vue
index 6cdaeb8be1..cc151238de 100644
--- a/frontend/src/views/ProfileDashboard.vue
+++ b/frontend/src/views/ProfileDashboard.vue
@@ -201,7 +201,6 @@ export default {
const editUser = () => {
const clone = cloneDeep(principal.value);
state.editingPrincipal = {
- id: clone.id,
name: clone.name,
};
state.editing = true;
@@ -216,7 +215,10 @@ export default {
const saveEdit = () => {
store
- .dispatch("principal/patchPrincipal", state.editingPrincipal)
+ .dispatch("principal/patchPrincipal", {
+ principalId: principal.value.id,
+ principalPatch: state.editingPrincipal,
+ })
.then(() => {
state.editingPrincipal = undefined;
state.editing = false;