From 960c2567bda7fea1a613ad86bd68835454df16a9 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 29 Aug 2018 12:36:44 -0400 Subject: [PATCH] can access premium for orgs --- src/Android/Services/DeviceActionService.cs | 4 ++-- src/App/Abstractions/Services/IAppSettingsService.cs | 1 + src/App/Constants.cs | 1 + .../Api/Response/ProfileOrganizationResponse.cs | 3 +++ src/App/Pages/Vault/VaultAttachmentsPage.cs | 4 +--- src/App/Pages/Vault/VaultViewCipherPage.cs | 8 +++----- src/App/Services/AppSettingsService.cs | 12 ++++++++++++ src/App/Services/AuthService.cs | 3 +++ src/App/Services/SyncService.cs | 1 + src/App/Utilities/Helpers.cs | 11 +++++++++++ src/iOS.Extension/LoginListViewController.cs | 9 +++++---- 11 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/Android/Services/DeviceActionService.cs b/src/Android/Services/DeviceActionService.cs index 93527ed14..9bc64c0e1 100644 --- a/src/Android/Services/DeviceActionService.cs +++ b/src/Android/Services/DeviceActionService.cs @@ -25,6 +25,7 @@ using System.Linq; using Plugin.Settings.Abstractions; using Android.Views.InputMethods; using Android.Widget; +using Bit.App.Utilities; namespace Bit.Android.Services { @@ -240,10 +241,9 @@ namespace Bit.Android.Services } else { - var isPremium = Resolver.Resolve()?.TokenPremium ?? false; var settings = Resolver.Resolve(); var autoCopyEnabled = !settings.GetValueOrDefault(Constants.SettingDisableTotpCopy, false); - if(isPremium && autoCopyEnabled && cipher.LoginTotp?.Value != null) + if(Helpers.CanAccessPremium() && autoCopyEnabled && cipher.LoginTotp?.Value != null) { CopyToClipboard(App.Utilities.Crypto.Totp(cipher.LoginTotp.Value)); } diff --git a/src/App/Abstractions/Services/IAppSettingsService.cs b/src/App/Abstractions/Services/IAppSettingsService.cs index c37d604a4..2249b019c 100644 --- a/src/App/Abstractions/Services/IAppSettingsService.cs +++ b/src/App/Abstractions/Services/IAppSettingsService.cs @@ -18,5 +18,6 @@ namespace Bit.App.Abstractions string IdentityUrl { get; set; } string IconsUrl { get; set; } bool ClearCiphersCache { get; set; } + bool OrganizationGivesPremium { get; set; } } } \ No newline at end of file diff --git a/src/App/Constants.cs b/src/App/Constants.cs index 96f038a92..a9dffa1d7 100644 --- a/src/App/Constants.cs +++ b/src/App/Constants.cs @@ -47,6 +47,7 @@ public const string IconsUrl = "other:iconsUrl"; public const string FailedPinAttempts = "other:failedPinAttempts"; public const string ClearCiphersCache = "other:clearCiphersCache"; + public const string OrgGivesPremium = "other:orgGivesPremium"; public const int SelectFileRequestCode = 42; public const int SelectFilePermissionRequestCode = 43; diff --git a/src/App/Models/Api/Response/ProfileOrganizationResponse.cs b/src/App/Models/Api/Response/ProfileOrganizationResponse.cs index 33f25c277..bbaddd5c0 100644 --- a/src/App/Models/Api/Response/ProfileOrganizationResponse.cs +++ b/src/App/Models/Api/Response/ProfileOrganizationResponse.cs @@ -8,7 +8,10 @@ namespace Bit.App.Models.Api public string Name { get; set; } public bool UseGroups { get; set; } public bool UseDirectory { get; set; } + public bool UseEvents { get; set; } public bool UseTotp { get; set; } + public bool Use2fa { get; set; } + public bool UsersGetPremium { get; set; } public int Seats { get; set; } public int MaxCollections { get; set; } public short? MaxStorageGb { get; set; } diff --git a/src/App/Pages/Vault/VaultAttachmentsPage.cs b/src/App/Pages/Vault/VaultAttachmentsPage.cs index 7aeb6f37c..6d5874195 100644 --- a/src/App/Pages/Vault/VaultAttachmentsPage.cs +++ b/src/App/Pages/Vault/VaultAttachmentsPage.cs @@ -19,7 +19,6 @@ namespace Bit.App.Pages private readonly IConnectivity _connectivity; private readonly IDeviceActionService _deviceActionService; private readonly IGoogleAnalyticsService _googleAnalyticsService; - private readonly ITokenService _tokenService; private readonly ICryptoService _cryptoService; private readonly string _cipherId; private Cipher _cipher; @@ -35,7 +34,6 @@ namespace Bit.App.Pages _connectivity = Resolver.Resolve(); _deviceActionService = Resolver.Resolve(); _googleAnalyticsService = Resolver.Resolve(); - _tokenService = Resolver.Resolve(); _cryptoService = Resolver.Resolve(); Init(); @@ -210,7 +208,7 @@ namespace Bit.App.Pages ToolbarItems.RemoveAt(0); } - if(_cipher != null && (_tokenService.TokenPremium || _cipher.OrganizationId != null)) + if(_cipher != null && (Helpers.CanAccessPremium() || _cipher.OrganizationId != null)) { ToolbarItems.Add(SaveToolbarItem); ListView.Footer = NewTable; diff --git a/src/App/Pages/Vault/VaultViewCipherPage.cs b/src/App/Pages/Vault/VaultViewCipherPage.cs index 477e3bd16..97fcca783 100644 --- a/src/App/Pages/Vault/VaultViewCipherPage.cs +++ b/src/App/Pages/Vault/VaultViewCipherPage.cs @@ -20,7 +20,6 @@ namespace Bit.App.Pages private readonly string _cipherId; private readonly ICipherService _cipherService; private readonly IDeviceActionService _deviceActionService; - private readonly ITokenService _tokenService; private DateTime? _timerStarted = null; private TimeSpan _timerMaxLength = TimeSpan.FromMinutes(5); @@ -30,7 +29,6 @@ namespace Bit.App.Pages _cipherId = cipherId; _cipherService = Resolver.Resolve(); _deviceActionService = Resolver.Resolve(); - _tokenService = Resolver.Resolve(); Init(); } @@ -363,7 +361,7 @@ namespace Bit.App.Pages { Table.Root.Remove(AttachmentsSection); } - if(Model.ShowAttachments && (_tokenService.TokenPremium || cipher.OrganizationId != null)) + if(Model.ShowAttachments && (Helpers.CanAccessPremium() || cipher.OrganizationId != null)) { AttachmentsSection = new TableSection(AppResources.Attachments); AttachmentCells = new List(); @@ -407,7 +405,7 @@ namespace Bit.App.Pages { ItemInformationSection.Remove(LoginTotpCodeCell); } - if(cipher.Login?.Totp != null && (_tokenService.TokenPremium || cipher.OrganizationUseTotp)) + if(cipher.Login?.Totp != null && (Helpers.CanAccessPremium() || cipher.OrganizationUseTotp)) { var totpKey = cipher.Login?.Totp.Decrypt(cipher.OrganizationId); if(!string.IsNullOrWhiteSpace(totpKey)) @@ -482,7 +480,7 @@ namespace Bit.App.Pages private async Task OpenAttachmentAsync(Cipher cipher, VaultViewCipherPageModel.Attachment attachment) { - if(!_tokenService.TokenPremium && !cipher.OrganizationUseTotp) + if(!Helpers.CanAccessPremium() && !cipher.OrganizationUseTotp) { await DisplayAlert(null, AppResources.PremiumRequired, AppResources.Ok); return; diff --git a/src/App/Services/AppSettingsService.cs b/src/App/Services/AppSettingsService.cs index a24052261..c02c66a07 100644 --- a/src/App/Services/AppSettingsService.cs +++ b/src/App/Services/AppSettingsService.cs @@ -208,5 +208,17 @@ namespace Bit.App.Services _settings.AddOrUpdateValue(Constants.ClearCiphersCache, value); } } + + public bool OrganizationGivesPremium + { + get + { + return _settings.GetValueOrDefault(Constants.OrgGivesPremium, false); + } + set + { + _settings.AddOrUpdateValue(Constants.OrgGivesPremium, value); + } + } } } diff --git a/src/App/Services/AuthService.cs b/src/App/Services/AuthService.cs index 41eb26f60..19c05dad6 100644 --- a/src/App/Services/AuthService.cs +++ b/src/App/Services/AuthService.cs @@ -367,6 +367,7 @@ namespace Bit.App.Services Email = _tokenService.TokenEmail; _settings.AddOrUpdateValue(Constants.LastLoginEmail, Email); _appSettingsService.FailedPinAttempts = 0; + _appSettingsService.OrganizationGivesPremium = false; if(response.PrivateKey != null) { @@ -374,6 +375,8 @@ namespace Bit.App.Services if(profile.Succeeded) { _cryptoService.SetOrgKeys(profile.Result); + _appSettingsService.OrganizationGivesPremium = + profile.Result?.Organizations?.Any(o => o.UsersGetPremium) ?? false; } } diff --git a/src/App/Services/SyncService.cs b/src/App/Services/SyncService.cs index 8fb769cee..b23cdb84b 100644 --- a/src/App/Services/SyncService.cs +++ b/src/App/Services/SyncService.cs @@ -543,6 +543,7 @@ namespace Bit.App.Services } _cryptoService.SetOrgKeys(profile); + _appSettingsService.OrganizationGivesPremium = profile.Organizations?.Any(o => o.UsersGetPremium) ?? false; return Task.FromResult(0); } diff --git a/src/App/Utilities/Helpers.cs b/src/App/Utilities/Helpers.cs index 9c2605457..663f604b3 100644 --- a/src/App/Utilities/Helpers.cs +++ b/src/App/Utilities/Helpers.cs @@ -558,5 +558,16 @@ namespace Bit.App.Utilities } return dict; } + + public static bool CanAccessPremium() + { + var tokenService = Resolver.Resolve(); + if(tokenService?.TokenPremium ?? false) + { + return true; + } + var appSettingsService = Resolver.Resolve(); + return appSettingsService?.OrganizationGivesPremium ?? false; + } } } diff --git a/src/iOS.Extension/LoginListViewController.cs b/src/iOS.Extension/LoginListViewController.cs index 2835ee21d..48a5648cb 100644 --- a/src/iOS.Extension/LoginListViewController.cs +++ b/src/iOS.Extension/LoginListViewController.cs @@ -15,6 +15,7 @@ using MobileCoreServices; using Bit.iOS.Core.Controllers; using Bit.App.Resources; using Bit.App.Models; +using Bit.App.Utilities; namespace Bit.iOS.Extension { @@ -107,13 +108,13 @@ namespace Bit.iOS.Extension private LoginListViewController _controller; private ICipherService _cipherService; private ISettings _settings; - private bool _isPremium; + private bool _accessPremium; public TableSource(LoginListViewController controller) { _context = controller.Context; _controller = controller; - _isPremium = Resolver.Resolve()?.TokenPremium ?? false; + _accessPremium = Helpers.CanAccessPremium(); _cipherService = Resolver.Resolve(); _settings = Resolver.Resolve(); } @@ -275,11 +276,11 @@ namespace Bit.iOS.Extension private string GetTotp(CipherViewModel item) { string totp = null; - if(_isPremium) + if(_accessPremium) { if(item != null && !string.IsNullOrWhiteSpace(item.Totp.Value)) { - totp = App.Utilities.Crypto.Totp(item.Totp.Value); + totp = Crypto.Totp(item.Totp.Value); } }