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:
@ -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())
|
||||
{
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user