From 0b7425d3b0666a637c6150adceef5441f9314e52 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 31 Jan 2021 15:52:52 +0200 Subject: [PATCH] Check for permission changes --- lib/redux/auth/auth_middleware.dart | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/lib/redux/auth/auth_middleware.dart b/lib/redux/auth/auth_middleware.dart index 1f080e6c4..44104006d 100644 --- a/lib/redux/auth/auth_middleware.dart +++ b/lib/redux/auth/auth_middleware.dart @@ -231,13 +231,32 @@ Middleware _createRefreshRequest(AuthRepository repository) { includeStatic: action.includeStatic || state.staticState.isStale, ) .then((data) { - if (action.clearData && !company.isLarge) { + bool permissionsWereChanged = false; + data.userCompanies.forEach((userCompany) { + state.userCompanyStates.forEach((userCompanyState) { + if (userCompany.company.id == userCompanyState.company.id) { + if (userCompanyState.userCompany.permissionsUpdatedAt > 0 && + userCompany.permissionsUpdatedAt != + userCompanyState.userCompany.permissionsUpdatedAt) { + permissionsWereChanged = true; + } + } + }); + }); + + if (permissionsWereChanged) { + print('## Permissions were changed'); store.dispatch(ClearData()); + store.dispatch(RefreshData(completer: action.completer)); + } else { + if (action.clearData && !company.isLarge) { + store.dispatch(ClearData()); + } + store.dispatch(LoadAccountSuccess( + completer: action.completer, + loginResponse: data, + )); } - store.dispatch(LoadAccountSuccess( - completer: action.completer, - loginResponse: data, - )); }).catchError((Object error) { final message = _parseError('$error'); if (action.completer != null) {