Esempio n. 1
0
        public void Process(GetContentEditorWarningsArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            if (!args.Item.IsPowerShellScript() && !args.Item.IsPowerShellLibrary() && !args.Item.InheritsFrom(Templates.ScriptModule.Id))
            {
                return;
            }

            var action = SessionElevationManager.GetToken(ApplicationNames.ItemSave).Action;

            var warning = new GetContentEditorWarningsArgs.ContentEditorWarning();

            switch (action)
            {
            case SessionElevationManager.TokenDefinition.ElevationAction.Password:
            case SessionElevationManager.TokenDefinition.ElevationAction.Confirm:
                if (SessionElevationManager.IsSessionTokenElevated(ApplicationNames.ItemSave))
                {
                    warning.Title = "You have temporarily enabled script viewing and editing.";
                    warning.Text  =
                        "Drop access if you no longer require it. For more information, refer to our <a href=\"https://sitecorepowershell.com/session-state-elevation/\" class=\"scEditorWarningOption\" target=\"_blank\">Documentation.</a>";
                    warning.AddOption("Drop access", "item:dropelevatescriptedit");
                    args.Warnings.Add(warning);
                }
                else
                {
                    warning.HideFields = true;
                    warning.Title      = "Elevated session state is required to view and edit scripts.";
                    warning.Text       =
                        "A security dialog will prompt you for your credentials before allowing access to view and edit scripts. For more information, refer to our <a href=\"https://sitecorepowershell.com/session-state-elevation/\" class=\"scEditorWarningOption\" target=\"_blank\">Documentation.</a>";
                    warning.AddOption("Elevate session", "item:elevatescriptedit");
                    args.Warnings.Add(warning);
                }
                break;

            case SessionElevationManager.TokenDefinition.ElevationAction.Block:
                warning.HideFields = true;
                warning.Title      = "Elevated session state is blocked. Access to view and edit scripts is disabled.";
                warning.Text       =
                    "For more information, refer to our <a href=\"https://sitecorepowershell.com/session-state-elevation/\" class=\"scEditorWarningOption\" target=\"_blank\">Documentation.</a>";
                args.Warnings.Add(warning);
                break;
            }
        }
Esempio n. 2
0
        private static void AddTranslateWarning(Item item, GetContentEditorWarningsArgs args, IList <Sitecore.Globalization.Language> notranslation, IList <Item> fallback, string sitename)
        {
            GetContentEditorWarningsArgs.ContentEditorWarning warning = args.Add();
            warning.Title = "This item is not translated for the site: " + sitename;
            warning.Text  = "Switch to the not translated language and create a version";

            foreach (var language in notranslation)
            {
                warning.AddOption(string.Format("Switch to {0}", language.GetDisplayName()), string.Format(CultureInfo.InvariantCulture, "item:load(id={0},language={1})", item.ID, language.Name));
            }

            if (fallback.Any())
            {
                foreach (var languageitem in fallback)
                {
                    warning.AddOption(string.Format("Switch to {0} (now uses {1} language fallback)", languageitem.Language.GetDisplayName(), languageitem.OriginalLanguage.GetDisplayName()), string.Format(CultureInfo.InvariantCulture, "item:load(id={0},language={1})", item.ID, languageitem.Language.Name));
                }
            }
            warning.IsExclusive = false;
        }
        // Methods
        #region Public methods

        /// <summary>
        /// Gets the field value.
        /// </summary>
        /// <param name="args">The arguments.</param>
        public void Process(GetContentEditorWarningsArgs args)
        {
            if (args != null)
            {
                Item item = args.Item;
                if (item != null)
                {
                    if (Settings.GetBoolSetting("VersionManager.ShowContentEditorWarnings", true) && VersionManager.IsItemUnderRoots(item))
                    {
                        int count   = item.Versions.Count;
                        int maximum = Settings.GetIntSetting("VersionManager.NumberOfVersionsToKeep", 5);
                        if (maximum < 1)
                        {
                            return;
                        }

                        if (count >= maximum)
                        {
                            GetContentEditorWarningsArgs.ContentEditorWarning warning = args.Add();
                            if (count == maximum)
                            {
                                warning.Title = Translate.Text("The current item has reached maximum allowed number of versions.");
                            }

                            if (count > maximum)
                            {
                                warning.Title = Translate.Text("The current item has exceeded maximum allowed number of versions.");
                                warning.AddOption("Delete obsolete versions", "version:clean");
                            }

                            if (Settings.GetBoolSetting("VersionManager.AutomaticCleanupEnabled", false))
                            {
                                warning.Text = this.GetText(item, count - maximum + 1) + ".";
                            }
                            else
                            {
                                warning.Text = string.Empty;
                            }

                            warning.IsExclusive = false;
                            warning.HideFields  = false;
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        public static void AddWarning(Item item, GetContentEditorWarningsArgs args, IList <Language> languages, string sitename)
        {
            GetContentEditorWarningsArgs.ContentEditorWarning warning = args.Add();

            warning.Title = "You are not in the language of the current site: " + sitename;
            warning.Text  = "Switch to the correct language";
            foreach (var language in languages)
            {
                if (language != null)
                {
                    warning.AddOption(string.Format("Switch to {0}", language.GetDisplayName()),
                                      string.Format(CultureInfo.InvariantCulture, "item:load(id={0},language={1})", item.ID,
                                                    language.Name));
                }
            }
            warning.IsExclusive = true;
        }
Esempio n. 5
0
        private static void ProcessNonSiteItem(Item item, GetContentEditorWarningsArgs args)
        {
            Version[] versionNumbers = item.Versions.GetVersionNumbers(false);
            if (versionNumbers != null && versionNumbers.Length > 0)
            {
                return;
            }

            LanguageCollection languages = LanguageManager.GetLanguages(Sitecore.Context.ContentDatabase);
            int lancount     = 0;
            var languageList = new List <string>();

            foreach (Language language in languages)
            {
                if (HasLanguage(item, language))
                {
                    lancount++;
                    languageList.Add(language.ToString());
                    if (lancount > 3)
                    {
                        //limit to 4, but add en if precent because this is the default
                        if (!languageList.Contains("en"))
                        {
                            var defaultlang = Sitecore.Globalization.Language.Parse("en");
                            if (defaultlang != null && HasLanguage(item, defaultlang))
                            {
                                languageList.Add(defaultlang.ToString());
                            }
                        }
                        break;
                    }
                }
            }
            if (languageList.Any())
            {
                GetContentEditorWarningsArgs.ContentEditorWarning contentEditorWarning = args.Add();
                contentEditorWarning.Title =
                    string.Format(Translate.Text("The current item does not have a version in \"{0}\"."),
                                  (object)item.Language.GetDisplayName());
                if (item.Access.CanWriteLanguage() && item.Access.CanWrite())
                {
                    contentEditorWarning.Text =
                        Translate.Text("To create a version, click Add a New Version or Switch language.");
                    contentEditorWarning.AddOption(Translate.Text("Add a new version."), "item:addversion");
                    foreach (var languageitem in languageList)
                    {
                        contentEditorWarning.AddOption(string.Format("Switch to {0}", languageitem), string.Format(CultureInfo.InvariantCulture, "item:load(id={0},language={1})", item.ID, languageitem));
                    }
                    contentEditorWarning.IsExclusive = true;
                }
                else
                {
                    contentEditorWarning.IsExclusive = false;
                }
                contentEditorWarning.HideFields = true;
                contentEditorWarning.Key        = HasNoVersions.Key;
            }
            else
            {
                GetContentEditorWarningsArgs.ContentEditorWarning contentEditorWarning = args.Add();
                contentEditorWarning.Title =
                    string.Format(Translate.Text("The current item does not have a version in \"{0}\"."),
                                  (object)item.Language.GetDisplayName());
                if (item.Access.CanWriteLanguage() && item.Access.CanWrite())
                {
                    contentEditorWarning.Text =
                        Translate.Text("To create a version, click Add a New Version or click Add on the Versions tab.");
                    contentEditorWarning.AddOption(Translate.Text("Add a new version."), "item:addversion");
                    contentEditorWarning.IsExclusive = true;
                }
                else
                {
                    contentEditorWarning.IsExclusive = false;
                }
                contentEditorWarning.HideFields = true;
                contentEditorWarning.Key        = HasNoVersions.Key;
            }
        }