@@ -287,6 +287,69 @@ await GetRightsAsync(entityId, key),
287287 }
288288 }
289289
290+ public async Task < Dictionary < long , int > > GetEffectiveRightsAsync ( long subjectId , long entityId , List < long > keys )
291+ {
292+ using ( var uow = this . GetUnitOfWork ( ) )
293+ {
294+ var entityPermissionRepository = uow . GetRepository < EntityPermission > ( ) ;
295+ var subjectRepository = uow . GetRepository < Subject > ( ) ;
296+ var partyUserRepository = uow . GetRepository < PartyUser > ( ) ;
297+ var entityRepository = uow . GetRepository < Entity > ( ) ;
298+ var partyRepository = uow . GetRepository < Party > ( ) ;
299+ var partyRelationshipRepository = uow . GetRepository < PartyRelationship > ( ) ;
300+
301+ var dictionary = new Dictionary < long , int > ( ) ;
302+
303+ foreach ( var key in keys )
304+ {
305+ var rights = new List < int >
306+ {
307+ // public
308+ await GetRightsAsync ( entityId , key ) ,
309+
310+ // private
311+ await GetRightsAsync ( subjectId , entityId , key )
312+ } ;
313+
314+ var subject = subjectRepository . Get ( subjectId ) ;
315+
316+ if ( subject is User )
317+ {
318+ var partyUser = partyUserRepository . Query ( m => m . UserId == subject . Id ) . FirstOrDefault ( ) ;
319+
320+ if ( partyUser != null )
321+ {
322+ var userParty = partyRepository . Get ( partyUser . PartyId ) ;
323+
324+ var entityName = entityRepository . Get ( entityId ) . Name ;
325+
326+ var entityParty = partyRepository
327+ . Query ( m => entityName . ToLowerInvariant ( ) == m . PartyType . Title . ToLowerInvariant ( ) && m . Name . ToLowerInvariant ( ) == key . ToString ( ) . ToLowerInvariant ( ) )
328+ . FirstOrDefault ( ) ;
329+
330+ if ( userParty != null && entityParty != null )
331+ {
332+ var partyRelationships = partyRelationshipRepository . Query ( m => m . SourceParty . Id == userParty . Id && m . TargetParty . Id == entityParty . Id ) ;
333+
334+ rights . AddRange ( partyRelationships . Select ( m => m . Permission ) ) ;
335+ }
336+ }
337+
338+ var user = subject as User ;
339+
340+ foreach ( var groupId in user . Groups . Select ( g => g . Id ) . ToList ( ) )
341+ {
342+ rights . Add ( await GetRightsAsync ( groupId , entityId , key ) ) ;
343+ }
344+ }
345+
346+ dictionary . Add ( entityId , rights . Aggregate ( 0 , ( left , right ) => left | right ) ) ;
347+ }
348+
349+ return dictionary ;
350+ }
351+ }
352+
290353 public async Task < int > GetEffectiveRightsAsync ( long subjectId , long entityId , long key )
291354 {
292355 using ( var uow = this . GetUnitOfWork ( ) )
0 commit comments