mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 15:42:48 -05:00
[EC-243] Grant premium status when member accepts org invite (#2043)
This commit is contained in:
@ -70,6 +70,7 @@ namespace Bit.Core.Services
|
||||
int? version = null);
|
||||
Task<bool> CheckPasswordAsync(User user, string password);
|
||||
Task<bool> CanAccessPremium(ITwoFactorProvidersUser user);
|
||||
Task<bool> HasPremiumFromOrganization(ITwoFactorProvidersUser user);
|
||||
Task<bool> TwoFactorIsEnabledAsync(ITwoFactorProvidersUser user);
|
||||
Task<bool> TwoFactorProviderIsEnabledAsync(TwoFactorProviderType provider, ITwoFactorProvidersUser user);
|
||||
Task<string> GenerateSignInTokenAsync(User user, string purpose);
|
||||
|
@ -1263,18 +1263,32 @@ namespace Bit.Core.Services
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (user.GetPremium())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
var orgs = await _currentContext.OrganizationMembershipAsync(_organizationUserRepository, userId.Value);
|
||||
if (!orgs.Any())
|
||||
|
||||
return user.GetPremium() || await this.HasPremiumFromOrganization(user);
|
||||
}
|
||||
|
||||
public async Task<bool> HasPremiumFromOrganization(ITwoFactorProvidersUser user)
|
||||
{
|
||||
var userId = user.GetUserId();
|
||||
if (!userId.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// orgUsers in the Invited status are not associated with a userId yet, so this will get
|
||||
// orgUsers in Accepted and Confirmed states only
|
||||
var orgUsers = await _organizationUserRepository.GetManyByUserAsync(userId.Value);
|
||||
|
||||
if (!orgUsers.Any())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var orgAbilities = await _applicationCacheService.GetOrganizationAbilitiesAsync();
|
||||
return orgs.Any(o => orgAbilities.ContainsKey(o.Id) &&
|
||||
orgAbilities[o.Id].UsersGetPremium && orgAbilities[o.Id].Enabled);
|
||||
return orgUsers.Any(ou =>
|
||||
orgAbilities.TryGetValue(ou.OrganizationId, out var orgAbility) &&
|
||||
orgAbility.UsersGetPremium &&
|
||||
orgAbility.Enabled);
|
||||
}
|
||||
|
||||
public async Task<bool> TwoFactorIsEnabledAsync(ITwoFactorProvidersUser user)
|
||||
|
Reference in New Issue
Block a user