1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-24 11:55:38 +01:00

can access premium for orgs

This commit is contained in:
Kyle Spearrin 2018-08-29 12:36:44 -04:00
parent 430e4dd445
commit 960c2567bd
11 changed files with 43 additions and 14 deletions

View File

@ -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<ITokenService>()?.TokenPremium ?? false;
var settings = Resolver.Resolve<ISettings>();
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));
}

View File

@ -18,5 +18,6 @@ namespace Bit.App.Abstractions
string IdentityUrl { get; set; }
string IconsUrl { get; set; }
bool ClearCiphersCache { get; set; }
bool OrganizationGivesPremium { get; set; }
}
}

View File

@ -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;

View File

@ -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; }

View File

@ -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<IConnectivity>();
_deviceActionService = Resolver.Resolve<IDeviceActionService>();
_googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();
_tokenService = Resolver.Resolve<ITokenService>();
_cryptoService = Resolver.Resolve<ICryptoService>();
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;

View File

@ -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<ICipherService>();
_deviceActionService = Resolver.Resolve<IDeviceActionService>();
_tokenService = Resolver.Resolve<ITokenService>();
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<AttachmentViewCell>();
@ -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;

View File

@ -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);
}
}
}
}

View File

@ -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;
}
}

View File

@ -543,6 +543,7 @@ namespace Bit.App.Services
}
_cryptoService.SetOrgKeys(profile);
_appSettingsService.OrganizationGivesPremium = profile.Organizations?.Any(o => o.UsersGetPremium) ?? false;
return Task.FromResult(0);
}

View File

@ -558,5 +558,16 @@ namespace Bit.App.Utilities
}
return dict;
}
public static bool CanAccessPremium()
{
var tokenService = Resolver.Resolve<ITokenService>();
if(tokenService?.TokenPremium ?? false)
{
return true;
}
var appSettingsService = Resolver.Resolve<IAppSettingsService>();
return appSettingsService?.OrganizationGivesPremium ?? false;
}
}
}

View File

@ -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<ITokenService>()?.TokenPremium ?? false;
_accessPremium = Helpers.CanAccessPremium();
_cipherService = Resolver.Resolve<ICipherService>();
_settings = Resolver.Resolve<ISettings>();
}
@ -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);
}
}