Example #1
0
        public void WhenSyncingPermissionsThenDanglingPermissionsAreDeleted()
        {
            var permission = new PermissionBuilder(this.Session).Build();

            new Permissions(this.Session).Sync();

            Assert.IsTrue(permission.Strategy.IsDeleted);
        }
        public void Sync()
        {
            var permissionByOperationByConcreteClassByOperandType = new Dictionary <OperandType, Dictionary <ObjectType, Dictionary <Operations, Permission> > >();

            foreach (Permission permission in new Permissions(this.Session).Extent())
            {
                if (permission.OperandType == null || !permission.ExistConcreteClass || !permission.ExistOperation)
                {
                    permission.Delete();
                    continue;
                }

                Dictionary <ObjectType, Dictionary <Operations, Permission> > permissionByOperationByConcreteClass;
                if (!permissionByOperationByConcreteClassByOperandType.TryGetValue(permission.OperandType, out permissionByOperationByConcreteClass))
                {
                    permissionByOperationByConcreteClass = new Dictionary <ObjectType, Dictionary <Operations, Permission> >();
                    permissionByOperationByConcreteClassByOperandType[permission.OperandType] = permissionByOperationByConcreteClass;
                }

                Dictionary <Operations, Permission> permissionByOperation;
                if (!permissionByOperationByConcreteClass.TryGetValue(permission.ConcreteClass, out permissionByOperation))
                {
                    permissionByOperation = new Dictionary <Operations, Permission>();
                    permissionByOperationByConcreteClass.Add(permission.ConcreteClass, permissionByOperation);
                }

                permissionByOperation[permission.Operation] = permission;
            }

            var domain = (MetaPopulation)this.Session.Database.ObjectFactory.MetaPopulation;

            foreach (var relationType in domain.RelationTypes)
            {
                {
                    // AssociationType
                    var associationType = relationType.AssociationType;
                    Dictionary <ObjectType, Dictionary <Operations, Permission> > permissionByOperationByConcreteClass;
                    permissionByOperationByConcreteClassByOperandType.TryGetValue(associationType, out permissionByOperationByConcreteClass);

                    var composite = associationType.RelationType.RoleType.ObjectType as Composite;
                    if (composite != null)
                    {
                        foreach (var concreteClass in composite.Classes)
                        {
                            Dictionary <Operations, Permission> permissionByOperation = null;
                            if (permissionByOperationByConcreteClass != null)
                            {
                                permissionByOperationByConcreteClass.TryGetValue(concreteClass, out permissionByOperation);
                            }

                            Operations[] operations = { Operations.Read };
                            foreach (var operation in operations)
                            {
                                Permission permission = null;
                                if (permissionByOperation != null)
                                {
                                    permissionByOperation.TryGetValue(operation, out permission);
                                }

                                if (permission == null)
                                {
                                    permission = new PermissionBuilder(this.Session).Build();
                                }

                                permission.Sync(concreteClass, associationType, operation);
                            }
                        }
                    }
                }

                {
                    // RoleType
                    var roleType = relationType.RoleType;
                    Dictionary <ObjectType, Dictionary <Operations, Permission> > permissionByOperationByConcreteClass;
                    permissionByOperationByConcreteClassByOperandType.TryGetValue(roleType, out permissionByOperationByConcreteClass);

                    foreach (var concreteClass in roleType.RelationType.AssociationType.ObjectType.Classes)
                    {
                        Dictionary <Operations, Permission> permissionByOperation = null;
                        if (permissionByOperationByConcreteClass != null)
                        {
                            permissionByOperationByConcreteClass.TryGetValue(concreteClass, out permissionByOperation);
                        }

                        var operations = new[] { Operations.Read, Operations.Write };

                        foreach (var operation in operations)
                        {
                            Permission permission = null;
                            if (permissionByOperation != null)
                            {
                                permissionByOperation.TryGetValue(operation, out permission);
                            }

                            if (operation == Operations.Write && roleType.RelationType.IsDerived)
                            {
                                if (permission != null)
                                {
                                    permission.Delete();
                                }
                            }
                            else
                            {
                                if (permission == null)
                                {
                                    permission = new PermissionBuilder(this.Session).Build();
                                }

                                permission.Sync(concreteClass, roleType, operation);
                            }
                        }
                    }
                }
            }

            foreach (var methodType in domain.MethodTypes)
            {
                Dictionary <ObjectType, Dictionary <Operations, Permission> > permissionByOperationByConcreteClass;
                permissionByOperationByConcreteClassByOperandType.TryGetValue(methodType, out permissionByOperationByConcreteClass);

                foreach (var concreteClass in methodType.ObjectType.Classes)
                {
                    Dictionary <Operations, Permission> permissionByOperation = null;
                    if (permissionByOperationByConcreteClass != null)
                    {
                        permissionByOperationByConcreteClass.TryGetValue(concreteClass, out permissionByOperation);
                    }

                    Permission permission = null;
                    if (permissionByOperation != null)
                    {
                        permissionByOperation.TryGetValue(Operations.Execute, out permission);
                    }

                    if (permission == null)
                    {
                        permission = new PermissionBuilder(this.Session).Build();
                    }

                    permission.Sync(concreteClass, methodType, Operations.Execute);
                }
            }
        }
Example #3
0
        public void WhenSyncingPermissionsThenObsolotePermissionsAreDeleted()
        {
            var domain = (Domain)this.Session.Database.MetaPopulation.Find(new Guid("AB41FD0C-C887-4A1D-BEDA-CED69527E69A"));

            var count = new Permissions(this.Session).Extent().Count;

            var permission = new PermissionBuilder(this.Session).WithConcreteClassPointer(new Guid()).WithOperation(Operation.Execute).WithOperandTypePointer(new Guid()).Build();

            new Permissions(this.Session).Sync();

            Assert.AreEqual(count, new Permissions(this.Session).Extent().Count);
        }
Example #4
0
        public void Sync()
        {
            var permissionByOperationByConcreteClassByOperandType = new Dictionary<OperandType, Dictionary<ObjectType, Dictionary<Operation, Permission>>>();

            foreach (Permission permission in new Permissions(this.Session).Extent())
            {
                if (permission.OperandType == null || !permission.ExistConcreteClass || !permission.ExistOperation)
                {
                    permission.Delete();
                    continue;
                }

                Dictionary<ObjectType, Dictionary<Operation, Permission>> permissionByOperationByConcreteClass;
                if (!permissionByOperationByConcreteClassByOperandType.TryGetValue(permission.OperandType, out permissionByOperationByConcreteClass))
                {
                    permissionByOperationByConcreteClass = new Dictionary<ObjectType, Dictionary<Operation, Permission>>();
                    permissionByOperationByConcreteClassByOperandType[permission.OperandType] = permissionByOperationByConcreteClass;
                }

                Dictionary<Operation, Permission> permissionByOperation;
                if (!permissionByOperationByConcreteClass.TryGetValue(permission.ConcreteClass, out permissionByOperation))
                {
                    permissionByOperation = new Dictionary<Operation, Permission>();
                    permissionByOperationByConcreteClass.Add(permission.ConcreteClass, permissionByOperation);
                }

                permissionByOperation[permission.Operation] = permission;
            }

            var domain = (MetaPopulation)this.Session.Database.ObjectFactory.MetaPopulation;
            foreach (var relationType in domain.RelationTypes)
            {
                {
                    // AssociationType
                    var associationType = relationType.AssociationType;
                    Dictionary<ObjectType, Dictionary<Operation, Permission>> permissionByOperationByConcreteClass;
                    permissionByOperationByConcreteClassByOperandType.TryGetValue(associationType, out permissionByOperationByConcreteClass);

                    var composite = associationType.RelationType.RoleType.ObjectType as Composite;
                    if (composite != null)
                    {
                        foreach (var concreteClass in composite.Classes)
                        {
                            Dictionary<Operation, Permission> permissionByOperation = null;
                            if (permissionByOperationByConcreteClass != null)
                            {
                                permissionByOperationByConcreteClass.TryGetValue(concreteClass, out permissionByOperation);
                            }

                            Operation[] operations = { Operation.Read };
                            foreach (var operation in operations)
                            {
                                Permission permission = null;
                                if (permissionByOperation != null)
                                {
                                    permissionByOperation.TryGetValue(operation, out permission);
                                }

                                if (permission == null)
                                {
                                    permission = new PermissionBuilder(this.Session).Build();
                                }

                                permission.Sync(concreteClass, associationType, operation);
                            }
                        }
                    }
                }

                {
                    // RoleType
                    var roleType = relationType.RoleType;
                    Dictionary<ObjectType, Dictionary<Operation, Permission>> permissionByOperationByConcreteClass;
                    permissionByOperationByConcreteClassByOperandType.TryGetValue(roleType, out permissionByOperationByConcreteClass);

                    foreach (var concreteClass in roleType.RelationType.AssociationType.ObjectType.Classes)
                    {
                        Dictionary<Operation, Permission> permissionByOperation = null;
                        if (permissionByOperationByConcreteClass != null)
                        {
                            permissionByOperationByConcreteClass.TryGetValue(concreteClass, out permissionByOperation);
                        }

                        var operations = new[] { Operation.Read, Operation.Write };

                        foreach (var operation in operations)
                        {
                            Permission permission = null;
                            if (permissionByOperation != null)
                            {
                                permissionByOperation.TryGetValue(operation, out permission);
                            }

                            if (operation == Operation.Write && roleType.RelationType.IsDerived)
                            {
                                if (permission != null)
                                {
                                    permission.Delete();
                                }
                            }
                            else
                            {
                                if (permission == null)
                                {
                                    permission = new PermissionBuilder(this.Session).Build();
                                }

                                permission.Sync(concreteClass, roleType, operation);
                            }
                        }
                    }
                }
            }

            foreach (var methodType in domain.MethodTypes)
            {
                Dictionary<ObjectType, Dictionary<Operation, Permission>> permissionByOperationByConcreteClass;
                permissionByOperationByConcreteClassByOperandType.TryGetValue(methodType, out permissionByOperationByConcreteClass);

                foreach (var concreteClass in methodType.ObjectType.Classes)
                {
                    Dictionary<Operation, Permission> permissionByOperation = null;
                    if (permissionByOperationByConcreteClass != null)
                    {
                        permissionByOperationByConcreteClass.TryGetValue(concreteClass, out permissionByOperation);
                    }

                    Permission permission = null;
                    if (permissionByOperation != null)
                    {
                        permissionByOperation.TryGetValue(Operation.Execute, out permission);
                    }

                    if (permission == null)
                    {
                        permission = new PermissionBuilder(this.Session).Build();
                    }

                    permission.Sync(concreteClass, methodType, Operation.Execute);
                }
            }
        }