Exemplo n.º 1
0
        public void GivenThereIsAPageCalled(string pageName, Table permissions)
        {
            var reset = false;
            var tabController = new TabController();
            var tab = tabController.GetTabByName(pageName, PortalId);
            if (tab == null)
            {
                tab = new TabInfo
                {
                    TabName = pageName,
                    PortalID = 0
                };
                tab.TabID = tabController.AddTab(tab);
                foreach (var row in permissions.Rows)
                {
                    var roleId = -1;
                    var roleController = new RoleController();
                    if (row[0] == "All Users")
                    {
                        roleId = -1;
                    }
                    else
                    {
                        var role = roleController.GetRoleByName(PortalId, row[0]);
                        if (role == null)
                        {
                            if (roleController.GetRoleByName(Null.NullInteger, row[0]) == null)
                            {
                                role = new RoleInfo { RoleName = row[0], RoleGroupID = Null.NullInteger };
                                roleId = roleController.AddRole(role);
                            }
                        }
                    }
                    var permissionController = new PermissionController();
                    var permission = permissionController.GetPermissionByCodeAndKey("SYSTEM_TAB", row[1]);
                    var tabPermission = new TabPermissionInfo
                    {
                        PermissionID = 3,
                        TabID = tab.TabID,
                        AllowAccess = true,
                        RoleID = roleId
                    };
                    tab.TabPermissions.Add(tabPermission);
                }

                tabController.UpdateTab(tab);
                reset = true;
            }
            Page = tab;
            if (reset)
            {
                Config.Touch();
            }
        }
 public static void ensureFolderExists(int portalId)
 {
     FolderMappingInfo fm = FolderMappingController.Instance.GetFolderMapping(portalId, "Secure");
     if (!FolderManager.Instance.FolderExists(portalId, IMAGE_FOLDER + "/"))
     {
         IFolderInfo f1 = FolderManager.Instance.AddFolder(fm, IMAGE_FOLDER);
         DotNetNuke.Security.Roles.RoleController rc = new DotNetNuke.Security.Roles.RoleController();
         DotNetNuke.Security.Permissions.PermissionController pc = new DotNetNuke.Security.Permissions.PermissionController();
         DotNetNuke.Security.Permissions.PermissionInfo w = (DotNetNuke.Security.Permissions.PermissionInfo)pc.GetPermissionByCodeAndKey("SYSTEM_FOLDER", "WRITE")[0];
         FolderManager.Instance.SetFolderPermission(f1, w.PermissionID, rc.GetRoleByName(portalId, "Accounts Team").RoleID);
     }
 }
 public static void checkFolderPermissions(int PortalId, IFolderInfo theFolder, int theUserId, List<UserInfo> approvers)
 {
     // Get the write permission
     PermissionController pc = new PermissionController();
     PermissionInfo w = (PermissionInfo)pc.GetPermissionByCodeAndKey("SYSTEM_FOLDER", "WRITE")[0];
     // Get a list of all the folderPermissions we currently have
     FolderPermissionCollection folderPermissions = theFolder.FolderPermissions;
     // Set up the first permission
     FolderPermissionInfo permission = new FolderPermissionInfo();
     // Set up some default values for the permission
     initFolderPermission(permission, theFolder.FolderID, PortalId, w.PermissionID);
     // Set the user id to be this user
     permission.UserID = theUserId;
     // Add folder permissions, with a check for duplicates.
     // This duplicate check (the 'True' parameter) will classify this as a "duplicate" if this permission
     // has the same PermissionID, UserID, and RoleID as a pre-existing one, and not add it if it is a duplicate
     folderPermissions.Add(permission, true);
     // Get all the possible approvers for this reimbursement
     try
     {
         foreach (var approver in approvers)
         {
             // Create a new permission for this approver
             permission = new FolderPermissionInfo();
             // Initialize all the variables
             initFolderPermission(permission, theFolder.FolderID, PortalId, w.PermissionID);
             // Set the userid to the approver's id
             permission.UserID = approver.UserID;
             // Add permission for approver
             folderPermissions.Add(permission, true);
         }
     }
     catch { }
     // Finally, add permissions for the accounts team:
     try
     {
         permission = new FolderPermissionInfo();
         // Initialize new folder permission
         initFolderPermission(permission, theFolder.FolderID, PortalId, w.PermissionID);
         // Set the role ID
         DotNetNuke.Security.Roles.RoleController rc = new DotNetNuke.Security.Roles.RoleController();
         permission.RoleID = rc.GetRoleByName(PortalId, "Accounts Team").RoleID;
         folderPermissions.Add(permission, true);
     }
     catch { }
     // Once we're finished adding these folder permissions, save it all
     FolderPermissionController.SaveFolderPermissions(theFolder);
 }
        /// <summary>
        /// Adds the module to page.
        /// </summary>
        /// <param name="portalId">The portal id.</param>
        /// <param name="tabId">The tab id.</param>
        /// <exception cref="System.ArgumentException">desktopModuleId</exception>
        private void AddModuleToPage(int portalId, int tabId)
        {
            TabPermissionCollection objTabPermissions = new TabController().GetTab(tabId, portalId, false).TabPermissions;
            var objPermissionController = new PermissionController();
            var objModules = new ModuleController();
            new EventLogController();

            int desktopModuleId =
                DesktopModuleController.GetDesktopModuleByFriendlyName("VanityURLs").DesktopModuleID;

            try
            {
                DesktopModuleInfo desktopModule;
                if (!DesktopModuleController.GetDesktopModules(portalId).TryGetValue(desktopModuleId, out desktopModule))
                {
                    throw new ArgumentException("desktopModuleId");
                }
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
            }

            foreach (ModuleDefinitionInfo objModuleDefinition in
                ModuleDefinitionController.GetModuleDefinitionsByDesktopModuleID(desktopModuleId).Values)
            {
                var objModule = new ModuleInfo();
                objModule.PortalID = portalId;
                objModule.TabID = tabId;
                objModule.ModuleOrder = 0;
                objModule.ModuleTitle = objModuleDefinition.FriendlyName;
                objModule.PaneName = "ContentPane";
                objModule.ModuleDefID = objModuleDefinition.ModuleDefID;
                objModule.InheritViewPermissions = true;
                objModule.CultureCode = Null.NullString;
                objModule.AllTabs = false;
                objModules.AddModule(objModule);
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PermissionController"/> class.
 /// </summary>
 public PermissionController()
 {
     this.permissionController = new DotNetNuke.Security.Permissions.PermissionController();
 }
Exemplo n.º 6
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// SaveFolderPermissions updates a Folder's permissions
        /// </summary>
        /// <param name="folder">The Folder to update</param>
        /// <history>
        ///     [cnurse]	04/15/2009   Created
        /// </history>
        /// -----------------------------------------------------------------------------
        public virtual void SaveFolderPermissions(IFolderInfo folder)
        {
            if ((folder.FolderPermissions != null))
            {
                FolderPermissionCollection folderPermissions = GetFolderPermissionsCollectionByFolder(folder.PortalID, folder.FolderPath);

                //Ensure that if role/user has been given a permission that is not Read/Browse then they also need Read/Browse
                var            permController = new PermissionController();
                ArrayList      permArray      = permController.GetPermissionByCodeAndKey("SYSTEM_FOLDER", "READ");
                PermissionInfo readPerm       = null;
                if (permArray.Count == 1)
                {
                    readPerm = permArray[0] as PermissionInfo;
                }

                PermissionInfo browsePerm = null;
                permArray = permController.GetPermissionByCodeAndKey("SYSTEM_FOLDER", "BROWSE");
                if (permArray.Count == 1)
                {
                    browsePerm = permArray[0] as PermissionInfo;
                }

                var additionalPermissions = new FolderPermissionCollection();
                foreach (FolderPermissionInfo folderPermission in folder.FolderPermissions)
                {
                    if (folderPermission.PermissionKey != "BROWSE" && folderPermission.PermissionKey != "READ")
                    {
                        //Try to add Read permission
                        var newFolderPerm = new FolderPermissionInfo(readPerm)
                        {
                            FolderID    = folderPermission.FolderID,
                            RoleID      = folderPermission.RoleID,
                            UserID      = folderPermission.UserID,
                            AllowAccess = folderPermission.AllowAccess
                        };

                        additionalPermissions.Add(newFolderPerm);

                        //Try to add Browse permission
                        newFolderPerm = new FolderPermissionInfo(browsePerm)
                        {
                            FolderID    = folderPermission.FolderID,
                            RoleID      = folderPermission.RoleID,
                            UserID      = folderPermission.UserID,
                            AllowAccess = folderPermission.AllowAccess
                        };

                        additionalPermissions.Add(newFolderPerm);
                    }
                }

                foreach (FolderPermissionInfo folderPermission in additionalPermissions)
                {
                    folder.FolderPermissions.Add(folderPermission, true);
                }

                if (!folderPermissions.CompareTo(folder.FolderPermissions))
                {
                    dataProvider.DeleteFolderPermissionsByFolderPath(folder.PortalID, folder.FolderPath);

                    foreach (FolderPermissionInfo folderPermission in folder.FolderPermissions)
                    {
                        dataProvider.AddFolderPermission(folder.FolderID,
                                                         folderPermission.PermissionID,
                                                         folderPermission.RoleID,
                                                         folderPermission.AllowAccess,
                                                         folderPermission.UserID,
                                                         UserController.GetCurrentUserInfo().UserID);
                    }
                }
            }
        }
Exemplo n.º 7
0
 public string ToString(string key)
 {
     return(PermissionController.BuildPermissions(List, key));
 }
        private IFolderInfo EnsureGroupFolder(int groupId, PortalSettings portalSettings)
        {
            const int AllUsersRoleId = -1;
            var groupFolderPath = "Groups/" + groupId;

            if (!FolderManager.Instance.FolderExists(portalSettings.PortalId, groupFolderPath))
            {
                var pc = new PermissionController();
                var browsePermission = pc.GetPermissionByCodeAndKey("SYSTEM_FOLDER", "BROWSE").Cast<PermissionInfo>().FirstOrDefault();
                var readPermission = pc.GetPermissionByCodeAndKey("SYSTEM_FOLDER", "READ").Cast<PermissionInfo>().FirstOrDefault(); 
                var writePermission = pc.GetPermissionByCodeAndKey("SYSTEM_FOLDER", "WRITE").Cast<PermissionInfo>().FirstOrDefault();

                if (!FolderManager.Instance.FolderExists(portalSettings.PortalId, "Groups"))
                {
                    var folder = FolderManager.Instance.AddFolder(portalSettings.PortalId, "Groups");

                    folder.FolderPermissions.Remove(browsePermission.PermissionID, AllUsersRoleId, Null.NullInteger);
                    folder.FolderPermissions.Remove(readPermission.PermissionID, AllUsersRoleId, Null.NullInteger);
                    folder.IsProtected = true;
                    FolderManager.Instance.UpdateFolder(folder);
                }

                var groupFolder = FolderManager.Instance.AddFolder(portalSettings.PortalId, groupFolderPath);

                groupFolder.FolderPermissions.Add(new FolderPermissionInfo(browsePermission) { FolderPath = groupFolder.FolderPath, RoleID = groupId, AllowAccess = true });
                groupFolder.FolderPermissions.Add(new FolderPermissionInfo(readPermission) { FolderPath = groupFolder.FolderPath, RoleID = groupId, AllowAccess = true });
                groupFolder.FolderPermissions.Add(new FolderPermissionInfo(writePermission) { FolderPath = groupFolder.FolderPath, RoleID = groupId, AllowAccess = true });

                groupFolder.IsProtected = true;
                FolderManager.Instance.UpdateFolder(groupFolder);
                return groupFolder;
            }

            return FolderManager.Instance.GetFolder(portalSettings.PortalId, groupFolderPath);        
        }
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// SaveFolderPermissions updates a Folder's permissions
        /// </summary>
        /// <param name="folder">The Folder to update</param>
        /// <history>
        /// 	[cnurse]	04/15/2009   Created
        /// </history>
        /// -----------------------------------------------------------------------------
        public virtual void SaveFolderPermissions(IFolderInfo folder)
        {
            if ((folder.FolderPermissions != null))
            {
                //Ensure that if role/user has been given a permission that is not Read/Browse then they also need Read/Browse
                var permController = new PermissionController();
                ArrayList permArray = permController.GetPermissionByCodeAndKey("SYSTEM_FOLDER", "READ");
                PermissionInfo readPerm = null;
                if (permArray.Count == 1)
                {
                    readPerm = permArray[0] as PermissionInfo;
                }

                PermissionInfo browsePerm = null;
                permArray = permController.GetPermissionByCodeAndKey("SYSTEM_FOLDER", "BROWSE");
                if (permArray.Count == 1)
                {
                    browsePerm = permArray[0] as PermissionInfo;
                }

                var additionalPermissions = new FolderPermissionCollection();
                foreach (FolderPermissionInfo folderPermission in folder.FolderPermissions)
                {
                    if (folderPermission.PermissionKey != "BROWSE" && folderPermission.PermissionKey != "READ" && folderPermission.AllowAccess)
                    {
                        //Try to add Read permission
                        var newFolderPerm = new FolderPermissionInfo(readPerm)
                                                {
                                                    FolderID = folderPermission.FolderID, 
                                                    RoleID = folderPermission.RoleID, 
                                                    UserID = folderPermission.UserID, 
                                                    AllowAccess = true
                                                };

                        additionalPermissions.Add(newFolderPerm);

                        //Try to add Browse permission
                        newFolderPerm = new FolderPermissionInfo(browsePerm)
                                            {
                                                FolderID = folderPermission.FolderID, 
                                                RoleID = folderPermission.RoleID, 
                                                UserID = folderPermission.UserID, 
                                                AllowAccess = true
                                            };

                        additionalPermissions.Add(newFolderPerm);
                    }
                }

                foreach (FolderPermissionInfo folderPermission in additionalPermissions)
                {
                    folder.FolderPermissions.Add(folderPermission, true);
                }

                dataProvider.DeleteFolderPermissionsByFolderPath(folder.PortalID, folder.FolderPath);
                foreach (FolderPermissionInfo folderPermission in folder.FolderPermissions)
                {
                    dataProvider.AddFolderPermission(folder.FolderID,
                                                        folderPermission.PermissionID,
                                                        folderPermission.RoleID,
                                                        folderPermission.AllowAccess,
                                                        folderPermission.UserID,
                                                        UserController.Instance.GetCurrentUserInfo().UserID);
                }                
            }
        }
Exemplo n.º 10
0
        private int LocalizeModuleInternal(ModuleInfo sourceModule)
        {
            int moduleId = Null.NullInteger;

            if (sourceModule != null)
            {
                // clone the module object ( to avoid creating an object reference to the data cache )
                var newModule = sourceModule.Clone();
                newModule.ModuleID = Null.NullInteger;

                string translatorRoles = PortalController.GetPortalSetting(string.Format("DefaultTranslatorRoles-{0}", sourceModule.CultureCode), sourceModule.PortalID, "").TrimEnd(';');

                //Add the default translators for this language, view and edit permissions
                var permissionController = new PermissionController();
                var viewPermissionsList = permissionController.GetPermissionByCodeAndKey("SYSTEM_MODULE_DEFINITION", "VIEW");
                var editPermissionsList = permissionController.GetPermissionByCodeAndKey("SYSTEM_MODULE_DEFINITION", "EDIT");
                PermissionInfo viewPermisison = null;
                PermissionInfo editPermisison = null;

                //View
                if (viewPermissionsList != null && viewPermissionsList.Count > 0)
                {
                    viewPermisison = (PermissionInfo)viewPermissionsList[0];
                }

                //Edit
                if (editPermissionsList != null && editPermissionsList.Count > 0)
                {
                    editPermisison = (PermissionInfo)editPermissionsList[0];
                }

                if (viewPermisison != null || editPermisison != null)
                {
                    foreach (string translatorRole in translatorRoles.Split(';'))
                    {
                        AddModulePermission(ref newModule, sourceModule.PortalID, translatorRole, viewPermisison, "VIEW");
                        AddModulePermission(ref newModule, sourceModule.PortalID, translatorRole, editPermisison, "EDIT");
                    }
                }

                //Add Module
                AddModuleInternal(newModule);

                //copy module settings
                Hashtable settings = GetModuleSettings(sourceModule.ModuleID);

                //Copy each setting to the new TabModule instance
                foreach (DictionaryEntry setting in settings)
                {
                    UpdateModuleSetting(newModule.ModuleID, Convert.ToString(setting.Key), Convert.ToString(setting.Value));
                }

                // update tabmodule
                dataProvider.UpdateTabModule(newModule.TabModuleID,
                                             newModule.TabID,
                                             newModule.ModuleID,
                                             newModule.ModuleTitle,
                                             newModule.Header,
                                             newModule.Footer,
                                             newModule.ModuleOrder,
                                             newModule.PaneName,
                                             newModule.CacheTime,
                                             newModule.CacheMethod,
                                             newModule.Alignment,
                                             newModule.Color,
                                             newModule.Border,
                                             newModule.IconFile,
                                             (int)newModule.Visibility,
                                             newModule.ContainerSrc,
                                             newModule.DisplayTitle,
                                             newModule.DisplayPrint,
                                             newModule.DisplaySyndicate,
                                             newModule.IsWebSlice,
                                             newModule.WebSliceTitle,
                                             newModule.WebSliceExpiryDate,
                                             newModule.WebSliceTTL,
                                             newModule.VersionGuid,
                                             newModule.DefaultLanguageGuid,
                                             newModule.LocalizedVersionGuid,
                                             newModule.CultureCode,
                                             UserController.GetCurrentUserInfo().UserID);

                if (!string.IsNullOrEmpty(newModule.DesktopModule.BusinessControllerClass))
                {
                    try
                    {
                        object businessController = Reflection.CreateObject(newModule.DesktopModule.BusinessControllerClass, newModule.DesktopModule.BusinessControllerClass);
                        var portableModule = businessController as IPortable;
                        if (portableModule != null)
                        {
                            string Content = portableModule.ExportModule(sourceModule.ModuleID);
                            if (!string.IsNullOrEmpty(Content))
                            {
                                portableModule.ImportModule(newModule.ModuleID, Content, newModule.DesktopModule.Version, UserController.GetCurrentUserInfo().UserID);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Exceptions.LogException(ex);
                    }
                }

                moduleId = newModule.ModuleID;

                //Clear Caches
                ClearCache(newModule.TabID);
                ClearCache(sourceModule.TabID);
            }

            return moduleId;
        }
Exemplo n.º 11
0
		public void InitialModulePermission(ModuleInfo module, int tabId, int permissionType)
		{
			var tabPermissions = TabPermissionController.GetTabPermissions(tabId, module.PortalID);
            var permissionController = new PermissionController();

            module.InheritViewPermissions = permissionType == 0;

            // get the default module view permissions
            ArrayList systemModuleViewPermissions = permissionController.GetPermissionByCodeAndKey("SYSTEM_MODULE_DEFINITION", "VIEW");

            // get the permissions from the page
			foreach (TabPermissionInfo tabPermission in tabPermissions)
			{
				if (tabPermission.PermissionKey == "VIEW" && permissionType == 0)
				{
					//Don't need to explicitly add View permisisons if "Same As Page"
					continue;
				}

				// get the system module permissions for the permissionkey
				ArrayList systemModulePermissions = permissionController.GetPermissionByCodeAndKey("SYSTEM_MODULE_DEFINITION", tabPermission.PermissionKey);
				// loop through the system module permissions
				int j;
				for (j = 0; j <= systemModulePermissions.Count - 1; j++)
				{
					// create the module permission
					var systemModulePermission = (PermissionInfo) systemModulePermissions[j];
					if (systemModulePermission.PermissionKey == "VIEW" && permissionType == 1 && tabPermission.PermissionKey != "EDIT")
					{
						//Only Page Editors get View permissions if "Page Editors Only"
						continue;
					}

					ModulePermissionInfo modulePermission = AddModulePermission(module, systemModulePermission, tabPermission.RoleID, tabPermission.UserID, tabPermission.AllowAccess);

					// ensure that every EDIT permission which allows access also provides VIEW permission
					if (modulePermission.PermissionKey == "EDIT" && modulePermission.AllowAccess)
					{
						AddModulePermission(module, (PermissionInfo) systemModuleViewPermissions[0], modulePermission.RoleID, modulePermission.UserID, true);
					}
				}

				//Get the custom Module Permissions,  Assume that roles with Edit Tab Permissions
				//are automatically assigned to the Custom Module Permissions
				if (tabPermission.PermissionKey == "EDIT")
				{
					ArrayList customModulePermissions = permissionController.GetPermissionsByModuleDefID(module.ModuleDefID);

					// loop through the custom module permissions
					for (j = 0; j <= customModulePermissions.Count - 1; j++)
					{
						// create the module permission
						var customModulePermission = (PermissionInfo)customModulePermissions[j];

						AddModulePermission(module, customModulePermission, tabPermission.RoleID, tabPermission.UserID, tabPermission.AllowAccess);
					}
				}
			}
		}
Exemplo n.º 12
0
        private int AddNewModule(TabInfo tab, string title, int desktopModuleId, string paneName, int permissionType, string align)
        {
            TabPermissionCollection objTabPermissions = tab.TabPermissions;
            var objPermissionController = new PermissionController();
            var objModules = new ModuleController();
            int j;
            var mdc = new ModuleDefinitionController();

            foreach (ModuleDefinitionInfo objModuleDefinition in ModuleDefinitionController.GetModuleDefinitionsByDesktopModuleID(desktopModuleId).Values)
            {
                var objModule = new ModuleInfo();
                objModule.Initialize(tab.PortalID);

                objModule.PortalID = tab.PortalID;
                objModule.TabID = tab.TabID;
                if (string.IsNullOrEmpty(title))
                {
                    objModule.ModuleTitle = objModuleDefinition.FriendlyName;
                }
                else
                {
                    objModule.ModuleTitle = title;
                }
                objModule.PaneName = paneName;
                objModule.ModuleDefID = objModuleDefinition.ModuleDefID;
                objModule.CacheTime = 0;
                objModule.InheritViewPermissions = true;
                objModule.DisplayTitle = false;

                // get the default module view permissions
                ArrayList arrSystemModuleViewPermissions = objPermissionController.GetPermissionByCodeAndKey("SYSTEM_MODULE_DEFINITION", "VIEW");

                // get the permissions from the page
                foreach (TabPermissionInfo objTabPermission in objTabPermissions)
                {
                    if (objTabPermission.PermissionKey == "VIEW" && permissionType == 0)
                    {
                        //Don't need to explicitly add View permisisons if "Same As Page"
                        continue;
                    }

                    // get the system module permissions for the permissionkey
                    ArrayList arrSystemModulePermissions = objPermissionController.GetPermissionByCodeAndKey("SYSTEM_MODULE_DEFINITION", objTabPermission.PermissionKey);
                    // loop through the system module permissions
                    for (j = 0; j <= arrSystemModulePermissions.Count - 1; j++)
                    {
                        // create the module permission
                        PermissionInfo objSystemModulePermission = default(PermissionInfo);
                        objSystemModulePermission = (PermissionInfo) arrSystemModulePermissions[j];
                        if (objSystemModulePermission.PermissionKey == "VIEW" && permissionType == 1 && objTabPermission.PermissionKey != "EDIT")
                        {
                            //Only Page Editors get View permissions if "Page Editors Only"
                            continue;
                        }

                        ModulePermissionInfo objModulePermission = AddModulePermission(objModule,
                                                                                       objSystemModulePermission,
                                                                                       objTabPermission.RoleID,
                                                                                       objTabPermission.UserID,
                                                                                       objTabPermission.AllowAccess);

                        // ensure that every EDIT permission which allows access also provides VIEW permission
                        if (objModulePermission.PermissionKey == "EDIT" & objModulePermission.AllowAccess)
                        {
                            ModulePermissionInfo objModuleViewperm = AddModulePermission(objModule,
                                                                                         (PermissionInfo) arrSystemModuleViewPermissions[0],
                                                                                         objModulePermission.RoleID,
                                                                                         objModulePermission.UserID,
                                                                                         true);
                        }
                    }
                }

                objModule.AllTabs = false;
                objModule.Alignment = align;

                return objModules.AddModule(objModule);
            }
            return -1;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="PermissionController"/> class.
 /// </summary>
 public PermissionController()
 {
     this.permissionController = new DotNetNuke.Security.Permissions.PermissionController();
 }
Exemplo n.º 14
0
        public ActionResult Save(int folderid, bool Copyfolder, dynamic Data)
        {
            ActionResult actionResult = new ActionResult();
            IFolderInfo  parentFolder = FolderManager.Instance.GetFolder(folderid);

            if (parentFolder != null)
            {
                parentFolder.FolderPermissions.Clear();

                DotNetNuke.Security.Permissions.PermissionController permController = new DotNetNuke.Security.Permissions.PermissionController();
                ArrayList permArray = permController.GetPermissionByCodeAndKey("SYSTEM_FOLDER", "READ");

                List <PermissionInfo> SYS_FOLDER_PERM = new List <PermissionInfo>();
                if (permArray.Count == 1)
                {
                    SYS_FOLDER_PERM.Add(permArray[0] as PermissionInfo);
                }

                permArray = permController.GetPermissionByCodeAndKey("SYSTEM_FOLDER", "BROWSE");
                if (permArray.Count == 1)
                {
                    SYS_FOLDER_PERM.Add(permArray[0] as PermissionInfo);
                }

                permArray = permController.GetPermissionByCodeAndKey("SYSTEM_FOLDER", "WRITE");
                if (permArray.Count == 1)
                {
                    SYS_FOLDER_PERM.Add(permArray[0] as PermissionInfo);
                }

                foreach (dynamic item in Data.PermissionsRoles)
                {
                    foreach (dynamic p in item.Permissions)
                    {
                        bool   AllowAcess   = bool.Parse(p.AllowAccess.ToString());
                        string PermissionID = p.PermissionId.ToString();
                        if (AllowAcess)
                        {
                            FolderPermissionInfo folderpermissioninfo = new FolderPermissionInfo
                            {
                                AllowAccess  = AllowAcess,
                                PermissionID = Convert.ToInt32(PermissionID)
                            };
                            PermissionInfo SYS_PERM = SYS_FOLDER_PERM.Where(a => a.PermissionID == folderpermissioninfo.PermissionID).FirstOrDefault();
                            if (SYS_PERM != null)
                            {
                                folderpermissioninfo.PermissionKey = SYS_PERM.PermissionKey;
                            }

                            folderpermissioninfo.RoleID = int.Parse(item.RoleId.ToString());
                            parentFolder.FolderPermissions.Add(folderpermissioninfo);
                        }
                    }
                }

                foreach (dynamic item in Data.PermissionsUsers)
                {
                    foreach (dynamic p in item.Permissions)
                    {
                        bool   AllowAcess   = bool.Parse(p.AllowAccess.ToString());
                        string PermissionID = p.PermissionId.ToString();
                        if (AllowAcess)
                        {
                            FolderPermissionInfo folderpermissioninfo = new FolderPermissionInfo
                            {
                                AllowAccess  = AllowAcess,
                                PermissionID = Convert.ToInt32(PermissionID)
                            };
                            PermissionInfo SYS_PERM = SYS_FOLDER_PERM.Where(a => a.PermissionID == folderpermissioninfo.PermissionID).FirstOrDefault();
                            if (SYS_PERM != null)
                            {
                                folderpermissioninfo.PermissionKey = SYS_PERM.PermissionKey;
                            }

                            folderpermissioninfo.UserID = int.Parse(item.UserId.ToString());
                            parentFolder.FolderPermissions.Add(folderpermissioninfo);
                        }
                    }
                }
                FolderManager.Instance.UpdateFolder(parentFolder);
                if (Copyfolder)
                {
                    FolderPermissionController.CopyPermissionsToSubfolders(parentFolder, parentFolder.FolderPermissions);
                }
            }
            Dictionary <int, bool> result = new Dictionary <int, bool>();

            if (Data != null && Data.FolderIds != null && Data.FolderIds.Count > 0)
            {
                foreach (dynamic id in Data.FolderIds)
                {
                    result.Add(int.Parse(id.Value), BrowseUploadFactory.HasBrowseOpenPerm(new Vanjaro.Common.Components.TreeView()
                    {
                        Value = int.Parse(id.Value)
                    }));
                }
            }
            actionResult.Data = result;
            return(actionResult);
        }
Exemplo n.º 15
0
        private void AddFolderPermissions(int portalId, int folderId)
        {
            var objPortal = GetPortal(portalId);
            FolderPermissionInfo objFolderPermission;
            var folderManager = FolderManager.Instance;
            var folder = folderManager.GetFolder(folderId);
            var objPermissionController = new PermissionController();
            foreach (PermissionInfo objpermission in objPermissionController.GetPermissionByCodeAndKey("SYSTEM_FOLDER", ""))
            {
                objFolderPermission = new FolderPermissionInfo(objpermission)
                {
                    FolderID = folder.FolderID,
                    RoleID = objPortal.AdministratorRoleId,
                    AllowAccess = true
                };

                folder.FolderPermissions.Add(objFolderPermission);
                if (objpermission.PermissionKey == "READ")
                {
                    //add READ permissions to the All Users Role
                    folderManager.AddAllUserReadPermission(folder, objpermission);
                }
            }
            FolderPermissionController.SaveFolderPermissions((FolderInfo)folder);
        }
Exemplo n.º 16
0
 private static void ParsePortalDesktopModules(XPathNavigator nav, int portalID)
 {
     string friendlyName = Null.NullString;
     DesktopModuleInfo desktopModule = null;
     foreach (XPathNavigator desktopModuleNav in nav.Select("portalDesktopModule"))
     {
         friendlyName = XmlUtils.GetNodeValue(desktopModuleNav, "friendlyname");
         if (!string.IsNullOrEmpty(friendlyName))
         {
             desktopModule = DesktopModuleController.GetDesktopModuleByFriendlyName(friendlyName);
             if (desktopModule != null)
             {
                 //Parse the permissions
                 DesktopModulePermissionCollection permissions = new DesktopModulePermissionCollection();
                 foreach (XPathNavigator permissionNav in
                     desktopModuleNav.Select("portalDesktopModulePermissions/portalDesktopModulePermission"))
                 {
                     string code = XmlUtils.GetNodeValue(permissionNav, "permissioncode");
                     string key = XmlUtils.GetNodeValue(permissionNav, "permissionkey");
                     DesktopModulePermissionInfo desktopModulePermission = null;
                     ArrayList arrPermissions = new PermissionController().GetPermissionByCodeAndKey(code, key);
                     if (arrPermissions.Count > 0)
                     {
                         PermissionInfo permission = arrPermissions[0] as PermissionInfo;
                         if (permission != null)
                         {
                             desktopModulePermission = new DesktopModulePermissionInfo(permission);
                         }
                     }
                     desktopModulePermission.AllowAccess = bool.Parse(XmlUtils.GetNodeValue(permissionNav, "allowaccess"));
                     string rolename = XmlUtils.GetNodeValue(permissionNav, "rolename");
                     if (!string.IsNullOrEmpty(rolename))
                     {
                         RoleInfo role = TestableRoleController.Instance.GetRole(portalID, r => r.RoleName == rolename);
                         if (role != null)
                         {
                             desktopModulePermission.RoleID = role.RoleID;
                         }
                     }
                     permissions.Add(desktopModulePermission);
                 }
                 DesktopModuleController.AddDesktopModuleToPortal(portalID, desktopModule, permissions, false);
             }
         }
     }
 }
Exemplo n.º 17
0
        private static void ParseFolderPermissions(XmlNodeList nodeFolderPermissions, int portalId, FolderInfo folder)
        {
            PermissionController permissionController = new PermissionController();
            int permissionId = 0;

            //Clear the current folder permissions
            folder.FolderPermissions.Clear();
            foreach (XmlNode xmlFolderPermission in nodeFolderPermissions)
            {
                string permissionKey = XmlUtils.GetNodeValue(xmlFolderPermission.CreateNavigator(), "permissionkey");
                string permissionCode = XmlUtils.GetNodeValue(xmlFolderPermission.CreateNavigator(), "permissioncode");
                string roleName = XmlUtils.GetNodeValue(xmlFolderPermission.CreateNavigator(), "rolename");
                bool allowAccess = XmlUtils.GetNodeValueBoolean(xmlFolderPermission, "allowaccess");
                foreach (PermissionInfo permission in permissionController.GetPermissionByCodeAndKey(permissionCode, permissionKey))
                {
                    permissionId = permission.PermissionID;
                }
                int roleId = int.MinValue;
                switch (roleName)
                {
                    case Globals.glbRoleAllUsersName:
                        roleId = Convert.ToInt32(Globals.glbRoleAllUsers);
                        break;
                    case Globals.glbRoleUnauthUserName:
                        roleId = Convert.ToInt32(Globals.glbRoleUnauthUser);
                        break;
                    default:
                        RoleInfo objRole = TestableRoleController.Instance.GetRole(portalId, r => r.RoleName == roleName);
                        if (objRole != null)
                        {
                            roleId = objRole.RoleID;
                        }
                        break;
                }

                //if role was found add, otherwise ignore
                if (roleId != int.MinValue)
                {
                    var folderPermission = new FolderPermissionInfo
                                                  {
                                                      FolderID = folder.FolderID,
                                                      PermissionID = permissionId,
                                                      RoleID = roleId,
                                                      UserID = Null.NullInteger,
                                                      AllowAccess = allowAccess
                                                  };

                    bool canAdd = !folder.FolderPermissions.Cast<FolderPermissionInfo>()
                                                .Any(fp => fp.FolderID == folderPermission.FolderID 
                                                        && fp.PermissionID == folderPermission.PermissionID 
                                                        && fp.RoleID == folderPermission.RoleID 
                                                        && fp.UserID == folderPermission.UserID);
                    if (canAdd)
                    {
                        folder.FolderPermissions.Add(folderPermission);
                    }
                }
            }
            FolderPermissionController.SaveFolderPermissions(folder);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Parses folder permissions
        /// </summary>
        /// <param name="nodeFolderPermissions">Node for folder permissions</param>
        /// <param name="PortalID">PortalId of new portal</param>
        /// <param name="FolderId">FolderId of folder being processed</param>
        /// <history>
        /// 	[cnurse]	11/09/2004	Created
        /// </history>
        private void ParseFolderPermissions( XmlNodeList nodeFolderPermissions, int PortalID, int FolderId, string folderPath )
        {
            FolderPermissionCollection objFolderPermissions = new FolderPermissionCollection();
            PermissionController objPermissionController = new PermissionController();
            PermissionInfo objPermission = null;
            FolderPermissionController objFolderPermissionController = new FolderPermissionController();
            RoleController objRoleController = new RoleController();
            RoleInfo objRole = null;
            int RoleID = 0;
            int PermissionID = 0;
            string PermissionKey = null;
            string PermissionCode = null;
            string RoleName = null;
            bool AllowAccess = false;
            ArrayList arrPermissions = null;
            int i = 0;

            foreach( XmlNode xmlFolderPermission in nodeFolderPermissions )
            {
                PermissionKey = XmlUtils.GetNodeValue( xmlFolderPermission, "permissionkey", "" );
                PermissionCode = XmlUtils.GetNodeValue( xmlFolderPermission, "permissioncode", "" );
                RoleName = XmlUtils.GetNodeValue( xmlFolderPermission, "rolename", "" );
                AllowAccess = XmlUtils.GetNodeValueBoolean( xmlFolderPermission, "allowaccess", false );
                arrPermissions = objPermissionController.GetPermissionByCodeAndKey( PermissionCode, PermissionKey );

                for( i = 0; i < arrPermissions.Count; i++ )
                {
                    objPermission = (PermissionInfo)( arrPermissions[i] );
                    PermissionID = objPermission.PermissionID;
                }
                RoleID = int.MinValue;
                if( RoleName == Globals.glbRoleAllUsersName )
                {
                    RoleID = Convert.ToInt32( Globals.glbRoleAllUsers );
                }
                else if( RoleName == Globals.glbRoleUnauthUserName )
                {
                    RoleID = Convert.ToInt32( Globals.glbRoleUnauthUser );
                }
                else
                {
                    objRole = objRoleController.GetRoleByName( PortalID, RoleName );
                    if( objRole != null )
                    {
                        RoleID = objRole.RoleID;
                    }
                }

                // if role was found add, otherwise ignore
                if( RoleID != int.MinValue )
                {
                    if( AllowAccess )
                    {
                        FileSystemUtils.SetFolderPermission( PortalID, FolderId, PermissionID, RoleID, folderPath );
                    }
                }
            }
        }
Exemplo n.º 19
0
        private void ParseModulePermissions( XmlNodeList nodeModulePermissions, int PortalId, int ModuleID )
        {
            RoleController objRoleController = new RoleController();
            RoleInfo objRole = null;
            ModulePermissionCollection objModulePermissions = new ModulePermissionCollection();
            ModulePermissionController objModulePermissionController = new ModulePermissionController();
            PermissionController objPermissionController = new PermissionController();
            PermissionInfo objPermission = null;
            ModulePermissionCollection objModulePermissionCollection = new ModulePermissionCollection();
            int PermissionID = 0;
            ArrayList arrPermissions = null;
            int i = 0;
            string PermissionKey = null;
            string PermissionCode = null;
            string RoleName = null;
            int RoleID = 0;
            bool AllowAccess = false;

            foreach( XmlNode node in nodeModulePermissions )
            {
                PermissionKey = XmlUtils.GetNodeValue( node, "permissionkey", "" );
                PermissionCode = XmlUtils.GetNodeValue( node, "permissioncode", "" );
                RoleName = XmlUtils.GetNodeValue( node, "rolename", "" );
                AllowAccess = XmlUtils.GetNodeValueBoolean( node, "allowaccess", false );

                RoleID = int.MinValue;
                if( RoleName == Globals.glbRoleAllUsersName )
                {
                    RoleID = Convert.ToInt32( Globals.glbRoleAllUsers );
                }
                else if( RoleName == Globals.glbRoleUnauthUserName )
                {
                    RoleID = Convert.ToInt32( Globals.glbRoleUnauthUser );
                }
                else
                {
                    objRole = objRoleController.GetRoleByName( PortalId, RoleName );
                    if( objRole != null )
                    {
                        RoleID = objRole.RoleID;
                    }
                }
                if( RoleID != int.MinValue )
                {
                    PermissionID = -1;
                    arrPermissions = objPermissionController.GetPermissionByCodeAndKey( PermissionCode, PermissionKey );

                    for( i = 0; i < arrPermissions.Count; i++ )
                    {
                        objPermission = (PermissionInfo)( arrPermissions[i] );
                        PermissionID = objPermission.PermissionID;
                    }

                    // if role was found add, otherwise ignore
                    if( PermissionID != -1 )
                    {
                        ModulePermissionInfo objModulePermission = new ModulePermissionInfo();
                        objModulePermission.ModuleID = ModuleID;
                        objModulePermission.PermissionID = PermissionID;
                        objModulePermission.RoleID = RoleID;
                        objModulePermission.AllowAccess = Convert.ToBoolean( XmlUtils.GetNodeValue( node, "allowaccess", "false" ) );
                        objModulePermissionController.AddModulePermission( objModulePermission );
                    }
                }
            }
        }
Exemplo n.º 20
0
 /// <summary>
 /// Sets a Folders Permissions
 /// </summary>
 /// <param name="PortalId">The Id of the Portal</param>
 /// <param name="FolderId">The Id of the Folder</param>
 /// <param name="AdministratorRoleId">The Id of the Administrator Role</param>
 /// <param name="relativePath">The folder's Relative Path</param>
 /// <remarks>
 /// </remarks>
 public static void SetFolderPermissions( int PortalId, int FolderId, int AdministratorRoleId, string relativePath )
 {
     //Set Permissions
     PermissionController objPermissionController = new PermissionController();
     ArrayList Permissions = objPermissionController.GetPermissionsByFolder( PortalId, "" );
     foreach( PermissionInfo objPermssionsInfo in Permissions )
     {
         SetFolderPermission( PortalId, FolderId, objPermssionsInfo.PermissionID, AdministratorRoleId, relativePath );
     }
 }
Exemplo n.º 21
0
        private static void DeserializeModulePermissions(XmlNodeList nodeModulePermissions, int portalId, ModuleInfo module)
        {
            var permissionController = new PermissionController();
            foreach (XmlNode node in nodeModulePermissions)
            {
                string permissionKey = XmlUtils.GetNodeValue(node.CreateNavigator(), "permissionkey");
                string permissionCode = XmlUtils.GetNodeValue(node.CreateNavigator(), "permissioncode");
                string roleName = XmlUtils.GetNodeValue(node.CreateNavigator(), "rolename");
                int roleID = int.MinValue;
                switch (roleName)
                {
                    case Globals.glbRoleAllUsersName:
                        roleID = Convert.ToInt32(Globals.glbRoleAllUsers);
                        break;
                    case Globals.glbRoleUnauthUserName:
                        roleID = Convert.ToInt32(Globals.glbRoleUnauthUser);
                        break;
                    default:
                        var role = TestableRoleController.Instance.GetRole(portalId, r => r.RoleName == roleName);
                        if (role != null)
                        {
                            roleID = role.RoleID;
                        }
                        break;
                }
                if (roleID != int.MinValue)
                {
                    int permissionID = -1;
                    ArrayList permissions = permissionController.GetPermissionByCodeAndKey(permissionCode, permissionKey);
                    for (int i = 0; i <= permissions.Count - 1; i++)
                    {
                        var permission = (PermissionInfo)permissions[i];
                        permissionID = permission.PermissionID;
                    }

                    //if role was found add, otherwise ignore
                    if (permissionID != -1)
                    {
                        var modulePermission = new ModulePermissionInfo
                        {
                            ModuleID = module.ModuleID,
                            PermissionID = permissionID,
                            RoleID = roleID,
                            AllowAccess = Convert.ToBoolean(XmlUtils.GetNodeValue(node.CreateNavigator(), "allowaccess"))
                        };

                        // do not add duplicate ModulePermissions
                        bool canAdd = !module.ModulePermissions.Cast<ModulePermissionInfo>()
                                                    .Any(mp => mp.ModuleID == modulePermission.ModuleID
                                                            && mp.PermissionID == modulePermission.PermissionID
                                                            && mp.RoleID == modulePermission.RoleID
                                                            && mp.UserID == modulePermission.UserID);
                        if (canAdd)
                        {
                            module.ModulePermissions.Add(modulePermission);
                        }
                    }
                }
            }
        }
Exemplo n.º 22
0
        private int DoAddExistingModule(int moduleId, int tabId, string paneName, int position, string align, bool cloneModule)
        {
            var moduleCtrl = new ModuleController();
            ModuleInfo moduleInfo = moduleCtrl.GetModule(moduleId, tabId, false);

            int userID = -1;
          
            UserInfo user = UserController.GetCurrentUserInfo();
            if (user != null)
            {
                userID = user.UserID;
            }
            

            if ((moduleInfo != null))
            {
                // Is this from a site other than our own? (i.e., is the user requesting "module sharing"?)
                var remote = moduleInfo.PortalID != PortalSettings.Current.PortalId;
                if (remote)
                {
                    switch (moduleInfo.DesktopModule.Shareable)
                    {
                        case ModuleSharing.Unsupported:
                            // Should never happen since the module should not be listed in the first place.
                            throw new ApplicationException(string.Format("Module '{0}' does not support Shareable and should not be listed in Add Existing Module from a different source site",
                                                                         moduleInfo.DesktopModule.FriendlyName));
                        case ModuleSharing.Supported:
                            break;
                        case ModuleSharing.Unknown:
                            break;
                    }
                }

                // clone the module object ( to avoid creating an object reference to the data cache )
                ModuleInfo newModule = moduleInfo.Clone();

                newModule.UniqueId = Guid.NewGuid(); // Cloned Module requires a different uniqueID

                newModule.TabID = PortalSettings.Current.ActiveTab.TabID;
                newModule.ModuleOrder = position;
                newModule.PaneName = paneName;
                newModule.Alignment = align;

                if ((cloneModule))
                {
                    newModule.ModuleID = Null.NullInteger;
                    //reset the module id
                    newModule.ModuleID = moduleCtrl.AddModule(newModule);

                    if (!string.IsNullOrEmpty(newModule.DesktopModule.BusinessControllerClass))
                    {
                        object objObject = DotNetNuke.Framework.Reflection.CreateObject(newModule.DesktopModule.BusinessControllerClass, newModule.DesktopModule.BusinessControllerClass);
                        if (objObject is IPortable)
                        {
                            string content = Convert.ToString(((IPortable)objObject).ExportModule(moduleId));
                            if (!string.IsNullOrEmpty(content))
                            {
                                ((IPortable)objObject).ImportModule(newModule.ModuleID, content, newModule.DesktopModule.Version, userID);
                            }
                        }
                    }
                }
                else
                {
                    moduleCtrl.AddModule(newModule);
                }

                if (remote)
                {
                    //Ensure the Portal Admin has View rights
                    var permissionController = new PermissionController();
                    ArrayList arrSystemModuleViewPermissions = permissionController.GetPermissionByCodeAndKey("SYSTEM_MODULE_DEFINITION", "VIEW");
                    AddModulePermission(newModule,
                                    (PermissionInfo)arrSystemModuleViewPermissions[0],
                                    PortalSettings.Current.AdministratorRoleId,
                                    Null.NullInteger,
                                    true);

                    //Set PortalID correctly
                    newModule.OwnerPortalID = newModule.PortalID;
                    newModule.PortalID = PortalSettings.Current.PortalId;
                    ModulePermissionController.SaveModulePermissions(newModule);
                }

                //Add Event Log
                var objEventLog = new EventLogController();
                objEventLog.AddLog(newModule, PortalSettings.Current, userID, "", EventLogController.EventLogType.MODULE_CREATED);

                return newModule.ModuleID;
            }

            return -1;
        }
Exemplo n.º 23
0
        protected void OnImportClick(object sender, EventArgs e)
        {
            try
            {
                if (cboTemplate.SelectedItem == null || cboTemplate.SelectedValue == "None_Specified")
                {
                    UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("SpecifyFile", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                    return;
                }
                if (optMode.SelectedIndex == -1)
                {
                    UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("SpecifyMode", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                    return;
                }
                var xmlDoc = new XmlDocument();
                xmlDoc.Load(PortalSettings.HomeDirectoryMapPath + cboFolders.SelectedValue + cboTemplate.SelectedValue);

                var tabNodes = new List<XmlNode>();
                foreach (XmlNode tabNode in xmlDoc.SelectSingleNode("//portal/tabs").ChildNodes)
                {
                    tabNodes.Add(tabNode);
                }
                if (tabNodes.Count == 0)
                {
                    UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("NoTabsInTemplate", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                    return;
                }

                TabInfo objTab;
                if (optMode.SelectedValue == "ADD")
                {
                    if (string.IsNullOrEmpty(txtTabName.Text))
                    {
                        UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("SpecifyName", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                        return;
                    }

                    //New Tab
                    objTab = new TabInfo {PortalID = PortalId, TabName = txtTabName.Text, IsVisible = true};
                    if (cboParentTab.SelectedItem != null)
                    {
                        objTab.ParentId = Int32.Parse(cboParentTab.SelectedItem.Value);
                    }
                    objTab.TabPath = Globals.GenerateTabPath(objTab.ParentId, objTab.TabName);
                    int tabID = TabController.GetTabByTabPath(objTab.PortalID, objTab.TabPath, Null.NullString);
                    var objTabs = new TabController();

                    //Check if tab exists
                    if (tabID != Null.NullInteger)
                    {
                        TabInfo existingTab = objTabs.GetTab(tabID, PortalId, false);
                        if (existingTab != null && existingTab.IsDeleted)
                        {
                            UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("TabRecycled", LocalResourceFile), ModuleMessage.ModuleMessageType.YellowWarning);
                        }
                        else
                        {
                            UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("TabExists", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                        }
                        return;
                    }

                    int positionTabID = Int32.Parse(cboPositionTab.SelectedItem.Value);

                    var pc = new PermissionController();

                    var permission = pc.GetPermissionByCodeAndKey("SYSTEM_TAB", "VIEW");
                    if (permission.Count > 0)
                    {
                        var pid = ((PermissionInfo)permission[0]).PermissionID;
                        objTab.TabPermissions.Add(new TabPermissionInfo { PermissionID = pid, AllowAccess = true, RoleID = 0 });
                    }

                    permission = pc.GetPermissionByCodeAndKey("SYSTEM_TAB", "EDIT");
                    if (permission.Count > 0)
                    {
                        var pid = ((PermissionInfo)permission[0]).PermissionID;
                        objTab.TabPermissions.Add(new TabPermissionInfo { PermissionID = pid, AllowAccess = true, RoleID = 0 });
                    }

                    var objEventLog = new EventLogController();
                    if (rbInsertPosition.SelectedValue == "After" && positionTabID > Null.NullInteger)
                    {
                        objTab.TabID = objTabs.AddTabAfter(objTab, positionTabID);
                    }
                    else if (rbInsertPosition.SelectedValue == "Before" && positionTabID > Null.NullInteger)
                    {
                        objTab.TabID = objTabs.AddTabBefore(objTab, positionTabID);
                    }
                    else
                    {
                        objTab.TabID = objTabs.AddTab(objTab);
                    }
                    objEventLog.AddLog(objTab, PortalSettings, UserId, "", EventLogController.EventLogType.TAB_CREATED);

                    //Update Tab properties from template - for the first tab only
                    objTab = TabController.DeserializeTab(tabNodes[0], objTab, PortalId, PortalTemplateModuleAction.Replace);

                    var exceptions = string.Empty;
                    //Create second tabs onwards. For firs tab, we like to use tab details from text box, for rest it'll come from template
                    for(var tab=1; tab < tabNodes.Count; tab++)
                    {
                        try
                        {
                            TabController.DeserializeTab(tabNodes[tab], null, PortalId, PortalTemplateModuleAction.Replace);
                        }
                        catch (Exception ex)
                        {
                            Exceptions.LogException(ex);
                            exceptions += string.Format("Template Tab # {0}. Error {1}<br/>", tab + 1, ex.Message);
                        }
                    }
                    if(!string.IsNullOrEmpty(exceptions))
                    {
                        UI.Skins.Skin.AddModuleMessage(this, exceptions, ModuleMessage.ModuleMessageType.RedError);
                        return;
                    }
                }
                else
                {
                    //Replace Existing Tab
                    objTab = TabController.DeserializeTab(tabNodes[0], Tab, PortalId, PortalTemplateModuleAction.Replace);
                }
                switch (optRedirect.SelectedValue)
                {
                    case "VIEW":
                        Response.Redirect(Globals.NavigateURL(objTab.TabID), true);
                        break;
                    default:
                        Response.Redirect(Globals.NavigateURL(objTab.TabID, "Tab", "action=edit"), true);
                        break;
                }
            }
            catch (Exception exc)
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
Exemplo n.º 24
0
        public static void DeserializeTabPermissions(XmlNodeList nodeTabPermissions, TabInfo tab)
        {
            var permissionController = new PermissionController();
            foreach (XmlNode xmlTabPermission in nodeTabPermissions)
            {
                var permissionKey = XmlUtils.GetNodeValue(xmlTabPermission.CreateNavigator(), "permissionkey");
                var permissionCode = XmlUtils.GetNodeValue(xmlTabPermission.CreateNavigator(), "permissioncode");
                var roleName = XmlUtils.GetNodeValue(xmlTabPermission.CreateNavigator(), "rolename");
                var allowAccess = XmlUtils.GetNodeValueBoolean(xmlTabPermission, "allowaccess");
                var permissions = permissionController.GetPermissionByCodeAndKey(permissionCode, permissionKey);
                var permissionId = permissions.Cast<PermissionInfo>().Last().PermissionID;

                var roleId = int.MinValue;
                switch (roleName)
                {
                    case Globals.glbRoleAllUsersName:
                        roleId = Convert.ToInt32(Globals.glbRoleAllUsers);
                        break;
                    case Globals.glbRoleUnauthUserName:
                        roleId = Convert.ToInt32(Globals.glbRoleUnauthUser);
                        break;
                    default:
                        var portal = PortalController.Instance.GetPortal(tab.PortalID);
                        var role = RoleController.Instance.GetRole(portal.PortalID, r => r.RoleName == roleName);
                        if (role != null)
                        {
                            roleId = role.RoleID;
                        }
                        break;
                }
                if (roleId != int.MinValue &&
                        !tab.TabPermissions.Cast<TabPermissionInfo>().Any(p =>
                                                                            p.RoleID == roleId
                                                                            && p.PermissionID == permissionId))
                {
                    var tabPermission = new TabPermissionInfo
                    {
                        TabID = tab.TabID,
                        PermissionID = permissionId,
                        RoleID = roleId,
                        AllowAccess = allowAccess
                    };

                    tab.TabPermissions.Add(tabPermission);
                }
            }

            TabController.Instance.UpdateTab(tab);
        }
Exemplo n.º 25
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Adds a New Module to a Pane
        /// </summary>
        /// <param name="align">The alignment for the Modue</param>
        /// <param name="desktopModuleId">The Id of the DesktopModule</param>
        /// <param name="permissionType">The View Permission Type for the Module</param>
        /// <param name="title">The Title for the resulting module</param>
        /// <param name="paneName">The pane to add the module to</param>
        /// <param name="position">The relative position within the pane for the module</param>
        /// <history>
        /// 	[cnurse]	01/11/2008  documented
        /// </history>
        /// -----------------------------------------------------------------------------
        protected void AddNewModule(string title, int desktopModuleId, string paneName, int position, ViewPermissionType permissionType, string align)
        {
            TabPermissionCollection objTabPermissions = PortalSettings.ActiveTab.TabPermissions;
            var objPermissionController = new PermissionController();
            try
            {
                DesktopModuleInfo desktopModule;
                if (!DesktopModuleController.GetDesktopModules(PortalSettings.PortalId).TryGetValue(desktopModuleId, out desktopModule))
                {
                    throw new ArgumentException("desktopModuleId");
                }
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
            }
            int UserId = -1;
            if (Request.IsAuthenticated)
            {
                UserInfo objUserInfo = UserController.Instance.GetCurrentUserInfo();
                UserId = objUserInfo.UserID;
            }
            foreach (ModuleDefinitionInfo objModuleDefinition in
                ModuleDefinitionController.GetModuleDefinitionsByDesktopModuleID(desktopModuleId).Values)
            {
                var objModule = new ModuleInfo();
                objModule.Initialize(PortalSettings.PortalId);
                objModule.PortalID = PortalSettings.PortalId;
                objModule.TabID = PortalSettings.ActiveTab.TabID;
                objModule.ModuleOrder = position;
                if (String.IsNullOrEmpty(title))
                {
                    objModule.ModuleTitle = objModuleDefinition.FriendlyName;
                }
                else
                {
                    objModule.ModuleTitle = title;
                }
                objModule.PaneName = paneName;
                objModule.ModuleDefID = objModuleDefinition.ModuleDefID;
                if (objModuleDefinition.DefaultCacheTime > 0)
                {
                    objModule.CacheTime = objModuleDefinition.DefaultCacheTime;
                    if (PortalSettings.Current.DefaultModuleId > Null.NullInteger && PortalSettings.Current.DefaultTabId > Null.NullInteger)
                    {
                        ModuleInfo defaultModule = ModuleController.Instance.GetModule(PortalSettings.Current.DefaultModuleId, PortalSettings.Current.DefaultTabId, true);
                        if (defaultModule != null)
                        {
                            objModule.CacheTime = defaultModule.CacheTime;
                        }
                    }
                }
                switch (permissionType)
                {
                    case ViewPermissionType.View:
                        objModule.InheritViewPermissions = true;
                        break;
                    case ViewPermissionType.Edit:
                        objModule.InheritViewPermissions = false;
                        break;
                }
				
                //get the default module view permissions
                ArrayList arrSystemModuleViewPermissions = objPermissionController.GetPermissionByCodeAndKey("SYSTEM_MODULE_DEFINITION", "VIEW");

                //get the permissions from the page
                foreach (TabPermissionInfo objTabPermission in objTabPermissions)
                {
                    if (objTabPermission.PermissionKey == "VIEW" && permissionType == ViewPermissionType.View)
                    {
						//Don't need to explicitly add View permisisons if "Same As Page"
                        continue;
                    }
					
                    //get the system module permissions for the permissionkey
                    ArrayList arrSystemModulePermissions = objPermissionController.GetPermissionByCodeAndKey("SYSTEM_MODULE_DEFINITION", objTabPermission.PermissionKey);
                    //loop through the system module permissions
                    int j;
                    for (j = 0; j <= arrSystemModulePermissions.Count - 1; j++)
                    {
                        PermissionInfo objSystemModulePermission;
                        objSystemModulePermission = (PermissionInfo) arrSystemModulePermissions[j];
                        if (objSystemModulePermission.PermissionKey == "VIEW" && permissionType == ViewPermissionType.Edit && objTabPermission.PermissionKey != "EDIT")
                        {
							//Only Page Editors get View permissions if "Page Editors Only"
                            continue;
                        }
                        ModulePermissionInfo objModulePermission = AddModulePermission(objModule,
                                                                                       objSystemModulePermission,
                                                                                       objTabPermission.RoleID,
                                                                                       objTabPermission.UserID,
                                                                                       objTabPermission.AllowAccess);

                        //ensure that every EDIT permission which allows access also provides VIEW permission
                        if (objModulePermission.PermissionKey == "EDIT" && objModulePermission.AllowAccess)
                        {
                            ModulePermissionInfo objModuleViewperm = AddModulePermission(objModule,
                                                                                         (PermissionInfo) arrSystemModuleViewPermissions[0],
                                                                                         objModulePermission.RoleID,
                                                                                         objModulePermission.UserID,
                                                                                         true);
                        }
                    }
					
                    //Get the custom Module Permissions,  Assume that roles with Edit Tab Permissions
                    //are automatically assigned to the Custom Module Permissions
                    if (objTabPermission.PermissionKey == "EDIT")
                    {
                        ArrayList arrCustomModulePermissions = objPermissionController.GetPermissionsByModuleDefID(objModule.ModuleDefID);

                        //loop through the custom module permissions
                        for (j = 0; j <= arrCustomModulePermissions.Count - 1; j++)
                        {
							//create the module permission
                            PermissionInfo objCustomModulePermission;
                            objCustomModulePermission = (PermissionInfo) arrCustomModulePermissions[j];
                            AddModulePermission(objModule, objCustomModulePermission, objTabPermission.RoleID, objTabPermission.UserID, objTabPermission.AllowAccess);
                        }
                    }
                }

                if (PortalSettings.Current.ContentLocalizationEnabled)
                {
                    Locale defaultLocale = LocaleController.Instance.GetDefaultLocale(PortalSettings.Current.PortalId);
                    //set the culture of the module to that of the tab
                    var tabInfo = TabController.Instance.GetTab(objModule.TabID, PortalSettings.Current.PortalId, false);
                    objModule.CultureCode = tabInfo != null ? tabInfo.CultureCode : defaultLocale.Code;
                }
                else
                {
                    objModule.CultureCode = Null.NullString;
                }

                objModule.AllTabs = false;
                objModule.Alignment = align;
                ModuleController.Instance.AddModule(objModule);
            }
        }
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// SaveModuleDefinition saves the Module Definition to the database
        /// </summary>
        /// <param name="moduleDefinition">The Module Definition to save</param>
        /// <param name="saveChildren">A flag that determines whether the child objects are also saved</param>
        /// <param name="clearCache">A flag that determines whether to clear the host cache</param>
        /// <history>
        /// 	[cnurse]	01/14/2008   Created
        /// </history>
        /// -----------------------------------------------------------------------------
        public static int SaveModuleDefinition(ModuleDefinitionInfo moduleDefinition, bool saveChildren, bool clearCache)
        {
            int moduleDefinitionID = moduleDefinition.ModuleDefID;
            if (moduleDefinitionID == Null.NullInteger)
            {
				//Add new Module Definition
                moduleDefinitionID = dataProvider.AddModuleDefinition(moduleDefinition.DesktopModuleID,
                                                                      moduleDefinition.FriendlyName,
                                                                      moduleDefinition.DefinitionName,
                                                                      moduleDefinition.DefaultCacheTime,
                                                                      UserController.Instance.GetCurrentUserInfo().UserID);
            }
            else
            {
				//Upgrade Module Definition
                dataProvider.UpdateModuleDefinition(moduleDefinition.ModuleDefID, moduleDefinition.FriendlyName, moduleDefinition.DefinitionName, moduleDefinition.DefaultCacheTime, UserController.Instance.GetCurrentUserInfo().UserID);
            }
            if (saveChildren)
            {
                foreach (KeyValuePair<string, PermissionInfo> kvp in moduleDefinition.Permissions)
                {
                    kvp.Value.ModuleDefID = moduleDefinitionID;

                    //check if permission exists
                    var permissionController = new PermissionController();
                    ArrayList permissions = permissionController.GetPermissionByCodeAndKey(kvp.Value.PermissionCode, kvp.Value.PermissionKey);
                    if (permissions != null && permissions.Count == 1)
                    {
                        var permission = (PermissionInfo) permissions[0];
                        kvp.Value.PermissionID = permission.PermissionID;
                        permissionController.UpdatePermission(kvp.Value);
                    }
                    else
                    {
                        permissionController.AddPermission(kvp.Value);
                    }
                }
                foreach (KeyValuePair<string, ModuleControlInfo> kvp in moduleDefinition.ModuleControls)
                {
                    kvp.Value.ModuleDefID = moduleDefinitionID;

                    //check if definition exists
                    ModuleControlInfo moduleControl = ModuleControlController.GetModuleControlByControlKey(kvp.Value.ControlKey, kvp.Value.ModuleDefID);
                    if (moduleControl != null)
                    {
                        kvp.Value.ModuleControlID = moduleControl.ModuleControlID;
                    }
                    ModuleControlController.SaveModuleControl(kvp.Value, clearCache);
                }
            }
            if (clearCache)
            {
                DataCache.ClearHostCache(true);
            }
            return moduleDefinitionID;
        }
        public string UpgradeModule(string Version)
        {
            try
            {
                switch (Version)
                {
                    case "01.00.00":
                        ModuleDefinitionInfo moduleDefinition = ModuleDefinitionController.GetModuleDefinitionByFriendlyName("Messaging");

                        if (moduleDefinition != null)
                        {
                            //Add Module to User Profile Page for all Portals
                            var objPortalController = new PortalController();
                            var objTabController = new TabController();
                            var objModuleController = new ModuleController();

                            ArrayList portals = objPortalController.GetPortals();
                            foreach (PortalInfo portal in portals)
                            {
                                int tabID = TabController.GetTabByTabPath(portal.PortalID, "//UserProfile", Null.NullString);
                                if ((tabID != Null.NullInteger))
                                {
                                    TabInfo tab = objTabController.GetTab(tabID, portal.PortalID, true);
                                    if ((tab != null))
                                    {
                                        int moduleId = Upgrade.AddModuleToPage(tab, moduleDefinition.ModuleDefID, "My Inbox", "", true);
                                        ModuleInfo objModule = objModuleController.GetModule(moduleId, tabID, false);

                                        var settings = new PortalSettings(portal);

                                        var modulePermission = (from ModulePermissionInfo p in objModule.ModulePermissions
                                                                where p.ModuleID == moduleId
                                                                   && p.RoleID == settings.RegisteredRoleId
                                                                   && p.UserID == Null.NullInteger
                                                                   && p.PermissionKey == "EDIT"
                                                                select p).SingleOrDefault();

                                        if (modulePermission == null)
                                        {
                                            ArrayList permissions = new PermissionController().GetPermissionByCodeAndKey("SYSTEM_MODULE_DEFINITION", "EDIT");
                                            PermissionInfo permission = null;
                                            if (permissions.Count == 1)
                                            {
                                                permission = permissions[0] as PermissionInfo;
                                            }
                                            if (permission != null)
                                            {
                                                modulePermission = new ModulePermissionInfo(permission)
                                                                            {
                                                                                ModuleID = moduleId,
                                                                                RoleID = settings.RegisteredRoleId,
                                                                                UserID = Null.NullInteger,
                                                                                AllowAccess = true
                                                                            };


                                                objModule.ModulePermissions.Add(modulePermission);

                                                ModulePermissionController.SaveModulePermissions(objModule);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        break;
                }
                return "Success";
            }
            catch (Exception exc)
            {
                Logger.Error(exc);

                return "Failed";
            }
        }
Exemplo n.º 28
0
        private static void UpgradeToVersion500()
        {
            ArrayList portals = PortalController.Instance.GetPortals();

            //Add Edit Permissions for Admin Tabs to legacy portals
            var permissionController = new PermissionController();
            ArrayList permissions = permissionController.GetPermissionByCodeAndKey("SYSTEM_TAB", "EDIT");
            int permissionId = -1;
            if (permissions.Count == 1)
            {
                var permission = permissions[0] as PermissionInfo;
                if (permission != null)
                {
                    permissionId = permission.PermissionID;
                }

                foreach (PortalInfo portal in portals)
                {
                    var adminTab = TabController.Instance.GetTab(portal.AdminTabId, portal.PortalID, true);
                    if (adminTab != null)
                    {
                        var tabPermission = new TabPermissionInfo { TabID = adminTab.TabID, PermissionID = permissionId, AllowAccess = true, RoleID = portal.AdministratorRoleId };
                        if (!TabPermissionExists(tabPermission, portal.PortalID))
                        {
                            adminTab.TabPermissions.Add(tabPermission);
                        }

                        //Save Tab Permissions to Data Base
                        TabPermissionController.SaveTabPermissions(adminTab);

                        foreach (var childTab in TabController.GetTabsByParent(portal.AdminTabId, portal.PortalID))
                        {
                            tabPermission = new TabPermissionInfo { TabID = childTab.TabID, PermissionID = permissionId, AllowAccess = true, RoleID = portal.AdministratorRoleId };
                            if (!TabPermissionExists(tabPermission, portal.PortalID))
                            {
                                childTab.TabPermissions.Add(tabPermission);
                            }
                            //Save Tab Permissions to Data Base
                            TabPermissionController.SaveTabPermissions(childTab);
                        }
                    }
                }
            }

            //Update Host/Admin modules Visibility setting
            bool superTabProcessed = Null.NullBoolean;
            foreach (PortalInfo portal in portals)
            {
                if (!superTabProcessed)
                {
                    //Process Host Tabs
                    foreach (TabInfo childTab in TabController.GetTabsByParent(portal.SuperTabId, Null.NullInteger))
                    {
                        foreach (ModuleInfo tabModule in ModuleController.Instance.GetTabModules(childTab.TabID).Values)
                        {
                            tabModule.Visibility = VisibilityState.None;
                            ModuleController.Instance.UpdateModule(tabModule);
                        }
                    }
                }

                //Process Portal Tabs
                foreach (TabInfo childTab in TabController.GetTabsByParent(portal.AdminTabId, portal.PortalID))
                {
                    foreach (ModuleInfo tabModule in ModuleController.Instance.GetTabModules(childTab.TabID).Values)
                    {
                        tabModule.Visibility = VisibilityState.None;
                        ModuleController.Instance.UpdateModule(tabModule);
                    }
                }
            }

            //Upgrade PortalDesktopModules to support new "model"
            permissions = permissionController.GetPermissionByCodeAndKey("SYSTEM_DESKTOPMODULE", "DEPLOY");
            if (permissions.Count == 1)
            {
                var permission = permissions[0] as PermissionInfo;
                if (permission != null)
                {
                    permissionId = permission.PermissionID;
                }
                foreach (PortalInfo portal in portals)
                {
                    foreach (DesktopModuleInfo desktopModule in DesktopModuleController.GetDesktopModules(Null.NullInteger).Values)
                    {
                        if (!desktopModule.IsPremium)
                        {
                            //Parse the permissions
                            var deployPermissions = new DesktopModulePermissionCollection();
                            DesktopModulePermissionInfo deployPermission;

                            // if Not IsAdmin add Registered Users
                            if (!desktopModule.IsAdmin)
                            {
                                deployPermission = new DesktopModulePermissionInfo { PermissionID = permissionId, AllowAccess = true, RoleID = portal.RegisteredRoleId };
                                deployPermissions.Add(deployPermission);
                            }

                            // if Not a Host Module add Administrators
                            const string hostModules = "Portals, SQL, HostSettings, Scheduler, SearchAdmin, Lists, SkinDesigner, Extensions";
                            if (!hostModules.Contains(desktopModule.ModuleName))
                            {
                                deployPermission = new DesktopModulePermissionInfo { PermissionID = permissionId, AllowAccess = true, RoleID = portal.AdministratorRoleId };
                                deployPermissions.Add(deployPermission);
                            }

                            //Add Portal/Module to PortalDesktopModules
                            DesktopModuleController.AddDesktopModuleToPortal(portal.PortalID, desktopModule, deployPermissions, false);
                        }
                    }

                    DataCache.ClearPortalCache(portal.PortalID, true);
                }
            }

            LegacyUtil.ProcessLegacyModules();
            LegacyUtil.ProcessLegacyLanguages();
            LegacyUtil.ProcessLegacySkins();
            LegacyUtil.ProcessLegacySkinControls();
        }
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// DeleteModuleDefinition deletes a Module Definition By ID
        /// </summary>
        /// <param name="moduleDefinitionId">The ID of the Module Definition to delete</param>
        /// <history>
        /// 	[cnurse]	01/11/2008   Documented
        /// </history>
        /// -----------------------------------------------------------------------------
        public void DeleteModuleDefinition(int moduleDefinitionId)
        {
			//Delete associated permissions
            var permissionController = new PermissionController();
            foreach (PermissionInfo permission in permissionController.GetPermissionsByModuleDefID(moduleDefinitionId))
            {
                permissionController.DeletePermission(permission.PermissionID);
            }
            dataProvider.DeleteModuleDefinition(moduleDefinitionId);
            DataCache.ClearHostCache(true);
        }
Exemplo n.º 30
0
        private static void AddManageUsersModulePermissions()
        {
           var permCtl = new PermissionController();
           var desktopInfo = DesktopModuleController.GetDesktopModuleByModuleName("Security", Null.NullInteger);
            //add new user dialog
            var md = ModuleDefinitionController.GetModuleDefinitionByFriendlyName("User Account", desktopInfo.DesktopModuleID);
               try
                   {
                   var pi = new PermissionInfo
                   {
                       ModuleDefID = md.ModuleDefID,
                       PermissionCode = "SECURITY_MODULE",
                       PermissionKey = "MANAGEUSER",
                       PermissionName = "Manage User"
                   };

                       permCtl.AddPermission(pi);

                     }
                catch
                {
                    //suppress
                }
               md = ModuleDefinitionController.GetModuleDefinitionByFriendlyName("User Accounts", desktopInfo.DesktopModuleID);
               try
               {
                   var pi = new PermissionInfo
                   {
                       ModuleDefID = md.ModuleDefID,
                       PermissionCode = "SECURITY_MODULE",
                       PermissionKey = "MANAGEUSERS",
                       PermissionName = "Manage Users"
                   };

                   permCtl.AddPermission(pi);

               }
               catch
               {
                   //suppress
               }
               md = ModuleDefinitionController.GetModuleDefinitionByFriendlyName("Security Roles", desktopInfo.DesktopModuleID);
               try
               {
                   var pi = new PermissionInfo
                   {
                       ModuleDefID = md.ModuleDefID,
                       PermissionCode = "SECURITY_MODULE",
                       PermissionKey = "MANAGEROLES",
                       PermissionName = "Manage Roles"
                   };

                   permCtl.AddPermission(pi);

               }
               catch
               {
                   //suppress
               }
            
        }
Exemplo n.º 31
0
        private static void UpgradeToVersion601()
        {
            //List module needs to be available to Portals also
            var pkg = PackageController.Instance.GetExtensionPackage(Null.NullInteger, p => p.Name == "DotNetNuke.Lists");
            if (pkg != null)
            {
                //List package is no longer a system package
                pkg.IsSystemPackage = false;
                PackageController.Instance.SaveExtensionPackage(pkg);

                //List desktop module is no longer premium or admin module
                var desktopModule = DesktopModuleController.GetDesktopModuleByPackageID(pkg.PackageID);
                desktopModule.IsAdmin = false;
                desktopModule.IsPremium = false;
                DesktopModuleController.SaveDesktopModule(desktopModule, false, true);

                var permissionController = new PermissionController();
                ArrayList permissions = permissionController.GetPermissionByCodeAndKey("SYSTEM_DESKTOPMODULE", "DEPLOY");
                if (permissions.Count == 1)
                {
                    var permission = permissions[0] as PermissionInfo;
                    if (permission != null)
                    {
                        foreach (PortalInfo portal in PortalController.Instance.GetPortals())
                        {
                            //ensure desktop module is not present in the portal
                            var pdmi = DesktopModuleController.GetPortalDesktopModule(portal.PortalID, desktopModule.DesktopModuleID);
                            if (pdmi == null)
                            {
                                //Parse the permissions
                                var deployPermissions = new DesktopModulePermissionCollection();
                                var deployPermission = new DesktopModulePermissionInfo { PermissionID = permission.PermissionID, AllowAccess = true, RoleID = portal.AdministratorRoleId };
                                deployPermissions.Add(deployPermission);

                                //Add Portal/Module to PortalDesktopModules
                                DesktopModuleController.AddDesktopModuleToPortal(portal.PortalID, desktopModule, deployPermissions, true);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 32
0
        /// <summary>
        /// Parses tab permissions
        /// </summary>
        /// <param name="nodeTabPermissions">Node for tab permissions</param>
        /// <param name="objPortal">Portal object of new portal</param>
        /// <param name="TabId">TabId of tab being processed</param>
        /// <param name="IsAdminTemplate">Flag to indicate if we are parsing admin template</param>
        /// <history>
        /// 	[Vicenç]	15/10/2004	Created
        /// </history>
        private TabPermissionCollection ParseTabPermissions( XmlNodeList nodeTabPermissions, PortalInfo objPortal, int TabId, bool IsAdminTemplate )
        {
            TabPermissionCollection objTabPermissions = new TabPermissionCollection();
            PermissionController objPermissionController = new PermissionController();
            PermissionInfo objPermission = null;
            TabPermissionInfo objTabPermission = null;
            RoleController objRoleController = new RoleController();
            RoleInfo objRole = null;
            int RoleID = 0;
            int PermissionID = 0;
            string PermissionKey = null;
            string PermissionCode = null;
            string RoleName = null;
            bool AllowAccess = false;
            ArrayList arrPermissions = null;
            int i = 0;

            foreach( XmlNode xmlTabPermission in nodeTabPermissions )
            {
                PermissionKey = XmlUtils.GetNodeValue( xmlTabPermission, "permissionkey", "" );
                PermissionCode = XmlUtils.GetNodeValue( xmlTabPermission, "permissioncode", "" );
                RoleName = XmlUtils.GetNodeValue( xmlTabPermission, "rolename", "" );
                AllowAccess = XmlUtils.GetNodeValueBoolean( xmlTabPermission, "allowaccess", false );
                arrPermissions = objPermissionController.GetPermissionByCodeAndKey( PermissionCode, PermissionKey );

                for( i = 0; i < arrPermissions.Count; i++ )
                {
                    objPermission = (PermissionInfo)( arrPermissions[i] );
                    PermissionID = objPermission.PermissionID;
                }
                RoleID = int.MinValue;
                if( RoleName == Globals.glbRoleAllUsersName )
                {
                    RoleID = Convert.ToInt32( Globals.glbRoleAllUsers );
                }
                else if( RoleName == Globals.glbRoleUnauthUserName )
                {
                    RoleID = Convert.ToInt32( Globals.glbRoleUnauthUser );
                }
                else
                {
                    objRole = objRoleController.GetRoleByName( objPortal.PortalID, RoleName );
                    if( objRole != null )
                    {
                        RoleID = objRole.RoleID;
                    }
                    else
                    {
                        // if parsing admin.template and role administrators redefined, use portal.administratorroleid
                        if( IsAdminTemplate && RoleName.ToLower() == "administrators" )
                        {
                            RoleID = objPortal.AdministratorRoleId;
                        }
                    }
                }

                // if role was found add, otherwise ignore
                if( RoleID != int.MinValue )
                {
                    objTabPermission = new TabPermissionInfo();
                    objTabPermission.TabID = TabId;
                    objTabPermission.PermissionID = PermissionID;
                    objTabPermission.RoleID = RoleID;
                    objTabPermission.AllowAccess = AllowAccess;
                    objTabPermissions.Add( objTabPermission );
                }
            }
            return objTabPermissions;
        }
Exemplo n.º 33
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// AddPagePermission adds a TabPermission to a TabPermission Collection
        /// </summary>
        ///	<param name="permissions">Page Permissions Collection for this page</param>
        ///	<param name="key">The Permission key</param>
        ///	<param name="roleId">The role given the permission</param>
        /// <history>
        /// 	[cnurse]	11/11/2004	created 
        /// </history>
        /// -----------------------------------------------------------------------------
        private static void AddPagePermission(TabPermissionCollection permissions, string key, int roleId)
        {
            DnnInstallLogger.InstallLogInfo(Localization.Localization.GetString("LogStart", Localization.Localization.GlobalResourceFile) + "AddPagePermission:" + key);
            var permissionController = new PermissionController();
            var permission = (PermissionInfo)permissionController.GetPermissionByCodeAndKey("SYSTEM_TAB", key)[0];

            var tabPermission = new TabPermissionInfo { PermissionID = permission.PermissionID, RoleID = roleId, AllowAccess = true };

            permissions.Add(tabPermission);
        }
Exemplo n.º 34
0
        /// <summary>
        /// Processess a template file for the new portal. This method will be called twice: for the portal template and for the admin template
        /// </summary>
        /// <param name="PortalId">PortalId of the new portal</param>
        /// <param name="TemplatePath">Path for the folder where templates are stored</param>
        /// <param name="TemplateFile">Template file to process</param>
        /// <param name="AdministratorId">UserId for the portal administrator. This is used to assign roles to this user</param>
        /// <param name="mergeTabs">Flag to determine whether Module content is merged.</param>
        /// <param name="IsNewPortal">Flag to determine is the template is applied to an existing portal or a new one.</param>
        /// <remarks>
        /// The roles and settings nodes will only be processed on the portal template file.
        /// </remarks>
        /// <history>
        /// 	[VMasanas]	27/08/2004	Created
        /// </history>
        public void ParseTemplate( int PortalId, string TemplatePath, string TemplateFile, int AdministratorId, PortalTemplateModuleAction mergeTabs, bool IsNewPortal )
        {
            XmlDocument xmlDoc = new XmlDocument();
            XmlNode node = null;
            int AdministratorRoleId = -1;
            int RegisteredRoleId = -1;
            int SubscriberRoleId = -1;
            RoleController objrole = new RoleController();
            bool isAdminTemplate = false;

            isAdminTemplate = ( TemplateFile == "admin.template" );

            // open the XML file
            try
            {
                xmlDoc.Load( TemplatePath + TemplateFile );
            }
            catch // error
            {
                // 
            }

            // settings, roles, folders and files can only be specified in portal templates, will be ignored on the admin template
            if( !isAdminTemplate )
            {
                // parse roles if available
                node = xmlDoc.SelectSingleNode( "//portal/roles" );
                if( node != null )
                {
                    ParseRoles( node, PortalId, AdministratorId, ref AdministratorRoleId, ref RegisteredRoleId, ref SubscriberRoleId );
                }

                // create required roles if not already created
                if( AdministratorRoleId == -1 )
                {
                    AdministratorRoleId = CreateRole( PortalId, "Administrators", "Portal Administrators", 0F, 0, "M", 0F, 0, "N", false, false );
                }
                if( RegisteredRoleId == -1 )
                {
                    RegisteredRoleId = CreateRole( PortalId, "Registered Users", "Registered Users", 0F, 0, "M", 0F, 0, "N", false, true );
                }
                if( SubscriberRoleId == -1 )
                {
                    SubscriberRoleId = CreateRole( PortalId, "Subscribers", "A public role for portal subscriptions", 0F, 0, "M", 0F, 0, "N", true, true );
                }

                objrole.AddUserRole( PortalId, AdministratorId, AdministratorRoleId, Null.NullDate, Null.NullDate );
                objrole.AddUserRole( PortalId, AdministratorId, RegisteredRoleId, Null.NullDate, Null.NullDate );
                objrole.AddUserRole( PortalId, AdministratorId, SubscriberRoleId, Null.NullDate, Null.NullDate );

                // parse portal folders
                node = xmlDoc.SelectSingleNode( "//portal/folders" );
                if( node != null )
                {
                    ParseFolders( node, PortalId );
                }
                // force creation of root folder if not present on template
                FolderController objController = new FolderController();
                if( objController.GetFolder( PortalId, "" ) == null )
                {
                    int folderid = objController.AddFolder( PortalId, "", (int)FolderController.StorageLocationTypes.InsecureFileSystem, true, false );
                    PermissionController objPermissionController = new PermissionController();
                    ArrayList arr = objPermissionController.GetPermissionByCodeAndKey( "SYSTEM_FOLDER", "" );
                    foreach( PermissionInfo objpermission in arr )
                    {
                        FileSystemUtils.SetFolderPermission( PortalId, folderid, objpermission.PermissionID, AdministratorRoleId, "" );
                        if( objpermission.PermissionKey == "READ" )
                        {
                            // add READ permissions to the All Users Role
                            FileSystemUtils.SetFolderPermission( PortalId, folderid, objpermission.PermissionID, int.Parse( Globals.glbRoleAllUsers ), "" );
                        }
                    }
                }

                // parse portal settings if available only for new portals
                node = xmlDoc.SelectSingleNode( "//portal/settings" );
                if( node != null & IsNewPortal )
                {
                    ParsePortalSettings( node, PortalId );
                }

                // update portal setup
                PortalInfo objportal = null;
                objportal = GetPortal( PortalId );
                UpdatePortalSetup( PortalId, AdministratorId, AdministratorRoleId, RegisteredRoleId, objportal.SplashTabId, objportal.HomeTabId, objportal.LoginTabId, objportal.UserTabId, objportal.AdminTabId );

                //Remove Exising Tabs if doing a "Replace"
                if( mergeTabs == PortalTemplateModuleAction.Replace )
                {
                    TabController objTabs = new TabController();
                    TabInfo objTab = null;
                    foreach( KeyValuePair<int, TabInfo> tabPair in objTabs.GetTabsByPortal( PortalId ) )
                    {
                        objTab = tabPair.Value;
                        if( !objTab.IsAdminTab )
                        {
                            //soft delete Tab
                            objTab.TabName = objTab.TabName + "_old";
                            objTab.IsDeleted = true;
                            objTabs.UpdateTab( objTab );
                            //Delete all Modules
                            ModuleController objModules = new ModuleController();
                            ModuleInfo objModule = null;
                            foreach( KeyValuePair<int, ModuleInfo> modulePair in objModules.GetTabModules( objTab.TabID ) )
                            {
                                objModule = modulePair.Value;
                                objModules.DeleteTabModule( objModule.TabID, objModule.ModuleID );
                            }
                        }
                    }
                }
            }

            // parse portal tabs
            node = xmlDoc.SelectSingleNode( "//portal/tabs" );
            if( node != null )
            {
                ParseTabs( node, PortalId, isAdminTemplate, mergeTabs, IsNewPortal );
            }
        }