Esempio n. 1
0
        /// <summary>
        /// Gets the typed entity by the given id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public TypedEntity GetEntityById(HiveId id)
        {
            var hive = _requestContext.Application.Hive.GetReader <IContentStore>(id.ToUri());

            using (var uow = hive.CreateReadonly())
            {
                return(uow.Repositories.Get(id));
            }
        }
Esempio n. 2
0
 public void CreateHiveIdFromRootValue(string input, string rootShouldBe, string providerShouldBe, string valueShouldBe, string toStringShouldBe)
 {
     var id = new HiveId(input);
     Assert.AreEqual(rootShouldBe, id.ProviderGroupRoot == null ? null : id.ProviderGroupRoot.ToString());
     Assert.AreEqual(providerShouldBe, id.ProviderId);
     Assert.AreEqual(valueShouldBe, id.Value.ToString());
     Assert.AreEqual(toStringShouldBe, id.ToUri().ToString());
     Assert.AreEqual(id.ToString(), new HiveId(id.ToString()).ToString());
 }
Esempio n. 3
0
        public void CreateHiveIdFromRootValue(string input, string rootShouldBe, string providerShouldBe, string valueShouldBe, string toStringShouldBe)
        {
            var id = new HiveId(input);

            Assert.AreEqual(rootShouldBe, id.ProviderGroupRoot == null ? null : id.ProviderGroupRoot.ToString());
            Assert.AreEqual(providerShouldBe, id.ProviderId);
            Assert.AreEqual(valueShouldBe, id.Value.ToString());
            Assert.AreEqual(toStringShouldBe, id.ToUri().ToString());
            Assert.AreEqual(id.ToString(), new HiveId(id.ToString()).ToString());
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the URL of the file in the upload field with the given property alias on the TypedEntity with the given id, at the specified size
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <param name="id">The id.</param>
        /// <param name="propertyAlias">The property alias.</param>
        /// <param name="size">The size (must be a prevalue on the upload property editor).</param>
        /// <returns></returns>
        public static string GetMediaUrl(this UrlHelper url, HiveId id, string propertyAlias, int size)
        {
            var hive = DependencyResolver.Current.GetService <IHiveManager>();

            // We have to handle User/Member entities slightly differently
            if (id.ProviderGroupRoot.AbsoluteUri.StartsWith("security://"))
            {
                using (var uow = hive.OpenReader <ISecurityStore>(id.ToUri()))
                {
                    var item = uow.Repositories.OfRevisionType(FixedStatusTypes.Published).FirstOrDefault(x => x.Id == id);

                    if (item == null)
                    {
                        return(null);
                    }

                    return(url.GetMediaUrl(item, propertyAlias, size));
                }
            }
            else
            {
                using (var uow = hive.OpenReader <IContentStore>(id.ToUri()))
                {
                    var item = uow.Repositories.OfRevisionType(FixedStatusTypes.Published).FirstOrDefault(x => x.Id == id);

                    if (item == null)
                    {
                        return(null);
                    }

                    return(url.GetMediaUrl(item, propertyAlias, size));

                    //var revision = uow.Repositories.Revisions.GetLatestRevision<TypedEntity>(id, FixedStatusTypes.Published);

                    //if (revision == null || revision.Item == null)
                    //    return null;

                    //return url.GetMediaUrl(revision.Item, propertyAlias, size);
                }
            }
        }
Esempio n. 5
0
        public void CreateFromValue_ToUriIsRelative()
        {
            // Arrange
            var val1 = new HiveId("my-string-id");

            // Assert
            var toCompare = new Uri("/string/my-string-id", UriKind.Relative);

            Assert.IsNull(val1.ProviderId);
            Assert.IsNull(val1.ProviderGroupRoot);
            Assert.AreEqual(toCompare, val1.ToUri());
        }
Esempio n. 6
0
 private static void AssertCompareHiveIds(HiveId hiveId, HiveId compareTo)
 {
     Assert.AreEqual(hiveId.ProviderGroupRoot, compareTo.ProviderGroupRoot);
     Assert.AreEqual(hiveId.ProviderId, compareTo.ProviderId);
     Assert.AreEqual(hiveId.Value, compareTo.Value);
     Assert.AreEqual(hiveId.Value.Type, compareTo.Value.Type);
     Assert.AreEqual(hiveId, compareTo);
     Assert.AreEqual(hiveId.ToString(), compareTo.ToString());
     Assert.AreEqual(hiveId.ToUri(), compareTo.ToUri());
     Assert.AreEqual(hiveId.ToString(HiveIdFormatStyle.AsUri), compareTo.ToString(HiveIdFormatStyle.AsUri));
     Assert.AreEqual(hiveId.ToString(HiveIdFormatStyle.UriSafe), compareTo.ToString(HiveIdFormatStyle.UriSafe));
     Assert.AreEqual(hiveId.ToString(HiveIdFormatStyle.AutoSingleValue), compareTo.ToString(HiveIdFormatStyle.AutoSingleValue));
 }
Esempio n. 7
0
        /// <summary>
        /// Gets the inherited permission.
        /// </summary>
        /// <param name="permissionId">The permission id.</param>
        /// <param name="userGroupIds">The user group ids.</param>
        /// <param name="entityId">The entity id.</param>
        /// <returns></returns>
        public PermissionResult GetInheritedPermission(Guid permissionId, IEnumerable <HiveId> userGroupIds, HiveId entityId = default(HiveId))
        {
            // Get the permission reference
            if (entityId.IsNullValueOrEmpty())
            {
                entityId = FixedHiveIds.SystemRoot;
            }

            var entityHive = Hive.GetReader <IContentStore>(entityId.ToUri());

            using (var uow = entityHive.CreateReadonly())
                return(GetInheritedPermission(permissionId, userGroupIds, uow, entityId));
        }
        /// <summary>
        /// Resolves the url for the specified id.
        /// </summary>
        /// <param name="routingEngine"></param>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public static string GetUrl(this IRoutingEngine routingEngine, HiveId id)
        {
            Mandate.ParameterNotEmpty(id, "id");

            var applicationContext = DependencyResolver.Current.GetService <IRebelApplicationContext>();

            var hive = applicationContext.Hive.GetReader <IContentStore>(id.ToUri());

            if (hive != null)
            {
                var key  = CacheKey.Create(new UrlCacheKey(id));
                var item = hive.HiveContext.GenerationScopedCache.GetOrCreate(key, () =>
                {
                    using (var uow = hive.CreateReadonly())
                    {
                        //var entity = uow.Repositories.Get<TypedEntity>(id);
                        var entity = uow.Repositories.OfRevisionType(FixedStatusTypes.Published).InIds(id).FirstOrDefault();
                        if (entity == null)
                        {
                            throw new NullReferenceException("Could not find a TypedEntity in the repository for a content item with id " + id.ToFriendlyString());
                        }

                        return(routingEngine.GetUrlForEntity(entity));
                    }
                });

                var urlResult = item.Value.Item;

                ////return from scoped cache so we don't have to lookup in the same session
                //var urlResult = applicationContext.FrameworkContext.ScopedCache.GetOrCreateTyped<UrlResolutionResult>("nice-url-" + id, () =>
                //    {
                //        using (var uow = hive.CreateReadonly())
                //        {
                //            var entity = uow.Repositories.Get<TypedEntity>(id);
                //            if (entity == null)
                //                throw new NullReferenceException("Could not find a TypedEntity in the repository for a content item with id " + id.ToFriendlyString());

                //            return routingEngine.GetUrlForEntity(entity);
                //        }
                //    });
                if (urlResult.IsSuccess())
                {
                    return(urlResult.Url);
                }

                //return a hashed url with the status
                return("#" + urlResult.Status);
            }

            return(id.ToString());
        }
        /// <summary>
        /// Resolves the url for the specified id.
        /// </summary>
        /// <param name="routingEngine"></param>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public static string GetUrl(this IRoutingEngine routingEngine, HiveId id)
        {
            Mandate.ParameterNotEmpty(id, "id");

            var applicationContext = DependencyResolver.Current.GetService<IRebelApplicationContext>();

            var hive = applicationContext.Hive.GetReader<IContentStore>(id.ToUri());
            if (hive != null)
            {
                var key = CacheKey.Create(new UrlCacheKey(id));
                var item = hive.HiveContext.GenerationScopedCache.GetOrCreate(key, () =>
                    {
                        using (var uow = hive.CreateReadonly())
                        {
                            //var entity = uow.Repositories.Get<TypedEntity>(id);
                            var entity = uow.Repositories.OfRevisionType(FixedStatusTypes.Published).InIds(id).FirstOrDefault();
                            if (entity == null)
                                throw new NullReferenceException("Could not find a TypedEntity in the repository for a content item with id " + id.ToFriendlyString());

                            return routingEngine.GetUrlForEntity(entity);
                        }
                    });

                var urlResult = item.Value.Item;

                ////return from scoped cache so we don't have to lookup in the same session
                //var urlResult = applicationContext.FrameworkContext.ScopedCache.GetOrCreateTyped<UrlResolutionResult>("nice-url-" + id, () =>
                //    {
                //        using (var uow = hive.CreateReadonly())
                //        {
                //            var entity = uow.Repositories.Get<TypedEntity>(id);
                //            if (entity == null)
                //                throw new NullReferenceException("Could not find a TypedEntity in the repository for a content item with id " + id.ToFriendlyString());

                //            return routingEngine.GetUrlForEntity(entity);
                //        }
                //    });
                if (urlResult.IsSuccess())
                {
                    return urlResult.Url;
                }

                //return a hashed url with the status
                return "#" + urlResult.Status;
            }

            return id.ToString();
        }
Esempio n. 10
0
        /// <summary>
        /// Gets the URL of the file in the upload field with the given property alias on the TypedEntity with the given id, at the specified size
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <param name="id">The id.</param>
        /// <param name="propertyAlias">The property alias.</param>
        /// <param name="size">The size (must be a prevalue on the upload property editor).</param>
        /// <returns></returns>
        public static string GetMediaUrl(this UrlHelper url, HiveId id, string propertyAlias, int size)
        {
            var hive = DependencyResolver.Current.GetService <IHiveManager>();

            using (var uow = hive.OpenReader <IContentStore>(id.ToUri()))
            {
                var revision = uow.Repositories.Revisions.GetLatestRevision <TypedEntity>(id, FixedStatusTypes.Published);

                if (revision == null || revision.Item == null)
                {
                    return(null);
                }

                return(url.GetMediaUrl(revision.Item, propertyAlias, size));
            }
        }
        protected override UmbracoTreeResult GetTreeData(HiveId parentId, FormCollection queryStrings)
        {
            //if its the first level
            if (parentId == RootNodeId)
            {
                var hive = BackOfficeRequestContext.Application.Hive.GetReader <ISecurityStore>(
                    //BUG: this check is only a work around because the way that Hive currently works cannot return the 'real' id of the entity. SD.
                    parentId == RootNodeId
                        ? new Uri("security://user-groups/")
                        : parentId.ToUri());

                Mandate.That(hive != null, x => new NotSupportedException("Could not find a hive provider for route: " + parentId.ToString(HiveIdFormatStyle.AsUri)));

                using (var uow = hive.CreateReadonly())
                {
                    //TODO: not sure how this is supposed to be casted to UserGroup
                    var items = uow.Repositories.GetEntityByRelationType <UserGroup>(FixedRelationTypes.DefaultRelationType, FixedHiveIds.UserGroupVirtualRoot)
                                .OrderBy(x => x.Name)
                                .ToArray();

                    foreach (var treeNode in items.Select(user =>
                                                          (TreeNode)CreateTreeNode(
                                                              user.Id,
                                                              queryStrings,
                                                              user.Name,
                                                              Url.GetEditorUrl(user.Id, EditorControllerId, BackOfficeRequestContext.RegisteredComponents, BackOfficeRequestContext.Application.Settings))))
                    {
                        treeNode.Icon        = "tree-user-type";
                        treeNode.HasChildren = false;

                        //add the menu items
                        if (treeNode.Title != "Administrator")
                        {
                            treeNode.AddEditorMenuItem <Delete>(this, "deleteUrl", "Delete");
                        }

                        NodeCollection.Add(treeNode);
                    }
                }
            }
            else
            {
                throw new NotSupportedException("The User Group tree does not support more than 1 level");
            }

            return(UmbracoTree());
        }
Esempio n. 12
0
        public void CreateFully_WithIntValue_ToUri()
        {
            // Arrange
            var val1 = new HiveId(new Uri("storage://stylesheets/"), "io-provider", new HiveIdValue(5));
            var val2 = new HiveId(new Uri("storage://stylesheets/"), "io-provider", new HiveIdValue(5));
            var val3 = new HiveId(new Uri("storage://stylesheets"), "io-provider", new HiveIdValue(5));
            var val4 = new HiveId(new Uri("storage://stylesheets"), "io-provider", new HiveIdValue(5));


            // Assert
            const string comparisonUri = "storage://stylesheets/p__io-provider/v__int32/5";

            Assert.AreEqual(new Uri(comparisonUri), val1.ToUri());
            Assert.AreEqual(new Uri(comparisonUri), val2.ToUri());
            Assert.AreEqual(new Uri(comparisonUri), val3.ToUri());
            Assert.AreEqual(new Uri(comparisonUri), val4.ToUri());
        }
        protected override UmbracoTreeResult GetTreeData(HiveId parentId, FormCollection queryStrings)
        {
            //if its the first level
            if (parentId == RootNodeId)
            {
                var hive = BackOfficeRequestContext.Application.Hive.GetReader<ISecurityStore>(
                    //BUG: this check is only a work around because the way that Hive currently works cannot return the 'real' id of the entity. SD.
                    parentId == RootNodeId
                        ? new Uri(ProviderGroupRoot)
                        : parentId.ToUri());

                Mandate.That(hive != null, x => new NotSupportedException("Could not find a hive provider for route: " + parentId.ToString(HiveIdFormatStyle.AsUri)));

                using (var uow = hive.CreateReadonly())
                {
                    //TODO: not sure how this is supposed to be casted to UserGroup
                    var items = uow.Repositories.GetChildren<UserGroup>(FixedRelationTypes.DefaultRelationType, VirtualRoot)
                        .OrderBy(x => x.Name)
                        .ToArray();

                    foreach (var treeNode in items.Select(userGroup =>
                                (TreeNode)CreateTreeNode(
                                    userGroup.Id,
                                    queryStrings,
                                    userGroup.Name,
                                    GetEditorUrl(userGroup.Id, queryStrings))))
                    {
                        treeNode.Icon = "tree-user-type";
                        treeNode.HasChildren = false;

                        //add the menu items
                        if (treeNode.Title != "Administrator")
                            treeNode.AddEditorMenuItem<Delete>(this, "deleteUrl", "Delete");

                        NodeCollection.Add(treeNode);
                    }
                }
            }
            else
            {
                throw new NotSupportedException("The User Group tree does not support more than 1 level");
            }

            return UmbracoTree();
        }
Esempio n. 14
0
        public void CreateFully_WithStringValue_ToUri()
        {
            // Arrange
            var val1 = new HiveId(new Uri("storage://stylesheets/"), "io-provider", new HiveIdValue("my-filename.aspx"));
            var val2 = new HiveId(new Uri("storage://stylesheets/"), "io-provider", new HiveIdValue("/my-filename.aspx"));
            var val3 = new HiveId(new Uri("storage://stylesheets"), "io-provider", new HiveIdValue("/my-filename.aspx"));
            var val4 = new HiveId(new Uri("storage://stylesheets"), "io-provider", new HiveIdValue("my-filename.aspx"));


            // Assert
            const string comparisonUri = "storage://stylesheets/p__io-provider/v__string/my-filename.aspx";
            const string comparisonUriWithFileSlash = "storage://stylesheets/p__io-provider/v__string/$$my-filename.aspx";

            Assert.AreEqual(new Uri(comparisonUri), val1.ToUri());
            Assert.AreEqual(new Uri(comparisonUriWithFileSlash), val2.ToUri());
            Assert.AreEqual(new Uri(comparisonUriWithFileSlash), val3.ToUri());
            Assert.AreEqual(new Uri(comparisonUri), val4.ToUri());
        }
Esempio n. 15
0
        public void CreateFully_WithGuidValue_ToUri()
        {
            // Arrange
            var guid = Guid.NewGuid();
            var val1 = new HiveId(new Uri("storage://stylesheets/"), "io-provider", new HiveIdValue(guid));
            var val2 = new HiveId(new Uri("storage://stylesheets/"), "io-provider", new HiveIdValue(guid));
            var val3 = new HiveId(new Uri("storage://stylesheets"), "io-provider", new HiveIdValue(guid));
            var val4 = new HiveId(new Uri("storage://stylesheets"), "io-provider", new HiveIdValue(guid));


            // Assert
            string comparisonUri = "storage://stylesheets/p__io-provider/v__guid/" + guid.ToString("N");

            Assert.AreEqual(new Uri(comparisonUri), val1.ToUri());
            Assert.AreEqual(new Uri(comparisonUri), val2.ToUri());
            Assert.AreEqual(new Uri(comparisonUri), val3.ToUri());
            Assert.AreEqual(new Uri(comparisonUri), val4.ToUri());
        }
        protected override UmbracoTreeResult GetTreeData(HiveId parentId, FormCollection queryStrings)
        {
            //if its the first level
            if (parentId == RootNodeId)
            {
                var hive = BackOfficeRequestContext.Application.Hive.GetReader<ISecurityStore>(
                    //BUG: this check is only a work around because the way that Hive currently works cannot return the 'real' id of the entity. SD.
                    (parentId == RootNodeId)
                        ? new Uri("security://users")
                        : parentId.ToUri());

                Mandate.That(hive != null, x => new NotSupportedException("Could not find a hive provider for route: " + parentId.ToString(HiveIdFormatStyle.AsUri)));

                using (var uow = hive.CreateReadonly())
                {
                    var items = uow.Repositories.GetEntityByRelationType<User>(FixedRelationTypes.DefaultRelationType, FixedHiveIds.UserVirtualRoot)
                        .OrderBy(x => x.Name)
                        .ToArray();

                    foreach (var treeNode in items.Select(user =>
                                (TreeNode)CreateTreeNode(
                                    user.Id,
                                    queryStrings,
                                    user.Name,
                                    Url.GetEditorUrl(user.Id, EditorControllerId, BackOfficeRequestContext.RegisteredComponents, BackOfficeRequestContext.Application.Settings))))
                    {
                        treeNode.Icon = "tree-user";
                        treeNode.HasChildren = false;

                        //add the menu items
                        treeNode.AddEditorMenuItem<Delete>(this, "deleteUrl", "Delete");

                        NodeCollection.Add(treeNode);
                    }
                }
            }
            else
            {
                throw new NotSupportedException("The User tree does not support more than 1 level");
            }

            return UmbracoTree();
        }
Esempio n. 17
0
        public PermissionResults GetInheritedPermissions(IEnumerable <HiveId> userGroupIds, HiveId entityId = default(HiveId), params Guid[] permissionIds)
        {
            var results = new List <PermissionResult>();

            // Get the permission reference
            if (entityId.IsNullValueOrEmpty())
            {
                entityId = FixedHiveIds.SystemRoot;
            }

            var entityHive = Hive.GetReader <IContentStore>(entityId.ToUri());

            using (var uow = entityHive.CreateReadonly())
            {
                results.AddRange(permissionIds.Select(permissionId => GetInheritedPermission(permissionId, userGroupIds, uow, entityId)));
            }

            return(new PermissionResults(results.ToArray()));
        }
Esempio n. 18
0
        protected virtual void PopulateFileContentFromStub(FileEditorModel model, HiveId stubFileId, IDictionary <string, string> replacements)
        {
            var stubHive = BackOfficeRequestContext.Application.Hive.GetReader <IFileStore>(stubFileId.ToUri());

            using (var uow = stubHive.CreateReadonly())
            {
                var stubFile = uow.Repositories.Get <File>(stubFileId);
                if (stubFile != null)
                {
                    var fileContent = Encoding.UTF8.GetString(stubFile.ContentBytes);

                    foreach (var replacement in replacements)
                    {
                        fileContent = fileContent.Replace(replacement.Key, replacement.Value);
                    }

                    model.FileContent = fileContent;
                }
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Gets the URL of the file in the upload field with the given property alias on the given TypedEntity at the specific size
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="propertyAlias">The property alias.</param>
        /// <param name="size">The size (must be a prevalue on the upload property editor).</param>
        /// <returns></returns>
        public static string GetMediaUrl(this UrlHelper url, TypedEntity entity, string propertyAlias, int size)
        {
            //TODO: There is a lot of duplication between this and the MediaProxyController (with slight differences). Need to find a way to reuse code.

            var appContext = DependencyResolver.Current.GetService<IUmbracoApplicationContext>();
            using (var securityUow = appContext.Hive.OpenReader<ISecurityStore>())
            {
                // Check to see if anonymous view is allowed
                var anonymousViewAllowed = !appContext.Security.PublicAccess.IsProtected(entity.Id);

                // Get upload property
                var prop = propertyAlias.IsNullOrWhiteSpace()
                    ? entity.Attributes.SingleOrDefault(x => x.AttributeDefinition.AttributeType.RenderTypeProvider.InvariantEquals(CorePluginConstants.FileUploadPropertyEditorId))
                    : entity.Attributes.SingleOrDefault(x => x.AttributeDefinition.Alias == propertyAlias);
                
                if (prop == null || !prop.Values.ContainsKey("MediaId"))
                    return null; // Couldn't find property so return null

                var mediaId = prop.Values["MediaId"].ToString();
                var fileId = new HiveId(prop.Values["Value"].ToString());

                // Get the file
                using (var fileUow = appContext.Hive.OpenReader<IFileStore>(fileId.ToUri()))
                {
                    var file = fileUow.Repositories.Get<File>(fileId);

                    if (file == null)
                        return null; // Couldn't find file so return null

                    // Fetch the thumbnail
                    if (size > 0)
                    {
                        var relation = fileUow.Repositories.GetLazyChildRelations(fileId, FixedRelationTypes.ThumbnailRelationType)
                                .SingleOrDefault(x => x.MetaData.Single(y => y.Key == "size").Value == size.ToString());

                        file = (relation != null && relation.Destination != null)
                            ? (File)relation.Destination
                            : null;
                    }

                    if (file == null)
                        return null; // Couldn't find file so return null

                    if (anonymousViewAllowed && !file.PublicUrl.StartsWith("~/App_Data/")) // Don't proxy
                    {
                        return url.Content(file.PublicUrl);
                    }
                    else // Proxy
                    {
                        //NOTE: THIS IS TEMPORARY CODE UNTIL MEMBER PERMISSIONS IS DONE
                        //if (anonymousViewAllowed)
                        //{
                        //    // If they are anonymous, but media happens to be in app_data folder proxy
                        //    return url.Action("Proxy", "MediaProxy", new { area = "", propertyAlias = prop.AttributeDefinition.Alias, mediaId, size, fileName = file.Name });
                        //}

                        //return null;

                        // Check permissions
                        //var authAttr = new UmbracoAuthorizeAttribute {AllowAnonymous = true, Permissions = new [] { FixedPermissionIds.View }};
                        //var authorized = authAttr.IsAuthorized(url.RequestContext.HttpContext, entity.Id);
                        //if (!authorized)
                        //    return null; // Not authorized so return null

                        var member = appContext.Security.Members.GetCurrent();
                        if (member == null || !appContext.Security.PublicAccess.GetPublicAccessStatus(member.Id, entity.Id).CanAccess)
                        {
                            // Member can't access,  but check to see if logged in identiy is a User, if so, just allow access
                            var wrapper = new HttpContextWrapper(HttpContext.Current);
                            var ticket = wrapper.GetUmbracoAuthTicket();
                            if (ticket == null || ticket.Expired)
                            {
                                return null;
                            }
                        }

                        return url.Action("Proxy", "MediaProxy", new { area = "", propertyAlias = prop.AttributeDefinition.Alias, mediaId, size, fileName = file.Name });
                    }
                }
            }
            
        }
Esempio n. 20
0
        public PermissionResults GetInheritedPermissions(IEnumerable<HiveId> userGroupIds, HiveId entityId = default(HiveId), params Guid[] permissionIds)
        {
            var results = new List<PermissionResult>();

            // Get the permission reference
            if (entityId.IsNullValueOrEmpty())
                entityId = FixedHiveIds.SystemRoot;

            var entityHive = Hive.GetReader<IContentStore>(entityId.ToUri());
            using (var uow = entityHive.CreateReadonly())
            {
                results.AddRange(permissionIds.Select(permissionId => GetInheritedPermission(permissionId, userGroupIds, uow, entityId)));
            }

            return new PermissionResults(results.ToArray());
        }
Esempio n. 21
0
        /// <summary>
        /// Gets the URL of the file in the upload field with the given property alias on the given TypedEntity at the specific size
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="propertyAlias">The property alias.</param>
        /// <param name="size">The size (must be a prevalue on the upload property editor).</param>
        /// <returns></returns>
        public static string GetMediaUrl(this UrlHelper url, TypedEntity entity, string propertyAlias, int size)
        {
            //TODO: There is a lot of duplication between this and the MediaProxyController (with slight differences). Need to find a way to reuse code.

            var appContext = DependencyResolver.Current.GetService <IRebelApplicationContext>();

            using (var securityUow = appContext.Hive.OpenReader <ISecurityStore>())
            {
                // Check to see if anonymous view is allowed
                var anonymousViewAllowed = !appContext.Security.PublicAccess.IsProtected(entity.Id);

                // Get upload property
                var prop = propertyAlias.IsNullOrWhiteSpace()
                    ? entity.Attributes.SingleOrDefault(x => x.AttributeDefinition.AttributeType.RenderTypeProvider.InvariantEquals(CorePluginConstants.FileUploadPropertyEditorId))
                    : entity.Attributes.SingleOrDefault(x => x.AttributeDefinition.Alias == propertyAlias);

                if (prop == null || !prop.Values.ContainsKey("MediaId"))
                {
                    return(null); // Couldn't find property so return null
                }
                var mediaId = prop.Values["MediaId"].ToString();
                var fileId  = new HiveId(prop.Values["Value"].ToString());

                // Get the file
                using (var fileUow = appContext.Hive.OpenReader <IFileStore>(fileId.ToUri()))
                {
                    var file = fileUow.Repositories.Get <File>(fileId);

                    if (file == null)
                    {
                        return(null); // Couldn't find file so return null
                    }
                    // Fetch the thumbnail
                    if (size > 0)
                    {
                        var relation = fileUow.Repositories.GetLazyChildRelations(fileId, FixedRelationTypes.ThumbnailRelationType)
                                       .SingleOrDefault(x => x.MetaData.Single(y => y.Key == "size").Value == size.ToString());

                        file = (relation != null && relation.Destination != null)
                            ? (File)relation.Destination
                            : null;
                    }

                    if (file == null)
                    {
                        return(null);                                                      // Couldn't find file so return null
                    }
                    if (anonymousViewAllowed && !file.PublicUrl.StartsWith("~/App_Data/")) // Don't proxy
                    {
                        return(url.Content(file.PublicUrl));
                    }
                    else // Proxy
                    {
                        //NOTE: THIS IS TEMPORARY CODE UNTIL MEMBER PERMISSIONS IS DONE
                        //if (anonymousViewAllowed)
                        //{
                        //    // If they are anonymous, but media happens to be in app_data folder proxy
                        //    return url.Action("Proxy", "MediaProxy", new { area = "", propertyAlias = prop.AttributeDefinition.Alias, mediaId, size, fileName = file.Name });
                        //}

                        //return null;

                        // Check permissions
                        //var authAttr = new RebelAuthorizeAttribute {AllowAnonymous = true, Permissions = new [] { FixedPermissionIds.View }};
                        //var authorized = authAttr.IsAuthorized(url.RequestContext.HttpContext, entity.Id);
                        //if (!authorized)
                        //    return null; // Not authorized so return null

                        var member = appContext.Security.Members.GetCurrent();
                        if (member == null || !appContext.Security.PublicAccess.GetPublicAccessStatus(member.Id, entity.Id).CanAccess)
                        {
                            // Member can't access,  but check to see if logged in identiy is a User, if so, just allow access
                            var wrapper = new HttpContextWrapper(HttpContext.Current);
                            var ticket  = wrapper.GetRebelAuthTicket();
                            if (ticket == null || ticket.Expired)
                            {
                                return(null);
                            }
                        }

                        return(url.Action("Proxy", "MediaProxy", new { area = "", propertyAlias = prop.AttributeDefinition.Alias, mediaId, size, fileName = file.Name }));
                    }
                }
            }
        }
Esempio n. 22
0
 protected override ReadonlyGroupUnitFactory GetHiveProvider(HiveId parentId, FormCollection queryStrings)
 {
     //we need to get the Hive Map based on Id                        
     return BackOfficeRequestContext.Application.Hive.GetReader(
         parentId == FixedHiveIds.MediaVirtualRoot ? new Uri("media://") : parentId.ToUri());
 }
        /// <summary>
        /// This adds some required elements to the ViewBag so that the Create view renders correctly
        /// </summary>
        /// <param name="model"></param>
        protected virtual void EnsureViewData(CreateFileModel model)
        {
            var controllerName = UmbracoController.GetControllerName(this.GetType());

            // Update thumbnails
            var thumbnailFolder = Url.Content(BackOfficeRequestContext.Application.Settings.UmbracoFolders.DocTypeThumbnailFolder);
            model.AvailableFileExtensions = AllowedFileExtensions;
            model.FileThumbnail = thumbnailFolder + "/doc.png";
            model.FolderThumbnail = thumbnailFolder + "/folder.png";

            // Populate avilable stubs
            var stubDirHiveId = new HiveId(new Uri("storage://stubs"), "stubs", new HiveIdValue(controllerName));
            var stubHive = BackOfficeRequestContext.Application.Hive.GetReader<IFileStore>(stubDirHiveId.ToUri());
            using (var uow = stubHive.CreateReadonly())
            {
                var stubFileRelations = uow.Repositories.GetChildRelations(stubDirHiveId, FixedRelationTypes.DefaultRelationType);
                if(stubFileRelations.Any())
                {
                    var stubFiles = uow.Repositories.Get<File>(true, stubFileRelations.Select(x => x.DestinationId).ToArray());
                    if(stubFiles.Any())
                    {
                        model.AvailableStubs = stubFiles.Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString() });
                    }
                }
            }

            // Populate viewbag
            ViewBag.Title = CreateNewTitle;
            ViewBag.ControllerId = UmbracoController.GetControllerId<EditorAttribute>(GetType());
        }
Esempio n. 24
0
 protected override ReadonlyGroupUnitFactory GetHiveProvider(HiveId parentId, FormCollection queryStrings)
 {
     //we need to get the Hive Map based on Id
     return(BackOfficeRequestContext.Application.Hive.GetReader(
                parentId == FixedHiveIds.DictionaryVirtualRoot ? new Uri("dictionary://") : parentId.ToUri()));
 }
        public virtual ActionResult Proxy(string propertyAlias, string mediaId, int size, string fileName)
        {
            var app = RoutableRequestContext.Application;
            using (var uow = app.Hive.OpenReader<IContentStore>())
            {
                // Lookup a TypedEntity with an Upload field that has a MediaId of the mediaId property
                var entity =
                    uow.Repositories.SingleOrDefault(
                        x => x.Attribute<string>(propertyAlias, "MediaId") == mediaId);

                if (entity == null)
                    return HttpNotFound();

                // Check permissions
                //var authAttr = new UmbracoAuthorizeAttribute { AllowAnonymous = true, Permissions = new[] { FixedPermissionIds.View } };
                //var authorized = authAttr.IsAuthorized(HttpContext, entity.Id);
                //if (!authorized)
                //    return null; // Not authorized so return null

                //NOTE: THIS IS TEMPORARY CODE UNTIL MEMBER PERMISSIONS IS DONE
                // Just perform an Anonymour permission check
                var resultIds = entity.Id.AsEnumerableOfOne().ToArray();

                using (var securityUow = app.Hive.OpenReader<ISecurityStore>())
                    resultIds = resultIds.FilterAnonymousWithPermissions(app.Security, uow, securityUow, new Guid(FixedPermissionIds.View)).ToArray();

                if (resultIds.Length == 0 && !HttpContext.User.Identity.IsAuthenticated)
                {
                    return null;
                }

                //NOTE: END TEMP CODE

                // Find the upload property
                var property = entity.Attributes.SingleOrDefault(x => x.AttributeDefinition.AttributeType.RenderTypeProvider.Equals(CorePluginConstants.FileUploadPropertyEditorId, StringComparison.InvariantCultureIgnoreCase) && x.Values["MediaId"].ToString() == mediaId);

                if (property == null)
                    return HttpNotFound();

                // Get the file
                var fileId = new HiveId(property.DynamicValue);
                using (var uow2 = app.Hive.OpenReader<IFileStore>(fileId.ToUri()))
                {
                    var file = uow2.Repositories.Get<File>(fileId);

                    if (size > 0)
                    {
                        // Look for thubnail file
                        var relation = uow2.Repositories.GetLazyChildRelations(fileId, FixedRelationTypes.ThumbnailRelationType)
                            .SingleOrDefault(x => x.MetaData.Single(y => y.Key == "size").Value == size.ToString());

                        if (relation != null && relation.Destination != null)
                        {
                            var thumbnail = (File)relation.Destination;
                            return File(thumbnail.ContentBytes, thumbnail.GetMimeType());
                        }

                        return HttpNotFound();
                    }

                    if (file != null)
                        return File(file.ContentBytes, file.GetMimeType());
                }
            }

            return HttpNotFound();
        }
Esempio n. 26
0
        /// <summary>
        /// Displays the image, ensuring the correct permissions are set.
        /// </summary>
        /// <param name="propertyAlias"></param>
        /// <param name="mediaId"></param>
        /// <param name="size"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public virtual ActionResult Proxy(string propertyAlias, string mediaId, int size, string fileName)
        {
            if (mediaId.IsNullOrWhiteSpace())
                return HttpNotFound();

            var app = RoutableRequestContext.Application;
            using (var uow = app.Hive.OpenReader<IContentStore>())
            {
                // Lookup a TypedEntity with an Upload field that has a MediaId of the mediaId property
                var entity =
                    uow.Repositories.SingleOrDefault(
                        x => x.InnerAttribute<string>(propertyAlias, "MediaId") == mediaId);

                if (entity == null)
                    return HttpNotFound();

                var member = app.Security.Members.GetCurrent();
                if (member == null || !app.Security.PublicAccess.GetPublicAccessStatus(member.Id, entity.Id).CanAccess)
                {
                    // Member can't access,  but check to see if logged in identiy is a User, if so, just allow access
                    var ticket = HttpContext.GetRebelAuthTicket();
                    if (ticket == null || ticket.Expired)
                    {
                        return HttpNotFound();
                    }
                }

                // Find the upload property
                var property = entity.Attributes.SingleOrDefault(x => x.AttributeDefinition.AttributeType.RenderTypeProvider.Equals(CorePluginConstants.FileUploadPropertyEditorId, StringComparison.InvariantCultureIgnoreCase) && x.Values["MediaId"].ToString() == mediaId);

                if (property == null)
                    return HttpNotFound();

                // Get the file
                var fileId = new HiveId(property.DynamicValue);
                using (var uow2 = app.Hive.OpenReader<IFileStore>(fileId.ToUri()))
                {
                    var file = uow2.Repositories.Get<File>(fileId);

                    if (size > 0)
                    {
                        // Look for thubnail file
                        var relation = uow2.Repositories.GetLazyChildRelations(fileId, FixedRelationTypes.ThumbnailRelationType)
                            .SingleOrDefault(x => x.MetaData.Single(y => y.Key == "size").Value == size.ToString());

                        if (relation != null && relation.Destination != null)
                        {
                            var thumbnail = (File)relation.Destination;
                            return File(thumbnail.ContentBytes, thumbnail.GetMimeType());
                        }

                        return HttpNotFound();
                    }

                    if (file != null)
                        return File(file.ContentBytes, file.GetMimeType());
                }
            }

            return HttpNotFound();
        }
        public virtual ActionResult Proxy(string propertyAlias, string mediaId, int size, string fileName)
        {
            var app = RoutableRequestContext.Application;

            using (var uow = app.Hive.OpenReader <IContentStore>())
            {
                // Lookup a TypedEntity with an Upload field that has a MediaId of the mediaId property
                var entity =
                    uow.Repositories.SingleOrDefault(
                        x => x.Attribute <string>(propertyAlias, "MediaId") == mediaId);

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

                // Check permissions
                //var authAttr = new UmbracoAuthorizeAttribute { AllowAnonymous = true, Permissions = new[] { FixedPermissionIds.View } };
                //var authorized = authAttr.IsAuthorized(HttpContext, entity.Id);
                //if (!authorized)
                //    return null; // Not authorized so return null

                //NOTE: THIS IS TEMPORARY CODE UNTIL MEMBER PERMISSIONS IS DONE
                // Just perform an Anonymour permission check
                var resultIds = entity.Id.AsEnumerableOfOne().ToArray();

                using (var securityUow = app.Hive.OpenReader <ISecurityStore>())
                    resultIds = resultIds.FilterAnonymousWithPermissions(app.Security, uow, securityUow, new Guid(FixedPermissionIds.View)).ToArray();

                if (resultIds.Length == 0 && !HttpContext.User.Identity.IsAuthenticated)
                {
                    return(null);
                }

                //NOTE: END TEMP CODE

                // Find the upload property
                var property = entity.Attributes.SingleOrDefault(x => x.AttributeDefinition.AttributeType.RenderTypeProvider.Equals(CorePluginConstants.FileUploadPropertyEditorId, StringComparison.InvariantCultureIgnoreCase) && x.Values["MediaId"].ToString() == mediaId);

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

                // Get the file
                var fileId = new HiveId(property.DynamicValue);
                using (var uow2 = app.Hive.OpenReader <IFileStore>(fileId.ToUri()))
                {
                    var file = uow2.Repositories.Get <File>(fileId);

                    if (size > 0)
                    {
                        // Look for thubnail file
                        var relation = uow2.Repositories.GetLazyChildRelations(fileId, FixedRelationTypes.ThumbnailRelationType)
                                       .SingleOrDefault(x => x.MetaData.Single(y => y.Key == "size").Value == size.ToString());

                        if (relation != null && relation.Destination != null)
                        {
                            var thumbnail = (File)relation.Destination;
                            return(File(thumbnail.ContentBytes, thumbnail.GetMimeType()));
                        }

                        return(HttpNotFound());
                    }

                    if (file != null)
                    {
                        return(File(file.ContentBytes, file.GetMimeType()));
                    }
                }
            }

            return(HttpNotFound());
        }
Esempio n. 28
0
        /// <summary>
        /// Displays the image, ensuring the correct permissions are set.
        /// </summary>
        /// <param name="propertyAlias"></param>
        /// <param name="mediaId"></param>
        /// <param name="size"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public virtual ActionResult Proxy(string propertyAlias, string mediaId, int size, string fileName)
        {
            if (mediaId.IsNullOrWhiteSpace())
            {
                return(HttpNotFound());
            }

            var app = RoutableRequestContext.Application;

            using (var uow = app.Hive.OpenReader <IContentStore>())
            {
                // Lookup a TypedEntity with an Upload field that has a MediaId of the mediaId property
                var entity =
                    uow.Repositories.SingleOrDefault(
                        x => x.InnerAttribute <string>(propertyAlias, "MediaId") == mediaId);

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

                var member = app.Security.Members.GetCurrent();
                if (member == null || !app.Security.PublicAccess.GetPublicAccessStatus(member.Id, entity.Id).CanAccess)
                {
                    // Member can't access,  but check to see if logged in identiy is a User, if so, just allow access
                    var ticket = HttpContext.GetRebelAuthTicket();
                    if (ticket == null || ticket.Expired)
                    {
                        return(HttpNotFound());
                    }
                }

                // Find the upload property
                var property = entity.Attributes.SingleOrDefault(x => x.AttributeDefinition.AttributeType.RenderTypeProvider.Equals(CorePluginConstants.FileUploadPropertyEditorId, StringComparison.InvariantCultureIgnoreCase) && x.Values["MediaId"].ToString() == mediaId);

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

                // Get the file
                var fileId = new HiveId(property.DynamicValue);
                using (var uow2 = app.Hive.OpenReader <IFileStore>(fileId.ToUri()))
                {
                    var file = uow2.Repositories.Get <File>(fileId);

                    if (size > 0)
                    {
                        // Look for thubnail file
                        var relation = uow2.Repositories.GetLazyChildRelations(fileId, FixedRelationTypes.ThumbnailRelationType)
                                       .SingleOrDefault(x => x.MetaData.Single(y => y.Key == "size").Value == size.ToString());

                        if (relation != null && relation.Destination != null)
                        {
                            var thumbnail = (File)relation.Destination;
                            return(File(thumbnail.ContentBytes, thumbnail.GetMimeType()));
                        }

                        return(HttpNotFound());
                    }

                    if (file != null)
                    {
                        return(File(file.ContentBytes, file.GetMimeType()));
                    }
                }
            }

            return(HttpNotFound());
        }
Esempio n. 29
0
        public JsonResult MacroContents(HiveId currentNodeId, string macroAlias,
                                        //custom model binder for this json dictionary
                                        [ModelBinder(typeof(JsonDictionaryModelBinder))]
                                        IDictionary <string, object> macroParams)
        {
            if (macroParams == null)
            {
                macroParams = new Dictionary <string, object>();
            }

            var stringOutput = _macroRenderer.RenderMacroAsString(
                macroAlias, macroParams.ToDictionary(x => x.Key, x => x.Value.ToString()), ControllerContext, true,
                () =>
            {
                if (currentNodeId.IsNullValueOrEmpty())
                {
                    return(null);
                }

                using (var uow = RoutableRequestContext.Application.Hive.OpenReader <IContentStore>(currentNodeId.ToUri()))
                {
                    var entity = uow.Repositories.Get <TypedEntity>(currentNodeId);
                    if (entity == null)
                    {
                        throw new NullReferenceException("Could not find entity with id " + currentNodeId.ToString());
                    }

                    return(RoutableRequestContext.Application.FrameworkContext.TypeMappers.Map <Content>(entity));
                }
            });

            return(Json(new
            {
                macroContent = stringOutput
            }));
        }
Esempio n. 30
0
        public JsonResult MacroContents(HiveId currentNodeId, string macroAlias,
            //custom model binder for this json dictionary
            [ModelBinder(typeof(JsonDictionaryModelBinder))]
            IDictionary<string, object> macroParams)
        {
            if (macroParams == null)
                macroParams = new Dictionary<string, object>();

            var stringOutput = _macroRenderer.RenderMacroAsString(
                macroAlias, macroParams.ToDictionary(x => x.Key, x => x.Value.ToString()), ControllerContext, true,
                () =>
                {

                    if (currentNodeId.IsNullValueOrEmpty())
                        return null;

                    using (var uow = RoutableRequestContext.Application.Hive.OpenReader<IContentStore>(currentNodeId.ToUri()))
                    {
                        var entity = uow.Repositories.Get<TypedEntity>(currentNodeId);
                        if (entity == null)
                            throw new NullReferenceException("Could not find entity with id " + currentNodeId.ToString());

                        return RoutableRequestContext.Application.FrameworkContext.TypeMappers.Map<Content>(entity);
                    }
                });

            return Json(new
            {
                macroContent = stringOutput
            });
        }
Esempio n. 31
0
        /// <summary>
        /// This adds some required elements to the ViewBag so that the Create view renders correctly
        /// </summary>
        /// <param name="model"></param>
        protected virtual void EnsureViewData(CreateFileModel model)
        {
            var controllerName = UmbracoController.GetControllerName(this.GetType());

            // Update thumbnails
            var thumbnailFolder = Url.Content(BackOfficeRequestContext.Application.Settings.UmbracoFolders.DocTypeThumbnailFolder);

            model.AvailableFileExtensions = AllowedFileExtensions;
            model.FileThumbnail           = thumbnailFolder + "/doc.png";
            model.FolderThumbnail         = thumbnailFolder + "/folder.png";

            // Populate avilable stubs
            var stubDirHiveId = new HiveId(new Uri("storage://stubs"), "stubs", new HiveIdValue(controllerName));
            var stubHive      = BackOfficeRequestContext.Application.Hive.GetReader <IFileStore>(stubDirHiveId.ToUri());

            using (var uow = stubHive.CreateReadonly())
            {
                var stubFileRelations = uow.Repositories.GetChildRelations(stubDirHiveId, FixedRelationTypes.DefaultRelationType);
                if (stubFileRelations.Any())
                {
                    var stubFiles = uow.Repositories.Get <File>(true, stubFileRelations.Select(x => x.DestinationId).ToArray());
                    if (stubFiles.Any())
                    {
                        model.AvailableStubs = stubFiles.Select(x => new SelectListItem {
                            Text = x.Name, Value = x.Id.ToString()
                        });
                    }
                }
            }

            // Populate viewbag
            ViewBag.Title        = CreateNewTitle;
            ViewBag.ControllerId = UmbracoController.GetControllerId <EditorAttribute>(GetType());
        }
Esempio n. 32
0
        /// <summary>
        /// Gets the URL of the file in the upload field with the given property alias on the TypedEntity with the given id, at the specified size
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <param name="id">The id.</param>
        /// <param name="propertyAlias">The property alias.</param>
        /// <param name="size">The size (must be a prevalue on the upload property editor).</param>
        /// <returns></returns>
        public static string GetMediaUrl(this UrlHelper url, HiveId id, string propertyAlias, int size)
        {
            var hive = DependencyResolver.Current.GetService<IHiveManager>();

            // We have to handle User/Member entities slightly differently
            if(id.ProviderGroupRoot.AbsoluteUri.StartsWith("security://"))
            {
                using (var uow = hive.OpenReader<ISecurityStore>(id.ToUri()))
                {
                    var item = uow.Repositories.OfRevisionType(FixedStatusTypes.Published).FirstOrDefault(x => x.Id == id);

                    if (item == null) return null;

                    return url.GetMediaUrl(item, propertyAlias, size);
                }
            }
            else
            {
                using (var uow = hive.OpenReader<IContentStore>(id.ToUri()))
                {
                    var item = uow.Repositories.OfRevisionType(FixedStatusTypes.Published).FirstOrDefault(x => x.Id == id);

                    if (item == null) return null;

                    return url.GetMediaUrl(item, propertyAlias, size);

                    //var revision = uow.Repositories.Revisions.GetLatestRevision<TypedEntity>(id, FixedStatusTypes.Published);

                    //if (revision == null || revision.Item == null)
                    //    return null;

                    //return url.GetMediaUrl(revision.Item, propertyAlias, size);
                }
            }
        }
Esempio n. 33
0
 /// <summary>
 /// Gets the typed entity by the given id.
 /// </summary>
 /// <param name="id">The id.</param>
 /// <returns></returns>
 public TypedEntity GetEntityById(HiveId id)
 {
     var hive = _requestContext.Application.Hive.GetReader<IContentStore>(id.ToUri());
     using (var uow = hive.CreateReadonly())
     {
         return uow.Repositories.Get(id);
     }
 }
Esempio n. 34
0
        public void CreateFully_WithGuidValue_ToUri()
        {
            // Arrange
            var guid = Guid.NewGuid();
            var val1 = new HiveId(new Uri("storage://stylesheets/"), "io-provider", new HiveIdValue(guid));
            var val2 = new HiveId(new Uri("storage://stylesheets/"), "io-provider", new HiveIdValue(guid));
            var val3 = new HiveId(new Uri("storage://stylesheets"), "io-provider", new HiveIdValue(guid));
            var val4 = new HiveId(new Uri("storage://stylesheets"), "io-provider", new HiveIdValue(guid));


            // Assert
            string comparisonUri = "storage://stylesheets/p__io-provider/v__guid/" + guid.ToString("N");
            Assert.AreEqual(new Uri(comparisonUri), val1.ToUri());
            Assert.AreEqual(new Uri(comparisonUri), val2.ToUri());
            Assert.AreEqual(new Uri(comparisonUri), val3.ToUri());
            Assert.AreEqual(new Uri(comparisonUri), val4.ToUri());
        }
        protected virtual void PopulateFileContentFromStub(FileEditorModel model, HiveId stubFileId, IDictionary<string, string> replacements)
        {
            var stubHive = BackOfficeRequestContext.Application.Hive.GetReader<IFileStore>(stubFileId.ToUri());
            using (var uow = stubHive.CreateReadonly())
            {
                var stubFile = uow.Repositories.Get<File>(stubFileId);
                if(stubFile != null)
                {
                    var fileContent = Encoding.UTF8.GetString(stubFile.ContentBytes);

                    foreach (var replacement in replacements)
                        fileContent = fileContent.Replace(replacement.Key, replacement.Value);

                    model.FileContent = fileContent;
                }
            }
        }
Esempio n. 36
0
        public void CreateFully_WithIntValue_ToUri()
        {
            // Arrange
            var val1 = new HiveId(new Uri("storage://stylesheets/"), "io-provider", new HiveIdValue(5));
            var val2 = new HiveId(new Uri("storage://stylesheets/"), "io-provider", new HiveIdValue(5));
            var val3 = new HiveId(new Uri("storage://stylesheets"), "io-provider", new HiveIdValue(5));
            var val4 = new HiveId(new Uri("storage://stylesheets"), "io-provider", new HiveIdValue(5));


            // Assert
            const string comparisonUri = "storage://stylesheets/p__io-provider/v__int32/5";
            Assert.AreEqual(new Uri(comparisonUri), val1.ToUri());
            Assert.AreEqual(new Uri(comparisonUri), val2.ToUri());
            Assert.AreEqual(new Uri(comparisonUri), val3.ToUri());
            Assert.AreEqual(new Uri(comparisonUri), val4.ToUri());
        }
Esempio n. 37
0
        /// <summary>
        /// Gets the inherited permission.
        /// </summary>
        /// <param name="permissionId">The permission id.</param>
        /// <param name="userGroupIds">The user group ids.</param>
        /// <param name="entityId">The entity id.</param>
        /// <returns></returns>
        public PermissionResult GetInheritedPermission(Guid permissionId, IEnumerable<HiveId> userGroupIds, HiveId entityId = default(HiveId))
        {
            // Get the permission reference
            if (entityId.IsNullValueOrEmpty())
                entityId = FixedHiveIds.SystemRoot;

            var entityHive = Hive.GetReader<IContentStore>(entityId.ToUri());
            using (var uow = entityHive.CreateReadonly())
                return GetInheritedPermission(permissionId, userGroupIds, uow, entityId);
        }
Esempio n. 38
0
 private static void AssertCompareHiveIds(HiveId hiveId, HiveId compareTo)
 {
     Assert.AreEqual(hiveId.ProviderGroupRoot, compareTo.ProviderGroupRoot);
     Assert.AreEqual(hiveId.ProviderId, compareTo.ProviderId);
     Assert.AreEqual(hiveId.Value, compareTo.Value);
     Assert.AreEqual(hiveId.Value.Type, compareTo.Value.Type);
     Assert.AreEqual(hiveId, compareTo);
     Assert.AreEqual(hiveId.ToString(), compareTo.ToString());
     Assert.AreEqual(hiveId.ToUri(), compareTo.ToUri());
     Assert.AreEqual(hiveId.ToString(HiveIdFormatStyle.AsUri), compareTo.ToString(HiveIdFormatStyle.AsUri));
     Assert.AreEqual(hiveId.ToString(HiveIdFormatStyle.UriSafe), compareTo.ToString(HiveIdFormatStyle.UriSafe));
     Assert.AreEqual(hiveId.ToString(HiveIdFormatStyle.AutoSingleValue), compareTo.ToString(HiveIdFormatStyle.AutoSingleValue));
 }
Esempio n. 39
0
        public void CreateFromValue_ToUriIsRelative()
        {
            // Arrange
            var val1 = new HiveId("my-string-id");

            // Assert
            var toCompare = new Uri("/string/my-string-id", UriKind.Relative);
            Assert.IsNull(val1.ProviderId);
            Assert.IsNull(val1.ProviderGroupRoot);
            Assert.AreEqual(toCompare, val1.ToUri());
        }
 /// <summary>
 /// Returns the Hive provider to be used to query for child nodes
 /// </summary>
 /// <param name="parentId"></param>
 /// <param name="queryStrings"></param>
 /// <returns></returns>
 protected override ReadonlyGroupUnitFactory GetHiveProvider(HiveId parentId, FormCollection queryStrings)
 {
     return(BackOfficeRequestContext.Application.Hive.GetReader(
                parentId == FixedHiveIds.ContentVirtualRoot ? new Uri("content://") : parentId.ToUri()));
 }
 /// <summary>
 /// Returns the Hive provider to be used to query for child nodes
 /// </summary>
 /// <param name="parentId"></param>
 /// <param name="queryStrings"></param>
 /// <returns></returns>
 protected override ReadonlyGroupUnitFactory GetHiveProvider(HiveId parentId, FormCollection queryStrings)
 {
     return BackOfficeRequestContext.Application.Hive.GetReader(
         parentId == FixedHiveIds.ContentVirtualRoot ? new Uri("content://") : parentId.ToUri());
 }
Esempio n. 42
0
        public void CreateFully_WithStringValue_ToUri()
        {
            // Arrange
            var val1 = new HiveId(new Uri("storage://stylesheets/"), "io-provider", new HiveIdValue("my-filename.aspx"));
            var val2 = new HiveId(new Uri("storage://stylesheets/"), "io-provider", new HiveIdValue("/my-filename.aspx"));
            var val3 = new HiveId(new Uri("storage://stylesheets"), "io-provider", new HiveIdValue("/my-filename.aspx"));
            var val4 = new HiveId(new Uri("storage://stylesheets"), "io-provider", new HiveIdValue("my-filename.aspx"));


            // Assert
            const string comparisonUri = "storage://stylesheets/p__io-provider/v__string/my-filename.aspx";
            const string comparisonUriWithFileSlash = "storage://stylesheets/p__io-provider/v__string/$$my-filename.aspx";
            Assert.AreEqual(new Uri(comparisonUri), val1.ToUri());
            Assert.AreEqual(new Uri(comparisonUriWithFileSlash), val2.ToUri());
            Assert.AreEqual(new Uri(comparisonUriWithFileSlash), val3.ToUri());
            Assert.AreEqual(new Uri(comparisonUri), val4.ToUri());
        }