示例#1
0
        public static void ConvertFromStringForPage(ref Dictionary <int, Dictionary <string, bool> > roleProperties, ref Dictionary <int, string> defaultViews, string value, SPList currentList)
        {
            string[] groups = value.Split("|".ToCharArray());
            Dictionary <int, string> groupValues = new Dictionary <int, string>();

            foreach (string group in groups)
            {
                if (!string.IsNullOrEmpty(group))
                {
                    string[] values  = group.Split("#".ToCharArray());
                    int      groupId = int.Parse(values[0]);
                    groupValues.Add(groupId, group);
                }
            }

            List <SPGroup> oGroups = new List <SPGroup>();

            foreach (SPGroup group in currentList.ParentWeb.Groups)
            {
                SPRoleCollection c = group.Roles;

                bool canUse = false;

                foreach (SPRole role in c)
                {
                    if (role.PermissionMask != (SPRights)134287360)
                    {
                        canUse = true;
                        break;
                    }
                }

                if (canUse)
                {
                    oGroups.Add(group);
                }
            }

            foreach (SPGroup group in oGroups)
            {
                roleProperties.Add(group.ID, new Dictionary <string, bool>());
                string defaultViewId = GetDefautView(groupValues, group.ID);

                SetDefaultVue(defaultViewId, currentList.DefaultView.Url, group.ID, currentList, ref defaultViews);

                foreach (SPView view in currentList.Views)
                {
                    if ((!view.Hidden) && (!view.PersonalView))
                    {
                        roleProperties[group.ID].Add(view.Url, IsViewAllowed(groupValues, group.ID, view.Url));
                    }
                }
            }
        }
示例#2
0
        protected override void OnLoad(EventArgs e)
        {
            this.Title = "View Permission Settings";
            checkPermissionScript.AppendLine("var viewUrls = new Array;");
            foreach (SPView view in this.CurrentList.Views)
            {
                if ((!view.Hidden) && (!view.PersonalView))
                {
                    views.Add(view);
                    // Populate list view urls in script for client side validation on save
                    checkPermissionScript.Append("viewUrls.push('" + view.Url + "');");
                }
            }

            if (this.CurrentList.ParentWeb.Properties.ContainsKey(String.Format("ViewPermissions{0}", this.CurrentList.ID.ToString())))
            {
                roleProperties = new Dictionary <int, Dictionary <string, bool> >();
                defaultViews   = new Dictionary <int, string>();
                ViewPermissionUtil.ConvertFromStringForPage(ref roleProperties, ref defaultViews, this.CurrentList.ParentWeb.Properties[String.Format("ViewPermissions{0}", this.CurrentList.ID.ToString())], this.CurrentList);
                // Grab collection of view which are not part of any group
                GetViewsNotInAnyGroup();
            }
            else
            {
                roleProperties = new Dictionary <int, Dictionary <string, bool> >();
                defaultViews   = new Dictionary <int, string>();

                // Retrieve groups from current list
                foreach (SPGroup group in this.CurrentList.ParentWeb.Groups)
                {
                    SPRoleCollection c = group.Roles;

                    bool canUse = false;

                    foreach (SPRole role in c)
                    {
                        if (role.PermissionMask != (SPRights)134287360)
                        {
                            canUse = true;
                            break;
                        }
                    }

                    if (canUse)
                    {
                        groups.Add(group);
                    }
                }

                // Retrieve views from current list


                foreach (SPGroup group in groups)
                {
                    roleProperties.Add(group.ID, new Dictionary <string, bool>());
                    defaultViews.Add(group.ID, this.CurrentList.DefaultView.Url);
                    foreach (SPView view in views)
                    {
                        roleProperties[group.ID].Add(view.Url, true);
                    }
                }
            }

            pageRender = this.PrepareRenderPage();
            // Populate permission group ids in script for client side validation on save
            groupIds = new int[roleProperties.Keys.Count];
            roleProperties.Keys.CopyTo(groupIds, 0);
            checkPermissionScript.AppendLine("var grpIds = new Array;");
            foreach (int id in groupIds)
            {
                checkPermissionScript.Append("grpIds.push('" + id + "');");
            }

            RegisterScript();

            this.Cancel.PostBackUrl = SPContext.Current.Web.Url + "/_layouts/listedit.aspx?List=" + this.CurrentList.ID.ToString();
        }