Esempio n. 1
0
        private void AddPermissionsToReason(AccessReason reason)
        {
            IEntityCollection <Permission> permissions = reason.AccessRule.PermissionAccess;
            IReadOnlyList <long>           permIds     = permissions.Select(perm => perm.Id).ToList();

            First                 first     = new First( );
            StringBuilder         sb        = new StringBuilder( );
            Action <string, long> checkPerm = (permName, permId) =>
            {
                if (!permIds.Contains(permId))
                {
                    return;
                }

                if (!first)
                {
                    sb.Append(", ");
                }
                sb.Append(permName);
            };

            checkPerm("Create", Permissions.Create.Id);
            checkPerm("Read", Permissions.Read.Id);
            checkPerm("Modify", Permissions.Modify.Id);
            checkPerm("Delete", Permissions.Delete.Id);

            reason.PermissionIds   = permIds;
            reason.PermissionsText = sb.ToString( );
        }
Esempio n. 2
0
        /// <summary>
        ///     Called to gather audit log entity details for save.
        /// </summary>
        /// <param name="accessRule">The access rule.</param>
        /// <returns></returns>
        protected override AuditLogAccessRuleDetails OnGatherAuditLogEntityDetailsForSave(AccessRule accessRule)
        {
            var accessRuleInternal = accessRule as IEntityInternal;
            IEntityFieldValues fields;
            IDictionary <long, IChangeTracker <IMutableIdKey> > forwardRelationships;
            IDictionary <long, IChangeTracker <IMutableIdKey> > reverseRelationships;

            accessRule.GetChanges(out fields, out forwardRelationships, out reverseRelationships);

            var oldAccessRule = new Lazy <AccessRule>(() => Entity.Get <AccessRule>(accessRule.Id));

            IEnumerable <EntityRef> idsToLoad = new List <EntityRef> {
                "core:accessRuleEnabled", "core:permissionAccess", "core:accessRuleReport"
            };

            Dictionary <string, IEntity> fieldEntities = Entity.Get(idsToLoad).ToDictionary(e => e.Alias);

            var accessRuleDetails = new AuditLogAccessRuleDetails {
                IsTemporaryId = accessRuleInternal.IsTemporaryId
            };

            if (fields != null && fields.Any())
            {
                object fieldObj;

                if (fields.TryGetValue(fieldEntities["accessRuleEnabled"].Id, out fieldObj))
                {
                    // Enabled was changed
                    accessRuleDetails.Enabled    = fieldObj as bool?;
                    accessRuleDetails.OldEnabled = oldAccessRule.Value.AccessRuleEnabled;
                }
            }

            SecurableEntity controlAccess = accessRule.ControlAccess;

            if (controlAccess != null)
            {
                accessRuleDetails.SecuredTypeName = controlAccess.Name;
            }

            Subject allowAccessBy = accessRule.AllowAccessBy;

            if (allowAccessBy != null)
            {
                accessRuleDetails.SubjectName = allowAccessBy.Name;
            }

            Report accessRuleReport = accessRule.AccessRuleReport;

            if (accessRuleReport != null)
            {
                accessRuleDetails.AccessRuleReportName = accessRuleReport.Name;
            }

            if (forwardRelationships != null && forwardRelationships.Count > 0)
            {
                IChangeTracker <IMutableIdKey> permissionsTracker;

                if (forwardRelationships.TryGetValue(fieldEntities["permissionAccess"].Id, out permissionsTracker))
                {
                    IEntityCollection <Permission> oldPermissions = oldAccessRule.Value.PermissionAccess;
                    if (oldPermissions != null)
                    {
                        accessRuleDetails.OldPermissions.UnionWith(oldPermissions.Select(e => e.Name));
                    }

                    IEntityCollection <Permission> newPermissions = accessRule.PermissionAccess;
                    if (newPermissions != null)
                    {
                        accessRuleDetails.NewPermissions.UnionWith(newPermissions.Select(e => e.Name));
                    }
                }

                IChangeTracker <IMutableIdKey> reportTracker;

                if (forwardRelationships.TryGetValue(fieldEntities["accessRuleReport"].Id, out reportTracker))
                {
                    accessRuleDetails.IsAccessRuleReportChanged = true;
                }
            }

            return(accessRuleDetails);
        }
Esempio n. 3
0
 /// <summary>
 /// Get the best email addresses for the attendees that have them
 /// </summary>
 static IList <EmailContact> GetAttendeesAddresses(IEntityCollection <Person> attendees)
 {
     return(attendees.Select(a => GetBestAddress(a)).Where(e => e != null).ToList());
 }