Skip to content

Commit

Permalink
implement patch_self & patch_other on the UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Anish9901 committed Nov 18, 2024
1 parent 5fef10f commit 7b31e81
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
19 changes: 16 additions & 3 deletions mathesar_ui/src/api/rpc/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,31 @@ export const users = {

delete: rpcMethodTypeContainer<{ user_id: User['id'] }, void>(),

patch: rpcMethodTypeContainer<
patch_self: rpcMethodTypeContainer<
{
username: UnsavedUser['username'];
email: UnsavedUser['email'];
full_name: UnsavedUser['full_name'];
display_language: UnsavedUser['display_language'];
},
User
>(),

patch_other: rpcMethodTypeContainer<
{
user_id: User['id'];
user_info: Partial<Omit<UnsavedUser, 'password'>>;
username: UnsavedUser['username'];
is_superuser: User['is_superuser'];
email: UnsavedUser['email'];
full_name: UnsavedUser['full_name'];
display_language: UnsavedUser['display_language'];
},
User
>(),

password: {
replace_own: rpcMethodTypeContainer<
{
user_id: User['id'];
old_password: string;
new_password: string;
},
Expand Down
1 change: 0 additions & 1 deletion mathesar_ui/src/systems/users/PasswordChangeForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
// logged in user is updating their own password
await api.users.password
.replace_own({
user_id: userId,
old_password: formValues.oldPassword,
new_password: formValues.password,
})
Expand Down
9 changes: 6 additions & 3 deletions mathesar_ui/src/systems/users/UserDetailsForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
is_superuser: formValues.userType === 'admin',
display_language: formValues.displayLanguage,
};
const { is_superuser: isSuperuser, ...updateSelfRequest } = request;
if (isNewUser && hasProperty(formValues, 'password')) {
const newUser = await api.users
Expand All @@ -89,11 +90,13 @@
}
if (user) {
await api.users.patch({ user_id: user.id, user_info: request }).run();
if (isUserUpdatingThemselves && userProfileStore) {
userProfileStore.update((details) => details.with(request));
const updatedLocale = request.display_language;
await api.users.patch_self({ ...updateSelfRequest }).run();
userProfileStore.update((details) => details.with(updateSelfRequest));
const updatedLocale = updateSelfRequest.display_language;
await setLanguage(updatedLocale);
} else {
await api.users.patch_other({ user_id: user.id, ...request }).run();
}
dispatch('update');
Expand Down

0 comments on commit 7b31e81

Please sign in to comment.