Esempio n. 1
0
        /// <summary>
        /// for a particular stored item, accessing user, and access mode, get all applicable rules, in order of least
        /// dependent rule to most
        /// </summary>
        /// <param name="ruleType"></param>
        /// <param name="storeItem"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        protected List <StoreAccessRule> GetItemRulesForUser(StoredItemAccessMode ruleType, IHasId storeItem, IUserInfoStore user)
        {
            //first look for item specific rules, and null item rules
            SearchFilterOf <StoreAccessRule> filter = new SearchFilterOf <StoreAccessRule>((x) =>
            {
                if (x.RuleType == ruleType &&
                    (x.Item == null || x.Item.Id.Equals(storeItem.Id)))
                {
                    return(true);
                }

                return(false);
            });

            var list = RuleStore.Search <StoreAccessRule>(filter);

            List <IHasDependencyOf <StoreAccessRule> > unsortedList = list.ConvertListTo <IHasDependencyOf <StoreAccessRule>, StoreAccessRule>();

            //now order the list by dependency from least to most
            var sortedList = DependencyUtil.SortHasADependency(unsortedList);

            //return
            var sortedConvertedList = sortedList.ConvertListTo <StoreAccessRule, IHasDependencyOf <StoreAccessRule> >();

            //add ALL overriding rules to the first on the list

            //RULE 1:  The owner will always have full access to item
            sortedConvertedList.Insert(0, new StoreAccessRule("OWNER", ruleType, (ihasId, accessUser) =>
            {
                if (accessUser.Id.Equals(user.Id))
                {
                    return(true);
                }
                return(null);
            }));

            return(sortedConvertedList);
        }
Esempio n. 2
0
        /// <summary>
        /// for a particular stored item, accessing user, and access mode, get all applicable rules, in order of least 
        /// dependent rule to most
        /// </summary>
        /// <param name="ruleType"></param>
        /// <param name="storeItem"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        protected List<StoreAccessRule> GetItemRulesForUser(StoredItemAccessMode ruleType, IHasId storeItem, IUserInfoStore user)
        {
            //first look for item specific rules, and null item rules
            SearchFilterOf<StoreAccessRule> filter = new SearchFilterOf<StoreAccessRule>((x) =>
            {
                if (x.RuleType == ruleType &&
                    (x.Item == null || x.Item.Id.Equals(storeItem.Id)))
                    return true;

                return false;
            });

            var list = RuleStore.Search<StoreAccessRule>(filter);

            List<IHasDependencyOf<StoreAccessRule>> unsortedList = list.ConvertListTo<IHasDependencyOf<StoreAccessRule>, StoreAccessRule>();

            //now order the list by dependency from least to most
            var sortedList = DependencyUtil.SortHasADependency(unsortedList);

            //return
            var sortedConvertedList = sortedList.ConvertListTo<StoreAccessRule, IHasDependencyOf<StoreAccessRule>>();

            //add ALL overriding rules to the first on the list

            //RULE 1:  The owner will always have full access to item
            sortedConvertedList.Insert(0, new StoreAccessRule("OWNER", ruleType, (ihasId, accessUser) =>
            {
                if (accessUser.Id.Equals(user.Id))
                {
                    return true;
                }
                return null;
            }));

            return sortedConvertedList;
        }