1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 15:42:48 -05:00

CanAccessPremium checks instead of User.Premium

This commit is contained in:
Kyle Spearrin
2018-08-28 16:23:58 -04:00
parent 90387cca0c
commit c41a1e0936
12 changed files with 130 additions and 35 deletions

View File

@ -14,6 +14,7 @@ namespace Bit.Core.Models.Data
Use2fa = organization.Use2fa;
Using2fa = organization.Use2fa && organization.TwoFactorProviders != null &&
organization.TwoFactorProviders != "{}";
UsersGetPremium = organization.UsersGetPremium;
Enabled = organization.Enabled;
}
@ -21,6 +22,7 @@ namespace Bit.Core.Models.Data
public bool UseEvents { get; set; }
public bool Use2fa { get; set; }
public bool Using2fa { get; set; }
public bool UsersGetPremium { get; set; }
public bool Enabled { get; set; }
}
}

View File

@ -7,6 +7,7 @@ using System.Linq;
using Bit.Core.Services;
using Bit.Core.Exceptions;
using Microsoft.AspNetCore.Identity;
using System.Threading.Tasks;
namespace Bit.Core.Models.Table
{
@ -92,15 +93,21 @@ namespace Bit.Core.Models.Table
_twoFactorProviders = providers;
}
public bool TwoFactorProviderIsEnabled(TwoFactorProviderType provider)
public async Task<bool> TwoFactorProviderIsEnabledAsync(TwoFactorProviderType provider,
IUserService userService)
{
var providers = GetTwoFactorProviders();
if(providers == null || !providers.ContainsKey(provider))
if(providers == null || !providers.ContainsKey(provider) || !providers[provider].Enabled)
{
return false;
}
return providers[provider].Enabled && (Premium || !TwoFactorProvider.RequiresPremium(provider));
if(!TwoFactorProvider.RequiresPremium(provider))
{
return true;
}
return await userService.CanAccessPremium(this);
}
public bool TwoFactorIsEnabled()
@ -111,7 +118,7 @@ namespace Bit.Core.Models.Table
return false;
}
return providers.Any(p => (p.Value?.Enabled ?? false) &&
return providers.Any(p => (p.Value?.Enabled ?? false) &&
(Premium || !TwoFactorProvider.RequiresPremium(p.Key)));
}