mirror of
https://github.com/bitwarden/android.git
synced 2024-11-01 07:35:52 +03:00
can access premium for orgs
This commit is contained in:
parent
430e4dd445
commit
960c2567bd
11 changed files with 43 additions and 14 deletions
|
@ -25,6 +25,7 @@ using System.Linq;
|
||||||
using Plugin.Settings.Abstractions;
|
using Plugin.Settings.Abstractions;
|
||||||
using Android.Views.InputMethods;
|
using Android.Views.InputMethods;
|
||||||
using Android.Widget;
|
using Android.Widget;
|
||||||
|
using Bit.App.Utilities;
|
||||||
|
|
||||||
namespace Bit.Android.Services
|
namespace Bit.Android.Services
|
||||||
{
|
{
|
||||||
|
@ -240,10 +241,9 @@ namespace Bit.Android.Services
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var isPremium = Resolver.Resolve<ITokenService>()?.TokenPremium ?? false;
|
|
||||||
var settings = Resolver.Resolve<ISettings>();
|
var settings = Resolver.Resolve<ISettings>();
|
||||||
var autoCopyEnabled = !settings.GetValueOrDefault(Constants.SettingDisableTotpCopy, false);
|
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));
|
CopyToClipboard(App.Utilities.Crypto.Totp(cipher.LoginTotp.Value));
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,5 +18,6 @@ namespace Bit.App.Abstractions
|
||||||
string IdentityUrl { get; set; }
|
string IdentityUrl { get; set; }
|
||||||
string IconsUrl { get; set; }
|
string IconsUrl { get; set; }
|
||||||
bool ClearCiphersCache { get; set; }
|
bool ClearCiphersCache { get; set; }
|
||||||
|
bool OrganizationGivesPremium { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -47,6 +47,7 @@
|
||||||
public const string IconsUrl = "other:iconsUrl";
|
public const string IconsUrl = "other:iconsUrl";
|
||||||
public const string FailedPinAttempts = "other:failedPinAttempts";
|
public const string FailedPinAttempts = "other:failedPinAttempts";
|
||||||
public const string ClearCiphersCache = "other:clearCiphersCache";
|
public const string ClearCiphersCache = "other:clearCiphersCache";
|
||||||
|
public const string OrgGivesPremium = "other:orgGivesPremium";
|
||||||
|
|
||||||
public const int SelectFileRequestCode = 42;
|
public const int SelectFileRequestCode = 42;
|
||||||
public const int SelectFilePermissionRequestCode = 43;
|
public const int SelectFilePermissionRequestCode = 43;
|
||||||
|
|
|
@ -8,7 +8,10 @@ namespace Bit.App.Models.Api
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public bool UseGroups { get; set; }
|
public bool UseGroups { get; set; }
|
||||||
public bool UseDirectory { get; set; }
|
public bool UseDirectory { get; set; }
|
||||||
|
public bool UseEvents { get; set; }
|
||||||
public bool UseTotp { get; set; }
|
public bool UseTotp { get; set; }
|
||||||
|
public bool Use2fa { get; set; }
|
||||||
|
public bool UsersGetPremium { get; set; }
|
||||||
public int Seats { get; set; }
|
public int Seats { get; set; }
|
||||||
public int MaxCollections { get; set; }
|
public int MaxCollections { get; set; }
|
||||||
public short? MaxStorageGb { get; set; }
|
public short? MaxStorageGb { get; set; }
|
||||||
|
|
|
@ -19,7 +19,6 @@ namespace Bit.App.Pages
|
||||||
private readonly IConnectivity _connectivity;
|
private readonly IConnectivity _connectivity;
|
||||||
private readonly IDeviceActionService _deviceActionService;
|
private readonly IDeviceActionService _deviceActionService;
|
||||||
private readonly IGoogleAnalyticsService _googleAnalyticsService;
|
private readonly IGoogleAnalyticsService _googleAnalyticsService;
|
||||||
private readonly ITokenService _tokenService;
|
|
||||||
private readonly ICryptoService _cryptoService;
|
private readonly ICryptoService _cryptoService;
|
||||||
private readonly string _cipherId;
|
private readonly string _cipherId;
|
||||||
private Cipher _cipher;
|
private Cipher _cipher;
|
||||||
|
@ -35,7 +34,6 @@ namespace Bit.App.Pages
|
||||||
_connectivity = Resolver.Resolve<IConnectivity>();
|
_connectivity = Resolver.Resolve<IConnectivity>();
|
||||||
_deviceActionService = Resolver.Resolve<IDeviceActionService>();
|
_deviceActionService = Resolver.Resolve<IDeviceActionService>();
|
||||||
_googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();
|
_googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();
|
||||||
_tokenService = Resolver.Resolve<ITokenService>();
|
|
||||||
_cryptoService = Resolver.Resolve<ICryptoService>();
|
_cryptoService = Resolver.Resolve<ICryptoService>();
|
||||||
|
|
||||||
Init();
|
Init();
|
||||||
|
@ -210,7 +208,7 @@ namespace Bit.App.Pages
|
||||||
ToolbarItems.RemoveAt(0);
|
ToolbarItems.RemoveAt(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(_cipher != null && (_tokenService.TokenPremium || _cipher.OrganizationId != null))
|
if(_cipher != null && (Helpers.CanAccessPremium() || _cipher.OrganizationId != null))
|
||||||
{
|
{
|
||||||
ToolbarItems.Add(SaveToolbarItem);
|
ToolbarItems.Add(SaveToolbarItem);
|
||||||
ListView.Footer = NewTable;
|
ListView.Footer = NewTable;
|
||||||
|
|
|
@ -20,7 +20,6 @@ namespace Bit.App.Pages
|
||||||
private readonly string _cipherId;
|
private readonly string _cipherId;
|
||||||
private readonly ICipherService _cipherService;
|
private readonly ICipherService _cipherService;
|
||||||
private readonly IDeviceActionService _deviceActionService;
|
private readonly IDeviceActionService _deviceActionService;
|
||||||
private readonly ITokenService _tokenService;
|
|
||||||
private DateTime? _timerStarted = null;
|
private DateTime? _timerStarted = null;
|
||||||
private TimeSpan _timerMaxLength = TimeSpan.FromMinutes(5);
|
private TimeSpan _timerMaxLength = TimeSpan.FromMinutes(5);
|
||||||
|
|
||||||
|
@ -30,7 +29,6 @@ namespace Bit.App.Pages
|
||||||
_cipherId = cipherId;
|
_cipherId = cipherId;
|
||||||
_cipherService = Resolver.Resolve<ICipherService>();
|
_cipherService = Resolver.Resolve<ICipherService>();
|
||||||
_deviceActionService = Resolver.Resolve<IDeviceActionService>();
|
_deviceActionService = Resolver.Resolve<IDeviceActionService>();
|
||||||
_tokenService = Resolver.Resolve<ITokenService>();
|
|
||||||
|
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
|
@ -363,7 +361,7 @@ namespace Bit.App.Pages
|
||||||
{
|
{
|
||||||
Table.Root.Remove(AttachmentsSection);
|
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);
|
AttachmentsSection = new TableSection(AppResources.Attachments);
|
||||||
AttachmentCells = new List<AttachmentViewCell>();
|
AttachmentCells = new List<AttachmentViewCell>();
|
||||||
|
@ -407,7 +405,7 @@ namespace Bit.App.Pages
|
||||||
{
|
{
|
||||||
ItemInformationSection.Remove(LoginTotpCodeCell);
|
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);
|
var totpKey = cipher.Login?.Totp.Decrypt(cipher.OrganizationId);
|
||||||
if(!string.IsNullOrWhiteSpace(totpKey))
|
if(!string.IsNullOrWhiteSpace(totpKey))
|
||||||
|
@ -482,7 +480,7 @@ namespace Bit.App.Pages
|
||||||
|
|
||||||
private async Task OpenAttachmentAsync(Cipher cipher, VaultViewCipherPageModel.Attachment attachment)
|
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);
|
await DisplayAlert(null, AppResources.PremiumRequired, AppResources.Ok);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -208,5 +208,17 @@ namespace Bit.App.Services
|
||||||
_settings.AddOrUpdateValue(Constants.ClearCiphersCache, value);
|
_settings.AddOrUpdateValue(Constants.ClearCiphersCache, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool OrganizationGivesPremium
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _settings.GetValueOrDefault(Constants.OrgGivesPremium, false);
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_settings.AddOrUpdateValue(Constants.OrgGivesPremium, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -367,6 +367,7 @@ namespace Bit.App.Services
|
||||||
Email = _tokenService.TokenEmail;
|
Email = _tokenService.TokenEmail;
|
||||||
_settings.AddOrUpdateValue(Constants.LastLoginEmail, Email);
|
_settings.AddOrUpdateValue(Constants.LastLoginEmail, Email);
|
||||||
_appSettingsService.FailedPinAttempts = 0;
|
_appSettingsService.FailedPinAttempts = 0;
|
||||||
|
_appSettingsService.OrganizationGivesPremium = false;
|
||||||
|
|
||||||
if(response.PrivateKey != null)
|
if(response.PrivateKey != null)
|
||||||
{
|
{
|
||||||
|
@ -374,6 +375,8 @@ namespace Bit.App.Services
|
||||||
if(profile.Succeeded)
|
if(profile.Succeeded)
|
||||||
{
|
{
|
||||||
_cryptoService.SetOrgKeys(profile.Result);
|
_cryptoService.SetOrgKeys(profile.Result);
|
||||||
|
_appSettingsService.OrganizationGivesPremium =
|
||||||
|
profile.Result?.Organizations?.Any(o => o.UsersGetPremium) ?? false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -543,6 +543,7 @@ namespace Bit.App.Services
|
||||||
}
|
}
|
||||||
|
|
||||||
_cryptoService.SetOrgKeys(profile);
|
_cryptoService.SetOrgKeys(profile);
|
||||||
|
_appSettingsService.OrganizationGivesPremium = profile.Organizations?.Any(o => o.UsersGetPremium) ?? false;
|
||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -558,5 +558,16 @@ namespace Bit.App.Utilities
|
||||||
}
|
}
|
||||||
return dict;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ using MobileCoreServices;
|
||||||
using Bit.iOS.Core.Controllers;
|
using Bit.iOS.Core.Controllers;
|
||||||
using Bit.App.Resources;
|
using Bit.App.Resources;
|
||||||
using Bit.App.Models;
|
using Bit.App.Models;
|
||||||
|
using Bit.App.Utilities;
|
||||||
|
|
||||||
namespace Bit.iOS.Extension
|
namespace Bit.iOS.Extension
|
||||||
{
|
{
|
||||||
|
@ -107,13 +108,13 @@ namespace Bit.iOS.Extension
|
||||||
private LoginListViewController _controller;
|
private LoginListViewController _controller;
|
||||||
private ICipherService _cipherService;
|
private ICipherService _cipherService;
|
||||||
private ISettings _settings;
|
private ISettings _settings;
|
||||||
private bool _isPremium;
|
private bool _accessPremium;
|
||||||
|
|
||||||
public TableSource(LoginListViewController controller)
|
public TableSource(LoginListViewController controller)
|
||||||
{
|
{
|
||||||
_context = controller.Context;
|
_context = controller.Context;
|
||||||
_controller = controller;
|
_controller = controller;
|
||||||
_isPremium = Resolver.Resolve<ITokenService>()?.TokenPremium ?? false;
|
_accessPremium = Helpers.CanAccessPremium();
|
||||||
_cipherService = Resolver.Resolve<ICipherService>();
|
_cipherService = Resolver.Resolve<ICipherService>();
|
||||||
_settings = Resolver.Resolve<ISettings>();
|
_settings = Resolver.Resolve<ISettings>();
|
||||||
}
|
}
|
||||||
|
@ -275,11 +276,11 @@ namespace Bit.iOS.Extension
|
||||||
private string GetTotp(CipherViewModel item)
|
private string GetTotp(CipherViewModel item)
|
||||||
{
|
{
|
||||||
string totp = null;
|
string totp = null;
|
||||||
if(_isPremium)
|
if(_accessPremium)
|
||||||
{
|
{
|
||||||
if(item != null && !string.IsNullOrWhiteSpace(item.Totp.Value))
|
if(item != null && !string.IsNullOrWhiteSpace(item.Totp.Value))
|
||||||
{
|
{
|
||||||
totp = App.Utilities.Crypto.Totp(item.Totp.Value);
|
totp = Crypto.Totp(item.Totp.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue