コード例 #1
0
        public bool SavePackageSettings(PackageSettingsDto packageSettings, out string errorMessage)
        {
            errorMessage = string.Empty;

            try
            {
                string value;
                var    changed      = false;
                var    languagePack = LanguagePackController.GetLanguagePackByPackage(packageSettings.PackageId);
                if (packageSettings.EditorActions.TryGetValue("languageId", out value) &&
                    !string.IsNullOrEmpty(value) && value != languagePack.LanguageID.ToString())
                {
                    languagePack.LanguageID = Convert.ToInt32(value);
                    changed = true;
                }

                if (changed)
                {
                    LanguagePackController.SaveLanguagePack(languagePack);
                }
                return(true);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                errorMessage = ex.Message;
                return(false);
            }
        }
コード例 #2
0
        public bool SavePackageSettings(PackageSettingsDto packageSettings, out string errorMessage)
        {
            errorMessage = string.Empty;

            try
            {
                var isHostUser = UserController.Instance.GetCurrentUserInfo().IsSuperUser;

                if (isHostUser)
                {
                    string value;
                    var    skin = SkinController.GetSkinByPackageID(packageSettings.PackageId);

                    if (packageSettings.EditorActions.TryGetValue("themePackageName", out value) &&
                        !string.IsNullOrEmpty(value))
                    {
                        skin.SkinName = value;
                        SkinController.UpdateSkinPackage(skin);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                errorMessage = ex.Message;
                return(false);
            }
        }
コード例 #3
0
        public bool SavePackageSettings(PackageSettingsDto packageSettings, out string errorMessage)
        {
            errorMessage = string.Empty;

            try
            {
                var desktopModule = DesktopModuleController.GetDesktopModuleByPackageID(packageSettings.PackageId);

                if (desktopModule == null)
                {
                    return(false);
                }

                var isHostUser = UserController.Instance.GetCurrentUserInfo().IsSuperUser;

                this.UpdatePermissions(desktopModule, packageSettings);

                if (isHostUser)
                {
                    this.UpdateModuleProperties(desktopModule, packageSettings.Settings);
                    this.UpdateModuleProperties(desktopModule, packageSettings.EditorActions);

                    DesktopModuleController.SaveDesktopModule(desktopModule, false, true);
                }
                return(true);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                errorMessage = ex.Message;
                return(false);
            }
        }
コード例 #4
0
        internal static List <IUIData> GetData(int PortalID, Dictionary <string, string> Parameters)
        {
            Dictionary <string, IUIData> Settings = new Dictionary <string, IUIData>();
            int pid = 0;

            try
            {
                pid = int.Parse(Parameters["pid"]);
            }
            catch { }

            PackageSettingsDto packageSettings = new PackageSettingsDto
            {
                PortalId = PortalID
            };

            PackageInfo package = PackageController.Instance.GetExtensionPackage(Null.NullInteger, p => p.PackageID == pid);

            if (package != null)
            {
                Dnn.PersonaBar.Extensions.Components.Editors.IPackageEditor packageEditor = PackageEditorFactory.GetPackageEditor(package.PackageType);
                PackageInfoDto packageDetail = packageEditor?.GetPackageDetail(PortalID, package) ?? new PackageInfoDto(PortalID, package);
                Settings.Add("packageDetail", new UIData {
                    Name = "packageDetail", Options = packageDetail
                });
                packageSettings.PackageId = packageDetail.PackageId;
                if (packageDetail is Dnn.PersonaBar.Extensions.Components.Dto.Editors.ModulePackagePermissionsDto)
                {
                    dynamic permissions = packageDetail as Dnn.PersonaBar.Extensions.Components.Dto.Editors.ModulePackagePermissionsDto;
                    Settings.Add("Permissions", new UIData {
                        Name = "Permissions", Options = Managers.ExtensionsManager.GetPermission(permissions.Permissions)
                    });
                }
            }
            Settings.Add("packageSettings", new UIData {
                Name = "packageSettings", Options = packageSettings
            });

            Settings.Add("ModuleCategory", new UIData {
                Name = "ModuleCategory", Options = Managers.ExtensionsManager.GetModuleCategories(), OptionsText = "Value", OptionsValue = "Key", Value = ""
            });
            Settings.Add("ModuleSharing", new UIData {
                Name = "ModuleSharing", Options = Managers.ExtensionsManager.GetModuleSharing(), OptionsText = "Value", OptionsValue = "Key", Value = ""
            });
            Settings.Add("ControlSourceFolder", new UIData {
                Name = "ControlSourceFolder", Options = new List <Managers.TempExt>(), OptionsText = "Value", OptionsValue = "Key"
            });
            Settings.Add("ControlSourceFile", new UIData {
                Name = "ControlSourceFile", Options = new List <Managers.TempExt>(), OptionsText = "Value", OptionsValue = "Key"
            });
            Settings.Add("ControlType", new UIData {
                Name = "ControlType", Options = Managers.ExtensionsManager.GetControlTypes(), OptionsText = "Value", OptionsValue = "Key"
            });
            Settings.Add("ControlIcon", new UIData {
                Name = "ControlIcon", Options = new List <Managers.TempExt>(), OptionsText = "Value", OptionsValue = "Key"
            });

            return(Settings.Values.ToList());
        }
コード例 #5
0
        public bool SavePackageSettings(PackageSettingsDto packageSettings, out string errorMessage)
        {
            errorMessage = string.Empty;

            try
            {
                var isHostUser = UserController.Instance.GetCurrentUserInfo().IsSuperUser;

                if (isHostUser)
                {
                    string value;
                    var    authSystem = AuthenticationController.GetAuthenticationServiceByPackageID(packageSettings.PackageId);

                    if (packageSettings.EditorActions.TryGetValue("loginControlSource", out value) &&
                        !string.IsNullOrEmpty(value))
                    {
                        authSystem.LoginControlSrc = value;
                    }
                    if (packageSettings.EditorActions.TryGetValue("logoffControlSource", out value) &&
                        !string.IsNullOrEmpty(value))
                    {
                        authSystem.LogoffControlSrc = value;
                    }
                    if (packageSettings.EditorActions.TryGetValue("settingsControlSource", out value) &&
                        !string.IsNullOrEmpty(value))
                    {
                        authSystem.SettingsControlSrc = value;
                    }
                    if (packageSettings.EditorActions.TryGetValue("enabled", out value) &&
                        !string.IsNullOrEmpty(value))
                    {
                        bool b;
                        bool.TryParse(value, out b);
                        authSystem.IsEnabled = b;
                    }

                    AuthenticationController.UpdateAuthentication(authSystem);
                    SaveCustomSettings(packageSettings);
                }

                return(true);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                errorMessage = ex.Message;
                return(false);
            }
        }
コード例 #6
0
        private static void SaveCustomSettings(PackageSettingsDto packageSettings)
        {
            // special case for specific DNN provided external authentication systems
            string authType;

            if (packageSettings.EditorActions.TryGetValue("authenticationType", out authType))
            {
                switch (authType.ToLowerInvariant())
                {
                case "facebook":
                case "google":
                case "live":
                case "twitter":
                    var    dirty = false;
                    string value;
                    var    config = OAuthConfigBase.GetConfig(authType, packageSettings.PortalId);

                    if (packageSettings.EditorActions.TryGetValue("appId", out value) &&
                        config.APIKey != value)
                    {
                        config.APIKey = value;
                        dirty         = true;
                    }

                    if (packageSettings.EditorActions.TryGetValue("appSecret", out value) &&
                        config.APISecret != value)
                    {
                        config.APISecret = value;
                        dirty            = true;
                    }

                    if (packageSettings.EditorActions.TryGetValue("appEnabled", out value) &&
                        config.Enabled.ToString().ToUpperInvariant() != value.ToUpperInvariant())
                    {
                        config.Enabled = "TRUE".Equals(value, StringComparison.OrdinalIgnoreCase);
                        dirty          = true;
                    }

                    if (dirty)
                    {
                        OAuthConfigBase.UpdateConfig(config);
                    }
                    break;
                }
            }
        }
コード例 #7
0
        public bool SavePackageSettings(PackageSettingsDto packageSettings, out string errorMessage)
        {
            errorMessage = string.Empty;

            try
            {
                string value;
                if (packageSettings.EditorActions.TryGetValue("customCdn", out value) &&
                    !string.IsNullOrEmpty(value))
                {
                    var library = JavaScriptLibraryController.Instance.GetLibrary(l => l.PackageID == packageSettings.PackageId);
                    HostController.Instance.Update("CustomCDN_" + library.LibraryName, value);
                }

                return(true);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                errorMessage = ex.Message;
                return(false);
            }
        }
コード例 #8
0
        public bool SavePackageSettings(PackageSettingsDto packageSettings, out string errorMessage)
        {
            errorMessage = string.Empty;

            try
            {
                string value;
                var    skinControl = SkinControlController.GetSkinControlByPackageID(packageSettings.PackageId);

                if (packageSettings.EditorActions.TryGetValue("controlKey", out value) &&
                    !string.IsNullOrEmpty(value))
                {
                    skinControl.ControlKey = value;
                }
                if (packageSettings.EditorActions.TryGetValue("controlSrc", out value) &&
                    !string.IsNullOrEmpty(value))
                {
                    skinControl.ControlSrc = value;
                }
                if (packageSettings.EditorActions.TryGetValue("supportsPartialRendering", out value) &&
                    !string.IsNullOrEmpty(value))
                {
                    bool b;
                    bool.TryParse(value, out b);
                    skinControl.SupportsPartialRendering = b;
                }

                SkinControlController.SaveSkinControl(skinControl);
                return(true);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                errorMessage = ex.Message;
                return(false);
            }
        }
コード例 #9
0
        internal static List <IUIData> GetData(int PortalID, Dictionary <string, string> Parameters)
        {
            Dictionary <string, IUIData> Settings = new Dictionary <string, IUIData>();
            int pid = 0;

            try
            {
                pid = int.Parse(Parameters["pid"]);
            }
            catch { }

            PackageSettingsDto packageSettings = new PackageSettingsDto
            {
                PortalId = PortalID
            };
            DeletePackageDto deletePackage = new DeletePackageDto();
            PackageInfo      package       = PackageController.Instance.GetExtensionPackage(Null.NullInteger, p => p.PackageID == pid);

            if (package != null)
            {
                Dnn.PersonaBar.Extensions.Components.Editors.IPackageEditor packageEditor = PackageEditorFactory.GetPackageEditor(package.PackageType);
                PackageInfoDto packageDetail = packageEditor?.GetPackageDetail(PortalID, package) ?? new PackageInfoDto(PortalID, package);
                Settings.Add("packageDetail", new UIData {
                    Name = "packageDetail", Options = packageDetail
                });
                packageSettings.PackageId = packageDetail.PackageId;
                deletePackage.Id          = packageDetail.PackageId;
            }
            Settings.Add("packageSettings", new UIData {
                Name = "packageSettings", Options = packageSettings
            });
            Settings.Add("deletePackage", new UIData {
                Name = "deletePackage", Options = deletePackage
            });
            return(Settings.Values.ToList());
        }
コード例 #10
0
        public bool SavePackageSettings(PackageSettingsDto packageSettings, out string errorMessage)
        {
            errorMessage = string.Empty;

            try
            {
                var desktopModule = DesktopModuleController.GetDesktopModuleByPackageID(packageSettings.PackageId);
                var isHostUser    = UserController.Instance.GetCurrentUserInfo().IsSuperUser;

                UpdatePermissions(desktopModule, packageSettings);

                if (isHostUser)
                {
                    foreach (var settingName in packageSettings.EditorActions.Keys)
                    {
                        var settingValue = packageSettings.EditorActions[settingName];

                        switch (settingName.ToLowerInvariant())
                        {
                        case "foldername":
                            desktopModule.FolderName = settingValue;
                            break;

                        case "category":
                            desktopModule.Category = settingValue;
                            break;

                        case "businesscontroller":
                            desktopModule.BusinessControllerClass = settingValue;
                            break;

                        case "dependencies":
                            desktopModule.Dependencies = settingValue;
                            break;

                        case "hostpermissions":
                            desktopModule.Permissions = settingValue;
                            break;

                        case "premiummodule":
                            desktopModule.IsPremium = Convert.ToBoolean(settingValue);
                            break;

                        case "shareable":
                            desktopModule.Shareable = (ModuleSharing)Convert.ToInt32(settingValue);
                            break;

                        case "assignportal":
                            AssignPortals(desktopModule, JsonConvert.DeserializeObject <IList <ListItemDto> >(settingValue));
                            break;

                        case "unassignportal":
                            UnassignPortals(desktopModule, JsonConvert.DeserializeObject <IList <ListItemDto> >(settingValue));
                            break;

                        case "savedefinition":
                            var definition = JsonConvert.DeserializeObject <ModuleDefinitionDto>(settingValue);
                            SaveModuleDefinition(definition);
                            break;

                        case "deletedefinition":
                            DeleteModuleDefinition(Convert.ToInt32(settingValue));
                            break;

                        case "savemodulecontrol":
                            var moduleControl = JsonConvert.DeserializeObject <ModuleControlDto>(settingValue);
                            SaveModuleControl(moduleControl);
                            break;

                        case "deletemodulecontrol":
                            DeleteModuleControl(Convert.ToInt32(settingValue));
                            break;
                        }
                    }

                    DesktopModuleController.SaveDesktopModule(desktopModule, false, true);
                }
                return(true);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                errorMessage = ex.Message;
                return(false);
            }
        }
コード例 #11
0
        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));
        }
コード例 #12
0
        public ActionResult Save(PackageSettingsDto packageSettings)
        {
            ActionResult actionResult = new ActionResult();

            try
            {
                PackageInfo package = PackageController.Instance.GetExtensionPackage(Null.NullInteger, p => p.PackageID == packageSettings.PackageId);
                if (package == null)
                {
                    actionResult.AddError("SavePackageSettings.PackageNotFound", Localization.GetString("SavePackageSettings.PackageNotFound", Components.Constants.ExtensionSharedResources));
                    return(actionResult);
                }

                if (UserInfo.IsSuperUser)
                {
                    AuthenticationInfo authService = AuthenticationController.GetAuthenticationServiceByPackageID(package.PackageID);
                    bool isReadOnly = authService != null && authService.AuthenticationType == Components.Constants.DnnAuthTypeName;
                    if (isReadOnly)
                    {
                        actionResult.AddError("ReadOnlyPackage.SaveErrorMessage", Localization.GetString("ReadOnlyPackage.SaveErrorMessage", Components.Constants.ExtensionSharedResources));
                        return(actionResult);
                    }

                    Type type       = package.GetType();
                    bool needUpdate = false;
                    foreach (KeyValuePair <string, string> kvp in packageSettings.Settings)
                    {
                        PropertyInfo property = type.GetProperty(kvp.Key, BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.Public);
                        if (property != null && property.CanWrite)
                        {
                            string value     = kvp.Value;
                            object propValue = property.GetValue(package);
                            if (propValue == null || propValue.ToString() != value)
                            {
                                object nativeValue = property.PropertyType == typeof(Version)
                                    ? new Version(value) : Convert.ChangeType(value, property.PropertyType);
                                property.SetValue(package, nativeValue);
                                needUpdate = true;
                            }
                        }
                    }

                    if (needUpdate)
                    {
                        PackageController.Instance.SaveExtensionPackage(package);
                    }
                }

                Dnn.PersonaBar.Extensions.Components.Editors.IPackageEditor packageEditor = PackageEditorFactory.GetPackageEditor(package.PackageType);
                if (packageEditor != null)
                {
                    packageEditor.SavePackageSettings(packageSettings, out string error);

                    if (!string.IsNullOrEmpty(error))
                    {
                        actionResult.AddError("error", error);
                        return(actionResult);
                    }
                }

                PackageInfoDto packageDetail = packageEditor?.GetPackageDetail(packageSettings.PortalId, package) ?? new PackageInfoDto(packageSettings.PortalId, package);
                actionResult.Data      = packageDetail;
                actionResult.IsSuccess = true;
                return(actionResult);
            }
            catch (Exception ex)
            {
                actionResult.AddError("", "", ex);
                return(actionResult);
            }
        }