Ejemplo n.º 1
0
        public bool ItemList([FromUri] Guid guid, List <SortedEntityItem> list, [FromUri] string part = null)
        {
            Log.Add($"list for:{guid}, items:{list?.Count}");
            if (list == null)
            {
                throw new ArgumentNullException(nameof(list));
            }

            var versioning = BlockBuilder.Environment.PagePublishing;

            void InternalSave(VersioningActionInfo args)
            {
                var cms    = new CmsManager(BlockBuilder.App, Log);
                var entity = cms.Read.AppState.List.One(guid);

                var sequence = list.Select(i => i.Index).ToArray();
                var fields   = part == ViewParts.ContentLower ? ViewParts.ContentPair : new[] { part };

                cms.Entities.FieldListReorder(entity, fields, sequence, cms.EnablePublishing);
            }

            // use dnn versioning - items here are always part of list
            var context = DnnDynamicCode.Create(BlockBuilder, Log);

            versioning.DoInsidePublishing(context.Dnn.Module.ModuleID, context.Dnn.User.UserID, InternalSave);

            return(true);
        }
Ejemplo n.º 2
0
        protected override void Initialize(HttpControllerContext controllerContext)
        {
            base.Initialize(controllerContext);
            //Log.Rename("Api.DynApi");
            var block = GetBlock();

            Log.Add($"HasBlock: {block != null}");
            // Note that the CmsBlock is created by the BaseClass, if it's detectable. Otherwise it's null
            // if it's null, use the log of this object
            DynCode = new DnnDynamicCode().Init(block, Log);

            // In case SxcBlock was null, there is no instance, but we may still need the app
            if (DynCode.App == null)
            {
                Log.Add("DynCode.App is null");
                TryToAttachAppFromUrlParams();
            }

            // must run this after creating AppAndDataHelpers
            controllerContext.Request.Properties.Add(Constants.DnnContextKey, Dnn);

            if (controllerContext.Request.Properties.TryGetValue(CodeCompiler.SharedCodeRootPathKeyInCache, out var value))
            {
                CreateInstancePath = value as string;
            }
        }
Ejemplo n.º 3
0
        [AllowAnonymous]   // will check security internally, so assume no requirements
        public Dictionary <string, IEnumerable <Dictionary <string, object> > > Query([FromUri] string name, [FromUri] bool includeGuid = false, [FromUri] string stream = null)
        {
            var wrapLog = Log.Call($"'{name}', inclGuid: {includeGuid}, stream: {stream}");
            var context = DnnDynamicCode.Create(BlockBuilder, Log);
            var result  = BuildQueryAndRun(BlockBuilder.App, name, stream, includeGuid, context.Dnn.Module, Log, BlockBuilder);

            wrapLog(null);
            return(result);
        }
Ejemplo n.º 4
0
        public void Replace(Guid guid, string part, int index, int entityId, bool add = false)
        {
            var wrapLog    = Log.Call($"target:{guid}, part:{part}, index:{index}, id:{entityId}");
            var versioning = BlockBuilder.Environment.PagePublishing;

            void InternalSave(VersioningActionInfo args)
            {
                var cms    = new CmsManager(BlockBuilder.App, Log);
                var entity = cms.AppState.List.One(guid);

                if (entity == null)
                {
                    throw new Exception($"Can't find item '{guid}'");
                }

                // correct casing of content / listcontent for now - TODO should already happen in JS-Call
                if (entity.Type.Name == BlocksRuntime.BlockTypeName)
                {
                    if (string.Equals(part, ViewParts.Content, OrdinalIgnoreCase))
                    {
                        part = ViewParts.Content;
                    }
                    if (string.Equals(part, ViewParts.ListContent, OrdinalIgnoreCase))
                    {
                        part = ViewParts.ListContent;
                    }
                }

                if (add)
                {
                    cms.Entities.FieldListAdd(entity, new[] { part }, index, new int?[] { entityId }, cms.EnablePublishing);
                }
                else
                {
                    cms.Entities.FieldListReplaceIfModified(entity, new[] { part }, index, new int?[] { entityId },
                                                            cms.EnablePublishing);
                }
            }

            // use dnn versioning - this is always part of page
            var context = DnnDynamicCode.Create(BlockBuilder, Log);

            versioning.DoInsidePublishing(context.Dnn.Module.ModuleID, context.Dnn.User.UserID, InternalSave);
            wrapLog(null);
        }
Ejemplo n.º 5
0
        public object GetFileByPath(string relativePath)
        {
            var context = DnnDynamicCode.Create(BlockBuilder, Log);

            relativePath = relativePath.Replace(context.Dnn.Portal.HomeDirectory, "");
            var file = FileManager.Instance.GetFile(context.Dnn.Portal.PortalId, relativePath);

            if (CanUserViewFile(file))
            {
                return new
                       {
                           file.FileId
                       }
            }
            ;

            return(null);
        }
Ejemplo n.º 6
0
        internal Dictionary <Guid, int> SaveWithinDnnPagePublishingAndUpdateParent <T>(
            int appId,
            List <BundleWithHeader <T> > items,
            bool partOfPage,
            Func <bool, Dictionary <Guid, int> > internalSaveMethod,
            IMultiPermissionCheck permCheck
            )
        {
            var allowWriteLive = permCheck.UserMayOnAll(GrantSets.WritePublished);
            var forceDraft     = !allowWriteLive;

            Log.Add($"allowWrite: {allowWriteLive} forceDraft: {forceDraft}");

            // list of saved IDs
            Dictionary <Guid, int> postSaveIds = null;

            // The internal call which will be used further down
            Dictionary <Guid, int> SaveAndSaveGroupsInnerCall(Func <bool, Dictionary <Guid, int> > call, bool forceSaveAsDraft)
            {
                var ids = call.Invoke(forceSaveAsDraft);

                // now assign all content-groups as needed
                new ContentGroupList(BlockBuilder, Log).IfChangesAffectListUpdateIt(appId, items, ids);
                return(ids);
            }

            // use dnn versioning if partOfPage
            if (partOfPage)
            {
                Log.Add("partOfPage - save with publishing");
                var versioning = Eav.Factory.Resolve <IEnvironmentFactory>().PagePublisher(Log);
                var context    = DnnDynamicCode.Create(BlockBuilder, Log);
                versioning.DoInsidePublishing(context.Dnn.Module.ModuleID, context.Dnn.User.UserID,
                                              args => postSaveIds = SaveAndSaveGroupsInnerCall(internalSaveMethod, forceDraft));
            }
            else
            {
                Log.Add("partOfPage false, save without publishing");
                postSaveIds = SaveAndSaveGroupsInnerCall(internalSaveMethod, forceDraft);
            }

            Log.Add(() => $"post save IDs: {string.Join(",", postSaveIds.Select(psi => psi.Key + "(" + psi.Value + ")"))}");
            return(postSaveIds);
        }
Ejemplo n.º 7
0
        protected override void ConfigurePage(WebPageBase parentPage)
        {
            base.ConfigurePage(parentPage);

            // Child pages need to get their context from the Parent
            Context = parentPage.Context;

            // Return if parent page is not a SexyContentWebPage
            if (!(parentPage is RazorComponentBase typedParent))
            {
                return;
            }

            // Forward the context
            Html    = typedParent.Html;
            DynCode = typedParent.DynCode;
            try
            {
                Log.Add("@RenderPage:" + VirtualPath);
            } catch { /* ignore */ }
        }
Ejemplo n.º 8
0
        public object GetFileByPath(string relativePath)
        {
            var dnnDynamicCode = new DnnDynamicCode().Init(GetBlock(), Log);
            var portal         = dnnDynamicCode.Dnn.Portal;

            relativePath = relativePath.Replace(portal.HomeDirectory, "");
            var file = FileManager.Instance.GetFile(portal.PortalId, relativePath);

            if (file == null)
            {
                return(null);
            }
            var folder = (FolderInfo)FolderManager.Instance.GetFolder(file.FolderId);

            return(FolderPermissionController.CanViewFolder(folder)
                ? new
            {
                file.FileId
            }
                : null);
        }