getAccessForMember static method

Future<Tuple2<PrivilegeLevel, bool>> getAccessForMember(
  1. MemberModel? member,
  2. String appId
)

Implementation

static Future<Tuple2<PrivilegeLevel, bool>> getAccessForMember(
    MemberModel? member, String appId) async {
  AccessModel? accessModel;
  if (member != null) {
    accessModel =
        await accessRepository(appId: appId)!.get(member.documentID);
  }
  PrivilegeLevel? privilegeLevel;
  bool isBlocked = false;
  if (accessModel != null) {
    privilegeLevel = accessModel.privilegeLevel;
    isBlocked = accessModel.blocked ?? false;
  } else {
    privilegeLevel = PrivilegeLevel.noPrivilege;
    if (member != null) {
      // normally this would have happened when accepting the app's terms, but anyway
      // create an access entry. creation with privilege level 0 is allowed
      await accessRepository(appId: appId)!.add(AccessModel(
        documentID: member.documentID,
        appId: appId,
        privilegeLevel: PrivilegeLevel.noPrivilege,
        points: 0,
      ));
    }
  }
  return Tuple2(privilegeLevel ?? PrivilegeLevel.noPrivilege, isBlocked);
}