예제 #1
0
        private bool PostSaveUpdateIdsInParent <T>(
            int appId,
            Dictionary <Guid, int> postSaveIds,
            IEnumerable <IGrouping <string, BundleWithHeader <T> > > pairsOrSingleItems)
        {
            var wrapLog = Log.Call <bool>($"{appId}");
            var app     = new Apps.App(new DnnTenant(PortalSettings.Current), Eav.Apps.App.AutoLookupZone, appId,
                                       ConfigurationProvider.Build(BlockBuilder, true), false, Log);

            foreach (var bundle in pairsOrSingleItems)
            {
                Log.Add("processing:" + bundle.Key);
                var entity = app.Data.List.One(bundle.First().Header.ListParent());
                var targetIsContentBlock = entity.Type.Name == BlocksRuntime.BlockTypeName;

                var primaryItem = targetIsContentBlock ? FindContentItem(bundle) : bundle.First();
                var primaryId   = GetIdFromGuidOrError(postSaveIds, primaryItem.EntityGuid);

                var ids = targetIsContentBlock
                    ? new[] { primaryId, FindPresentationItem(postSaveIds, bundle) }
                    : new[] { primaryId as int? };

                var index = primaryItem.Header.ListIndex();

                // add or update slots
                //var itemIsReallyNew = primaryItem.EntityId == 0; // only really add if it's really new
                var willAdd = primaryItem.Header.ListAdd();// && itemIsReallyNew;

                // 2019-07-01 2dm needed to add this, because new-save already gives it an ID
                //if (primaryItem.Header.ReallyAddBecauseAlreadyVerified != null)
                //    willAdd = primaryItem.Header.ReallyAddBecauseAlreadyVerified.Value;

                Log.Add($"will add: {willAdd}; " + // add-pre-verified:{primaryItem.Header.ReallyAddBecauseAlreadyVerified}; " +
                        $"Group.Add:{primaryItem.Header.Add}; EntityId:{primaryItem.EntityId}");

                var cms       = new CmsManager(app, Log);
                var fieldPair = targetIsContentBlock
                    ? ViewParts.PickPair(primaryItem.Header.Group.Part)
                    : new[] { primaryItem.Header.Field };

                if (willAdd) // this cannot be auto-detected, it must be specified
                {
                    cms.Entities.FieldListAdd(entity, fieldPair, index, ids, cms.EnablePublishing);
                }
                else
                {
                    cms.Entities.FieldListReplaceIfModified(entity, fieldPair, index, ids, cms.EnablePublishing);
                }
            }

            // update-module-title
            BlockBuilder.Block.Editor.UpdateTitle();
            return(wrapLog("ok", true));
        }
예제 #2
0
        [AllowAnonymous]   // will check security internally, so assume no requirements
        public Dictionary <string, object> CreateOrUpdate([FromUri] string contentType, [FromBody] Dictionary <string, object> newContentItem, [FromUri] int?id = null, [FromUri] string appPath = null)
        {
            Log.Add($"create or update type:{contentType}, id:{id}, path:{appPath}");
            // if app-path specified, use that app, otherwise use from context
            var appIdentity = AppFinder.GetAppIdFromPathOrContext(appPath, BlockBuilder);

            // Check that this ID is actually of this content-type,
            // this throws an error if it's not the correct type
            var itm = id == null
                ? null
                : new EntityApi(appIdentity.AppId, true, Log).GetOrThrow(contentType, id.Value);

            var ok = itm == null
                ? new MultiPermissionsTypes(BlockBuilder, appIdentity.AppId, contentType, Log)
                     .EnsureAll(Grants.Create.AsSet(), out var exp)
                : new MultiPermissionsItems(BlockBuilder, appIdentity.AppId, itm, Log)
                     .EnsureAll(Grants.Update.AsSet(), out exp);

            if (!ok)
            {
                throw exp;
            }

            //2018-09-15 2dm moved/disabled
            //var context = GetContext(SxcBlock, Log);
            //PerformSecurityCheck(appIdentity, contentType, perm, appPath == null ? context.Dnn.Module : null, itm);

            // Convert to case-insensitive dictionary just to be safe!
            newContentItem = new Dictionary <string, object>(newContentItem, StringComparer.OrdinalIgnoreCase);

            // Now create the cleaned up import-dictionary so we can create a new entity
            var cleanedNewItem = new AppContentEntityBuilder(Log)
                                 .CreateEntityDictionary(contentType, newContentItem, appIdentity.AppId);

            var userName = new DnnUser().IdentityToken;

            // try to create
            var publish = Factory.Resolve <IEnvironmentFactory>().PagePublisher(Log);
            // 2018-09-22 new
            // todo: something looks wrong here, I think create/update would fail if it doesn't have a moduleid
            var currentApp = new Apps.App(new DnnTenant(PortalSettings), appIdentity.ZoneId, appIdentity.AppId,
                                          ConfigurationProvider.Build(false, publish.IsEnabled(ActiveModule.ModuleID),
                                                                      BlockBuilder.Block.Data.Configuration.LookUps), true, Log);

            if (id == null)
            {
                currentApp.Data.Create(contentType, cleanedNewItem, userName);
                // Todo: try to return the newly created object
                return(null);
            }

            currentApp.Data.Update(id.Value, cleanedNewItem, userName);
            return(InitEavAndSerializer(appIdentity.AppId).Convert(currentApp.Data.List.One(id.Value)));
        }
예제 #3
0
        [AllowAnonymous]   // will check security internally, so assume no requirements
        public Dictionary <string, IEnumerable <Dictionary <string, object> > > PublicQuery([FromUri] string appPath, [FromUri] string name, [FromUri] string stream = null)
        {
            var wrapLog     = Log.Call($"path:{appPath}, name:{name}");
            var appIdentity = AppFinder.GetCurrentAppIdFromPath(appPath);
            var queryApp    = new Apps.App(new DnnTenant(PortalSettings), appIdentity.ZoneId, appIdentity.AppId,
                                           ConfigurationProvider.Build(false, false), false, Log);

            // now just run the default query check and serializer
            var result = BuildQueryAndRun(queryApp, name, stream, false, null, Log, BlockBuilder);

            wrapLog(null);
            return(result);
        }
예제 #4
0
 public Dependencies(IContextOfSite siteCtx, JsContextLanguage jsCtx, Apps.App appToLaterInitialize)
 {
     SiteCtx = siteCtx;
     JsCtx   = jsCtx;
     AppToLaterInitialize = appToLaterInitialize;
 }
예제 #5
0
 public ImpExpHelpers(Apps.App unInitializedApp, AppConfigDelegate configProvider) : base("Sxc.ImExHl")
 {
     _unInitializedApp = unInitializedApp;
     _configProvider   = configProvider.Init(Log);
 }