loadBasicPerms method

  1. @override
Future<RequestResponse<BasicPermInfo?>> loadBasicPerms()
override

Returns the basic params from the backend for the current user defined by BasicPermInfo.

In addition, it adds the received permissions in basicPerms.

If a user isn't signed in, the Guest basic permissions is retrieved.

Implementation

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

  if (basicPerms != null) {
    if (basicPerms!.isLoading!) {
      await Future<dynamic>.delayed(Duration(milliseconds: 50));
      return loadBasicPerms();
    } else {
      return RequestResponse.success(basicPerms);
    }
  }

  basicPerms = BasicPermInfo()..isLoading = true;

  final user = config.coreInstance.auth.currentUser ?? 'Guest';

  final response = await Request.initiateRequest(
      url: config.hostUrl +
          '/api/method/renovation_core.utils.client.get_current_user_permissions',
      method: HttpMethod.POST,
      contentType: ContentTypeLiterals.APPLICATION_JSON);
  if (response.isSuccess && response.data != null) {
    response.data!.message != null
        ? basicPerms = (BasicPermInfo.fromJson(response.data!.message)
          ..user = user
          ..isLoading = false)
        : basicPerms = BasicPermInfo();
  }
  return response.isSuccess
      ? RequestResponse.success(basicPerms, rawResponse: response.rawResponse)
      : RequestResponse.fail(handleError('load_basic_perms', response.error));
}