예제 #1
0
        private void AddEntityPermission(Authority authority, ActivityGrant grant, EntityGroupPermission entPerm)
        {
            // Entity group permission. Go through each entity in groups
            var filter = grant.Filter;

            foreach (var entGroupRes in entPerm.GroupResources)
            {
                foreach (var entRes in entGroupRes.Entities)
                {
                    var entType     = entRes.EntityType;
                    var newRecPerms = new UserRecordPermission(entPerm.AccessType, entRes.MemberMask);
                    //Find/create entity permission set for the entity type
                    UserEntityPermissionSet permSet = authority.GetEntityPermissionSet(entType, create: true);
                    var log = "  Source permission " + entPerm.Name + ":";
                    // Go through each permission and try to merge
                    var compatiblePerm = permSet.ConditionalPermissions.FirstOrDefault(p => p.CanMerge(grant));
                    if (compatiblePerm == null)
                    {
                        //create new cumulative permission
                        var permId  = "P" + permSet.ConditionalPermissions.Count; //artificial Id
                        var newPerm = new CumulativeRecordPermission(permId, entType, newRecPerms, grant);
                        permSet.ConditionalPermissions.Add(newPerm);
                        log += " - added as " + permId;
                    }
                    else
                    {
                        //merge
                        compatiblePerm.RecordPermission.Merge(newRecPerms);
                        compatiblePerm.SourceGrants.Add(grant); //add grant
                        log += " - merged into " + compatiblePerm.Id;
                    }
                    permSet.LogBuilder.AppendLine(log);
                } //foreach entRes
            }     //foreach entGroupRes
        }
예제 #2
0
 private void AddEntityPermission(Authority authority, ActivityGrant grant, EntityGroupPermission entPerm)
 {
     // Entity group permission. Go through each entity in groups
       var filter = grant.Filter;
       foreach(var entGroupRes in entPerm.GroupResources) {
     foreach(var entRes in entGroupRes.Entities) {
       var entType = entRes.EntityType;
       var newRecPerms = new UserRecordPermission(entPerm.AccessType, entRes.MemberMask);
       //Find/create entity permission set for the entity type
       UserEntityPermissionSet permSet = authority.GetEntityPermissionSet(entType, create: true);
       var log = "  Source permission " + entPerm.Name + ":";
       // Go through each permission and try to merge
       var compatiblePerm = permSet.ConditionalPermissions.FirstOrDefault(p => p.CanMerge(grant));
       if(compatiblePerm == null) {
     //create new cumulative permission
     var permId = "P" + permSet.ConditionalPermissions.Count; //artificial Id
     var newPerm = new CumulativeRecordPermission(permId, entType, newRecPerms, grant);
     permSet.ConditionalPermissions.Add(newPerm);
     log += " - added as " + permId;
       } else {
     //merge
     compatiblePerm.RecordPermission.Merge(newRecPerms);
     compatiblePerm.SourceGrants.Add(grant); //add grant
     log += " - merged into " + compatiblePerm.Id;
       }
       permSet.LogBuilder.AppendLine(log);
     } //foreach entRes
       }//foreach entGroupRes
 }