Skip to content

Commit 258654c

Browse files
chore: replace deprecated methods in 8.0.0 (#6644)
* feat: deprecate getUserRoles * feat: remove deprecated method setUserPassword and setUserProfileMethod * fix: comments * fix: encrypt currentPassword * fix: change serverVersion to compare in getUserRoles
1 parent db378e8 commit 258654c

File tree

5 files changed

+33
-25
lines changed

5 files changed

+33
-25
lines changed

app/definitions/IUser.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,11 @@ export interface IUser extends IRocketChatRecord, ILoggedUser {
149149
ldap?: boolean;
150150
muted?: boolean;
151151
}
152-
152+
export interface IRoleUser {
153+
_id: string;
154+
username: string;
155+
roles: string[];
156+
}
153157
export interface IRegisterUser extends IUser {
154158
username: string;
155159
name: string;

app/definitions/rest/v1/roles.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { IRole } from '../../IRole';
22
import { RocketChatRecordDeleted } from '../../IRocketChatRecord';
3-
import { IUser } from '../../IUser';
3+
import { IRoleUser, IUser } from '../../IUser';
44

55
type RoleCreateProps = Pick<IRole, 'name'> & Partial<Pick<IRole, 'description' | 'scope' | 'mandatory2fa'>>;
66

@@ -73,4 +73,11 @@ export type RolesEndpoints = {
7373
role: IRole;
7474
};
7575
};
76+
77+
'roles.getUsersInPublicRoles': {
78+
GET: () => {
79+
users: IRoleUser[];
80+
success: boolean;
81+
};
82+
};
7683
};

app/lib/services/restApi.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
INotificationPreferences,
66
IPreviewItem,
77
IProfileParams,
8+
IRoleUser,
89
IRoom,
910
IRoomNotifications,
1011
IServerRoom,
@@ -1069,15 +1070,6 @@ export const videoConferenceStart = (roomId: string) => sdk.post('video-conferen
10691070

10701071
export const videoConferenceCancel = (callId: string) => sdk.post('video-conference.cancel', { callId });
10711072

1072-
export const saveUserProfileMethod = (
1073-
params: IProfileParams,
1074-
customFields = {},
1075-
twoFactorOptions: {
1076-
twoFactorCode: string;
1077-
twoFactorMethod: string;
1078-
} | null
1079-
) => sdk.current.methodCall('saveUserProfile', params, customFields, twoFactorOptions);
1080-
10811073
export const deleteOwnAccount = (password: string, confirmRelinquish = false): any =>
10821074
// RC 0.67.0
10831075
sdk.post('users.deleteOwnAccount', { password, confirmRelinquish });
@@ -1087,9 +1079,19 @@ export const postMessage = (roomId: string, text: string) => sdk.post('chat.post
10871079
export const notifyUser = (type: string, params: Record<string, any>): Promise<boolean> =>
10881080
sdk.methodCall('stream-notify-user', type, params);
10891081

1090-
export const getUsersRoles = (): Promise<boolean> => sdk.methodCall('getUserRoles');
1082+
export const getUsersRoles = async (): Promise<boolean | IRoleUser[]> => {
1083+
const serverVersion = reduxStore.getState().server.version;
1084+
if (compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '7.10.0')) {
1085+
// RC 7.10.0
1086+
const response = await sdk.get('roles.getUsersInPublicRoles');
1087+
if (response.success) {
1088+
return response.users;
1089+
}
1090+
return false;
1091+
}
1092+
// https://github.com/RocketChat/Rocket.Chat/blob/7787147da2be90f5f4d137ba477e708083dcf814/apps/meteor/app/lib/server/methods/getUserRoles.ts#L20
1093+
return sdk.methodCall('getUserRoles');
1094+
};
10911095

10921096
export const getSupportedVersionsCloud = (uniqueId?: string, domain?: string) =>
10931097
fetch(`https://releases.rocket.chat/v2/server/supportedVersions?uniqueId=${uniqueId}&domain=${domain}&source=mobile`);
1094-
1095-
export const setUserPassword = (password: string) => sdk.methodCall('setUserPassword', password);

app/views/ChangePasswordView/index.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { NativeStackNavigationProp } from '@react-navigation/native-stack';
77
import { useDispatch } from 'react-redux';
88
import { sha256 } from 'js-sha256';
99

10+
import { IProfileParams } from '../../definitions/IProfile';
1011
import { twoFactor } from '../../lib/services/twoFactor';
1112
import { ProfileStackParamList } from '../../stacks/types';
1213
import { ControlledFormTextInput } from '../../containers/TextInput';
@@ -104,11 +105,11 @@ const ChangePasswordView = ({ navigation }: IChangePasswordViewProps) => {
104105
};
105106

106107
const changePassword = async () => {
107-
const { newPassword } = inputValues;
108+
const { newPassword, currentPassword } = inputValues;
108109

109110
try {
110111
setValue('saving', true);
111-
await Services.setUserPassword(newPassword);
112+
await Services.saveUserProfile({ newPassword, currentPassword: sha256(currentPassword) } as IProfileParams);
112113
dispatch(setUser({ requirePasswordChange: false }));
113114
navigation.goBack();
114115
} catch (error: any) {
@@ -131,10 +132,8 @@ const ChangePasswordView = ({ navigation }: IChangePasswordViewProps) => {
131132
const { username, emails } = user;
132133
if (fromProfileView) {
133134
const params = { currentPassword: sha256(currentPassword), newPassword, username, email: emails?.[0].address || '' };
134-
const twoFactorOptions = currentPassword
135-
? { twoFactorCode: params?.currentPassword, twoFactorMethod: TwoFactorMethods.PASSWORD }
136-
: null;
137-
const result = await Services.saveUserProfileMethod(params, {}, twoFactorCode || twoFactorOptions);
135+
136+
const result = await Services.saveUserProfile(params);
138137

139138
if (result) {
140139
logEvent(events.PROFILE_SAVE_CHANGES);

app/views/ProfileView/index.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,7 @@ const ProfileView = ({ navigation }: IProfileViewProps): React.ReactElement => {
194194
}
195195

196196
try {
197-
const twoFactorOptions = params.currentPassword
198-
? { twoFactorCode: params.currentPassword, twoFactorMethod: TwoFactorMethods.PASSWORD }
199-
: null;
200-
201-
const result = await Services.saveUserProfileMethod(params, customFields, twoFactorCode || twoFactorOptions);
197+
const result = await Services.saveUserProfile(params, customFields);
202198

203199
if (result) {
204200
logEvent(events.PROFILE_SAVE_CHANGES);

0 commit comments

Comments
 (0)