Example #1
0
        public AdamNavigator(SxcInstance sexy, App app, PortalSettings ps, Guid entityGuid, string fieldName)
        {
            EntityBase = new EntityBase(sexy, app, ps, entityGuid, fieldName);
            Manager = new AdamManager(ps.PortalId, app);

            if (!Exists)
                return;

            var f = Manager.Get(Root) as FolderInfo;

            if (f == null)
                return;

            PortalID = f.PortalID;
            FolderPath = f.FolderPath;
            MappedPath = f.MappedPath;
            StorageLocation = f.StorageLocation;
            IsProtected = f.IsProtected;
            IsCached = f.IsCached;
            FolderMappingID = f.FolderMappingID;
            LastUpdated = f.LastUpdated;
            FolderID = f.FolderID;
            DisplayName = f.DisplayName;
            DisplayPath = f.DisplayPath;
            IsVersioned = f.IsVersioned;
            KeyID = f.KeyID;
            ParentID = f.ParentID;
            UniqueId = f.UniqueId;
            VersionGuid = f.VersionGuid;
            WorkflowID = f.WorkflowID;

            // IAdamItem interface properties
            Name = DisplayName;
        }
Example #2
0
 public TemplateEditor(SxcInstance sexy, int templateId, UserInfo userInfo, PortalSettings portalSettings)
 {
     Sexy           = sexy;
     Template       = Sexy.AppTemplates.GetTemplate(templateId);
     UserInfo       = userInfo;
     PortalSettings = portalSettings;
 }
Example #3
0
 public AdamAppContext(ITenant tenant, App app, SxcInstance sxcInstance)
 {
     Tenant        = tenant;
     App           = app;
     SxcInstance   = sxcInstance;
     EnvironmentFs = Factory.Resolve <IEnvironmentFileSystem>();
 }
 public MultiPermissionsItems(SxcInstance sxcInstance, int appId, IEntity item, Log parentLog)
     : base(sxcInstance, appId, parentLog)
 {
     Items = new List <IEntity> {
         item
     };
 }
Example #5
0
        public void Init(Template template, App app, ModuleInfo hostingModule, IDataSource dataSource, InstancePurposes instancePurposes, SxcInstance sexy)
        {
            var templatePath = VirtualPathUtility.Combine(Internal.TemplateManager.GetTemplatePathRoot(template.Location, app) + "/", template.Path);

            // Throw Exception if Template does not exist
            if (!File.Exists(HostingEnvironment.MapPath(templatePath)))
                // todo: rendering exception
                throw new SexyContentException("The template file '" + templatePath + "' does not exist.");

            Template = template;
            TemplatePath = templatePath;
            App = app;
            ModuleInfo = hostingModule;
            DataSource = dataSource;
            InstancePurposes = instancePurposes;
            Sexy = sexy;

            // check common errors
            CheckExpectedTemplateErrors();

            // check access permissions - before initializing or running data-code in the template
            CheckTemplatePermissions(sexy.AppPortalSettings);

            // Run engine-internal init stuff
            Init();

            // call engine internal feature to optionally change what data is actually used or prepared for search...
            CustomizeData();

            // check if rendering is possible, or throw exceptions...
            CheckExpectedNoRenderConditions();

            if(PreRenderStatus == RenderStatusType.Unknown)
                PreRenderStatus = RenderStatusType.Ok;
        }
Example #6
0
        internal static ViewDataSource ForContentGroupInSxc(SxcInstance sxc, Template overrideTemplate, int moduleId = 0)
        {
            var showDrafts = sxc.Environment.Permissions.UserMayEditContent;
            var configurationProvider = DataSources.ConfigurationProvider.GetConfigProviderForModule(moduleId, sxc.App, sxc);

            // Get ModuleDataSource
            var initialSource = DataSource.GetInitialDataSource(sxc.ZoneId, sxc.AppId, showDrafts);
            var moduleDataSource = DataSource.GetDataSource<ModuleDataSource>(sxc.ZoneId, sxc.AppId, initialSource, configurationProvider);
            moduleDataSource.ModuleId = moduleId;

            moduleDataSource.OverrideTemplate = overrideTemplate; // new
            moduleDataSource.UseSxcInstanceContentGroup = true; // new
            //moduleDataSource.SxcContext = sxc;

            // If the Template has a Data-Pipeline, use an empty upstream, else use the ModuleDataSource created above
            var viewDataSourceUpstream = (overrideTemplate?.Pipeline == null)
                ? moduleDataSource
                : null;

            var viewDataSource = DataSource.GetDataSource<ViewDataSource>(sxc.ZoneId, sxc.AppId, viewDataSourceUpstream, configurationProvider);

            // Take Publish-Properties from the View-Template
            if (overrideTemplate != null)
            {
                viewDataSource.Publish.Enabled = overrideTemplate.PublishData;
                viewDataSource.Publish.Streams = overrideTemplate.StreamsToPublish;

                // Append Streams of the Data-Pipeline (this doesn't require a change of the viewDataSource itself)
                if (overrideTemplate.Pipeline != null)
                    DataPipelineFactory.GetDataSource(sxc.AppId ?? -999, overrideTemplate.Pipeline.EntityId, configurationProvider, viewDataSource, showDrafts: showDrafts);
            }

            return viewDataSource;
        }
Example #7
0
 public AdamAppContext(ITenant tenant, App app, SxcInstance sxcInstance, Log parentLog) : base("Adm.ApCntx", parentLog, "starting")
 {
     Tenant        = tenant;
     _app          = app;
     AppRuntime    = new AppRuntime(app, null);
     SxcInstance   = sxcInstance;
     EnvironmentFs = Factory.Resolve <IEnvironmentFileSystem>();
 }
Example #8
0
        public DnnAppAndDataHelpers(SxcInstance sxcInstance, Log parentLog = null) : base(sxcInstance, new DnnTenant(null), parentLog)
        {
            // Init things than require module-info or similar, but not 2sxc
            var instance = sxcInstance?.EnvInstance;

            Dnn  = new DnnHelper(instance);
            Link = new DnnLinkHelper(Dnn);
        }
Example #9
0
 public EntityBase(SxcInstance sexy, App app, PortalSettings ps, Guid eGuid, string fName)
 {
     _portalSettings = ps;
     _adamManager = new AdamManager(ps.PortalId, app);
     Sexy = sexy;
     App = app;
     //Dnn = dnn;
     entityGuid = eGuid;
     fieldName = fName;
 }
Example #10
0
 public EntityBase(SxcInstance sexy, App app, PortalSettings ps, Guid eGuid, string fName)
 {
     _portalSettings = ps;
     _adamManager    = new AdamManager(ps.PortalId, app);
     Sexy            = sexy;
     App             = app;
     //Dnn = dnn;
     entityGuid = eGuid;
     fieldName  = fName;
 }
Example #11
0
        private void _constructor(IContentBlock parent, Eav.Interfaces.IEntity cbDefinition)
        {
            Parent = parent;
            ParseContentBlockDefinition(cbDefinition);
            ParentId       = parent.ParentId;
            ContentBlockId = -cbDefinition.EntityId;

            // Ensure we know what portal the stuff is coming from
            Tenant = Parent.App.Tenant;

            ZoneId = Parent.ZoneId;

            AppId = AppHelpers.GetAppIdFromGuidName(ZoneId, _appName); // should be 0 if unknown, must test

            if (AppId == Settings.DataIsMissingInDb)
            {
                _dataIsMissing = true;
                return;
            }

            // 2018-09-22 new, must come before the AppId == 0 check
            SxcInstance = new SxcInstance(this, Parent.SxcInstance.EnvInstance, Parent.SxcInstance.Parameters, Log);

            if (AppId == 0)
            {
                return;
            }

            // 2018-09-22 old
            // try to load the app - if possible
            //App = new App(Tenant, ZoneId, AppId);

            //Configuration = ConfigurationProvider.GetConfigProviderForModule(ParentId, App, SxcInstance);

            // maybe ensure that App.Data is ready
            //var userMayEdit = SxcInstance.UserMayEdit;
            //var publishingEnabled = SxcInstance.Environment.PagePublishing.IsEnabled(Parent.SxcInstance.EnvInstance.Id);
            //App.InitData(userMayEdit, publishingEnabled, Configuration);

            // 2018-09-22 new
            App = new App(Tenant, ZoneId, AppId, ConfigurationProvider.Build(SxcInstance, false), true, Log);

            ContentGroup = App.ContentGroupManager.GetContentGroupOrGeneratePreview(_contentGroupGuid, _previewTemplateGuid);

            // handle cases where the content group is missing - usually because of uncomplete import
            if (ContentGroup.DataIsMissing)
            {
                _dataIsMissing = true;
                App            = null;
                return;
            }

            // use the content-group template, which already covers stored data + module-level stored settings
            SxcInstance.SetTemplateOrOverrideFromUrl(ContentGroup.Template);
        }
Example #12
0
        /// <summary>
        /// Create a module-content block
        /// </summary>
        /// <param name="instanceInfo">the dnn module-info</param>
        /// <param name="parentLog">a parent-log; can be null but where possible you should wire one up</param>
        /// <param name="tenant"></param>
        /// <param name="overrideParams">optional override parameters</param>
        public ModuleContentBlock(IInstanceInfo instanceInfo, Log parentLog, ITenant tenant = null, IEnumerable <KeyValuePair <string, string> > overrideParams = null) : base(parentLog, "CB.Mod")
        {
            InstanceInfo   = instanceInfo ?? throw new Exception("Need valid Instance/ModuleInfo / ModuleConfiguration of runtime");
            ParentId       = instanceInfo.Id;
            ContentBlockId = ParentId;

            // url-params
            _urlParams = overrideParams ?? DnnWebForms.Helpers.SystemWeb.GetUrlParams();

            // Ensure we know what portal the stuff is coming from
            // PortalSettings is null, when in search mode
            Tenant = tenant;

            // important: don't use the SxcInstance.Environment, as it would try to init the Sxc-object before the app is known, causing various side-effects
            var tempEnv = Factory.Resolve <IEnvironmentFactory>().Environment(parentLog);

            ZoneId = tempEnv.ZoneMapper.GetZoneId(tenant.Id);                                              // use tenant as reference, as it can be different from instance.TennantId

            AppId = Factory.Resolve <IMapAppToInstance>().GetAppIdFromInstance(instanceInfo, ZoneId) ?? 0; // fallback/undefined YET

            Log.Add($"parent#{ParentId}, content-block#{ContentBlockId}, z#{ZoneId}, a#{AppId}");

            if (AppId == Settings.DataIsMissingInDb)
            {
                _dataIsMissing = true;
                Log.Add("data is missing, will stop here");
                return;
            }

            if (AppId != 0)
            {
                Log.Add("real app, will load data");
                // try to load the app - if possible
                App = new App(Tenant, ZoneId, AppId, parentLog: Log);

                Configuration = ConfigurationProvider.GetConfigProviderForModule(InstanceInfo.Id, App, SxcInstance);

                // maybe ensure that App.Data is ready
                var userMayEdit = SxcInstance.UserMayEdit;// Factory.Resolve<IPermissions>().UserMayEditContent(SxcInstance.InstanceInfo);
                App.InitData(userMayEdit, SxcInstance.Environment.PagePublishing.IsEnabled(InstanceInfo.Id),
                             Configuration);

                ContentGroup = App.ContentGroupManager.GetInstanceContentGroup(instanceInfo.Id, instanceInfo.PageId);

                if (ContentGroup.DataIsMissing)
                {
                    _dataIsMissing = true;
                    App            = null;
                    return;
                }

                SxcInstance.SetTemplateOrOverrideFromUrl(ContentGroup.Template);
            }
        }
Example #13
0
        internal RenderingHelpers(SxcInstance sxc, Log parentLog) : base("DN.Render", parentLog)
        {
            string appRoot = VirtualPathUtility.ToAbsolute("~/");

            _moduleInfo     = sxc?.ModuleInfo;
            _sxcInstance    = sxc;
            _portalSettings = PortalSettings.Current;

            _userInfo        = PortalSettings.Current.UserInfo;
            _applicationRoot = appRoot;
        }
Example #14
0
        internal RenderingHelpers(SxcInstance sxc)
        {
            string appRoot = VirtualPathUtility.ToAbsolute("~/");

            _moduleInfo     = sxc?.ModuleInfo;        // mi;// mic.Configuration;
            _sxcInstance    = sxc;
            _portalSettings = PortalSettings.Current; // mic.PortalSettings;// PortalSettings.Current;

            _userInfo        = PortalSettings.Current.UserInfo;
            _applicationRoot = appRoot;
        }
Example #15
0
 // todo: try to cache the result of settings-stored in a static variable, this full check
 // todo: shouldn't have to happen every time
 /// <summary>
 /// Returns true if the Portal HomeDirectory Contains the 2sxc Folder and this folder contains the web.config and a Content folder
 /// </summary>
 public void EnsurePortalIsConfigured(SxcInstance sxc, HttpServerUtility server, string controlPath)
 {
     var sexyFolder = new DirectoryInfo(server.MapPath(Path.Combine(sxc.AppPortalSettings.HomeDirectory, Settings.TemplateFolder)));
     var contentFolder = new DirectoryInfo(Path.Combine(sexyFolder.FullName, Constants.ContentAppName));
     var webConfigTemplate = new FileInfo(Path.Combine(sexyFolder.FullName, Settings.WebConfigFileName));
     if (!(sexyFolder.Exists && webConfigTemplate.Exists && contentFolder.Exists))
     {
         // configure it
         var tm = new TemplateManager(sxc.App);
         tm.EnsureTemplateFolderExists(Settings.TemplateLocations.PortalFileSystem);
     };
 }
Example #16
0
        public IRenderingHelpers Init(SxcInstance sxc, Log parentLog)
        {
            LinkLog(parentLog);
            var appRoot = VirtualPathUtility.ToAbsolute("~/");

            _moduleInfo     = sxc?.EnvInstance;
            _sxcInstance    = sxc;
            _portalSettings = PortalSettings.Current;

            _userInfo        = PortalSettings.Current.UserInfo;
            _applicationRoot = appRoot;

            return(this);
        }
Example #17
0
        // todo: try to cache the result of settings-stored in a static variable, this full check
        // todo: shouldn't have to happen every time

        /// <summary>
        /// Returns true if the Portal HomeDirectory Contains the 2sxc Folder and this folder contains the web.config and a Content folder
        /// </summary>
        public void EnsurePortalIsConfigured(SxcInstance sxc, HttpServerUtility server, string controlPath)
        {
            var sexyFolder        = new DirectoryInfo(server.MapPath(Path.Combine(sxc.AppPortalSettings.HomeDirectory, Settings.TemplateFolder)));
            var contentFolder     = new DirectoryInfo(Path.Combine(sexyFolder.FullName, "Content"));
            var webConfigTemplate = new FileInfo(Path.Combine(sexyFolder.FullName, Settings.WebConfigFileName));

            if (!(sexyFolder.Exists && webConfigTemplate.Exists && contentFolder.Exists))
            {
                // configure it
                var tm = new TemplateManager(sxc.App);
                tm.EnsureTemplateFolderExists(server, Settings.TemplateLocations.PortalFileSystem);
            }
            ;
        }
Example #18
0
        public DnnAppAndDataHelpers(SxcInstance sxcInstance, Log parentLog) : base(sxcInstance, new DnnTenant(null), parentLog)
        {
            // Init things than require module-info or similar, but not 2sxc
            var instance = sxcInstance?.EnvInstance;

            Dnn  = new DnnHelper(instance);
            Link = new DnnLinkHelper(Dnn);

            // 2018-09-22 #1624 old
            //// If PortalSettings is null - for example, while search index runs - HasEditPermission would fail
            //// But in search mode, it shouldn't show drafts, so this is ok.
            //// Note that app could be null, if a user is in admin-ui of a module which hasn't actually be configured yet
            //InitAppDataFromContext(App, PortalSettings.Current, sxcInstance);
        }
Example #19
0
        public void UpdateTitle(SxcInstance sxcInstance, Eav.Interfaces.IEntity titleItem)
        {
            Log.Add("update title");

            var languages = sxcInstance.Environment.ZoneMapper.CulturesWithState(sxcInstance.EnvInstance.TenantId,
                                                                                 sxcInstance.ZoneId.Value);

            // Find Module for default language
            var moduleController = new ModuleController();
            var originalModule   = moduleController.GetModule(sxcInstance.EnvInstance.Id);

            foreach (var dimension in languages)
            {
                if (!originalModule.IsDefaultLanguage)
                {
                    originalModule = originalModule.DefaultLanguageModule;
                }

                try // this can sometimes fail, like if the first item is null - https://github.com/2sic/2sxc/issues/817
                {
                    // Break if default language module is null
                    if (originalModule == null)
                    {
                        return;
                    }

                    // Get Title value of Entitiy in current language
                    var titleValue = titleItem.Title[dimension.Key].ToString();

                    // Find module for given Culture
                    var moduleByCulture = moduleController.GetModuleByCulture(originalModule.ModuleID,
                                                                              originalModule.TabID, sxcInstance.EnvInstance.TenantId,
                                                                              DotNetNuke.Services.Localization.LocaleController.Instance.GetLocale(dimension.Key));

                    // Break if no title module found
                    if (moduleByCulture == null || titleValue == null)
                    {
                        return;
                    }

                    moduleByCulture.ModuleTitle = titleValue;
                    moduleController.UpdateModule(moduleByCulture);
                }
                catch
                {
                    // ignored
                }
            }
        }
Example #20
0
        // note: not sure yet where the best place for this method is, so it's here for now
        // will probably move again some day
        internal static ValueCollectionProvider GetConfigProviderForModule(int moduleId, SexyContent.App app, SxcInstance sxc)
        {
            var portalSettings = PortalSettings.Current;

            var provider = new SxcValueCollectionProvider(sxc);

            // only add these in running inside an http-context. Otherwise leave them away!
            if (HttpContext.Current != null)
            {
                var request = HttpContext.Current.Request;

                // new
                NameValueCollection paramList = new NameValueCollection();
                if(sxc?.Parameters != null)
                    foreach (var pair in sxc.Parameters)
                        paramList.Add(pair.Key, pair.Value);
                else
                    paramList = request.QueryString;
                provider.Sources.Add("querystring", new FilteredNameValueCollectionPropertyAccess("querystring", paramList));
                // old
                // provider.Sources.Add("querystring", new FilteredNameValueCollectionPropertyAccess("querystring", request.QueryString));
                provider.Sources.Add("server", new FilteredNameValueCollectionPropertyAccess("server", request.ServerVariables));
                provider.Sources.Add("form", new FilteredNameValueCollectionPropertyAccess("form", request.Form));
            }

            // Add the standard DNN property sources if PortalSettings object is available
            if (portalSettings != null)
            {
                var dnnUsr = portalSettings.UserInfo;
                var dnnCult = Thread.CurrentThread.CurrentCulture;
                var dnn = new TokenReplaceDnn(app, moduleId, portalSettings, dnnUsr);
                var stdSources = dnn.PropertySources;
                foreach (var propertyAccess in stdSources)
                    provider.Sources.Add(propertyAccess.Key,
                        new ValueProviderWrapperForPropertyAccess(propertyAccess.Key, propertyAccess.Value, dnnUsr, dnnCult));
            }

            provider.Sources.Add("app", new AppPropertyAccess("app", app));

            // add module if it was not already added previously
            if (!provider.Sources.ContainsKey("module"))
            {
                var modulePropertyAccess = new StaticValueProvider("module");
                modulePropertyAccess.Properties.Add("ModuleID", moduleId.ToString(CultureInfo.InvariantCulture));
                provider.Sources.Add(modulePropertyAccess.Name, modulePropertyAccess);
            }
            return provider;
            //return _valueCollectionProvider;
        }
Example #21
0
        public ClientInfoContentGroup(SxcInstance sxc, bool isCreated)
        {
            IsCreated = isCreated;
            IsContent = sxc.IsContentApp;

            Id         = sxc.ContentGroup?.ContentGroupId ?? 0;
            Guid       = sxc.ContentGroup?.ContentGroupGuid ?? Guid.Empty;
            AppId      = sxc.AppId ?? 0;
            AppUrl     = sxc.App?.Path ?? "" + "/";
            HasContent = sxc.Template != null && (sxc.ContentGroup?.Exists ?? false);

            ZoneId          = sxc.ZoneId ?? 0;
            TemplateId      = sxc.Template?.TemplateId ?? 0;                   // todo: check if the 0 (previously null) causes problems
            ContentTypeName = sxc.Template?.ContentTypeStaticName ?? "";
            IsList          = sxc.ContentGroup?.Template?.UseForList ?? false; //  isCreated && ((sxc.ContentGroup?.Content?.Count ?? 0) > 1);
        }
Example #22
0
        private void _constructor(IContentBlock parent, Eav.Interfaces.IEntity cbDefinition)
        {
            Parent = parent;
            ParseContentBlockDefinition(cbDefinition);
            ParentId       = parent.ParentId;
            ContentBlockId = -cbDefinition.EntityId; // "mod:" + ParentId +  "-ent:" + cbDefinition.EntityId;


            // Ensure we know what portal the stuff is coming from
            PortalSettings = Parent.App.OwnerPortalSettings;

            ZoneId = Parent.ZoneId;


            AppId = AppHelpers.GetAppIdFromGuidName(ZoneId, _appName); // should be 0 if unknown, must test

            if (AppId == Settings.DataIsMissingInDb)
            {
                _dataIsMissing = true;
                return;
            }

            if (AppId != 0)
            {
                // try to load the app - if possible
                App = new App(ZoneId, AppId, PortalSettings);

                Configuration = ConfigurationProvider.GetConfigProviderForModule(ParentId, App, SxcInstance);

                // maybe ensure that App.Data is ready
                App.InitData(SxcInstance.Environment.Permissions.UserMayEditContent, SxcInstance.Environment.PagePublishing /*new Environment.Dnn7.PagePublishing(Log)*/.IsEnabled(Parent.SxcInstance.ModuleInfo.ModuleID), Configuration /* Data.ConfigurationProvider*/);

                ContentGroup = App.ContentGroupManager.GetContentGroupOrGeneratePreview(_contentGroupGuid, _previewTemplateGuid);

                // handle cases where the content group is missing - usually because of uncomplete import
                if (ContentGroup.DataIsMissing)
                {
                    _dataIsMissing = true;
                    App            = null;
                    return;
                }

                // use the content-group template, which already covers stored data + module-level stored settings
                //Template = ContentGroup.Template;
                SxcInstance.SetTemplateOrOverrideFromUrl(ContentGroup.Template);
            }
        }
Example #23
0
        protected MultiPermissionsApp(SxcInstance sxcInstance, int zoneId, int appId, Log parentLog)
            : base("Api.Perms", parentLog)
        {
            var wrapLog = Log.New("AppAndPermissions", $"..., appId: {appId}, ...");

            SxcInstance = sxcInstance;
            var tenant        = new DnnTenant(PortalSettings.Current);
            var environment   = Factory.Resolve <IEnvironmentFactory>().Environment(Log);
            var contextZoneId = environment.ZoneMapper.GetZoneId(tenant.Id);

            App = new App(tenant, zoneId, appId,
                          ConfigurationProvider.Build(sxcInstance, true),
                          false, Log);
            SamePortal             = contextZoneId == zoneId;
            PortalForSecurityCheck = SamePortal ? PortalSettings.Current : null;
            wrapLog($"ready for z/a:{zoneId}/{appId} t/z:{tenant.Id}/{contextZoneId} same:{SamePortal}");
        }
        /// <summary>
        /// Generate a delegate which will be used to build the configuration based on a new sxc-instance
        /// </summary>
        internal static Func <Eav.Apps.App, IAppDataConfiguration> Build(SxcInstance sxcInstance, bool useExistingConfig)
        {
            return(appToUse =>
            {
                // the module id
                var envInstanceId = sxcInstance.EnvInstance.Id;

                // check if we'll use the config already on the sxc-instance, or generate a new one
                var config = useExistingConfig
                    ? sxcInstance.Data.ConfigurationProvider
                    : GetConfigProviderForModule(envInstanceId, appToUse as App, sxcInstance);

                // return results
                return new AppDataConfiguration(sxcInstance.UserMayEdit,
                                                sxcInstance.Environment.PagePublishing.IsEnabled(envInstanceId), config);
            });
        }
Example #25
0
        internal static ViewDataSource ForContentGroupInSxc(SxcInstance sxc, Template overrideTemplate, ValueCollectionProvider configurationProvider, Log parentLog, int moduleId = 0)
        {
            var log        = new Log("DS.CreateV", parentLog, "will create view data source");
            var showDrafts = sxc.Environment.Permissions.UserMayEditContent;

            log.Add($"mid#{moduleId}, draft:{showDrafts}, template:{overrideTemplate?.Name}");
            // Get ModuleDataSource
            var initialSource    = DataSource.GetInitialDataSource(sxc.ZoneId, sxc.AppId, showDrafts, configurationProvider, parentLog);
            var moduleDataSource = DataSource.GetDataSource <ModuleDataSource>(sxc.ZoneId, sxc.AppId, initialSource, configurationProvider, parentLog);

            moduleDataSource.InstanceId = moduleId;

            moduleDataSource.OverrideTemplate           = overrideTemplate; // new
            moduleDataSource.UseSxcInstanceContentGroup = true;             // new

            // If the Template has a Data-Pipeline, use an empty upstream, else use the ModuleDataSource created above
            var viewDataSourceUpstream = overrideTemplate?.Pipeline == null
                ? moduleDataSource
                : null;

            log.Add($"use pipeline upstream:{viewDataSourceUpstream != null}");

            var viewDataSource = DataSource.GetDataSource <ViewDataSource>(sxc.ZoneId, sxc.AppId, viewDataSourceUpstream, configurationProvider, parentLog);

            // Take Publish-Properties from the View-Template
            if (overrideTemplate != null)
            {
                viewDataSource.Publish.Enabled = overrideTemplate.PublishData;
                viewDataSource.Publish.Streams = overrideTemplate.StreamsToPublish;

                log.Add($"override template, & pipe#{overrideTemplate.Pipeline?.EntityId}");
                // Append Streams of the Data-Pipeline (this doesn't require a change of the viewDataSource itself)
                if (overrideTemplate.Pipeline != null)
                {
                    new DataPipelineFactory(parentLog).GetDataSource(sxc.AppId ?? -999, overrideTemplate.Pipeline /*.EntityId*/,
                                                                     configurationProvider, viewDataSource, showDrafts: showDrafts);
                }
            }
            else
            {
                log.Add("no template override");
            }

            return(viewDataSource);
        }
Example #26
0
        /// <summary>
        /// Initializes the object and performs all the initial security checks
        /// </summary>
        public AdamSecureState(SxcInstance sxcInstance, int appId, string contentType, string field, Guid guid, bool usePortalRoot, Log log)
            : base(sxcInstance, appId, contentType, log)
        {
            // only do checks on field/guid if it's actually accessing that, if it's on the portal root, don't.
            if (!usePortalRoot)
            {
                Field = field;
                Guid  = guid;
            }

            var firstChecker          = PermissionCheckers.First().Value;
            var userMayAdminSomeFiles = firstChecker.UserMay(GrantSets.WritePublished);

            UserMayAdminSiteFiles = firstChecker.GrantedBecause == ConditionType.EnvironmentGlobal ||
                                    firstChecker.GrantedBecause == ConditionType.EnvironmentInstance;

            UserIsRestricted = !(usePortalRoot
                ? UserMayAdminSiteFiles
                : userMayAdminSomeFiles);


            Log.Add($"AdamSecureState - field:{field}, guid:{guid}, adminSome:{userMayAdminSomeFiles}, restricted:{UserIsRestricted}");

            SecurityChecks.ThrowIfAccessingRootButNotAllowed(usePortalRoot, UserIsRestricted);

            Log.Add("check if feature enabled");
            if (UserIsRestricted && !Feats.Enabled(FeaturesForRestrictedUsers))
            {
                throw Http.PermissionDenied(
                          $"low-permission users may not access this - {Feats.MsgMissingSome(FeaturesForRestrictedUsers)}");
            }

            PrepCore(App, guid, field, usePortalRoot);

            if (string.IsNullOrEmpty(contentType) || string.IsNullOrEmpty(field))
            {
                return;
            }

            Attribute = Definition(appId, contentType, field);
            if (!FileTypeIsOkForThisField(out var exp))
            {
                throw exp;
            }
        }
Example #27
0
        public DnnAppAndDataHelpers(SxcInstance sxcInstance, IInstanceInfo instance, Log parentLog) : base(sxcInstance, new DnnTenant(null), parentLog)
        {
            // Init things than require module-info or similar, but not 2sxc
            Dnn  = new DnnHelper(instance);
            Link = new DnnLinkHelper(Dnn);

            if (sxcInstance == null)
            {
                return;
            }

            // If PortalSettings is null - for example, while search index runs - HasEditPermission would fail
            // But in search mode, it shouldn't show drafts, so this is ok.
            // Note that app could be null, if a user is in admin-ui of a module which hasn't actually be configured yet
            var userMayEdit = sxcInstance.UserMayEdit;// Eav.Factory.Resolve<IPermissions>().UserMayEditContent(sexy.InstanceInfo);

            App?.InitData(PortalSettings.Current != null && userMayEdit,
                          PortalSettings.Current != null && sxcInstance.Environment.PagePublishing.IsEnabled(instance.Id),
                          Data.ConfigurationProvider);
        }
Example #28
0
        public void Init(Template template, App app, IInstanceInfo hostingModule, IDataSource dataSource, InstancePurposes instancePurposes, SxcInstance sxcInstance, Log parentLog)
        {
            var templatePath = VirtualPathUtility.Combine(Internal.TemplateHelpers.GetTemplatePathRoot(template.Location, app) + "/", template.Path);

            Log = new Log("Htm.RendEn", parentLog);

            // Throw Exception if Template does not exist
            if (!File.Exists(HostingEnvironment.MapPath(templatePath)))
            {
                // todo: change to some kind of "rendering exception"
                throw new SexyContentException("The template file '" + templatePath + "' does not exist.");
            }

            Template         = template;
            TemplatePath     = templatePath;
            App              = app;
            InstInfo         = hostingModule;
            DataSource       = dataSource;
            InstancePurposes = instancePurposes;
            Sexy             = sxcInstance;

            // check common errors
            CheckExpectedTemplateErrors();

            // check access permissions - before initializing or running data-code in the template
            CheckTemplatePermissions(sxcInstance.Tenant);

            // Run engine-internal init stuff
            Init();

            // call engine internal feature to optionally change what data is actually used or prepared for search...
            CustomizeData();

            // check if rendering is possible, or throw exceptions...
            CheckExpectedNoRenderConditions();

            if (PreRenderStatus == RenderStatusType.Unknown)
            {
                PreRenderStatus = RenderStatusType.Ok;
            }
        }
Example #29
0
        internal static ViewDataSource ForContentGroupInSxc(SxcInstance sxc, Template overrideTemplate, int moduleId = 0)
        {
            bool showDrafts            = sxc.Environment.Permissions.UserMayEditContent;
            var  configurationProvider = DataSources.ConfigurationProvider.GetConfigProviderForModule(moduleId, /*sxc.PortalSettingsOfVisitedPage,*/ sxc.App);

            // Get ModuleDataSource
            var initialSource    = DataSource.GetInitialDataSource(sxc.ZoneId, sxc.AppId, showDrafts);
            var moduleDataSource = DataSource.GetDataSource <ModuleDataSource>(sxc.ZoneId, sxc.AppId, initialSource, configurationProvider);

            moduleDataSource.ModuleId = moduleId;

            //if (template != null)
            //{
            //moduleDataSource.OverrideTemplateId = template.TemplateId; // old
            //}
            moduleDataSource.OverrideTemplate           = overrideTemplate; // new
            moduleDataSource.UseSxcInstanceContentGroup = true;             // new
            moduleDataSource.SxcContext = sxc;

            // If the Template has a Data-Pipeline, use an empty upstream, else use the ModuleDataSource created above
            var viewDataSourceUpstream = (overrideTemplate?.Pipeline == null)
                ? moduleDataSource
                : null;

            var viewDataSource = DataSource.GetDataSource <ViewDataSource>(sxc.ZoneId, sxc.AppId, viewDataSourceUpstream, configurationProvider);

            // Take Publish-Properties from the View-Template
            if (overrideTemplate != null)
            {
                viewDataSource.Publish.Enabled = overrideTemplate.PublishData;
                viewDataSource.Publish.Streams = overrideTemplate.StreamsToPublish;

                // Append Streams of the Data-Pipeline (this doesn't require a change of the viewDataSource itself)
                if (overrideTemplate.Pipeline != null)
                {
                    DataPipelineFactory.GetDataSource(sxc.AppId.Value, overrideTemplate.Pipeline.EntityId, configurationProvider, viewDataSource);
                }
            }

            return(viewDataSource);
        }
Example #30
0
        /// <summary>
        /// Retrieve the appId - either based on the parameter, or if missing, use context
        /// Note that this will fail, if both appPath and context are missing
        /// </summary>
        /// <returns></returns>
        internal IAppIdentity GetAppIdFromPathOrContext(string appPath, SxcInstance sxcInstance)
        {
            var wrapLog = Log.Call("GetAppIdFromPathOrContext", $"{appPath}, ...", "detect app from query string parameters");

            // try to override detection based on additional zone/app-id in urls
            var appId = GetAppIdentityFromQueryAppZone();

            if (appId == null)
            {
                Log.Add($"auto detect app and init eav - path:{appPath}, context null: {sxcInstance == null}");
                appId = appPath == null || appPath == "auto"
                    ? new AppIdentity(
                    sxcInstance?.ZoneId ??
                    throw new ArgumentException("try to get app-id from context, but none found"),
                    sxcInstance.AppId ?? 0, Log)
                    : GetCurrentAppIdFromPath(appPath);
            }

            wrapLog(appId.LogState);

            return(appId);
        }
Example #31
0
        public HttpResponseMessage GetContentBlockData()
        {
            Log.Add("get content block data");
            InitEavAndSerializer();
            // Important note: we are NOT supporting url-view switch at the moment for this
            // reason is, that this kind of data-access is fairly special
            // and not recommended for future use cases, where we have the query etc.
            // IF you want to support View-switching in this, do a deep review w/2dm first!
            // - note that it's really not needed, as you can always use a query or something similar instead
            // - not also that if ever you do support view switching, you will need to ensure security checks

            var dataHandler = new GetContentBlockDataLight(SxcInstance);

            // must access engine to ensure pre-processing of data has happened,
            // especially if the cshtml contains a override void CustomizeData()
            SxcInstance.GetRenderingEngine(InstancePurposes.PublishData);

            var    dataSource = SxcInstance.Data;
            string json;

            if (dataSource.Publish.Enabled)
            {
                var publishedStreams = dataSource.Publish.Streams;
                var streamList       = publishedStreams.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                json = dataHandler.GetJsonFromStreams(dataSource, streamList);
            }
            else
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)
                {
                    ReasonPhrase = dataHandler.GeneratePleaseEnableDataError(SxcInstance.EnvInstance.Id)
                });
            }
            var response = Request.CreateResponse(HttpStatusCode.OK);

            response.Content = new StringContent(json, Encoding.UTF8, "application/json");
            return(response);
        }
Example #32
0
        public AdamNavigator(SxcInstance sexy, App app, PortalSettings ps, Guid entityGuid, string fieldName)
        {
            EntityBase = new EntityBase(sexy, app, ps, entityGuid, fieldName);
            Manager    = new AdamManager(ps.PortalId, app);

            if (!Exists)
            {
                return;
            }

            var f = Manager.Get(Root) as FolderInfo;

            if (f == null)
            {
                return;
            }

            PortalID        = f.PortalID;
            FolderPath      = f.FolderPath;
            MappedPath      = f.MappedPath;
            StorageLocation = f.StorageLocation;
            IsProtected     = f.IsProtected;
            IsCached        = f.IsCached;
            FolderMappingID = f.FolderMappingID;
            LastUpdated     = f.LastUpdated;
            FolderID        = f.FolderID;
            DisplayName     = f.DisplayName;
            DisplayPath     = f.DisplayPath;
            IsVersioned     = f.IsVersioned;
            KeyID           = f.KeyID;
            ParentID        = f.ParentID;
            UniqueId        = f.UniqueId;
            VersionGuid     = f.VersionGuid;
            WorkflowID      = f.WorkflowID;

            // IAdamItem interface properties
            Name = DisplayName;
        }
Example #33
0
        public ClientInfoContentGroup(SxcInstance sxc, bool isCreated)
        {
            IsCreated = isCreated;
            IsContent = sxc.IsContentApp;

            Id = sxc.ContentGroup?.ContentGroupId ?? 0;
            Guid = sxc.ContentGroup?.ContentGroupGuid ?? Guid.Empty;
            AppId = sxc.AppId ?? 0;
            AppUrl = sxc.App?.Path ?? "" + "/" ;
            AppSettingsId = (sxc.App?.Settings?.Entity?.Attributes?.Count > 0)
                ? sxc.App?.Settings?.EntityId : null;    // the real id (if entity exists), 0 (if entity missing, but type has fields), or null (if not available)
            AppResourcesId = (sxc.App?.Resources?.Entity?.Attributes?.Count > 0)
                ? sxc.App?.Resources?.EntityId : null;  // the real id (if entity exists), 0 (if entity missing, but type has fields), or null (if not available)

            HasContent = sxc.Template != null && (sxc.ContentGroup?.Exists ?? false);

            ZoneId = sxc.ZoneId ?? 0;
            TemplateId = sxc.Template?.TemplateId ?? 0;
            QueryId = sxc.Template?.Pipeline?.EntityId; // will be null if not defined
            ContentTypeName = sxc.Template?.ContentTypeStaticName ?? "";
            IsList = sxc.ContentGroup?.Template?.UseForList ?? false;//  isCreated && ((sxc.ContentGroup?.Content?.Count ?? 0) > 1);
            SupportsAjax = sxc.IsContentApp || sxc.App?.Configuration?.SupportsAjaxReload ?? false;
        }
Example #34
0
        public ClientInfoContentGroup(SxcInstance sxc, bool isCreated)
        {
            IsCreated = isCreated;
            IsContent = sxc.IsContentApp;

            Id            = sxc.ContentGroup?.ContentGroupId ?? 0;
            Guid          = sxc.ContentGroup?.ContentGroupGuid ?? Guid.Empty;
            AppId         = sxc.AppId ?? 0;
            AppUrl        = sxc.App?.Path ?? "" + "/";
            AppSettingsId = (sxc.App?.Settings?.Entity?.Attributes?.Count > 0)
                ? sxc.App?.Settings?.EntityId : null;   // the real id (if entity exists), 0 (if entity missing, but type has fields), or null (if not available)
            AppResourcesId = (sxc.App?.Resources?.Entity?.Attributes?.Count > 0)
                ? sxc.App?.Resources?.EntityId : null;  // the real id (if entity exists), 0 (if entity missing, but type has fields), or null (if not available)

            HasContent = sxc.Template != null && (sxc.ContentGroup?.Exists ?? false);

            ZoneId          = sxc.ZoneId ?? 0;
            TemplateId      = sxc.Template?.TemplateId ?? 0;
            QueryId         = sxc.Template?.Pipeline?.EntityId;                // will be null if not defined
            ContentTypeName = sxc.Template?.ContentTypeStaticName ?? "";
            IsList          = sxc.ContentGroup?.Template?.UseForList ?? false; //  isCreated && ((sxc.ContentGroup?.Content?.Count ?? 0) > 1);
            SupportsAjax    = sxc.IsContentApp || sxc.App?.Configuration?.SupportsAjaxReload ?? false;
        }
Example #35
0
 public InPageEditingHelper(SxcInstance sxc)
     : base(sxc)
 {
 }
Example #36
0
        public ClientInfosEnvironment(string systemRootUrl, PortalSettings ps, IInstanceInfo mic, SxcInstance sxcInstance)
        {
            WebsiteId = ps.PortalId;

            WebsiteUrl = "//" + ps.PortalAlias.HTTPAlias + "/";

            PageId  = mic.PageId;
            PageUrl = ps.ActiveTab.FullUrl;

            InstanceId = mic.Id;

            SxcVersion = Settings.Version.ToString();

            SxcRootUrl = systemRootUrl;

            var userMayEdit = sxcInstance?.UserMayEdit ?? false;// Eav.Factory.Resolve<IPermissions>().UserMayEditContent(sxc?.InstanceInfo);

            IsEditable = userMayEdit;
            parameters = sxcInstance?.Parameters;
        }
Example #37
0
        internal RenderingHelpers(SxcInstance sxc)
        {
            string appRoot = VirtualPathUtility.ToAbsolute("~/");
            _moduleInfo = sxc?.ModuleInfo;// mi;// mic.Configuration;
            _sxcInstance = sxc;
            _portalSettings = PortalSettings.Current; // mic.PortalSettings;// PortalSettings.Current;

            _userInfo = PortalSettings.Current.UserInfo;
            _applicationRoot = appRoot;
        }
Example #38
0
        public ClientInfosEnvironment(string systemRootUrl, PortalSettings ps, ModuleInfo mic, SxcInstance sxc)
        {
            WebsiteId = ps.PortalId;

            WebsiteUrl = "//" + ps.PortalAlias.HTTPAlias + "/";

            PageId = mic.TabID;
            PageUrl = ps.ActiveTab.FullUrl;

            InstanceId = mic.ModuleID;

            SxcVersion = Settings.Version.ToString();

            SxcRootUrl = systemRootUrl;

            IsEditable = sxc?.Environment?.Permissions.UserMayEditContent ?? false;
            parameters = sxc?.Parameters;
        }
Example #39
0
        public ClientInfosAll(string systemRootUrl, PortalSettings ps, ModuleInfo mic, SxcInstance sxc, UserInfo uinfo, int zoneId, bool isCreated)
        {
            Environment = new ClientInfosEnvironment(systemRootUrl, ps, mic, sxc);
            Language = new ClientInfosLanguages(ps, zoneId);
            User = new ClientInfosUser(uinfo);

            ContentBlock = new ClientInfoContentBlock(sxc.ContentBlock, null, 0);
            ContentGroup = new ClientInfoContentGroup(sxc, isCreated);
            error = new ClientInfosError(sxc.ContentBlock);
        }
Example #40
0
	    /// <summary>
	    /// Common constructor, directly preparing it with 2sxc
	    /// </summary>
	    /// <param name="sxcInstance"></param>
	    /// <param name="languages"></param>
	    public Serializer(SxcInstance sxcInstance, string[] languages = null)
        {
            Sxc = sxcInstance;
            Languages = languages;
        }
 internal EntityContentGroupReferenceManager(SxcInstance sxc): base(sxc)
 {
 }
Example #42
0
 internal static DnnAppAndDataHelpers GetContext(SxcInstance sxcInstance, Log log)
 => new DnnAppAndDataHelpers(sxcInstance, sxcInstance?.Log ?? log);
Example #43
0
 public SxcValueCollectionProvider(SxcInstance sxc)
 {
     SxcInstance = sxc;
 }
Example #44
0
 public GetContentBlockDataLight(SxcInstance sxc)
 {
     _sxci = sxc;
 }
Example #45
0
 internal InPageEditingHelperBase(SxcInstance sxc)
 {
     _sxcInstance = sxc;
 }
 internal ContentGroupReferenceManagerBase(SxcInstance sxc)
 {
     SxcContext = sxc;
     ModuleId = SxcContext.ModuleInfo.ModuleID;
 }
Example #47
0
        public ClientInfosAll(string systemRootUrl, PortalSettings ps, IInstanceInfo mic, SxcInstance sxc, UserInfo uinfo, int zoneId, bool isCreated, Log parentLog)
            : base("Sxc.CliInf", parentLog, "building entire client-context")
        {
            var versioning = sxc.Environment.PagePublishing;

            Environment = new ClientInfosEnvironment(systemRootUrl, ps, mic, sxc);
            Language    = new ClientInfosLanguages(ps, zoneId);
            User        = new ClientInfosUser(uinfo);

            ContentBlock = new ClientInfoContentBlock(sxc.ContentBlock, null, 0, versioning.Requirements(mic.Id));
            ContentGroup = new ClientInfoContentGroup(sxc, isCreated);
            error        = new ClientInfosError(sxc.ContentBlock);
        }
 public ModuleContentGroupReferenceManager(SxcInstance sxc) : base(sxc)
 {
 }