// find item (and optional version) from request values (compare WebExtension.GetEditableWrapper)
        public static ContentItem FindItem(IVersionManager versions, ContentVersionRepository versionRepository, Navigator navigator, NameValueCollection request)
        {
            var item = navigator.Navigate(request[PathData.ItemQueryKey]);

            return(versionRepository.ParseVersion(request[PathData.VersionIndexQueryKey],
                                                  request[PathData.VersionKeyQueryKey], item) ?? item);
        }
Ejemplo n.º 2
0
        public override void SetUp()
        {
            base.SetUp();

            var types = new[] { typeof(Items.PageItem), typeof(Items.DataItem) };

            versionRepository = TestSupport.CreateVersionRepository(types);
            var versions = TestSupport.SetupVersionManager(persister, versionRepository);
            //definitions = TestSupport.SetupDefinitions(types);

            ITemplateAggregator templates;
            ContentActivator    activator;

            TestSupport.Setup(out definitions, out templates, out activator, types);
            creator = new CreateUrlProvider(
                persister,
                new EditUrlManager(null, new EditSection()),
                definitions,
                templates,
                activator,
                new Navigator(persister, TestSupport.SetupHost(), new VirtualNodeFactory(), TestSupport.SetupContentSource()),
                versions,
                versionRepository);
            request = new NameValueCollection();

            root = CreateOneItem <Items.PageItem>(0, "root", null);
        }
Ejemplo n.º 3
0
        //private void SettingsPublishing(object sender, ContentEventArgs e)
        //{
        //}

        protected virtual void SettingsPublished(object sender, ContentEventArgs e)
        {
            try
            {
                if (e.ContentLink.CompareToIgnoreWorkID(ConfigurationPageLink))
                {
                    var page     = (AzureAdSecuritySettingsPage)e.Content;
                    var newRoles = page.Settings?.Roles ?? new List <string>();

                    var previousVersion = ContentVersionRepository.List(ConfigurationPageLink)
                                          .Where(x => x.Status == VersionStatus.PreviouslyPublished)
                                          .OrderByDescending(x => x.Saved)
                                          .FirstOrDefault();

                    var previousPage = previousVersion != null?ContentRepository.Get <AzureAdSecuritySettingsPage>(previousVersion.ContentLink, DefaultLoaderOptions) : null;

                    var diff = Diff(newRoles, previousPage?.Settings?.Roles ?? new List <string>());

                    if (!diff.IsEmpty)
                    {
                        RolesWatcher.RolesChanged(diff);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error($"Error handling roles update (published page #{e.ContentLink.ID}): {ex}");
            }
        }
 public VersionAjaxService(Navigator navigator, ContentVersionRepository versionRepository, IWebContext webContext, ISecurityManager security)
 {
     _navigator         = navigator;
     _versionRepository = versionRepository;
     _security          = security;
     _webContext        = webContext;
 }
 public PublishScheduledAction(ContentVersionRepository versionRepository, IVersionManager versioner, IPersister persister, ISecurityManager security, StateChanger changer)
 {
     this.versionRepository = versionRepository;
     this.versioner         = versioner;
     this.persister         = persister;
     this.security          = security;
     this.changer           = changer;
 }
 protected PartsModifyingAjaxService(Navigator navigator, IIntegrityManager integrity, IVersionManager versions, ContentVersionRepository versionRepository, IDefinitionManager definitionManager)
 {
     this.navigator         = navigator;
     this.integrity         = integrity;
     this.versions          = versions;
     this.versionRepository = versionRepository;
     this.definitionManager = definitionManager;
 }
Ejemplo n.º 7
0
 public override void SetUp()
 {
     base.SetUp();
     persister  = null;
     activator  = null;
     repository = TestSupport.CreateVersionRepository(ref persister, ref activator, typeof(Items.NormalPage), typeof(Items.NormalItem));
     drafts     = new DraftRepository(repository, new FakeCacheWrapper());
 }
Ejemplo n.º 8
0
 public ItemMover(IPersister persister, Navigator navigator, IIntegrityManager integrity, IVersionManager versions, ContentVersionRepository versionRepository)
 {
     this.persister         = persister;
     this.navigator         = navigator;
     this.integrity         = integrity;
     this.versions          = versions;
     this.versionRepository = versionRepository;
 }
Ejemplo n.º 9
0
 public CreateUrlProvider(IPersister persister, IEditUrlManager editUrlManager, IDefinitionManager definitions, ContentActivator activator, Navigator navigator, IVersionManager versions, ContentVersionRepository versionRepository)
 {
     this.persister         = persister;
     this.managementPaths   = editUrlManager;
     this.definitions       = definitions;
     this.activator         = activator;
     this.navigator         = navigator;
     this.versions          = versions;
     this.versionRepository = versionRepository;
 }
Ejemplo n.º 10
0
        public static ContentItem ParseVersion(this ContentVersionRepository versionRepository, string versionIndexParameterValue, string versionKey, ContentItem masterVersion)
        {
            var path = new PathData(Find.ClosestPage(masterVersion), masterVersion);

            if (TryParseVersion(versionRepository, versionIndexParameterValue, versionKey, path))
            {
                return(path.CurrentItem);
            }
            return(null);
        }
Ejemplo n.º 11
0
 public static bool TryParseVersion(this ContentVersionRepository versionRepository, string versionIndexParameterValue, string versionKey, PathData path)
 {
     if (!path.IsEmpty() && !string.IsNullOrEmpty(versionIndexParameterValue))
     {
         int versionIndex = int.Parse(versionIndexParameterValue);
         var version      = versionRepository.GetVersion(path.CurrentPage, versionIndex);
         return(path.TryApplyVersion(version, versionKey));
     }
     return(false);
 }
 protected override void OnPreInit(EventArgs e)
 {
     base.OnPreInit(e);
     Security        = Engine.SecurityManager;
     Definitions     = Engine.Definitions;
     Versions        = Engine.Resolve <IVersionManager>();
     Commands        = Engine.Resolve <CommandDispatcher>();
     EditManager     = Engine.EditManager;
     ManagementPaths = Engine.ManagementPaths;
     Repository      = Engine.Resolve <ContentVersionRepository>();
 }
Ejemplo n.º 13
0
        public static PathData EnsureDraft(IVersionManager versions, ContentVersionRepository versionRepository, string versionIndex, string versionKey, ContentItem item)
        {
            item = versionRepository.ParseVersion(versionIndex, versionKey, item)
                   ?? item;

            var page = Find.ClosestPage(item);

            if (!page.VersionOf.HasValue)
            {
                page = versions.GetOrCreateDraft(page);
                item = page.FindPartVersion(item);
            }

            return(new PathData(page, item));
        }
Ejemplo n.º 14
0
        public override void SetUp()
        {
            base.SetUp();
            repository = TestSupport.CreateVersionRepository(ref persister, ref activator, typeof(NormalPage), typeof(NormalItem));
            master     = CreateOneItem <NormalPage>(0, "root", null);
            persister.Save(master);

            version              = CreateOneItem <NormalPage>(0, "root version", null);
            version.State        = ContentState.Unpublished;
            version.VersionOf    = master;
            version.VersionIndex = master.VersionIndex + 1;
            version.SavedBy      = "test";
            persister.Save(master);

            worker = new UpgradeVersionWorker(repository, persister.Repository);
        }
Ejemplo n.º 15
0
        public static PathData EnsureDraft(IVersionManager versions, ContentVersionRepository versionRepository, Edit.Navigator navigator, NameValueCollection request)
        {
            var item = navigator.Navigate(request["item"]);

            item = versionRepository.ParseVersion(request[PathData.VersionIndexQueryKey], request["versionKey"], item)
                   ?? item;

            var page = Find.ClosestPage(item);

            if (!page.VersionOf.HasValue)
            {
                page = versions.AddVersion(page, asPreviousVersion: false);
                item = page.FindPartVersion(item);
            }

            return(new PathData(page, item));
        }
        public override void SetUp()
        {
            base.SetUp();

            var types = new[] { typeof(Items.PageItem), typeof(Items.DataItem) };

            versionRepository = TestSupport.CreateVersionRepository(ref persister, ref activator, types);
            versions          = TestSupport.SetupVersionManager(persister, versionRepository);
            mover             = new ItemMover(
                // persister,
                new Navigator(persister, TestSupport.SetupHost(), new VirtualNodeFactory(), TestSupport.SetupContentSource()),
                new FakeIntegrityManager(),
                versions,
                versionRepository);
            request = new NameValueCollection();

            root = base.CreateOneItem <Items.PageItem>(0, "root", null);
        }
        public void TestFixtureSetUp()
        {
            var definitionProviders = TestSupport.SetupDefinitionProviders(new DefinitionMap(), typeof(NormalPage), typeof(NormalItem));
            var proxies             = new N2.Persistence.Proxying.InterceptingProxyFactory();

            proxies.Initialize(definitionProviders.SelectMany(dp => dp.GetDefinitions()));

            itemRepository       = new MongoContentItemRepository(
                databaseProvider = new MongoDatabaseProvider(TestSupport.CreateDependencyInjector(), proxies, new N2.Configuration.ConfigurationManagerWrapper("n2mongo"),
                                                             definitionProviders,
                                                             new AdaptiveContext()));

            persister = new ContentPersister(TestSupport.SetupContentSource(itemRepository), itemRepository);
            IRepository <ContentVersion> versionRepository = new MongoDbRepository <ContentVersion>(databaseProvider);

            repository = TestSupport.CreateVersionRepository(
                ref persister,
                ref activator,
                ref versionRepository,
                typeof(NormalPage), typeof(NormalItem));
            drafts = new DraftRepository(repository, new FakeCacheWrapper());
        }
Ejemplo n.º 18
0
        private void DeleteRecursive(ContentItem itemToDelete, ContentVersionRepository versionRepository)
        {
            using (logger.Indent())
            {
                foreach (ContentItem child in itemToDelete.Children.ToList())
                {
                    DeleteRecursive(child, versionRepository);
                }
            }

            itemToDelete.AddTo(null);
            logger.InfoFormat("Deleting {0}", itemToDelete);

            //Delete item versions
            var itemVersions = versionRepository.GetVersions(itemToDelete).ToArray();

            foreach (var version in itemVersions)
            {
                versionRepository.Repository.Delete(version);
            }
            //Delete item
            repository.Delete(itemToDelete);
        }
Ejemplo n.º 19
0
 public static PathData EnsureDraft(IVersionManager versions, ContentVersionRepository versionRepository, Edit.Navigator navigator, NameValueCollection request)
 {
     return(EnsureDraft(versions, versionRepository, navigator, key => request[key]));
 }
Ejemplo n.º 20
0
 public static VersionManager SetupVersionManager(IPersister persister, ContentVersionRepository versionRepository)
 {
     return(new VersionManager(versionRepository, persister.Repository, new N2.Edit.Workflow.StateChanger(), new EditSection()));
 }
 public ItemUpdater(Navigator navigator, IIntegrityManager integrity, IVersionManager versions, ContentVersionRepository versionRepository, IDefinitionManager definitionManager = null)
     : base(navigator, integrity, versions, versionRepository, definitionManager)
 {
 }
Ejemplo n.º 22
0
        // see also UseDraftCommand.cs (should use it here?)
        public static PathData EnsureDraft(ContentItem item, IVersionManager versions, ContentVersionRepository versionRepository, out bool isNew)
        {
            isNew = false;

            // find containing page
            var page = Find.ClosestPage(item);

            if (versions.IsVersionable(page) && page.State != ContentState.Draft)
            {
                // current version is not draft, see if there are any drafts
                // page is not versioned, add a new version
                page = versions.AddVersion(page, asPreviousVersion: false);

                // find part to be modified on new page version
                item  = page.FindPartVersion(item);
                isNew = true;
            }

            return(new PathData(page, item));
        }
Ejemplo n.º 23
0
        public static PathData EnsureDraft(IVersionManager versions, ContentVersionRepository versionRepository, Edit.Navigator navigator, Func <string, string> requestValueAccessor)
        {
            var item = navigator.Navigate(requestValueAccessor(PathData.ItemQueryKey));

            return(EnsureDraft(versions, versionRepository, requestValueAccessor(PathData.VersionIndexQueryKey), requestValueAccessor(PathData.VersionKeyQueryKey), item));
        }
Ejemplo n.º 24
0
        public static bool TryApplyVersion(this PathData path, ContentVersion version, string versionKey, ContentVersionRepository repository)
        {
            if (version != null)
            {
                var page = repository.DeserializeVersion(version);
                if (!string.IsNullOrEmpty(versionKey))
                {
                    var item = page.FindDescendantByVersionKey(versionKey);
                    if (item != null)
                    {
                        path.CurrentPage = page;
                        path.CurrentItem = item;
                        return(true);
                    }
                }

                if (path.CurrentItem.IsPage)
                {
                    path.CurrentPage = null;
                    path.CurrentItem = page;
                }
                else
                {
                    path.CurrentPage = page;
                    path.CurrentItem = page.FindDescendantByVersionKey(versionKey)
                                       ?? page.FindPartVersion(path.CurrentItem);
                }

                return(true);
            }
            return(false);
        }
Ejemplo n.º 25
0
 public UpgradeVersionWorker(ContentVersionRepository versionRepository, IContentItemRepository itemRepository)
 {
     this.versionRepository = versionRepository;
     this.itemRepository    = itemRepository;
 }