Beispiel #1
0
        internal void RemoveAppInTenantAndEav(int appId, ITenant tenant)
        {
            var zoneId = ZoneRuntime.ZoneId;

            // check portal assignment and that it's not the default app
            if (zoneId != CmsZones.Env.ZoneMapper.GetZoneId(tenant.Id))
            {
                throw new Exception("This app does not belong to portal " + tenant.Id);
            }

            if (appId == ZoneRuntime /*new ZoneRuntime(zoneId, parentLog)*/.DefaultAppId)
            {
                throw new Exception("The default app of a zone cannot be removed.");
            }

            // Prepare to Delete folder in dnn - this must be done, before deleting the app in the DB
            var sexyApp  = GetApp.LightWithoutData(tenant, zoneId, appId, null);
            var folder   = sexyApp.Folder;
            var physPath = sexyApp.PhysicalPath;

            // now remove from DB. This sometimes fails, so we do this before trying to clean the files
            // as the db part should be in a transaction, and if it fails, everything should stay as is
            new ZoneManager(zoneId, Log).DeleteApp(appId);

            // now really delete the files - if the DB didn't end up throwing an error
            if (!string.IsNullOrEmpty(folder) && Directory.Exists(physPath))
            {
                Directory.Delete(physPath, true);
            }
        }
        public string TemplatesRoot(int zoneId, int appId)
        {
            var app = GetApp.LightWithoutData(new DnnTenant(PortalSettings.Current), zoneId, appId, false, Log);

            // Copy all files in 2sexy folder to (portal file system) 2sexy folder
            var templateRoot = HttpContext.Current.Server.MapPath(TemplateHelpers.GetTemplatePathRoot(Settings.TemplateLocations.PortalFileSystem, app));

            return(templateRoot);
        }
Beispiel #3
0
        public override XmlExporter Init(int zoneId, int appId, AppRuntime appRuntime, bool appExport, string[] attrSetIds, string[] entityIds, ILog parentLog)
        {
            var tenant = new DnnTenant(PortalSettings.Current);
            var app    = GetApp.LightWithoutData(tenant, zoneId, appId, parentLog: Log);

            AdamAppContext = new AdamAppContext(tenant, app, null, 10, Log);
            Constructor(zoneId, appRuntime, app.AppGuid, appExport, attrSetIds, entityIds, parentLog);

            // this must happen very early, to ensure that the file-lists etc. are correct for exporting when used externally
            InitExportXDocument(PortalSettings.Current.DefaultLanguage, Settings.ModuleVersion);

            return(this);
        }
Beispiel #4
0
        private AssetEditor GetAssetEditorOrThrowIfInsufficientPermissions(int appId, int templateId, bool global, string path)
        {
            var wrapLog = Log.Call <AssetEditor>($"{appId}, {templateId}, {global}, {path}");
            var isAdmin = UserInfo.IsInRole(PortalSettings.AdministratorRoleName);
            var app     = BlockBuilder.App;

            if (appId != 0 && appId != app.AppId)
            {
                app = GetApp.LightWithoutData(new DnnTenant(PortalSettings.Current), appId, Log);
            }
            var assetEditor = (templateId != 0 && path == null)
                ? new AssetEditor(app, templateId, UserInfo.IsSuperUser, isAdmin, Log)
                : new AssetEditor(app, path, UserInfo.IsSuperUser, isAdmin, global, Log);

            assetEditor.EnsureUserMayEditAssetOrThrow();
            return(wrapLog(null, assetEditor));
        }
        private string ResolveAppPath(int appId, bool global, bool allowFullAccess)
        {
            var thisApp = GetApp.LightWithoutData(new DnnTenant(PortalSettings.Current), appId, Log);

            if (global && !allowFullAccess)
            {
                throw new NotSupportedException("only host user may access global files");
            }

            var appPath = TemplateHelpers.GetTemplatePathRoot(
                global
                    ? Settings.TemplateLocations.HostFileSystem
                    : Settings.TemplateLocations.PortalFileSystem
                , thisApp); // get root in global system

            appPath = global::System.Web.Hosting.HostingEnvironment.MapPath(appPath);
            return(appPath);
        }
Beispiel #6
0
        public dynamic GetManyForEditing([FromBody] List <ItemIdentifier> items, int appId)
        {
            var wrapLog = Log.Call($"get many a#{appId}, items⋮{items.Count}");

            // before we start, we have to convert the indexes into something more useful, because
            // otherwise in content-list scenarios we don't have the type
            var appForSecurityChecks = GetApp.LightWithoutData(new DnnTenant(PortalSettings), SystemRuntime.ZoneIdOfApp(appId), appId, Log);

            items = new ContentGroupList(BlockBuilder, Log).ConvertListIndexToId(items, appForSecurityChecks);

            // to do full security check, we'll have to see what content-type is requested
            var permCheck = new MultiPermissionsTypes(BlockBuilder, appId, items, Log);

            if (!permCheck.EnsureAll(GrantSets.WriteSomething, out var exception))
            {
                throw exception;
            }

            var list = new EntityApi(appId, permCheck.EnsureAny(GrantSets.ReadDraft), Log).GetEntitiesForEditing(appId, items);

            // Reformat to the Entity-WithLanguage setup
            var listAsEwH = list.Select(p => new BundleWithHeader <EntityWithLanguages>
            {
                Header = p.Header,
                Entity = p.Entity != null
                    ? EntityWithLanguages.Build(appId, p.Entity)
                    : null
            }).ToList();

            // 2018-09-26 2dm
            // if we're giving items which already exist, then we must verify that edit/read is allowed.
            // important, this code is shared/duplicated in the UiController.Load
            if (list.Any(set => set.Entity != null))
            {
                if (!permCheck.EnsureAll(GrantSets.ReadSomething, out exception))
                {
                    throw exception;
                }
            }

            wrapLog($"will return items⋮{list.Count}");
            return(listAsEwH);
        }
Beispiel #7
0
        public bool Create([FromUri] int appId, [FromUri] string path, [FromBody] ContentHelper content, bool global = false)
        {
            Log.Add($"create a#{appId}, path:{path}, global:{global}, cont-length:{content.Content?.Length}");
            path = path.Replace("/", "\\");

            var thisApp = GetApp.LightWithoutData(new DnnTenant(PortalSettings.Current), appId, Log);

            if (content.Content == null)
            {
                content.Content = "";
            }

            path = SanitizePathAndContent(path, content);

            var isAdmin     = UserInfo.IsInRole(PortalSettings.AdministratorRoleName);
            var assetEditor = new AssetEditor(thisApp, path, UserInfo.IsSuperUser, isAdmin, global, Log);

            assetEditor.EnsureUserMayEditAssetOrThrow(path);
            return(assetEditor.Create(content.Content));
        }