protected override void OnLoad(EventArgs e)
        {
            if (this.Visible)
            {
                //using (SPSite site = SPContext.Current.Site)
                SPSite site = SPContext.Current.Site;
                {
                    //SPFeature listDisplaySettingFeature = site.Features[new Guid("88E9E47A-BA92-47ab-A253-8AA472CCC76B")];

                    //if ((listDisplaySettingFeature != null) && (listDisplaySettingFeature.Definition.Status == Microsoft.SharePoint.Administration.SPObjectStatus.Online))
                    //{
                    if (View.ParentList.ParentWeb.Properties.ContainsKey(String.Format("ViewPermissions{0}", View.ParentList.ID.ToString())))
                    {
                        featureEnabled = true;
                        roleProperties = new Dictionary <int, Dictionary <string, bool> >();
                        defaultViews   = new Dictionary <int, string>();

                        SPWeb web = View.ParentList.ParentWeb;
                        {
                            ViewPermissionUtil.ConvertFromString(ref roleProperties, ref defaultViews, web.Properties[String.Format("ViewPermissions{0}", View.ParentList.ID.ToString())], View.ParentList);

                            if (!UserCanSeeView(base.RenderContext.ViewContext.View.Url, roleProperties))
                            {
                                SPUtility.Redirect(GoToDefaultView(defaultViews).ServerRelativeUrl, SPRedirectFlags.Default, HttpContext.Current, "redirect=true");
                            }
                            else
                            {
                                if (!ComeFromView())
                                {
                                    SPUtility.Redirect(GoToDefaultView(defaultViews).ServerRelativeUrl, SPRedirectFlags.Default, HttpContext.Current, "redirect=true");
                                }
                            }
                        }
                    }
                    foreach (SPView view in View.ParentList.Views)
                    {
                        if ((!view.Hidden) && (!view.PersonalView))
                        {
                            views.Add(view);
                        }
                    }
                    //}
                }

                base.OnLoad(e);
            }
            else
            {
                base.OnLoad(e);
            }
        }
Beispiel #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();
        }
        protected override void OnLoad(EventArgs e)
        {
            if (this.Visible)
            {
                //using (SPSite site = SPContext.Current.Site)
                SPSite site = SPContext.Current.Site;
                {
                    //SPFeature listDisplaySettingFeature = site.Features[new Guid("88E9E47A-BA92-47ab-A253-8AA472CCC76B")];

                    //if ((listDisplaySettingFeature != null) && (listDisplaySettingFeature.Definition.Status == Microsoft.SharePoint.Administration.SPObjectStatus.Online))
                    //{
                    if (View.ParentList.ParentWeb.Properties.ContainsKey(String.Format("ViewPermissions{0}", View.ParentList.ID.ToString())))
                    {
                        featureEnabled = true;
                        roleProperties = new Dictionary <int, Dictionary <string, bool> >();
                        defaultViews   = new Dictionary <int, string>();

                        SPWeb web = View.ParentList.ParentWeb;
                        {
                            ViewPermissionUtil.ConvertFromString(ref roleProperties, ref defaultViews, web.Properties[String.Format("ViewPermissions{0}", View.ParentList.ID.ToString())], View.ParentList);
                        }
                    }
                    foreach (SPView view in View.ParentList.Views)
                    {
                        if ((!view.Hidden) && (!view.PersonalView))
                        {
                            views.Add(view);
                        }
                    }
                    //}
                }

                base.OnLoad(e);

                //if(featureEnabled)
                {
                    try
                    {
                        NameValueCollection nv    = HttpUtility.ParseQueryString(Page.Request.UrlReferrer.Query);
                        StringBuilder       sbUrl = new StringBuilder();


                        bool bPersonal = false;
                        try
                        {
                            if (nv["PageView"] == "Personal")
                            {
                                bPersonal = true;
                            }
                        }
                        catch { }

                        if (!bPersonal)
                        {
                            foreach (string key in nv.AllKeys)
                            {
                                if (isValidQS(key))
                                {
                                    sbUrl.Append("&");
                                    sbUrl.Append(key);
                                    sbUrl.Append("=");
                                    sbUrl.Append(HttpUtility.UrlEncode(nv[key]));
                                }
                            }

                            foreach (Control item in base.MenuTemplateControl.Controls)
                            {
                                try
                                {
                                    if ((item is MenuItemTemplate) && (View.ParentList.Views[((MenuItemTemplate)item).Text]) != null)
                                    {
                                        if (featureEnabled)
                                        {
                                            item.Visible = UserCanSeeView(View.ParentList.Views[((MenuItemTemplate)item).Text].Url, roleProperties);
                                        }
                                    }

                                    Microsoft.SharePoint.WebControls.MenuItemTemplate mn = (Microsoft.SharePoint.WebControls.MenuItemTemplate)item;
                                    string sDoc = System.IO.Path.GetFileName(mn.ClientOnClickNavigateUrl);

                                    if (!sDoc.Contains("ViewEdit.aspx?") && !sDoc.Contains("ViewType.aspx?"))
                                    {
                                        if (sbUrl.ToString() != "")
                                        {
                                            //mn.ClientOnClickScript = mn.ClientOnClickScript.Insert(mn.ClientOnClickScript.Length - 3, "?" + sbUrl.ToString().TrimStart('&'));
                                            mn.ClientOnClickNavigateUrl += "?" + sbUrl.ToString().TrimStart('&');
                                        }
                                    }
                                }
                                catch { }
                            }
                        }
                    }
                    catch { }
                }
            }
            else
            {
                base.OnLoad(e);
            }
        }