1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-03 00:52:49 -05:00

reference OrganizationMembership instead

This commit is contained in:
Kyle Spearrin
2018-08-31 17:05:27 -04:00
parent b2d63b2383
commit 2562d5a40d
8 changed files with 54 additions and 61 deletions

View File

@ -46,35 +46,16 @@ namespace Bit.Core.Services
};
var orgAbilities = await _applicationCacheService.GetOrganizationAbilitiesAsync();
IEnumerable<IEvent> orgEvents;
if(_currentContext.UserId.HasValue)
{
orgEvents = _currentContext.Organizations
.Where(o => CanUseEvents(orgAbilities, o.Id))
.Select(o => new EventMessage(_currentContext)
{
OrganizationId = o.Id,
UserId = userId,
ActingUserId = userId,
Type = type,
Date = DateTime.UtcNow
});
}
else
{
var orgs = await _currentContext.OrganizationMembershipAsync(_organizationUserRepository, userId);
orgEvents = orgs
.Where(o => o.Status == OrganizationUserStatusType.Confirmed &&
CanUseEvents(orgAbilities, o.OrganizationId))
.Select(o => new EventMessage(_currentContext)
{
OrganizationId = o.OrganizationId,
UserId = userId,
ActingUserId = userId,
Type = type,
Date = DateTime.UtcNow
});
}
var orgs = await _currentContext.OrganizationMembershipAsync(_organizationUserRepository, userId);
var orgEvents = orgs.Where(o => CanUseEvents(orgAbilities, o.Id))
.Select(o => new EventMessage(_currentContext)
{
OrganizationId = o.Id,
UserId = userId,
ActingUserId = userId,
Type = type,
Date = DateTime.UtcNow
});
if(orgEvents.Any())
{

View File

@ -831,13 +831,13 @@ namespace Bit.Core.Services
{
return true;
}
if(!_currentContext?.Organizations?.Any() ?? true)
var orgs = await _currentContext.OrganizationMembershipAsync(_organizationUserRepository, user.Id);
if(!orgs.Any())
{
return false;
}
var orgAbilities = await _applicationCacheService.GetOrganizationAbilitiesAsync();
return _currentContext.Organizations.Any(o => orgAbilities.ContainsKey(o.Id) &&
return orgs.Any(o => orgAbilities.ContainsKey(o.Id) &&
orgAbilities[o.Id].UsersGetPremium && orgAbilities[o.Id].Enabled);
}