Esempio n. 1
0
        public void DeletePortalGroup(PortalGroupInfo portalGroup)
        {
            //Argument Contract
            Requires.NotNull("portalGroup", portalGroup);
            Requires.PropertyNotNegative("portalGroup", "PortalGroupId", portalGroup.PortalGroupId);

            //Update portal
            var portal = _portalController.GetPortal(portalGroup.MasterPortalId);

            if (portal != null)
            {
                portal.PortalGroupID = -1;
                _portalController.UpdatePortalInfo(portal);
            }

            _dataService.DeletePortalGroup(portalGroup);

            ClearCache();
        }
        public int AddPortalGroup(PortalGroupInfo portalGroup)
        {
            //Argument Contract
            Requires.NotNull("portalGroup", portalGroup);

            portalGroup.PortalGroupId = _dataService.AddPortalGroup(portalGroup, UserController.GetCurrentUserInfo().UserID);

            //Update portal
            var portal = _portalController.GetPortal(portalGroup.MasterPortalId);

            if (portal != null)
            {
                portal.PortalGroupID = portalGroup.PortalGroupId;
                _portalController.UpdatePortalInfo(portal);
            }

            ClearCache();

            return(portalGroup.PortalGroupId);
        }
Esempio n. 3
0
        public void DeletePortalGroup(PortalGroupInfo portalGroup)
        {
            // Argument Contract
            Requires.NotNull("portalGroup", portalGroup);
            Requires.PropertyNotNegative("portalGroup", "PortalGroupId", portalGroup.PortalGroupId);

            // Update portal
            var portal = this._portalController.GetPortal(portalGroup.MasterPortalId);

            if (portal != null)
            {
                this.DeleteSharedModules(portal);
                portal.PortalGroupID = -1;
                PortalController.Instance.UpdatePortalInfo(portal);
            }

            this._dataService.DeletePortalGroup(portalGroup);
            this.LogEvent(EventLogController.EventLogType.PORTALGROUP_DELETED, portalGroup, null);

            ClearCache();
        }
Esempio n. 4
0
        public int AddPortalGroup(PortalGroupInfo portalGroup)
        {
            //Argument Contract
            Requires.NotNull("portalGroup", portalGroup);

            portalGroup.PortalGroupId = _dataService.AddPortalGroup(portalGroup, UserController.Instance.GetCurrentUserInfo().UserID);

            //Update portal
            var portal = _portalController.GetPortal(portalGroup.MasterPortalId);

            if (portal != null)
            {
                portal.PortalGroupID = portalGroup.PortalGroupId;
                _portalController.UpdatePortalInfo(portal);
            }
            LogEvent(EventLogController.EventLogType.PORTALGROUP_CREATED, portalGroup, null);

            ClearCache();

            return(portalGroup.PortalGroupId);
        }
Esempio n. 5
0
        public static int AddPortalGroup(Components.PortalGroupInfo portalGroup)
        {
            PortalGroupController portalGroupController = new PortalGroupController();
            UserCopiedCallback    callback = delegate { };
            var group = new DotNetNuke.Entities.Portals.PortalGroupInfo
            {
                AuthenticationDomain   = portalGroup.AuthenticationDomain,
                MasterPortalId         = portalGroup.MasterPortal.PortalID,
                PortalGroupDescription = portalGroup.Description,
                PortalGroupName        = portalGroup.PortalGroupName
            };

            portalGroupController.AddPortalGroup(@group);
            if (portalGroup.Portals != null)
            {
                foreach (var portal in portalGroup.Portals)
                {
                    var p = new PortalController().GetPortal(portal.PortalID);
                    portalGroupController.AddPortalToGroup(p, @group, callback);
                }
            }
            return(@group.PortalGroupId);
        }
Esempio n. 6
0
 private void LogEvent(EventLogController.EventLogType eventType, PortalGroupInfo portalGroup, PortalInfo portal)
 {
     try
     {
         var log = new LogInfo
         {
             BypassBuffering = true,
             LogTypeKey      = eventType.ToString()
         };
         log.LogProperties.Add(new LogDetailInfo("PortalGroup:", portalGroup.PortalGroupName));
         log.LogProperties.Add(new LogDetailInfo("PortalGroupID:", portalGroup.PortalGroupId.ToString()));
         if (portal != null)
         {
             log.LogProperties.Add(new LogDetailInfo("Portal:", portal.PortalName));
             log.LogProperties.Add(new LogDetailInfo("PortalID:", portal.PortalID.ToString()));
         }
         LogController.Instance.AddLog(log);
     }
     catch (Exception exc)
     {
         Logger.Error(exc);
     }
 }
        public void RemovePortalFromGroup(PortalInfo portal, PortalGroupInfo portalGroup, bool copyUsers, UserCopiedCallback callback)
        {
            //Argument Contract
            Requires.NotNull("portal", portal);
            Requires.PropertyNotNegative("portal", "PortalId", portal.PortalID);
            Requires.NotNull("portalGroup", portalGroup);
            Requires.PropertyNotNegative("portalGroup", "PortalGroupId", portalGroup.PortalGroupId);
            Requires.PropertyNotNegative("portalGroup", "MasterPortalId", portalGroup.MasterPortalId);

            //Callback to update progress bar
            var args = new UserCopiedEventArgs
            {
                TotalUsers = 0,
                UserNo     = 0,
                UserName   = "",
                PortalName = portal.PortalName,
                Stage      = "startingremove"
            };

            callback(args);

            //Remove portal from group
            DeleteSharedModules(portal);
            portal.PortalGroupID = -1;
            _portalController.UpdatePortalInfo(portal);

            var userNo = 0;

            if (copyUsers)
            {
                var users = UserController.GetUsers(portalGroup.MasterPortalId);
                foreach (UserInfo masterUser in users)
                {
                    userNo += 1;

                    //Copy user to portal
                    UserController.CopyUserToPortal(masterUser, portal, false, false);

                    //Callback to update progress bar
                    args = new UserCopiedEventArgs
                    {
                        TotalUsers = users.Count,
                        UserNo     = userNo,
                        UserName   = masterUser.Username,
                        PortalName = portal.PortalName
                    };

                    callback(args);
                }
            }
            else
            {
                //Get admin users
                var roleController = new RoleController();
                var adminUsers     = roleController.GetUsersByRoleName(Null.NullInteger, portal.AdministratorRoleName)
                                     .Cast <UserInfo>()
                                     .Where(u => roleController.GetUserRole(portal.PortalID, u.UserID, portal.AdministratorRoleId) != null);

                foreach (var user in adminUsers)
                {
                    //Copy Administrator to portal
                    UserController.CopyUserToPortal(user, portal, false, false);

                    //Callback to update progress bar
                    args = new UserCopiedEventArgs
                    {
                        TotalUsers = 1,
                        UserNo     = ++userNo,
                        UserName   = user.Username,
                        PortalName = portal.PortalName
                    };

                    callback(args);
                }
            }
            //Callback to update progress bar
            args = new UserCopiedEventArgs
            {
                TotalUsers    = 1,
                UserNo        = userNo,
                UserName      = "",
                PortalName    = portal.PortalName,
                Stage         = "finishedremove",
                PortalGroupId = portalGroup.PortalGroupId
            };
            callback(args);
        }
        private void OnAddPortalToGroupFinished(UserCopiedCallback callback, PortalInfo portal, PortalGroupInfo portalGroup, int totalUsers)
        {
            if (callback == null)
            {
                return;
            }

            var args = new UserCopiedEventArgs
            {
                TotalUsers    = totalUsers,
                UserNo        = totalUsers,
                UserName      = "",
                PortalName    = portal.PortalName,
                Stage         = "finished",
                PortalGroupId = portalGroup.PortalGroupId
            };

            callback(args);
        }
Esempio n. 9
0
 private static PortalGroupInfo CreateValidPortalGroup()
 {
     var portalGroup = new PortalGroupInfo 
                                 {
                                     PortalGroupName = Constants.PORTALGROUP_ValidName,
                                     PortalGroupDescription = Constants.PORTALGROUP_ValidDescription,
                                     MasterPortalId = Constants.PORTAL_ValidPortalId
                                 };
     return portalGroup;
 }
Esempio n. 10
0
        public void PortalGroupController_UpdatePortalGroup_Throws_On_Negative_PortalGroupId()
        {
            //Arrange
            var mockDataService = new Mock<IDataService>();
            var mockPortalController = new Mock<IPortalController>();
            var controller = new PortalGroupController(mockDataService.Object, mockPortalController.Object);

            var portalGroup = new PortalGroupInfo();
            portalGroup.PortalGroupId = Null.NullInteger;

            Assert.Throws<ArgumentOutOfRangeException>(() => controller.UpdatePortalGroup(portalGroup));
        }
Esempio n. 11
0
        public void PortalGroupController_RemovePortalFromGroup_Throws_On_Negative_PortalId()
        {
            //Arrange
            var mockDataService = new Mock<IDataService>();
            var mockPortalController = new Mock<IPortalController>();
            var controller = new PortalGroupController(mockDataService.Object, mockPortalController.Object);

            var portal = new PortalInfo { PortalID = -1 };

            PortalGroupInfo portalGroup = new PortalGroupInfo { PortalGroupId = Constants.PORTALGROUP_ValidPortalGroupId };

            //Act, Assert
            controller.RemovePortalFromGroup(portal, portalGroup, false, userCopied);
        }
Esempio n. 12
0
        public void PortalGroupController_AddPortalToGroup_Throws_On_Null_Portal()
        {
            //Arrange
            var mockDataService = new Mock<IDataService>();
            var mockPortalController = new Mock<IPortalController>();
            var controller = new PortalGroupController(mockDataService.Object, mockPortalController.Object);
            var portalGroup = new PortalGroupInfo { PortalGroupId = Constants.PORTALGROUP_ValidPortalGroupId };


            //Act, Assert
            controller.AddPortalToGroup(null, portalGroup, userCopied);
        }
        private static PortalGroupInfo CreatePortalGroupInfo(int portalGroupId, int masterPortalId)
        {
            var mockPortalGroupInfo = new PortalGroupInfo
            {
                PortalGroupId = portalGroupId,
                MasterPortalId = masterPortalId,
                PortalGroupName = Constants.PORTALGROUP_ValidName,
                PortalGroupDescription = Constants.PORTALGROUP_ValidDescription
            };

            return mockPortalGroupInfo;
        }
Esempio n. 14
0
        public void RemovePortalFromGroup(PortalInfo portal, PortalGroupInfo portalGroup, bool copyUsers, UserCopiedCallback callback)
        {
            // Argument Contract
            Requires.NotNull("portal", portal);
            Requires.PropertyNotNegative("portal", "PortalId", portal.PortalID);
            Requires.NotNull("portalGroup", portalGroup);
            Requires.PropertyNotNegative("portalGroup", "PortalGroupId", portalGroup.PortalGroupId);
            Requires.PropertyNotNegative("portalGroup", "MasterPortalId", portalGroup.MasterPortalId);

            // Callback to update progress bar
            var args = new UserCopiedEventArgs
            {
                TotalUsers = 0,
                UserNo     = 0,
                UserName   = string.Empty,
                PortalName = portal.PortalName,
                Stage      = "startingremove",
            };

            callback(args);

            // Remove portal from group
            this.DeleteSharedModules(portal);
            portal.PortalGroupID = -1;
            PortalController.Instance.UpdatePortalInfo(portal);
            this.LogEvent(EventLogController.EventLogType.PORTAL_REMOVEDFROMPORTALGROUP, portalGroup, portal);

            this.CopyPropertyDefinitions(portal.PortalID, portalGroup.MasterPortalId);

            var userNo = 0;

            if (copyUsers)
            {
                var users = UserController.GetUsers(portalGroup.MasterPortalId);
                foreach (UserInfo masterUser in users)
                {
                    userNo += 1;

                    UserController.CopyUserToPortal(masterUser, portal, false);

                    // Callback to update progress bar
                    args = new UserCopiedEventArgs
                    {
                        TotalUsers = users.Count,
                        UserNo     = userNo,
                        UserName   = masterUser.Username,
                        PortalName = portal.PortalName,
                    };

                    callback(args);
                }
            }
            else
            {
                // Get admin users
                var adminUsers = RoleController.Instance.GetUsersByRole(Null.NullInteger, portal.AdministratorRoleName)
                                 .Where(u => RoleController.Instance.GetUserRole(portal.PortalID, u.UserID, portal.AdministratorRoleId) != null);

                foreach (var user in adminUsers)
                {
                    UserController.CopyUserToPortal(user, portal, false);

                    // Callback to update progress bar
                    args = new UserCopiedEventArgs
                    {
                        TotalUsers = 1,
                        UserNo     = ++userNo,
                        UserName   = user.Username,
                        PortalName = portal.PortalName,
                    };

                    callback(args);
                }
            }

            // Callback to update progress bar
            args = new UserCopiedEventArgs
            {
                TotalUsers    = 1,
                UserNo        = userNo,
                UserName      = string.Empty,
                PortalName    = portal.PortalName,
                Stage         = "finishedremove",
                PortalGroupId = portalGroup.PortalGroupId,
            };
            callback(args);
        }
Esempio n. 15
0
        public void AddPortalToGroup(PortalInfo portal, PortalGroupInfo portalGroup, UserCopiedCallback callback)
        {
            //Argument Contract
            Requires.NotNull("portal", portal);
            Requires.PropertyNotNegative("portal", "PortalId", portal.PortalID);
            Requires.NotNull("portalGroup", portalGroup);
            Requires.PropertyNotNegative("portalGroup", "PortalGroupId", portalGroup.PortalGroupId);
            Requires.PropertyNotNegative("portalGroup", "MasterPortalId", portalGroup.MasterPortalId);

            var masterPortal = _portalController.GetPortal(portalGroup.MasterPortalId);

            var users       = UserController.GetUsers(portal.PortalID);
            var masterUsers = UserController.GetUsers(masterPortal.PortalID);
            var userNo      = 0;

            foreach (UserInfo user in users)
            {
                userNo += 1;

                //move user to master portal
                UserController.CopyUserToPortal(user, masterPortal, true, true);

                //Callback to update progress bar
                var args = new UserCopiedEventArgs
                {
                    TotalUsers = users.Count + masterUsers.Count,
                    UserNo     = userNo,
                    UserName   = user.Username,
                    PortalName = portal.PortalName
                };

                callback(args);
            }

            var roleController = new RoleController();

            //Assign the new portal's roles to master portal users
            foreach (UserInfo user in masterUsers)
            {
                userNo += 1;

                foreach (var role in TestableRoleController.Instance.GetRoles(portal.PortalID, role => role.AutoAssignment && role.Status == RoleStatus.Approved))
                {
                    roleController.AddUserRole(masterPortal.PortalID, user.UserID, role.RoleID, Null.NullDate, Null.NullDate);
                }

                //Callback to update progress bar
                var args = new UserCopiedEventArgs
                {
                    TotalUsers = users.Count + masterUsers.Count,
                    UserNo     = userNo,
                    UserName   = user.Username,
                    PortalName = portal.PortalName
                };

                callback(args);
            }

            //Remove Profile Definitions
            foreach (ProfilePropertyDefinition definition in ProfileController.GetPropertyDefinitionsByPortal(portal.PortalID))
            {
                ProfileController.DeletePropertyDefinition(definition);
            }

            //Add portal to group
            portal.PortalGroupID = portalGroup.PortalGroupId;
            _portalController.UpdatePortalInfo(portal);
        }