Esempio n. 1
0
        protected override void AddPermission(PermissionInfo permission, int roleId, string roleName, int userId, string displayName, bool allowAccess)
        {
            var objPermission = new DesktopModulePermissionInfo(permission);

            objPermission.PortalDesktopModuleID = PortalDesktopModuleID;
            objPermission.RoleID      = roleId;
            objPermission.RoleName    = roleName;
            objPermission.AllowAccess = allowAccess;
            objPermission.UserID      = userId;
            objPermission.DisplayName = displayName;
            _DesktopModulePermissions.Add(objPermission, true);

            //Clear Permission List
            _PermissionsList = null;
        }
Esempio n. 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));
                        }
                    }
                }
            }
        }
        /// -----------------------------------------------------------------------------
        /// <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));
                        }
                    }
                }
            }
        }
        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));
        }