Пример #1
0
        public Rock.CMS.DTO.Block ApiGet(string id, string apiKey)
        {
            using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope())
            {
                Rock.CMS.UserService userService = new Rock.CMS.UserService();
                Rock.CMS.User        user        = userService.Queryable().Where(u => u.ApiKey == apiKey).FirstOrDefault();

                if (user != null)
                {
                    uow.objectContext.Configuration.ProxyCreationEnabled = false;
                    Rock.CMS.BlockService BlockService = new Rock.CMS.BlockService();
                    Rock.CMS.Block        Block        = BlockService.Get(int.Parse(id));
                    if (Block.Authorized("View", user))
                    {
                        return(Block.DataTransferObject);
                    }
                    else
                    {
                        throw new WebFaultException <string>("Not Authorized to View this Block", System.Net.HttpStatusCode.Forbidden);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Пример #2
0
        public void UpdateBlock(string id, Rock.CMS.DTO.Block Block)
        {
            var currentUser = Rock.CMS.UserService.GetCurrentUser();

            if (currentUser == null)
            {
                throw new WebFaultException <string>("Must be logged in", System.Net.HttpStatusCode.Forbidden);
            }

            using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope())
            {
                uow.objectContext.Configuration.ProxyCreationEnabled = false;
                Rock.CMS.BlockService BlockService  = new Rock.CMS.BlockService();
                Rock.CMS.Block        existingBlock = BlockService.Get(int.Parse(id));
                if (existingBlock.Authorized("Edit", currentUser))
                {
                    uow.objectContext.Entry(existingBlock).CurrentValues.SetValues(Block);

                    if (existingBlock.IsValid)
                    {
                        BlockService.Save(existingBlock, currentUser.PersonId);
                    }
                    else
                    {
                        throw new WebFaultException <string>(existingBlock.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to Edit this Block", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Пример #3
0
        public void ApiDeleteBlock(string id, string apiKey)
        {
            using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope())
            {
                Rock.CMS.UserService userService = new Rock.CMS.UserService();
                Rock.CMS.User        user        = userService.Queryable().Where(u => u.ApiKey == apiKey).FirstOrDefault();

                if (user != null)
                {
                    uow.objectContext.Configuration.ProxyCreationEnabled = false;
                    Rock.CMS.BlockService BlockService = new Rock.CMS.BlockService();
                    Rock.CMS.Block        Block        = BlockService.Get(int.Parse(id));
                    if (Block.Authorized("Edit", user))
                    {
                        BlockService.Delete(Block, user.PersonId);
                        BlockService.Save(Block, user.PersonId);
                    }
                    else
                    {
                        throw new WebFaultException <string>("Not Authorized to Edit this Block", System.Net.HttpStatusCode.Forbidden);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Пример #4
0
        public void DeleteBlock(string id)
        {
            var currentUser = Rock.CMS.UserService.GetCurrentUser();

            if (currentUser == null)
            {
                throw new WebFaultException <string>("Must be logged in", System.Net.HttpStatusCode.Forbidden);
            }

            using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope())
            {
                uow.objectContext.Configuration.ProxyCreationEnabled = false;
                Rock.CMS.BlockService BlockService = new Rock.CMS.BlockService();
                Rock.CMS.Block        Block        = BlockService.Get(int.Parse(id));
                if (Block.Authorized("Edit", currentUser))
                {
                    BlockService.Delete(Block, currentUser.PersonId);
                    BlockService.Save(Block, currentUser.PersonId);
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to Edit this Block", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Пример #5
0
        public void ApiCreateBlock(string apiKey, Rock.CMS.DTO.Block Block)
        {
            using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope())
            {
                Rock.CMS.UserService userService = new Rock.CMS.UserService();
                Rock.CMS.User        user        = userService.Queryable().Where(u => u.ApiKey == apiKey).FirstOrDefault();

                if (user != null)
                {
                    uow.objectContext.Configuration.ProxyCreationEnabled = false;
                    Rock.CMS.BlockService BlockService  = new Rock.CMS.BlockService();
                    Rock.CMS.Block        existingBlock = new Rock.CMS.Block();
                    BlockService.Add(existingBlock, user.PersonId);
                    uow.objectContext.Entry(existingBlock).CurrentValues.SetValues(Block);

                    if (existingBlock.IsValid)
                    {
                        BlockService.Save(existingBlock, user.PersonId);
                    }
                    else
                    {
                        throw new WebFaultException <string>(existingBlock.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Пример #6
0
        private void LoadBlockTypes()
        {
            using (new Rock.Data.UnitOfWorkScope())
            {
                Rock.CMS.BlockService blockService = new Rock.CMS.BlockService();

                // Add any unregistered blocks
                foreach (Rock.CMS.Block block in blockService.GetUnregisteredBlocks(Request.MapPath("~")))
                {
                    try
                    {
                        Control control = LoadControl(block.Path);
                        if (control is Rock.Web.UI.Block)
                        {
                            block.Name = Path.GetFileNameWithoutExtension(block.Path);
                            // Split the name on intercapped changes (ie, "HelloWorld" becomes "Hello World")
                            block.Name        = System.Text.RegularExpressions.Regex.Replace(block.Name, "([a-z](?=[A-Z])|[A-Z](?=[A-Z][a-z]))", "$1 ");
                            block.Description = block.Path;

                            blockService.Add(block, CurrentPersonId);
                            blockService.Save(block, CurrentPersonId);
                        }
                    }
                    catch
                    {
                    }
                }

                ddlBlockType.DataSource     = blockService.Queryable().ToList();
                ddlBlockType.DataTextField  = "Name";
                ddlBlockType.DataValueField = "Id";
                ddlBlockType.DataBind();
            }
        }
Пример #7
0
        public void ApiDeleteBlock( string id, string apiKey )
        {
            using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() )
            {
                Rock.CMS.UserService userService = new Rock.CMS.UserService();
                Rock.CMS.User user = userService.Queryable().Where( u => u.ApiKey == apiKey ).FirstOrDefault();

                if (user != null)
                {
                    uow.objectContext.Configuration.ProxyCreationEnabled = false;
                    Rock.CMS.BlockService BlockService = new Rock.CMS.BlockService();
                    Rock.CMS.Block Block = BlockService.Get( int.Parse( id ) );
                    if ( Block.Authorized( "Edit", user ) )
                    {
                        BlockService.Delete( Block, user.PersonId );
                        BlockService.Save( Block, user.PersonId );
                    }
                    else
                        throw new WebFaultException<string>( "Not Authorized to Edit this Block", System.Net.HttpStatusCode.Forbidden );
                }
                else
                    throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden );
            }
        }
Пример #8
0
        public void ApiCreateBlock( string apiKey, Rock.CMS.DTO.Block Block )
        {
            using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() )
            {
                Rock.CMS.UserService userService = new Rock.CMS.UserService();
                Rock.CMS.User user = userService.Queryable().Where( u => u.ApiKey == apiKey ).FirstOrDefault();

                if (user != null)
                {
                    uow.objectContext.Configuration.ProxyCreationEnabled = false;
                    Rock.CMS.BlockService BlockService = new Rock.CMS.BlockService();
                    Rock.CMS.Block existingBlock = new Rock.CMS.Block();
                    BlockService.Add( existingBlock, user.PersonId );
                    uow.objectContext.Entry(existingBlock).CurrentValues.SetValues(Block);

                    if (existingBlock.IsValid)
                        BlockService.Save( existingBlock, user.PersonId );
                    else
                        throw new WebFaultException<string>( existingBlock.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest );
                }
                else
                    throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden );
            }
        }
Пример #9
0
        public Rock.CMS.DTO.Block Get(string id)
        {
            var currentUser = Rock.CMS.UserService.GetCurrentUser();

            if (currentUser == null)
            {
                throw new WebFaultException <string>("Must be logged in", System.Net.HttpStatusCode.Forbidden);
            }

            using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope())
            {
                uow.objectContext.Configuration.ProxyCreationEnabled = false;
                Rock.CMS.BlockService BlockService = new Rock.CMS.BlockService();
                Rock.CMS.Block        Block        = BlockService.Get(int.Parse(id));
                if (Block.Authorized("View", currentUser))
                {
                    return(Block.DataTransferObject);
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to View this Block", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Пример #10
0
        private void LoadBlockTypes()
        {
            using ( new Rock.Data.UnitOfWorkScope() )
            {
                Rock.CMS.BlockService blockService = new Rock.CMS.BlockService();

                // Add any unregistered blocks
                foreach ( Rock.CMS.Block block in blockService.GetUnregisteredBlocks( Request.MapPath( "~" ) ) )
                {
                    try
                    {
                        Control control = LoadControl( block.Path );
                        if ( control is Rock.Web.UI.Block )
                        {
                            block.Name = Path.GetFileNameWithoutExtension( block.Path );
                            // Split the name on intercapped changes (ie, "HelloWorld" becomes "Hello World")
                            block.Name = System.Text.RegularExpressions.Regex.Replace( block.Name, "([a-z](?=[A-Z])|[A-Z](?=[A-Z][a-z]))", "$1 " );
                            block.Description = block.Path;

                            blockService.Add( block, CurrentPersonId );
                            blockService.Save( block, CurrentPersonId );
                        }
                    }
                    catch
                    {
                    }
                }

                ddlBlockType.DataSource = blockService.Queryable().ToList();
                ddlBlockType.DataTextField = "Name";
                ddlBlockType.DataValueField = "Id";
                ddlBlockType.DataBind();
            }
        }
Пример #11
0
        public Rock.CMS.DTO.Block ApiGet( string id, string apiKey )
        {
            using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope())
            {
                Rock.CMS.UserService userService = new Rock.CMS.UserService();
                Rock.CMS.User user = userService.Queryable().Where( u => u.ApiKey == apiKey ).FirstOrDefault();

                if (user != null)
                {
                    uow.objectContext.Configuration.ProxyCreationEnabled = false;
                    Rock.CMS.BlockService BlockService = new Rock.CMS.BlockService();
                    Rock.CMS.Block Block = BlockService.Get( int.Parse( id ) );
                    if ( Block.Authorized( "View", user ) )
                        return Block.DataTransferObject;
                    else
                        throw new WebFaultException<string>( "Not Authorized to View this Block", System.Net.HttpStatusCode.Forbidden );
                }
                else
                    throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden );
            }
        }
Пример #12
0
        public void UpdateBlock( string id, Rock.CMS.DTO.Block Block )
        {
            var currentUser = Rock.CMS.UserService.GetCurrentUser();
            if ( currentUser == null )
                throw new WebFaultException<string>("Must be logged in", System.Net.HttpStatusCode.Forbidden );

            using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() )
            {
                uow.objectContext.Configuration.ProxyCreationEnabled = false;
                Rock.CMS.BlockService BlockService = new Rock.CMS.BlockService();
                Rock.CMS.Block existingBlock = BlockService.Get( int.Parse( id ) );
                if ( existingBlock.Authorized( "Edit", currentUser ) )
                {
                    uow.objectContext.Entry(existingBlock).CurrentValues.SetValues(Block);

                    if (existingBlock.IsValid)
                        BlockService.Save( existingBlock, currentUser.PersonId );
                    else
                        throw new WebFaultException<string>( existingBlock.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest );
                }
                else
                    throw new WebFaultException<string>( "Not Authorized to Edit this Block", System.Net.HttpStatusCode.Forbidden );
            }
        }
Пример #13
0
        public Rock.CMS.DTO.Block Get( string id )
        {
            var currentUser = Rock.CMS.UserService.GetCurrentUser();
            if ( currentUser == null )
                throw new WebFaultException<string>("Must be logged in", System.Net.HttpStatusCode.Forbidden );

            using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope())
            {
                uow.objectContext.Configuration.ProxyCreationEnabled = false;
                Rock.CMS.BlockService BlockService = new Rock.CMS.BlockService();
                Rock.CMS.Block Block = BlockService.Get( int.Parse( id ) );
                if ( Block.Authorized( "View", currentUser ) )
                    return Block.DataTransferObject;
                else
                    throw new WebFaultException<string>( "Not Authorized to View this Block", System.Net.HttpStatusCode.Forbidden );
            }
        }
Пример #14
0
        public void DeleteBlock( string id )
        {
            var currentUser = Rock.CMS.UserService.GetCurrentUser();
            if ( currentUser == null )
                throw new WebFaultException<string>("Must be logged in", System.Net.HttpStatusCode.Forbidden );

            using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() )
            {
                uow.objectContext.Configuration.ProxyCreationEnabled = false;
                Rock.CMS.BlockService BlockService = new Rock.CMS.BlockService();
                Rock.CMS.Block Block = BlockService.Get( int.Parse( id ) );
                if ( Block.Authorized( "Edit", currentUser ) )
                {
                    BlockService.Delete( Block, currentUser.PersonId );
                    BlockService.Save( Block, currentUser.PersonId );
                }
                else
                    throw new WebFaultException<string>( "Not Authorized to Edit this Block", System.Net.HttpStatusCode.Forbidden );
            }
        }