Exemple #1
0
        public void Test_LoginFailureWithAccessRuleContainingCalculatedColumn()
        {
            StructuredQuery securityStructuredQuery;
            UserAccount     userAccount;
            Guid            entitiesNodeGuid;
            Guid            selectColumnGuid;

            // Create the query containing a calculated column
            entitiesNodeGuid        = Guid.NewGuid();
            selectColumnGuid        = Guid.NewGuid();
            securityStructuredQuery = new StructuredQuery
            {
                RootEntity = new ResourceEntity
                {
                    NodeId       = entitiesNodeGuid,
                    ExactType    = false,
                    EntityTypeId = new EntityRef("core:resource")
                },
                SelectColumns = new List <SelectColumn>()
            };
            securityStructuredQuery.Conditions.Add(new QueryCondition()
            {
                Expression = new ColumnReference()
                {
                    ColumnId = selectColumnGuid
                },
                Operator = ConditionType.Equal,
                Argument = new TypedValue("allow")
            });
            securityStructuredQuery.SelectColumns.Add(new SelectColumn()
            {
                Expression = new IdExpression()
                {
                    NodeId = entitiesNodeGuid
                },
                ColumnName  = "Id",
                DisplayName = "Id"
            });
            securityStructuredQuery.SelectColumns.Add(new SelectColumn()
            {
                ColumnId   = selectColumnGuid,
                Expression = new ScriptExpression()
                {
                    Script = "iif(description = 'foobar', 'deny', 'allow')",
                    NodeId = entitiesNodeGuid
                },
                ColumnName  = "Access",
                DisplayName = "Access"
            });

            // Create test user and grant the user access to everything
            // returned by the above structured query.
            userAccount      = new UserAccount();
            userAccount.Name = "Test User " + Guid.NewGuid();
            userAccount.Save();
            new AccessRuleFactory().AddAllowByQuery(
                userAccount.As <Subject>(),
                ReadiNow.Model.Entity.Get <SecurableEntity>("core:resource"),
                new[] { Permissions.Read, Permissions.Modify, Permissions.Delete, Permissions.Create },
                securityStructuredQuery.ToReport());

            Factory.EntityAccessControlService.ClearCaches();

            using (new SetUser(userAccount))
            {
                Assert.That(
                    () => ReadiNow.Model.Entity.GetByField <ReadiNowIdentityProvider>("ReadiNow", ReadiNowIdentityProvider.Name_Field).FirstOrDefault(),
                    Is.Not.Null);
            }
        }
Exemple #2
0
        public void TestReportConditionForCalculatedFieldUnknownType_Bug25079()
        {
            using (new SecurityBypassContext())
            {
                // Get the report root type
                EntityType dogBreedsType = Entity.GetByName <EntityType>("AA_DogBreeds").FirstOrDefault();

                // Build the query and report
                var re = new ResourceEntity(dogBreedsType);

                var structuredQuery = new StructuredQuery
                {
                    RootEntity = re
                };

                // Build id column
                var idColumn = new SelectColumn
                {
                    Expression = new IdExpression
                    {
                        NodeId = re.NodeId
                    },
                    IsHidden    = true,
                    DisplayName = "_id"
                };

                // Build calculated column
                var calcColumn = new SelectColumn
                {
                    Expression = new ReadiNow.Metadata.Query.Structured.ScriptExpression
                    {
                        NodeId     = re.NodeId,
                        Script     = @"iif(iif([Group] = 'Herding', 1, iif([Group] = 'Non-sporting', 2, iif([Group] = 'Scenthound', 3, iif([Group] = 'Terrier', 4, iif([Group] = 'toy', 5, iif([Group] = 'Working', 5, 0)))))) > 4, 'Requires attention', 'On track')",
                        ResultType = new StringType()
                    },
                    DisplayName = "Calc"
                };

                // Add columns to query
                structuredQuery.SelectColumns.Add(idColumn);
                structuredQuery.SelectColumns.Add(calcColumn);

                // Build condition on calc column
                var calcCondition = new QueryCondition
                {
                    Expression = new ColumnReference
                    {
                        ColumnId = calcColumn.ColumnId
                    },
                    Operator = ConditionType.Unspecified,
                    Argument = new TypedValue
                    {
                        Type = new UnknownType()
                    }
                };

                // Add condition to query
                structuredQuery.Conditions.Add(calcCondition);

                // Convert to report and save
                ReadiNow.Model.Report report = structuredQuery.ToReport();
                report.Name = "Test Calc Report " + Guid.NewGuid();
                report.Save();

                // Get strcutured query back so that we have entity ids
                // for structured query elements
                structuredQuery = ReportToQueryConverter.Instance.Convert(report);

                // Add the ad-hoc condition and run the report
                var settings = new ReportSettings
                {
                    ReportParameters = new ReportParameters
                    {
                        AnalyserConditions = new List <SelectedColumnCondition>()
                    },
                    InitialRow = 0,
                    PageSize   = 100
                };

                settings.ReportParameters.AnalyserConditions.Add(new SelectedColumnCondition
                {
                    Operator     = ConditionType.Contains,
                    Value        = "Requires attention",
                    ExpressionId = structuredQuery.Conditions[0].EntityId.ToString(CultureInfo.InvariantCulture),
                    Type         = new StringType()
                });

                var          reportInterface = new ReportingInterface();
                ReportResult result          = reportInterface.RunReport(report, settings);

                // Verify that correct rows are returned
                Assert.IsTrue(result.GridData.All(r => r.Values[0].Value.ToLowerInvariant().Contains(settings.ReportParameters.AnalyserConditions[0].Value.ToLowerInvariant())));
            }
        }