Exemplo n.º 1
0
        /// <summary>
        /// ازروی شناسه قانون غالب و شناسه گروه قانون , قانون را استخراج میکند
        /// </summary>
        /// <param name="ruleTmpId">شناسه قانون قالب</param>
        /// <param name="ruleCategoryCode">شناسه گروه قانون</param>
        public BRuleParameter(decimal ruleTmpId, decimal ruleCategoryCode)
        {
            IList <Rule> list = new RuleRepository(false).GetByCriteria(new CriteriaStruct(Utility.GetPropertyName(() => new Rule().TemplateId), ruleTmpId),
                                                                        new CriteriaStruct(Utility.GetPropertyName(() => new Rule().Category), new RuleCategory()
            {
                ID = ruleCategoryCode
            }));

            if (list.Count == 1)
            {
                workingRule = list.First();
            }
            else if (list.Count == 0)
            {
                UIValidationExceptions exception = new UIValidationExceptions();
                exception.Add(ExceptionResourceKeys.AssignParameterRuleIDInvalid, "پارامترهای ارسال شده معرف قانونی نمیباشد", ExceptionSrc);
                throw exception;
            }
            else
            {
                UIValidationExceptions exception = new UIValidationExceptions();
                exception.Add(ExceptionResourceKeys.AssignParameterRuleIDInvalid, "پارامترهای ارسال شده معرف بیش از یک قانون میباشد", ExceptionSrc);
                throw exception;
            }
        }
Exemplo n.º 2
0
        public void TestSinglePermissionQuery(string permissionAlias)
        {
            QueryRepository          queryRepository;
            SecurableEntity          securableEntityType;
            AccessRule               accessRule;
            Role                     subject;
            ICollection <AccessRule> result;
            IEntityRepository        entityRepository = Factory.EntityRepository;
            Permission               permission;
            Permission               permissionToSet;

            using (DatabaseContext.GetContext(true))
            {
                permission      = permissionAlias == null ? null : Entity.Get <Permission>(permissionAlias);
                permissionToSet = permission ?? Entity.Get <Permission>("core:read");

                securableEntityType = Entity.Create <EntityType>().As <SecurableEntity>();
                securableEntityType.Save();

                accessRule = Entity.Create <AccessRule>();
                accessRule.AccessRuleEnabled = true;
                accessRule.PermissionAccess.Add(permissionToSet);
                accessRule.ControlAccess = securableEntityType;
                accessRule.Save();

                subject = Entity.Create <Role>();
                subject.AllowAccess.Add(accessRule.As <AccessRule>());
                subject.Save();

                queryRepository = new QueryRepository();
                result          = new RuleRepository(entityRepository).GetAccessRules(subject.Id,
                                                                                      permission, new[] { securableEntityType.Id });

                Assert.That(result, Has.Count.EqualTo(1));
                Assert.That(result.First( ).Id, Is.EqualTo(accessRule.Id));
            }
        }