Example #1
0
 /// <summary>
 /// Handles after save event of the form. All form data are stored to the database.
 /// </summary>
 private void OnAfterSave(object sender, EventArgs eventArgs)
 {
     foreach (var key in mSettingKeyNames)
     {
         SettingsKeyInfoProvider.SetGlobalValue(key, form.Data[key], false);
     }
 }
 /// <summary>
 /// Generates a new JWT encryption key and stores it in <see cref="ValidationHelper.CMS_SETTINGS_JWT_TOKEN_ENCRYPTION_KEY"/> settings key.
 /// </summary>
 private static void SetJWTEncryptionKey()
 {
     if (string.IsNullOrWhiteSpace(SettingsKeyInfoProvider.GetValue(ValidationHelper.CMS_SETTINGS_JWT_TOKEN_ENCRYPTION_KEY)))
     {
         var generatedSecret = Convert.ToBase64String(Guid.NewGuid().ToByteArray()).Substring(0, 16);
         SettingsKeyInfoProvider.SetGlobalValue(ValidationHelper.CMS_SETTINGS_JWT_TOKEN_ENCRYPTION_KEY, generatedSecret, false);
     }
 }
Example #3
0
        private void SettingsKeyUpdate_After(object sender, ObjectEventArgs e)
        {
            SettingsKeyInfo setting = e.Object as SettingsKeyInfo;

            if (setting.KeyName == "CMSSalesForceLeadReplicationMapping")
            {
                SettingsKeyInfoProvider.SetGlobalValue("CMSSalesForceLeadReplicationMappingDateTime", DateTime.Now.ToString("s"));
            }
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         RestoreParameters();
         if (RequestHelper.IsPostBack() && Page.Request.Params[postEventSourceID] == "SaveButton")
         {
             // The access to the Settings page was lost, it might happen as the Internet Explorer opens the target URL of SalesForce redirection in a new window.
             if (CurrentUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Admin))
             {
                 // The current user is a global administrator, so it is safe to proceed.
                 // Without this check there is a security vulnerability as any CMS Desk user could choose a site and authorize access to his or her Sales Cloud organization.
                 CloseDialog(GetString("sf.authorization.partialsuccess"));
                 SettingsKeyInfoProvider.SetGlobalValue("CMSSalesForceCredentials", CredentialsHiddenField.Value);
                 CredentialsHiddenField.Value = String.Empty;
             }
         }
         else
         {
             RedirectUrlLiteral.Text = HTMLHelper.HTMLEncode(RedirectUrl);
             string authorizationCode = QueryHelper.GetString("code", null);
             if (!String.IsNullOrEmpty(authorizationCode))
             {
                 SalesForceAuthorizationHelper   authorizationHelper = new SalesForceAuthorizationHelper(Credentials.ClientId, Credentials.ClientSecret, RedirectUrl);
                 GetAuthenticationTokensResponse response            = authorizationHelper.GetAuthenticationTokens(authorizationCode);
                 Identity identity = authorizationHelper.GetIdentity(response);
                 Credentials.RefreshToken        = response.RefreshToken;
                 Credentials.OrganizationBaseUrl = response.InstanceBaseUrl;
                 Credentials.UserName            = identity.UserName;
                 Credentials.OrganizationName    = GetOrganizationName(Credentials, identity.OrganizationId);
                 StoreParameters();
                 if (RequestContext.CurrentScheme != SourceUrlScheme)
                 {
                     RedirectToScheme(SourceUrlScheme, SourceUrlPort);
                 }
                 else
                 {
                     CloseDialog(GetString("sf.authorization.success"));
                 }
             }
             else
             {
                 string state = QueryHelper.GetString("state", null);
                 if (!String.IsNullOrEmpty(state))
                 {
                     CloseDialog(GetString("sf.authorization.success"));
                 }
             }
         }
     }
     catch (Exception exception)
     {
         HandleError(exception);
     }
 }
Example #5
0
    /// <summary>
    /// Enables tasks after separation is over.
    /// </summary>
    private void EnableTasks()
    {
        if (ValidationHelper.GetBoolean(PersistentStorageHelper.GetValue("CMSSchedulerTasksEnabled"), false))
        {
            SettingsKeyInfoProvider.SetGlobalValue("CMSSchedulerTasksEnabled", true);

            // Restart win service
            WinServiceHelper.RestartService(WinServiceHelper.HM_SERVICE_BASENAME, false);
        }
        PersistentStorageHelper.RemoveValue("CMSSchedulerTasksEnabled");
    }
Example #6
0
 /// <inheritdoc/>
 public void SetSettingValue(string siteName, string settingKey, object newVal)
 {
     if (siteName == null)
     {
         SettingsKeyInfoProvider.SetGlobalValue(settingKey, newVal);
     }
     else
     {
         SettingsKeyInfoProvider.SetValue(settingKey, siteName, newVal);
     }
 }
    private static void UpgradeApplication(Func <bool> versionSpecificMethod, string newVersion, string packageName)
    {
        // Increase the timeout for upgrade request due to expensive operations like macro signing and conversion (needed for large DBs)
        HttpContext.Current.Server.ScriptTimeout = 14400;

        // CI can't be enabled during (and after) upgrade because repository won't be consistent with actual data on the database
        SettingsKeyInfoProvider.SetGlobalValue("CMSEnableCI", false);

        EventLogProvider.LogInformation(EventLogSource, "START");

        // Set the path to the upgrade package (this has to be done here, not in the Import method, because it's an async procedure without HttpContext)
        mUpgradePackagePath = HttpContext.Current.Server.MapPath("~/CMSSiteUtils/Import/" + packageName);
        mWebsitePath        = HttpContext.Current.Server.MapPath("~/");

        // Update class form and alt.form definitions
        var classFormDefinitionUpdateHelper = new ClassFormDefinitionUpdateHelper(EventLogSource);

        classFormDefinitionUpdateHelper.UpdateClassFormDefinitions();

        // Set data version
        SettingsKeyInfoProvider.SetGlobalValue("CMSDataVersion", newVersion);
        SettingsKeyInfoProvider.SetGlobalValue("CMSDBVersion", newVersion);

        // Clear hashtables
        ModuleManager.ClearHashtables();

        // Clear the cache
        CacheHelper.ClearCache(null, true);

        // Drop the routes
        CMSDocumentRouteHelper.DropAllRoutes();

        // Call version specific operations
        if (versionSpecificMethod != null)
        {
            using (var context = new CMSActionContext())
            {
                context.DisableLogging();
                context.CreateVersion  = false;
                context.LogIntegration = false;

                versionSpecificMethod.Invoke();
            }
        }

        // Import upgrade package with webparts, widgets...
        UpgradeImportPackage();

        RefreshMacroSignatures();

        EventLogProvider.LogInformation(EventLogSource, "FINISH");
    }
Example #8
0
    /// <summary>
    /// Enables tasks after separation is over.
    /// </summary>
    private void EnableTasks()
    {
        if (ValidationHelper.GetBoolean(PersistentStorageHelper.GetValue("CMSSchedulerTasksEnabled"), false))
        {
            SettingsKeyInfoProvider.SetGlobalValue("CMSSchedulerTasksEnabled", true);

            // Restart win service
            WinServiceItem def = WinServiceHelper.GetServiceDefinition(WinServiceHelper.HM_SERVICE_BASENAME);
            if (def != null)
            {
                WinServiceHelper.RestartService(def.GetServiceName());
            }
        }
        PersistentStorageHelper.RemoveValue("CMSSchedulerTasksEnabled");
    }
    /// <summary>
    /// Stop tasks.
    /// </summary>
    void btnStopTasks_Click(object sender, EventArgs e)
    {
        // Stop tasks
        PersistentStorageHelper.SetValue("CMSSchedulerTasksEnabled", SettingsKeyInfoProvider.GetBoolValue("CMSSchedulerTasksEnabled"));
        if (SchedulingHelper.EnableScheduler)
        {
            SettingsKeyInfoProvider.SetGlobalValue("CMSSchedulerTasksEnabled", false);
        }

        WinServiceHelper.RestartService(WinServiceHelper.HM_SERVICE_BASENAME, false);

        // Display stopping progress
        iconHelp.Visible = btnStopTasks.Visible = false;
        DisplayStoppingTasks();
        TasksManuallyStopped = true;
    }
Example #10
0
    /// <summary>
    /// Enables the setting for actual scope and by which button user has chosen.
    /// If scope is Both, and global button is pressed then global setting is set and site setting inherits, otherwise only site setting is set.
    /// If scope is Site, only for current site is setting set.
    /// If scope is Global, only global setting is set.
    /// If scope is CurrentSiteAndGlobal, current site's setting and global setting are set.
    /// If scope is AllSiteAndGlobal, all sites settings and global setting are set.
    /// </summary>
    /// <param name="isSite">Site button or global button.</param>
    /// <param name="key">Setting to enable.</param>
    private void EnableSettingByActualScope(string key, bool isSite)
    {
        // If scope is only global, then set only global setting
        if (KeyScope == DisabledModuleScope.Global)
        {
            SettingsKeyInfoProvider.SetGlobalValue(key, true);
            return;
        }

        // If setting is only global setting, set global setting
        var ski = SettingsKeyInfoProvider.GetSettingsKeyInfo(key);

        if (ski.KeyIsGlobal)
        {
            SettingsKeyInfoProvider.SetGlobalValue(key, true);
            return;
        }

        switch (KeyScope)
        {
        case DisabledModuleScope.Both:
            if (isSite)
            {
                SettingsKeyInfoProvider.SetValue(key, SiteName, true);
                break;
            }

            //If global button was pressed, set global setting, and inherit site setting
            SettingsKeyInfoProvider.SetGlobalValue(key, true);
            SettingsKeyInfoProvider.SetValue(key, SiteName, null);
            break;

        case DisabledModuleScope.Site:
            SettingsKeyInfoProvider.SetValue(key, SiteName, true);
            break;

        case DisabledModuleScope.CurrentSiteAndGlobal:
            SettingsKeyInfoProvider.SetGlobalValue(key, true);
            SettingsKeyInfoProvider.SetValue(key, SiteName, true);
            break;

        case DisabledModuleScope.AllSitesAndGlobal:
            SiteInfoProvider.GetSites().ForEachObject(site => SettingsKeyInfoProvider.SetValue(key, SiteName, true));
            SettingsKeyInfoProvider.SetGlobalValue(key, true);
            break;
        }
    }
Example #11
0
        public void SendingEmailsEnabled_CreateOrder_SendsStatusNotifications()
        {
            var cart = CreateCartWithCustomerInfo(Factory.CustomerAnonymous, Factory.CustomerAddressUSA);

            cart.AddItem(Factory.SKUAvailable.SKUID);

            SettingsKeyInfoProvider.SetGlobalValue(ECommerceSettings.SEND_ORDER_NOTIFICATION, true);

            using (new CMSActionContext {
                SendEmails = true
            })
            {
                ShoppingService.CreateOrder(cart);
            }

            var logger = (OrderInfoProviderWithMailLogging)OrderInfoProvider.ProviderObject;

            Assert.That(logger.EmailTemplatesSendToCustomer.Contains("Ecommerce.OrderStatusNotificationToCustomer"), "'Order status changed' notification not sent to customer");
            Assert.That(logger.EmailTemplatesSendToAdmin.Contains("Ecommerce.OrderStatusNotificationToAdmin"), "'Order status changed' notification not sent to admin");
        }