Exemple #1
0
        public ActionResult Index(string folderPath, string type, int?replaceId)
        {
            if (!_mediaLibraryService.CheckMediaFolderPermission(Permissions.SelectMediaContent, folderPath))
            {
                return(new HttpUnauthorizedResult());
            }

            // Check permission
            if (!_mediaLibraryService.CanManageMediaFolder(folderPath))
            {
                return(new HttpUnauthorizedResult());
            }

            var viewModel = new OEmbedViewModel {
                FolderPath = folderPath,
            };

            if (replaceId != null)
            {
                var replaceMedia = Services.ContentManager.Get <MediaPart>(replaceId.Value);
                if (replaceMedia == null)
                {
                    return(HttpNotFound());
                }

                viewModel.Replace = replaceMedia;

                if (!replaceMedia.TypeDefinition.Name.Equals("OEmbed"))
                {
                    Services.Notifier.Error(T("Cannot replace {0} with OEmbed", replaceMedia.ContentItem.TypeDefinition.Name));
                }
            }

            return(View(viewModel));
        }
        public ActionResult Index(string folderPath, string type, int?replaceId = null)
        {
            if (!_mediaLibraryService.CheckMediaFolderPermission(Permissions.SelectMediaContent, folderPath))
            {
                return(new HttpUnauthorizedResult());
            }

            // Check permission
            if (!_mediaLibraryService.CanManageMediaFolder(folderPath))
            {
                return(new HttpUnauthorizedResult());
            }

            var viewModel = new ImportMediaViewModel {
                FolderPath = folderPath,
                Type       = type,
            };

            if (replaceId != null)
            {
                var replaceMedia = Services.ContentManager.Get <MediaPart>(replaceId.Value);
                if (replaceMedia == null)
                {
                    return(HttpNotFound());
                }

                viewModel.Replace = replaceMedia;
            }

            return(View(viewModel));
        }
        public ActionResult Edit(string folderPath, string filename)
        {
            if (!_mediaLibraryService.CheckMediaFolderPermission(Permissions.EditMediaContent, folderPath))
            {
                return(new HttpUnauthorizedResult());
            }

            // Check permission.
            var rootMediaFolder = _mediaLibraryService.GetRootMediaFolder();

            if (!_mediaLibraryService.CanManageMediaFolder(folderPath))
            {
                return(new HttpUnauthorizedResult());
            }

            var media = Services.ContentManager.Query <MediaPart, MediaPartRecord>().Where(x => x.FolderPath == folderPath && x.FileName == filename).Slice(0, 1).FirstOrDefault();

            if (media == null)
            {
                return(HttpNotFound());
            }

            var contentItem = Services.ContentManager.New("ImageEditor").As <ImageEditorPart>();

            contentItem.ImagePart = media.As <ImagePart>();
            contentItem.MediaPart = media.As <MediaPart>();

            var shape = Services.ContentManager.BuildDisplay(contentItem);

            shape.MediaContentItem(media.ContentItem);

            return(View(shape));
        }
Exemple #4
0
        public void Adjust(CheckAccessContext context)
        {
            var mediaPart = context.Content.As <MediaPart>();

            if (mediaPart != null)
            {
                context.Granted = _mediaLibraryService.CheckMediaFolderPermission(context.Permission, mediaPart.FolderPath);
            }
        }
        public ActionResult MediaItem(int id, string displayType = "SummaryAdmin")
        {
            var contentItem = Services.ContentManager.Get <MediaPart>(id, VersionOptions.Latest);

            if (contentItem == null)
            {
                return(HttpNotFound());
            }

            if (!_mediaLibraryService.CheckMediaFolderPermission(om.Permissions.SelectMediaContent, contentItem.FolderPath))
            {
                // Services.Notifier.Add(UI.Notify.NotifyType.Error, T("Cannot select media"));
                return(new HttpUnauthorizedResult());
            }

            dynamic model = Services.ContentManager.BuildDisplay(contentItem, displayType);

            return(new ShapeResult(this, model));
        }
Exemple #6
0
        public ActionResult Create(string folderPath)
        {
            if (!(_mediaLibraryService.CheckMediaFolderPermission(Permissions.ImportMediaContent, folderPath) || _mediaLibraryService.CheckMediaFolderPermission(Permissions.EditMediaContent, folderPath)))
            {
                Services.Notifier.Error(T("Couldn't create media folder"));
                return(RedirectToAction("Index", "Admin", new { area = "Orchard.MediaLibrary", folderPath = folderPath }));
            }

            // If the user is trying to access a folder above his boundaries, redirect him to his home folder
            var rootMediaFolder = _mediaLibraryService.GetRootMediaFolder();

            if (!_mediaLibraryService.CanManageMediaFolder(folderPath))
            {
                return(RedirectToAction("Create", new { folderPath = rootMediaFolder.MediaPath }));
            }

            var viewModel = new MediaManagerFolderCreateViewModel {
                Hierarchy  = _mediaLibraryService.GetMediaFolders(folderPath),
                FolderPath = folderPath
            };

            return(View(viewModel));
        }
        public ActionResult MediaItems(string folderPath, int skip = 0, int count = 0, string order = "created", string mediaType = "", string culture = "")
        {
            if (String.IsNullOrWhiteSpace(folderPath))
            {
                folderPath = null;
            }
            if (!_mediaLibraryService.CheckMediaFolderPermission(Permissions.SelectMediaContent, folderPath))
            {
                Services.Notifier.Add(UI.Notify.NotifyType.Error, T("Cannot select media"));
                var model = new MediaManagerMediaItemsViewModel {
                    MediaItems      = new List <MediaManagerMediaItemViewModel>(),
                    MediaItemsCount = 0,
                    FolderPath      = folderPath
                };

                return(View(model));
            }

            // Check permission
            if (!_mediaLibraryService.CheckMediaFolderPermission(Permissions.SelectMediaContent, folderPath) && !_mediaLibraryService.CanManageMediaFolder(folderPath))
            {
                var model = new MediaManagerMediaItemsViewModel {
                    MediaItems      = new List <MediaManagerMediaItemViewModel>(),
                    MediaItemsCount = 0,
                    FolderPath      = folderPath
                };

                return(View(model));
            }

            IEnumerable <MediaPart> mediaParts;
            var mediaPartsCount = 0;

            if (culture == "")
            {
                mediaParts      = _mediaLibraryService.GetMediaContentItems(folderPath, skip, count, order, mediaType, VersionOptions.Latest);
                mediaPartsCount = _mediaLibraryService.GetMediaContentItemsCount(folderPath, mediaType, VersionOptions.Latest);
            }
            else
            {
                var cultureId = _cultureManager.GetCultureByName(culture).Id;
                var query     = BuildGetMediaContentItemsQuery(Services.ContentManager, folderPath, order: order, mediaType: mediaType, versionOptions: VersionOptions.Latest)
                                .Join <LocalizationPartRecord>()
                                .Where(x => x.CultureId == cultureId)
                                .Join <MediaPartRecord>();
                mediaParts = query
                             .Slice(skip, count);
                mediaPartsCount = query.Count();
            }

            var mediaItems = mediaParts.Select(x => new MediaManagerMediaItemViewModel {
                MediaPart = x,
                Shape     = Services.ContentManager.BuildDisplay(x.ContentItem, "Thumbnail")
            }).ToList();

            var viewModel = new MediaManagerMediaItemsViewModel {
                MediaItems      = mediaItems,
                MediaItemsCount = mediaPartsCount,
                FolderPath      = folderPath
            };

            return(View(viewModel));
        }
        public ActionResult Index(string folderPath = "", bool dialog = false)
        {
            if (!_mediaLibraryService.CheckMediaFolderPermission(Permissions.SelectMediaContent, folderPath))
            {
                Services.Notifier.Add(UI.Notify.NotifyType.Error, T("Cannot select media"));
                return(new HttpUnauthorizedResult());
            }

            var userMediaFolder = _mediaLibraryService.GetUserMediaFolder();

            if (Services.Authorizer.Authorize(Permissions.ManageOwnMedia) && !Services.Authorizer.Authorize(Permissions.ManageMediaContent))
            {
                _storageProvider.TryCreateFolder(userMediaFolder.MediaPath);
            }

            // If the user is trying to access a folder above his boundaries, redirect him to his home folder
            var rootMediaFolder = _mediaLibraryService.GetRootMediaFolder();

            if (!_mediaLibraryService.CheckMediaFolderPermission(Permissions.SelectMediaContent, folderPath) && !_mediaLibraryService.CanManageMediaFolder(folderPath))
            {
                return(RedirectToAction("Index", new { folderPath = rootMediaFolder.MediaPath, dialog }));
            }

            // let other modules enhance the ui by providing custom navigation and actions
            var explorer = Services.ContentManager.New("MediaLibraryExplorer");

            explorer.Weld(new MediaLibraryExplorerPart());

            var explorerShape       = Services.ContentManager.BuildDisplay(explorer);
            var rootMediaFolderPath = rootMediaFolder == null ? null : rootMediaFolder.MediaPath;

            var viewModel = new MediaManagerIndexViewModel {
                DialogMode            = dialog,
                FolderPath            = folderPath,
                RootFolderPath        = rootMediaFolderPath,
                ChildFoldersViewModel = new MediaManagerChildFoldersViewModel {
                    Children = _mediaLibraryService.GetMediaFolders(rootMediaFolderPath)
                },
                MediaTypes             = _mediaLibraryService.GetMediaTypes(),
                CustomActionsShapes    = explorerShape.Actions,
                CustomNavigationShapes = explorerShape.Navigation,
            };

            foreach (var shape in explorerShape.Actions.Items)
            {
                shape.MediaManagerIndexViewModel = viewModel;
            }

            foreach (var shape in explorerShape.Navigation.Items)
            {
                shape.MediaManagerIndexViewModel = viewModel;
            }

            return(View(viewModel));
        }