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); }
[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); }
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); }
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); }
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); }
protected override void Initialize(HttpControllerContext controllerContext) { base.Initialize(controllerContext); Log.Rename("Api.DynApi"); Log.Add($"HasBlock: {BlockBuilder != 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 = DnnDynamicCode.Create(BlockBuilder, BlockBuilder?.Log ?? 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; } }