getCurrentUserRoles method

  1. @override
Future<RequestResponse<List<String>>?> getCurrentUserRoles()
override

Returns an array of roles assigned to the currently logged in user.

Implementation

@override
Future<RequestResponse<List<String>>?> getCurrentUserRoles() async {
  await getFrappe().checkAppInstalled(features: ['getCurrentUserRoles']);

  final response = await Request.initiateRequest(
      url: config.hostUrl +
          '/api/method/renovation_core.utils.client.get_current_user_roles',
      method: HttpMethod.GET);

  if (response.isSuccess && response.data != null) {
    final map = Request.convertToMap(response.rawResponse!)!;

    // Since the return is List<dynamic>
    currentUserRoles = <String>[...map['message']];
  } else {
    currentUserRoles = null;
  }

  return response.isSuccess
      ? RequestResponse.success(currentUserRoles!,
          rawResponse: response.rawResponse)
      : handleError('get_current_user_roles', response.error)
          as FutureOr<RequestResponse<List<String>>?>;
}