当前位置: 首页>>代码示例>>C#>>正文


C# ISecurityContext.GetConfigurationList方法代码示例

本文整理汇总了C#中ISecurityContext.GetConfigurationList方法的典型用法代码示例。如果您正苦于以下问题:C# ISecurityContext.GetConfigurationList方法的具体用法?C# ISecurityContext.GetConfigurationList怎么用?C# ISecurityContext.GetConfigurationList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ISecurityContext的用法示例。


在下文中一共展示了ISecurityContext.GetConfigurationList方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetSecurityConfigsForField

        /// <summary>
        /// Gets security configurations for the field specified.
        /// </summary>
        /// <param name="securityContext">The security context.</param>
        /// <param name="fieldDefinition">The field definition.</param>
        /// <param name="identity">The user identity.</param>
        /// <returns>The collection of AggregateSecurityConfig objects.</returns>
        public static IList<SecurityConfig> GetSecurityConfigsForField(ISecurityContext securityContext, IBaseFieldDefinition fieldDefinition, IMQ1Identity identity)
        {
            var result = new HashSet<SecurityConfig>();

            if (Utils.CurrentUserHasAdministratorRights)
                return new List<SecurityConfig>();

            if (securityContext == null || fieldDefinition == null || identity == null)
                return new List<SecurityConfig>();

            if (AlwaysVisible(fieldDefinition.SystemName))
                return new List<SecurityConfig>();

            var fieldConfigs = securityContext.GetConfigurationList(fieldDefinition.GetTableName(), fieldDefinition.SystemName);
            if (fieldConfigs != null)
            {
                fieldConfigs = fieldConfigs.Where(x =>
                    (x.BusinessUnitId == Constants.AllBusinessUnitsId || x.BusinessUnitId == identity.BusinessUnitId) &&
                    (x.RoleId == Constants.AllRolesId || identity.RolesId.Contains(x.RoleId)) && x.CanView).ToList();

                if (!fieldConfigs.Any(c =>
                        c.StateGuid == Constants.AllStatesGuid &&
                        c.PersonFieldName == Constants.AllPersonFieldsSystemName))
                {
                    var personsForAllStates =
                        fieldConfigs.Where(x => x.StateGuid == Constants.AllStatesGuid)
                            .Select(x => x.PersonFieldName)
                            .Distinct()
                            .ToList();

                    var statesForAllPersons =
                        fieldConfigs.Where(x => x.PersonFieldName == Constants.AllPersonFieldsSystemName)
                            .Select(x => x.StateGuid)
                            .Distinct()
                            .ToList();

                    foreach (var config in fieldConfigs)
                    {
                        var secConf = new SecurityConfig(
                            personsForAllStates.Contains(config.PersonFieldName) ? null : config.StateGuid.ToString("D"),
                            statesForAllPersons.Contains(config.StateGuid) ? null : config.PersonFieldName);

                        secConf.SetPersonId(identity.PersonId.ToString(CultureInfo.InvariantCulture));
                        result.Add(secConf);
                    }
                }
            }

            return result.ToList();
        }
开发者ID:mparsin,项目名称:Elements,代码行数:57,代码来源:QueryGeneratorSecurityHelper.cs

示例2: CanAccessField

        /// <summary>
        /// Gets the value indicating whether user has chances to read value from the field specified.
        /// </summary>
        /// <param name="securityContext">The security context.</param>
        /// <param name="fieldDefinition">The field definition.</param>
        /// <param name="identity">The user identity.</param>
        /// <returns><c>true</c> if can calculate aggregates, otherwise <c>false</c>.</returns>
        public static bool CanAccessField(ISecurityContext securityContext, IBaseFieldDefinition fieldDefinition, IMQ1Identity identity)
        {
            if (securityContext == null || fieldDefinition == null || identity == null)
                return false;

            if (AlwaysVisible(fieldDefinition.SystemName))
                return true;

            if (Utils.CurrentUserHasAdministratorRights)
                return true;

            var fieldConfigs = securityContext.GetConfigurationList(fieldDefinition.GetTableName(), fieldDefinition.SystemName);
            if (fieldConfigs != null)
            {
                var matches = fieldConfigs.Where(sc =>
                    (sc.BusinessUnitId == Constants.AllBusinessUnitsId || sc.BusinessUnitId == identity.BusinessUnitId) &&
                    (sc.RoleId == Constants.AllRolesId || identity.RolesId.Contains(sc.RoleId))).ToList();

                if (matches.Any(x => x.CanView))
                    return true;
            }

            return false;
        }
开发者ID:mparsin,项目名称:Elements,代码行数:31,代码来源:QueryGeneratorSecurityHelper.cs


注:本文中的ISecurityContext.GetConfigurationList方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。