Beispiel #1
0
        private List <Folder> GetFolders(IFolderInfo fldObj, AdamAppContext appContext = null)
        {
            var firstList = _folderManager.GetFolders(fldObj);
            var folders   = firstList?.Select(f => DnnToAdam(appContext, f)).ToList()
                            ?? new List <Folder>();

            return(folders);
        }
Beispiel #2
0
        public IAdamFileSystem <int, int> Init(AdamAppContext <int, int> adamContext, ILog parentLog)
        {
            Log.LinkTo(parentLog);
            var wrapLog = Log.Call();

            AdamContext = adamContext;
            wrapLog("ok");
            return(this);
        }
Beispiel #3
0
 protected override void PrepCore(IApp app, Guid entityGuid, string fieldName, bool usePortalRoot)
 {
     Log.Add("PrepCore(...)");
     AdamAppContext = new AdamAppContext <TFolderId, TFileId>();
     AdamAppContext.Init(Permissions.Context.Tenant, app, Block, 10, Log);
     ContainerContext = usePortalRoot
         ? new AdamOfTenant <TFolderId, TFileId>(AdamAppContext) as AdamOfBase <TFolderId, TFileId>
         : new AdamOfField <TFolderId, TFileId>(AdamAppContext, entityGuid, fieldName);
 }
Beispiel #4
0
        private void PrepCore(App app, Guid entityGuid, string fieldName, bool usePortalRoot)
        {
            var tenant = new DnnTenant(Dnn.Portal);

            AdamAppContext   = new AdamAppContext(tenant, app, SxcInstance);
            ContainerContext = usePortalRoot
                ? new ContainerOfTenant(AdamAppContext) as ContainerBase
                : new ContainerOfField(AdamAppContext, entityGuid, fieldName);
        }
Beispiel #5
0
        /// <inheritdoc />
        public IFolder AsAdam(IEntity entity, string fieldName)
        {
            var envFs = Factory.Resolve <IEnvironmentFileSystem>();

            if (_adamAppContext == null)
            {
                _adamAppContext = new AdamAppContext(_tenant, App, BlockBuilder, CompatibilityLevel, Log);
            }
            return(new FolderOfField(envFs, _adamAppContext, entity.EntityGuid, fieldName));
        }
        /// <summary>
        /// Provides an Adam instance for this item and field
        /// </summary>
        /// <param name="entity">The entity, often Content or similar</param>
        /// <param name="fieldName">The field name, like "Gallery" or "Pics"</param>
        /// <returns>An Adam object for navigating the assets</returns>
        public FolderOfField AsAdam(Eav.Interfaces.IEntity entity, string fieldName)
        {
            var envFs = Factory.Resolve <IEnvironmentFileSystem>();

            if (_adamAppContext == null)
            {
                _adamAppContext = new AdamAppContext(_tenant, App, SxcInstance, Log);
            }
            return(new FolderOfField(envFs, _adamAppContext, entity.EntityGuid, fieldName));
        }
Beispiel #7
0
        private void PrepCore(App app, Guid entityGuid, string fieldName, bool usePortalRoot)
        {
            Log.Add("PrepCore(...)");
            var dnn    = new DnnHelper(SxcInstance?.EnvInstance);
            var tenant = new DnnTenant(dnn.Portal);

            AdamAppContext   = new AdamAppContext(tenant, app, SxcInstance, Log);
            ContainerContext = usePortalRoot
                ? new ContainerOfTenant(AdamAppContext) as ContainerBase
                : new ContainerOfField(AdamAppContext, entityGuid, fieldName);
        }
Beispiel #8
0
        private void PrepCore(IApp app, Guid entityGuid, string fieldName, bool usePortalRoot)
        {
            Log.Add("PrepCore(...)");
            var dnn    = new DnnContext(BlockBuilder?.Container);
            var tenant = new DnnTenant(dnn.Portal);

            AdamAppContext   = new AdamAppContext(tenant, app, BlockBuilder, 10, Log);
            ContainerContext = usePortalRoot
                ? new ContainerOfTenant(AdamAppContext) as ContainerBase
                : new ContainerOfField(AdamAppContext, entityGuid, fieldName);
        }
Beispiel #9
0
        private Folder DnnToAdam(AdamAppContext appContext, IFolderInfo f)
        => new Folder(appContext, this)
        {
            Path = f.FolderPath,
            Id   = f.FolderID,

            Name     = f.DisplayName,
            Created  = f.CreatedOnDate,
            Modified = f.LastUpdated,
            // note: there are more properties in the DNN data, but we don't use it,
            // because it will probably never be cross-platform
        };
Beispiel #10
0
        public override XmlExporter Init(int zoneId, int appId, AppRuntime appRuntime, bool appExport, string[] attrSetIds, string[] entityIds, Log parentLog)
        {
            var tenant = new DnnTenant(PortalSettings.Current);
            var app    = new App(tenant, zoneId, appId);

            AdamAppContext = new AdamAppContext(tenant, app, null);
            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 #11
0
        public List <File> GetFiles(int folderId, AdamAppContext appContext)
        {
            var fldObj = _folderManager.GetFolder(folderId);

            // sometimes the folder doesn't exist for whatever reason
            if (fldObj == null)
            {
                return(new List <File>());
            }

            // try to find the files
            var firstList = _folderManager.GetFiles(fldObj);
            var files     = firstList?.Select(f => DnnToAdam(appContext, f)).ToList()
                            ?? new List <File>();

            return(files);
        }
Beispiel #12
0
        private static File DnnToAdam(AdamAppContext appContext, IFileInfo f)
        => new File(appContext)
        {
            FullName  = f.FileName,
            Extension = f.Extension,
            Size      = f.Size,
            Id        = f.FileId,
            Folder    = f.Folder,
            FolderId  = f.FolderId,

            Path = f.RelativePath,

            Created = f.CreatedOnDate,
            Name    = System.IO.Path.GetFileNameWithoutExtension(f.FileName)
                      // note: there are more properties in the DNN data, but we don't use it,
                      // because it will probably never be cross-platform
        };
Beispiel #13
0
 public IAdamFileSystem <string, string> Init(AdamAppContext <string, string> adamContext, ILog parentLog)
 {
     Log.LinkTo(parentLog);
     AdamContext = adamContext;
     return(this);
 }
Beispiel #14
0
 public IAdamFileSystem <int, int> Init(AdamAppContext <int, int> adamContext, ILog parentLog)
 {
     Log.LinkTo(parentLog);
     AdamContext = adamContext;
     return(this);
 }
Beispiel #15
0
 public AdamOfTenant(AdamAppContext <TFolderId, TFileId> appContext) : base(appContext)
 {
 }
Beispiel #16
0
 protected ContainerBase(AdamAppContext appContext)
 {
     AppContext = appContext;
 }
Beispiel #17
0
 protected AdamOfBase(AdamAppContext <TFolderId, TFileId> appContext)
 {
     AppContext = appContext;
 }
Beispiel #18
0
        public IFile UploadOne(Stream stream, string originalFileName, string contentType, Guid guid, string field, string subFolder, bool usePortalRoot, bool skipFieldAndContentTypePermissionCheck)
        {
            Log.Add($"upload one a:{_appId}, i:{guid}, field:{field}, subfold:{subFolder}, useRoot:{usePortalRoot}");

            var state = new AdamSecureState(BlockBuilder, _appId, contentType, field, guid, usePortalRoot, Log);
            HttpResponseException exp;

            if (!skipFieldAndContentTypePermissionCheck)
            {
                if (!state.UserIsPermittedOnField(GrantSets.WriteSomething, out exp))
                {
                    throw exp;
                }

                // check that if the user should only see drafts, he doesn't see items of published data
                if (!state.UserIsNotRestrictedOrItemIsDraft(guid, out var permissionException))
                {
                    throw permissionException;
                }
            }

            var folder = state.ContainerContext.Folder();

            if (!string.IsNullOrEmpty(subFolder))
            {
                folder = state.ContainerContext.Folder(subFolder, false);
            }

            // start with a security check...
            var dnnFolder = FolderManager.Instance.GetFolder(folder.Id);

            // validate that dnn user have write permissions for folder in case dnn file system is used (usePortalRoot)
            if (usePortalRoot && !SecurityChecks.CanEdit(dnnFolder))
            {
                throw Http.PermissionDenied("can't upload - permission denied");
            }

            // we only upload into valid adam if that's the scenario
            if (!state.SuperUserOrAccessingItemFolder(dnnFolder.PhysicalPath, out exp))
            {
                throw exp;
            }

            #region check content-type extensions...

            // Check file size and extension
            var fileName = String.Copy(originalFileName);
            if (!state.ExtensionIsOk(fileName, out exp))
            {
                throw exp;
            }

            // check metadata of the FieldDef to see if still allowed extension
            var additionalFilter = state.Attribute.Metadata.GetBestValue <string>("FileFilter");
            if (!string.IsNullOrWhiteSpace(additionalFilter) &&
                !state.CustomFileFilterOk(additionalFilter, originalFileName))
            {
                throw Http.NotAllowedFileType(fileName, "field has custom file-filter, which doesn't match");
            }

            // note 2018-04-20 2dm: can't do this for wysiwyg, as it doesn't have a setting for allowed file-uploads

            #endregion

            if (stream.Length > 1024 * MaxFileSizeKb)
            {
                throw new Exception($"file too large - more than {MaxFileSizeKb}Kb");
            }

            // remove forbidden / troubling file name characters
            fileName = fileName
                       .Replace("+", "plus")
                       .Replace("%", "per")
                       .Replace("#", "hash");

            if (fileName != originalFileName)
            {
                Log.Add($"cleaned file name from'{originalFileName}' to '{fileName}'");
            }

            // Make sure the image does not exist yet, cycle through numbers (change file name)
            fileName = RenameFileToNotOverwriteExisting(fileName, dnnFolder);

            // Everything is ok, add file to DNN
            var dnnFile = FileManager.Instance.AddFile(dnnFolder, Path.GetFileName(fileName),
                                                       stream);

            var adamcontext = new AdamAppContext(BlockBuilder.Block.Tenant, state.App, BlockBuilder, 10, Log);
            var eavFile     = new File(adamcontext)
            {
                Created   = dnnFile.CreatedOnDate,
                Extension = dnnFile.Extension,
                FullName  = dnnFile.FileName,
                Folder    = dnnFile.Folder,
                FolderId  = dnnFile.FolderId,
                Id        = dnnFile.FileId,
                Modified  = dnnFile.LastModificationTime
            };

            return(eavFile);
        }
Beispiel #19
0
 public DnnXmlExporter(AdamAppContext <int, int> adamAppContext, IContextResolver ctxResolver, XmlSerializer xmlSerializer) : base(xmlSerializer, DnnConstants.LogName)
 {
     _ctxResolver   = ctxResolver.Init(Log);
     AdamAppContext = adamAppContext;
 }
Beispiel #20
0
 public Eav.Apps.Assets.Folder Get(int tenantId, string path, AdamAppContext appContext)
 => DnnToAdam(appContext, _folderManager.GetFolder(tenantId, path));
Beispiel #21
0
 public List <Folder> GetFolders(int folderId, AdamAppContext appContext)
 => GetFolders(GetFolder(folderId), appContext);
Beispiel #22
0
 public AdamOfSite(AdamAppContext <TFolderId, TFileId> appContext) : base(appContext)
 {
 }
Beispiel #23
0
 public ContainerOfTenant(AdamAppContext appContext) : base(appContext)
 {
 }