private void cmdUpdate_Click(object sender, EventArgs e)
        {
            if (ModuleContext.PortalSettings.ActiveTab.IsSuperTab)
            {
                UpdatePackage();
            }
            else
            {
                //Update DesktopModule Permissions
                DesktopModulePermissionCollection objCurrentPermissions = DesktopModulePermissionController.GetDesktopModulePermissions(dgPermissions.PortalDesktopModuleID);
                if (!objCurrentPermissions.CompareTo(dgPermissions.Permissions))
                {
                    DesktopModulePermissionController.DeleteDesktopModulePermissionsByPortalDesktopModuleID(dgPermissions.PortalDesktopModuleID);
                    foreach (DesktopModulePermissionInfo objPermission in dgPermissions.Permissions)
                    {
                        DesktopModulePermissionController.AddDesktopModulePermission(objPermission);
                    }
                }
                DataCache.RemoveCache(string.Format(DataCache.PortalDesktopModuleCacheKey, ModuleContext.PortalId));

                dgPermissions.ResetPermissions();
            }
        }
Example #2
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Load the ViewState
        /// </summary>
        /// <param name="savedState">The saved state</param>
        /// -----------------------------------------------------------------------------
        protected override void LoadViewState(object savedState)
        {
            if (savedState != null)
            {
                //Load State from the array of objects that was saved with SaveViewState.
                var myState = (object[])savedState;

                //Load Base Controls ViewState
                if (myState[0] != null)
                {
                    base.LoadViewState(myState[0]);
                }

                //Load DesktopModuleId
                if (myState[1] != null)
                {
                    PortalDesktopModuleID = Convert.ToInt32(myState[1]);
                }

                //Load DesktopModulePermissions
                if (myState[2] != null)
                {
                    _DesktopModulePermissions = new DesktopModulePermissionCollection();
                    string state = Convert.ToString(myState[2]);
                    if (!String.IsNullOrEmpty(state))
                    {
                        //First Break the String into individual Keys
                        string[] permissionKeys = state.Split(new[] { "##" }, StringSplitOptions.None);
                        foreach (string key in permissionKeys)
                        {
                            string[] Settings = key.Split('|');
                            _DesktopModulePermissions.Add(ParseKeys(Settings));
                        }
                    }
                }
            }
        }
Example #3
0
 /// -----------------------------------------------------------------------------
 /// <summary>
 /// Gets the DesktopModulePermissions from the Data Store
 /// </summary>
 /// -----------------------------------------------------------------------------
 private void GetDesktopModulePermissions()
 {
     _DesktopModulePermissions = new DesktopModulePermissionCollection(DesktopModulePermissionController.GetDesktopModulePermissions(PortalDesktopModuleID));
 }
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Load the ViewState
        /// </summary>
        /// <param name="savedState">The saved state</param>
        /// <history>
        ///     [cnurse]    02/22/2008  Created
        /// </history>
        /// -----------------------------------------------------------------------------
        protected override void LoadViewState(object savedState)
        {
            if (savedState != null)
            {
                //Load State from the array of objects that was saved with SaveViewState.
                var myState = (object[])savedState;

                //Load Base Controls ViewState
                if (myState[0] != null)
                {
                    base.LoadViewState(myState[0]);
                }

                //Load DesktopModuleId
                if (myState[1] != null)
                {
                    PortalDesktopModuleID = Convert.ToInt32(myState[1]);
                }

                //Load DesktopModulePermissions
                if (myState[2] != null)
                {
                    _DesktopModulePermissions = new DesktopModulePermissionCollection();
                    string state = Convert.ToString(myState[2]);
                    if (!String.IsNullOrEmpty(state))
                    {
                        //First Break the String into individual Keys
                        string[] permissionKeys = state.Split(new[] { "##" }, StringSplitOptions.None);
                        foreach (string key in permissionKeys)
                        {
                            string[] Settings = key.Split('|');
                            _DesktopModulePermissions.Add(ParseKeys(Settings));
                        }
                    }
                }
            }
        }
 /// -----------------------------------------------------------------------------
 /// <summary>
 /// Gets the DesktopModulePermissions from the Data Store
 /// </summary>
 /// <history>
 ///     [cnurse]    02/22/2008  Created
 /// </history>
 /// -----------------------------------------------------------------------------
 private void GetDesktopModulePermissions()
 {
     _DesktopModulePermissions = new DesktopModulePermissionCollection(DesktopModulePermissionController.GetDesktopModulePermissions(PortalDesktopModuleID));
 }
        public static int AddDesktopModuleToPortal(int portalID, DesktopModuleInfo desktopModule, DesktopModulePermissionCollection permissions, bool clearCache)
        {
            int portalDesktopModuleID = AddDesktopModuleToPortal(portalID, desktopModule.DesktopModuleID, false, clearCache);

            if (portalDesktopModuleID > Null.NullInteger)
            {
                DesktopModulePermissionController.DeleteDesktopModulePermissionsByPortalDesktopModuleID(portalDesktopModuleID);
                foreach (DesktopModulePermissionInfo permission in permissions)
                {
                    permission.PortalDesktopModuleID = portalDesktopModuleID;
                    DesktopModulePermissionController.AddDesktopModulePermission(permission);
                }
            }
            return(portalDesktopModuleID);
        }
        private void UpdatePermissions(DesktopModuleInfo desktopModule, PackageSettingsDto packageSettings)
        {
            if (!packageSettings.EditorActions.ContainsKey("permissions") || string.IsNullOrEmpty(packageSettings.EditorActions["permissions"]))
            {
                return;
            }

            var portalModule = DesktopModuleController.GetPortalDesktopModule(packageSettings.PortalId, desktopModule.DesktopModuleID);

            if (portalModule == null)
            {
                return;
            }

            var portalSettings = new PortalSettings(packageSettings.PortalId);
            var permissions    = JsonConvert.DeserializeObject <PermissionsDto>(packageSettings.EditorActions["permissions"]);
            var hasAdmin       = permissions.RolePermissions == null ? false : permissions.RolePermissions.Any(permission => permission.RoleId == portalSettings.AdministratorRoleId);

            var desktopModulePermissions = new DesktopModulePermissionCollection();

            //add default permissions for administrators
            if (!hasAdmin || (permissions.RolePermissions.Count == 0 && permissions.UserPermissions.Count == 0))
            {
                //add default permissions
                var permissionController = new PermissionController();
                var permissionsList      = permissionController.GetPermissionByCodeAndKey("SYSTEM_DESKTOPMODULE", "DEPLOY");
                foreach (PermissionInfo permissionInfo in permissionsList)
                {
                    var permission = new DesktopModulePermissionInfo(permissionInfo)
                    {
                        RoleID = portalSettings.AdministratorRoleId,
                        UserID = Null.NullInteger,
                        PortalDesktopModuleID = portalModule.PortalDesktopModuleID,
                        AllowAccess           = true,
                        RoleName = portalSettings.AdministratorRoleName
                    };
                    desktopModulePermissions.Add(permission);
                }
            }

            //add role permissions
            if (permissions.RolePermissions != null)
            {
                foreach (var rolePermission in permissions.RolePermissions)
                {
                    foreach (var permission in rolePermission.Permissions)
                    {
                        desktopModulePermissions.Add(new DesktopModulePermissionInfo()
                        {
                            PermissionID          = permission.PermissionId,
                            RoleID                = rolePermission.RoleId,
                            UserID                = Null.NullInteger,
                            PortalDesktopModuleID = portalModule.PortalDesktopModuleID,
                            AllowAccess           = permission.AllowAccess
                        });
                    }
                }
            }


            //add user permissions
            if (permissions.UserPermissions != null)
            {
                foreach (var userPermission in permissions.UserPermissions)
                {
                    foreach (var permission in userPermission.Permissions)
                    {
                        int roleId;
                        int.TryParse(Globals.glbRoleNothing, out roleId);
                        desktopModulePermissions.Add(new DesktopModulePermissionInfo()
                        {
                            PermissionID          = permission.PermissionId,
                            RoleID                = roleId,
                            UserID                = userPermission.UserId,
                            PortalDesktopModuleID = portalModule.PortalDesktopModuleID,
                            AllowAccess           = permission.AllowAccess
                        });
                    }
                }
            }

            //Update DesktopModule Permissions
            var currentPermissions = DesktopModulePermissionController.GetDesktopModulePermissions(portalModule.PortalDesktopModuleID);

            if (!currentPermissions.CompareTo(desktopModulePermissions))
            {
                DesktopModulePermissionController.DeleteDesktopModulePermissionsByPortalDesktopModuleID(portalModule.PortalDesktopModuleID);
                foreach (DesktopModulePermissionInfo objPermission in desktopModulePermissions)
                {
                    DesktopModulePermissionController.AddDesktopModulePermission(objPermission);
                }
            }
            DataCache.RemoveCache(string.Format(DataCache.PortalDesktopModuleCacheKey, portalSettings.PortalId));
        }