Beispiel #1
0
        public static bool HasEditPermissions(int ModuleId)
        {
            ModulePermissionController objModulePermissionController = new ModulePermissionController();
            ModulePermissionCollection objModulePermissions          = objModulePermissionController.GetModulePermissionsCollectionByModuleID(ModuleId);

            return(HasEditPermissions(objModulePermissions));
        }
Beispiel #2
0
        /// <param name="moduleId"></param>
        /// <param name="tabId"></param>
        /// <param name="permissionKey">You can use the constants, but for modules there are only
        /// those two</param>
        /// <returns></returns>
        public static bool canUserAccessModule(UserInfo user, int portalId, int tabId, ModuleInfo moduleInfo, string permissionKey)
        {
            var    retVal            = false;
            string permissionsString = null;

            if (moduleInfo.InheritViewPermissions)
            {
                var tabPermissionController = new TabPermissionController();
                var tabPermissionCollection =
                    tabPermissionController.GetTabPermissionsCollectionByTabID(tabId, portalId);
                permissionsString = tabPermissionController.GetTabPermissions(tabPermissionCollection, permissionKey);
            }
            else
            {
                var modulePermissionController = new ModulePermissionController();
                var permissionCollection       =
                    modulePermissionController.GetModulePermissionsCollectionByModuleID(moduleInfo.ModuleID, tabId);
                permissionsString = modulePermissionController.GetModulePermissions(permissionCollection, permissionKey);
            }

            char[] splitter = { ';' };
            var    roles    = permissionsString.Split(splitter);

            foreach (var role in roles)
            {
                if (role.Length > 0)
                {
                    if (user != null && user.IsInRole(role))
                    {
                        retVal = true;
                    }
                    else if (user == null && role.ToLower().Equals("all users"))
                    {
                        retVal = true;
                    }
                }
            }
            return(retVal);
        }
 /// <summary>
 /// Gets the ModulePermissions from the Data Store
 /// </summary>
 private void GetModulePermissions()
 {
     ModulePermissionController objModulePermissionController = new ModulePermissionController();
     ModulePermissions = objModulePermissionController.GetModulePermissionsCollectionByModuleID( ModuleID, TabId );
 }
Beispiel #4
0
        /// <summary>
        /// Gets the ModulePermissions from the Data Store
        /// </summary>
        private void GetModulePermissions()
        {
            ModulePermissionController objModulePermissionController = new ModulePermissionController();

            ModulePermissions = objModulePermissionController.GetModulePermissionsCollectionByModuleID(ModuleID, TabId);
        }
Beispiel #5
0
        private ModuleInfo FillModuleInfo(IDataReader dr, bool CheckForOpenDataReader, bool IncludePermissions)
        {
            ModuleInfo objModuleInfo = new ModuleInfo();
            ModulePermissionController objModulePermissionController = new ModulePermissionController();
            // read datareader
            bool canContinue = true;

            if (CheckForOpenDataReader)
            {
                canContinue = false;
                if (dr.Read())
                {
                    canContinue = true;
                }
            }
            if (canContinue)
            {
                objModuleInfo.PortalID    = Convert.ToInt32(Null.SetNull(dr["PortalID"], objModuleInfo.PortalID));
                objModuleInfo.TabID       = Convert.ToInt32(Null.SetNull(dr["TabID"], objModuleInfo.TabID));
                objModuleInfo.TabModuleID = Convert.ToInt32(Null.SetNull(dr["TabModuleID"], objModuleInfo.TabModuleID));
                objModuleInfo.ModuleID    = Convert.ToInt32(Null.SetNull(dr["ModuleID"], objModuleInfo.ModuleID));
                objModuleInfo.ModuleDefID = Convert.ToInt32(Null.SetNull(dr["ModuleDefID"], objModuleInfo.ModuleDefID));
                objModuleInfo.ModuleOrder = Convert.ToInt32(Null.SetNull(dr["ModuleOrder"], objModuleInfo.ModuleOrder));
                objModuleInfo.PaneName    = Convert.ToString(Null.SetNull(dr["PaneName"], objModuleInfo.PaneName));
                objModuleInfo.ModuleTitle = Convert.ToString(Null.SetNull(dr["ModuleTitle"], objModuleInfo.ModuleTitle));
                objModuleInfo.CacheTime   = Convert.ToInt32(Null.SetNull(dr["CacheTime"], objModuleInfo.CacheTime));
                objModuleInfo.Alignment   = Convert.ToString(Null.SetNull(dr["Alignment"], objModuleInfo.Alignment));
                objModuleInfo.Color       = Convert.ToString(Null.SetNull(dr["Color"], objModuleInfo.Color));
                objModuleInfo.Border      = Convert.ToString(Null.SetNull(dr["Border"], objModuleInfo.Border));
                objModuleInfo.IconFile    = Convert.ToString(Null.SetNull(dr["IconFile"], objModuleInfo.IconFile));
                objModuleInfo.AllTabs     = Convert.ToBoolean(Null.SetNull(dr["AllTabs"], objModuleInfo.AllTabs));
                int intVisibility = 0;
                if (((Convert.ToInt32(Null.SetNull(dr["Visibility"], intVisibility))) == 0) || ((Convert.ToInt32(Null.SetNull(dr["Visibility"], intVisibility))) == Null.NullInteger))
                {
                    objModuleInfo.Visibility = VisibilityState.Maximized;
                }
                else if ((Convert.ToInt32(Null.SetNull(dr["Visibility"], intVisibility))) == 1)
                {
                    objModuleInfo.Visibility = VisibilityState.Minimized;
                }
                else if ((Convert.ToInt32(Null.SetNull(dr["Visibility"], intVisibility))) == 2)
                {
                    objModuleInfo.Visibility = VisibilityState.None;
                }
                objModuleInfo.IsDeleted               = Convert.ToBoolean(Null.SetNull(dr["IsDeleted"], objModuleInfo.IsDeleted));
                objModuleInfo.Header                  = Convert.ToString(Null.SetNull(dr["Header"], objModuleInfo.Header));
                objModuleInfo.Footer                  = Convert.ToString(Null.SetNull(dr["Footer"], objModuleInfo.Footer));
                objModuleInfo.StartDate               = Convert.ToDateTime(Null.SetNull(dr["StartDate"], objModuleInfo.StartDate));
                objModuleInfo.EndDate                 = Convert.ToDateTime(Null.SetNull(dr["EndDate"], objModuleInfo.EndDate));
                objModuleInfo.ContainerSrc            = Convert.ToString(Null.SetNull(dr["ContainerSrc"], objModuleInfo.ContainerSrc));
                objModuleInfo.DisplayTitle            = Convert.ToBoolean(Null.SetNull(dr["DisplayTitle"], objModuleInfo.DisplayTitle));
                objModuleInfo.DisplayPrint            = Convert.ToBoolean(Null.SetNull(dr["DisplayPrint"], objModuleInfo.DisplayPrint));
                objModuleInfo.DisplaySyndicate        = Convert.ToBoolean(Null.SetNull(dr["DisplaySyndicate"], objModuleInfo.DisplaySyndicate));
                objModuleInfo.InheritViewPermissions  = Convert.ToBoolean(Null.SetNull(dr["InheritViewPermissions"], objModuleInfo.InheritViewPermissions));
                objModuleInfo.DesktopModuleID         = Convert.ToInt32(Null.SetNull(dr["DesktopModuleID"], objModuleInfo.DesktopModuleID));
                objModuleInfo.FriendlyName            = Convert.ToString(Null.SetNull(dr["FriendlyName"], objModuleInfo.FriendlyName));
                objModuleInfo.Description             = Convert.ToString(Null.SetNull(dr["Description"], objModuleInfo.Description));
                objModuleInfo.Version                 = Convert.ToString(Null.SetNull(dr["Version"], objModuleInfo.Version));
                objModuleInfo.IsPremium               = Convert.ToBoolean(Null.SetNull(dr["IsPremium"], objModuleInfo.IsPremium));
                objModuleInfo.IsAdmin                 = Convert.ToBoolean(Null.SetNull(dr["IsAdmin"], objModuleInfo.IsAdmin));
                objModuleInfo.BusinessControllerClass = Convert.ToString(Null.SetNull(dr["BusinessControllerClass"], objModuleInfo.BusinessControllerClass));
                objModuleInfo.SupportedFeatures       = Convert.ToInt32(Null.SetNull(dr["SupportedFeatures"], objModuleInfo.SupportedFeatures));
                objModuleInfo.ModuleControlId         = Convert.ToInt32(Null.SetNull(dr["ModuleControlId"], objModuleInfo.ModuleControlId));
                objModuleInfo.ControlSrc              = Convert.ToString(Null.SetNull(dr["ControlSrc"], objModuleInfo.ControlSrc));
                int intControlType = 0;
                if ((Convert.ToInt32(Null.SetNull(dr["ControlType"], intControlType))) == -3)
                {
                    objModuleInfo.ControlType = SecurityAccessLevel.ControlPanel;
                }
                else if ((Convert.ToInt32(Null.SetNull(dr["ControlType"], intControlType))) == -2)
                {
                    objModuleInfo.ControlType = SecurityAccessLevel.SkinObject;
                }
                else if (((Convert.ToInt32(Null.SetNull(dr["ControlType"], intControlType))) == -1) || ((Convert.ToInt32(Null.SetNull(dr["ControlType"], intControlType))) == Null.NullInteger))
                {
                    objModuleInfo.ControlType = SecurityAccessLevel.Anonymous;
                }
                else if ((Convert.ToInt32(Null.SetNull(dr["ControlType"], intControlType))) == 0)
                {
                    objModuleInfo.ControlType = SecurityAccessLevel.View;
                }
                else if ((Convert.ToInt32(Null.SetNull(dr["ControlType"], intControlType))) == 1)
                {
                    objModuleInfo.ControlType = SecurityAccessLevel.Edit;
                }
                else if ((Convert.ToInt32(Null.SetNull(dr["ControlType"], intControlType))) == 2)
                {
                    objModuleInfo.ControlType = SecurityAccessLevel.Admin;
                }
                else if ((Convert.ToInt32(Null.SetNull(dr["ControlType"], intControlType))) == 3)
                {
                    objModuleInfo.ControlType = SecurityAccessLevel.Host;
                }
                objModuleInfo.ControlTitle = Convert.ToString(Null.SetNull(dr["ControlTitle"], objModuleInfo.ControlTitle));
                objModuleInfo.HelpUrl      = Convert.ToString(Null.SetNull(dr["HelpUrl"], objModuleInfo.HelpUrl));

                if (IncludePermissions)
                {
                    if (objModuleInfo != null)
                    {
                        //Get the Module permissions first (then we can parse the collection to determine the View/Edit Roles)
                        objModuleInfo.ModulePermissions   = objModulePermissionController.GetModulePermissionsCollectionByModuleID(objModuleInfo.ModuleID, objModuleInfo.TabID);
                        objModuleInfo.AuthorizedEditRoles = objModulePermissionController.GetModulePermissions(objModuleInfo.ModulePermissions, "EDIT");
                        if (objModuleInfo.AuthorizedEditRoles == ";")
                        {
                            // this code is here for legacy support - the AuthorizedEditRoles were stored as a concatenated list of roleids prior to DNN 3.0
                            try
                            {
                                objModuleInfo.AuthorizedEditRoles = Convert.ToString(Null.SetNull(dr["AuthorizedEditRoles"], objModuleInfo.AuthorizedEditRoles));
                            }
                            catch
                            {
                                // the AuthorizedEditRoles field was removed from the Tabs table in 3.0
                            }
                        }
                        try
                        {
                            if (objModuleInfo.InheritViewPermissions)
                            {
                                TabPermissionController objTabPermissionController = new TabPermissionController();
                                TabPermissionCollection objTabPermissionCollection = objTabPermissionController.GetTabPermissionsCollectionByTabID(objModuleInfo.TabID, objModuleInfo.PortalID);
                                objModuleInfo.AuthorizedViewRoles = objTabPermissionController.GetTabPermissions(objTabPermissionCollection, "VIEW");
                            }
                            else
                            {
                                objModuleInfo.AuthorizedViewRoles = objModulePermissionController.GetModulePermissions(objModuleInfo.ModulePermissions, "VIEW");
                            }
                            if (objModuleInfo.AuthorizedViewRoles == ";")
                            {
                                // this code is here for legacy support - the AuthorizedViewRoles were stored as a concatenated list of roleids prior to DNN 3.0
                                try
                                {
                                    objModuleInfo.AuthorizedViewRoles = Convert.ToString(Null.SetNull(dr["AuthorizedViewRoles"], objModuleInfo.AuthorizedViewRoles));
                                }
                                catch
                                {
                                    // the AuthorizedViewRoles field was removed from the Tabs table in 3.0
                                }
                            }
                        }
                        catch
                        {
                        }
                    }
                }
            }
            else
            {
                objModuleInfo = null;
            }
            return(objModuleInfo);
        }
Beispiel #6
0
        public void UpdateModule(ModuleInfo objModule)
        {
            // update module
            DataProvider.Instance().UpdateModule(objModule.ModuleID, objModule.ModuleTitle, objModule.AllTabs, objModule.Header, objModule.Footer, objModule.StartDate, objModule.EndDate, objModule.InheritViewPermissions, objModule.IsDeleted);

            // update module permissions
            ModulePermissionController objModulePermissionController = new ModulePermissionController();
            ModulePermissionCollection objCurrentModulePermissions;

            objCurrentModulePermissions = objModulePermissionController.GetModulePermissionsCollectionByModuleID(objModule.ModuleID, objModule.TabID);
            if (!objCurrentModulePermissions.CompareTo(objModule.ModulePermissions))
            {
                objModulePermissionController.DeleteModulePermissionsByModuleID(objModule.ModuleID);
                foreach (ModulePermissionInfo objModulePermission in objModule.ModulePermissions)
                {
                    objModulePermission.ModuleID = objModule.ModuleID;
                    if (objModule.InheritViewPermissions && objModulePermission.PermissionKey == "VIEW")
                    {
                        objModulePermissionController.DeleteModulePermission(objModulePermission.ModulePermissionID);
                    }
                    else
                    {
                        if (objModulePermission.AllowAccess)
                        {
                            objModulePermissionController.AddModulePermission(objModulePermission, objModule.TabID);
                        }
                    }
                }
            }

            if (!Null.IsNull(objModule.TabID))
            {
                // update tabmodule
                DataProvider.Instance().UpdateTabModule(objModule.TabID, objModule.ModuleID, objModule.ModuleOrder, objModule.PaneName, objModule.CacheTime, objModule.Alignment, objModule.Color, objModule.Border, objModule.IconFile, (int)objModule.Visibility, objModule.ContainerSrc, objModule.DisplayTitle, objModule.DisplayPrint, objModule.DisplaySyndicate);

                // update module order in pane
                UpdateModuleOrder(objModule.TabID, objModule.ModuleID, objModule.ModuleOrder, objModule.PaneName);

                // set the default module
                if (objModule.IsDefaultModule)
                {
                    PortalSettings.UpdatePortalSetting(objModule.PortalID, "defaultmoduleid", objModule.ModuleID.ToString());
                    PortalSettings.UpdatePortalSetting(objModule.PortalID, "defaulttabid", objModule.TabID.ToString());
                }

                // apply settings to all desktop modules in portal
                if (objModule.AllModules)
                {
                    TabController objTabs = new TabController();
                    foreach (KeyValuePair <int, TabInfo> tabPair in objTabs.GetTabsByPortal(objModule.PortalID))
                    {
                        TabInfo objTab = tabPair.Value;
                        if (!objTab.IsAdminTab)
                        {
                            foreach (KeyValuePair <int, ModuleInfo> modulePair in GetTabModules(objTab.TabID))
                            {
                                ModuleInfo objTargetModule = modulePair.Value;
                                DataProvider.Instance().UpdateTabModule(objTargetModule.TabID, objTargetModule.ModuleID, objTargetModule.ModuleOrder, objTargetModule.PaneName, objModule.CacheTime, objModule.Alignment, objModule.Color, objModule.Border, objModule.IconFile, (int)objModule.Visibility, objModule.ContainerSrc, objModule.DisplayTitle, objModule.DisplayPrint, objModule.DisplaySyndicate);
                            }
                        }
                    }
                }
            }
            ClearCache(objModule.TabID);
        }