예제 #1
0
        public ActionResult Create(int defaultRoleId, int[] templateIds)
        {
            Site site = new Site();
            try
            {
                UpdateModel(site, new [] { "Name", "SiteUrl", "WebmasterEmail", "UserFriendlyUrls", "DefaultCulture"});
                site.DefaultRole = this._userService.GetRoleById(defaultRoleId);
                if (ValidateModel(site))
                {
                    IList<Template> templates = new List<Template>();
                    if (templateIds.Length > 0)
                    {
                        templates = this._templateService.GetAllSystemTemplates().Where(t => templateIds.Contains(t.Id)).ToList();
                    }
                    string systemTemplateDir = Server.MapPath(Config.GetConfiguration()["TemplateDir"]);
                    this._siteService.CreateSite(site, Server.MapPath("~/SiteData"), templates, systemTemplateDir);

                    return RedirectToAction("CreateSuccess", new { siteId = site.Id });
                }
            }
            catch (Exception ex)
            {
                Messages.AddException(ex);
            }
            ViewData["Roles"] = new SelectList(this._userService.GetAllGlobalRoles(), "Id", "Name", site.DefaultRole.Id);
            ViewData["Cultures"] = new SelectList(Globalization.GetOrderedCultures(), "Key", "Value", site.DefaultCulture);
            ViewData["Templates"] = this._templateService.GetAllSystemTemplates();
            return View("NewSite", site);
        }
예제 #2
0
        public void DeleteSiteUsers(Site site)
        {
            ISession session = this._sessionManager.OpenSession();
            //IList<User> siteUsers = GetUsersBySiteID(site.Id);
            foreach (User u in site.Users)
            {
                if (u.Sites != null && u.Sites.Count > 1)
                {
                    u.Sites.Remove(site);
                }
                else
                {
                    session.Delete(u);
                }
            }

            //Need to find a better way to handle large numbers of users?
            //
            //ISession session = this._sessionManager.OpenSession();

            //string deletesql = " DELETE FROM cuyahoga_user " +
            //                   " FROM cuyahoga_user INNER JOIN " +
            //                   " cuyahoga_userrole ON cuyahoga_user.userid = cuyahoga_userrole.userid " +
            //                   " WHERE cuyahoga_user.siteid = " + site.Id.ToString(); //add [; select @@ROWCOUNT count;] after delete query to get number of deleted users

            //Object result = session.CreateSQLQuery(deletesql)
            //    .AddScalar("count", NHibernateUtil.Int32)
            //    .UniqueResult();
        }
예제 #3
0
        public void DeleteSite(Site site)
        {
            if (site.RootNodes.Count > 0)
            {
                throw new Exception("Can't delete a site when there are still related nodes. Please delete all nodes before deleting an entire site.");
            }
            else
            {
                IList aliases = this._siteStructureDao.GetSiteAliasesBySite(site);
                if (aliases.Count > 0)
                {
                    throw new Exception("Unable to delete a site when a site has related aliases.");
                }
                else
                {
                    try
                    {
                        // We need to use a specific DAO to also enable clearing the query cache.
                        this._siteStructureDao.DeleteSite(site);
                    }
                    catch (Exception ex)
                    {
                        log.Error("Error deleting site", ex);
                        throw;
                    }

                }
            }
        }
 /// <summary>
 /// Gets all root categories, ordered by path for a given site
 /// </summary>
 /// <returns></returns>
 public IList<Category> GetAllRootCategories(Site site)
 {
     ISession session = this.sessionManager.OpenSession();
     string hql = "from Cuyahoga.Core.Domain.Category c where c.Site = :site and c.ParentCategory is null order by c.Path asc";
     IQuery query = session.CreateQuery(hql);
     query.SetParameter("site", site);
     return query.List<Category>();
 }
예제 #5
0
        public virtual void CreateSite(Site site, string siteDataRoot, IList<Template> templatesToCopy, string systemTemplatesDirectory)
        {
            try
            {
                // 1. Add global roles to site
                IList<Role> roles = this._commonDao.GetAll<Role>();
                foreach (Role role in roles)
                {
                    if (role.IsGlobal)
                    {
                        site.Roles.Add(role);
                    }
                }

                // 2. Save site in database
                this._commonDao.SaveObject(site);

                // 3. Create SiteData folder structure
                if (! this._fileService.CheckIfDirectoryIsWritable(siteDataRoot))
                {
                    throw new IOException(string.Format("Unable to create the site because the directory {0} is not writable.", siteDataRoot));
                }
                string siteDataPhysicalDirectory = Path.Combine(siteDataRoot, site.Id.ToString());
                this._fileService.CreateDirectory(siteDataPhysicalDirectory);
                this._fileService.CreateDirectory(Path.Combine(siteDataPhysicalDirectory, "UserFiles"));
                this._fileService.CreateDirectory(Path.Combine(siteDataPhysicalDirectory, "index"));
                string siteTemplatesDirectory = Path.Combine(siteDataPhysicalDirectory, "Templates");
                this._fileService.CreateDirectory(siteTemplatesDirectory);

                // 4. Copy templates
                IList<string> templateDirectoriesToCopy = new List<string>();
                foreach (Template template in templatesToCopy)
                {
                    string templateDirectoryName = template.BasePath.Substring(template.BasePath.IndexOf("/") + 1);
                    if (! templateDirectoriesToCopy.Contains(templateDirectoryName))
                    {
                        templateDirectoriesToCopy.Add(templateDirectoryName);
                    }
                    Template newTemplate = template.GetCopy();
                    newTemplate.Site = site;
                    site.Templates.Add(newTemplate);
                    this._commonDao.SaveOrUpdateObject(newTemplate);
                    this._commonDao.SaveOrUpdateObject(site);
                }
                foreach (string templateDirectory in templateDirectoriesToCopy)
                {
                    string sourceDir = Path.Combine(systemTemplatesDirectory, templateDirectory);
                    string targetDir = Path.Combine(siteTemplatesDirectory, templateDirectory);
                    this._fileService.CopyDirectoryContents(sourceDir, targetDir);
                }
            }
            catch (Exception ex)
            {
                log.Error("An unexpected error occured while creating a new site.", ex);
                throw;
            }
        }
 /// <summary>
 /// Gets categories by the specified partial category path, ordered by path
 /// </summary>
 /// <param name="path"></param>
 public IList<Category> GetByPathByParent(Site site, string path)
 {
     ISession session = this.sessionManager.OpenSession();
         string hql = "from Cuyahoga.Core.Domain.Category c where c.Site = :site and c.Path like :path order by c.Path asc";
         IQuery query = session.CreateQuery(hql);
         query.SetEntity("site", site);
         query.SetString("path", string.Concat(path, "%"));
         return query.List<Category>();
 }
 public void ApplyTemplateAllNodesInSite(Template template, Site site)
 {
     ISession session = this._sessionManager.OpenSession();
     string sql = "UPDATE cuyahoga_node  SET templateid = :Template  WHERE (siteid = :Site)";
     ISQLQuery SQLQuery = session.CreateSQLQuery(sql);
     SQLQuery.SetInt32("Template", template.Id);
     SQLQuery.SetInt32("Site", site.Id);
     SQLQuery.ExecuteUpdate();
 }
 public void DeleteSiteUsers(Site site)
 {
     User currentUser = Thread.CurrentPrincipal as User;
     if (currentUser.Sites.Contains(site))
     {
         throw new DeleteForbiddenException("DeleteYourselfNotAllowedException");
     }
     this._userDao.DeleteSiteUsers(site);
 }
 /// <summary>
 /// Gets a category by the specified category path
 /// </summary>
 /// <param name="path"></param>
 public Category GetByExactPathAndSite(Site site, string path)
 {
     ISession session = this.sessionManager.OpenSession();
         string hql = "from Cuyahoga.Core.Domain.Category c where c.Site = :site and c.Path = :path";
         IQuery query = session.CreateQuery(hql);
         query.SetEntity("site", site);
         query.SetString("path", path);
         return query.UniqueResult<Category>();
 }
예제 #10
0
 /// <summary>
 /// Get a dictionary of rootnodes for the current site with the culture as the key.
 /// </summary>
 /// <param name="site"></param>
 /// <returns></returns>
 public Dictionary<string, Node> GetCultureRootNodesBySite(Site site)
 {
     IList<Node> rootNodes = this._nodeService.GetRootNodes(site);
     Dictionary<string, Node> cultureNodes = new Dictionary<string, Node>(rootNodes.Count);
     foreach (Node node in rootNodes)
     {
         cultureNodes.Add(node.Culture, node);
     }
     return cultureNodes;
 }
예제 #11
0
        public void DeleteSite(Site site)
        {
            ISession session = this._sessionManager.OpenSession();

            // Clear query cache first
            session.SessionFactory.EvictQueries("Sites");

            // Delete site
            session.Delete(site);
        }
 public Node CreateRootNode(Site site, Node newNode)
 {
     // ShortDescription is equal to language part of culture by default.
         CultureInfo ci = new CultureInfo(newNode.Culture);
         newNode.ShortDescription = ci.TwoLetterISOLanguageName;
         newNode.Site = site;
         newNode.Position = site.RootNodes.Count;
         site.RootNodes.Add(newNode);
         this._commonDao.SaveObject(newNode);
         return newNode;
 }
        public string CreateUser(string username, string email, Site currentSite)
        {
            User user = new User();
            user.UserName = username;
            user.Email = email;
            user.IsActive = true;
            string newPassword = user.GeneratePassword();
            // Add the default role from the current site.
            user.Roles.Add(currentSite.DefaultRole);
            this._commonDao.SaveOrUpdateObject(user);

            return newPassword;
        }
예제 #14
0
        public virtual ArticleCategory FindCategoryByTitleAndSite(string title, Site site)
        {
            string hql = "from Cuyahoga.Modules.Articles.Domain.Category c where lower(c.Title) = :title and c.Site.Id = :siteId";
            ISession session = this._sessionManager.OpenSession();

            // HACK: set the FlushMode of the session to temporarily to Commit because this method is being called in a transaction
            // (in ArticleModule.cs) and we have to prevent Flushing until the transaction is comitted.
            FlushMode originalFlushMode = session.FlushMode;
            session.FlushMode = FlushMode.Commit;

            IQuery q = this._sessionManager.OpenSession().CreateQuery(hql);
            q.SetString("title", title.ToLower(CultureInfo.InvariantCulture));
            q.SetInt32("siteId", site.Id);
            ArticleCategory category = q.UniqueResult() as ArticleCategory;
            session.FlushMode = originalFlushMode;
            return category;
        }
        public void DeleteSiteTemplates(Site site)
        {
            ISession session = this._sessionManager.OpenSession();

            //Count before
            int templatecount = site.Templates.Count - 1;

            for (int i = 0; i <= templatecount; i++)
            {
                Template t = site.Templates[0];
                site.Templates.Remove(t);
                session.Delete(t);
            }
            site.DefaultTemplate = null;
            session.Save(site);
            session.Flush();
        }
예제 #16
0
        public ActionResult Browse(string username, int?roleId, bool?isActive, bool?globalSearch, int?page)
        {
            ViewData["username"] = username;
            ViewData["roles"]    = new SelectList(this._userService.GetAllRolesBySite(CuyahogaContext.CurrentSite), "Id", "Name", roleId);
            ViewData["roleid"]   = roleId;
            IDictionary <bool, string> isActiveOptions = new Dictionary <bool, string>()
            {
                { true, GetText("Yes") }, { false, GetText("No") }
            };

            ViewData["isactiveoptions"]     = new SelectList(isActiveOptions, "Key", "Value", isActive);
            ViewData["isactive"]            = isActive;
            ViewData["globalsearchallowed"] = CuyahogaContext.CurrentUser.HasRight(Rights.GlobalPermissions);
            ViewData["globalsearch"]        = globalSearch;

            int          totalCount;
            CuyahogaSite siteToFilter = globalSearch.HasValue && globalSearch.Value == true ? null : CuyahogaContext.CurrentSite;
            IList <User> users        = _userService.FindUsers(username, roleId, isActive, siteToFilter, pageSize, page, out totalCount);

            return(View("Index", new PagedList <User>(users, page.HasValue ? page.Value - 1 : 0, pageSize, totalCount)));
        }
예제 #17
0
        private HtmlGenericControl CreateDisplaySite(Site site)
        {
            string imgFolder = UrlHelper.GetSiteUrl() + "/Admin/Images/";
                string adminUrl = UrlHelper.GetSiteUrl() + "/Admin/";

                HtmlGenericControl container = new HtmlGenericControl("div");
                container.Attributes.Add("class", "sitepanel");
                container.Attributes.Add("id", "site" + site.Id.ToString());

                HtmlGenericControl siteul = new HtmlGenericControl("ul");
                container.Controls.Add(siteul);

                HtmlGenericControl siteli = new HtmlGenericControl("li");
                siteli.Attributes.Add("class", "site");
                siteli.Attributes.Add("site", site.Id.ToString());

                siteul.Controls.Add(siteli);
                Image img = new Image();
                img.ImageUrl = imgFolder + "site.png";
                img.ImageAlign = ImageAlign.Left;
                img.AlternateText = "Site";
                siteli.Controls.Add(img);

                HyperLink hpl = new HyperLink();
                hpl.Text = String.Format("{0}", site.SiteUrl);
                hpl.NavigateUrl = String.Format("{0}SiteEdit.aspx?SiteId={1}", adminUrl, site.Id.ToString());
                hpl.CssClass = "nodeLink";
                siteli.Controls.Add(hpl);

                DisplayNodes(site.RootNodes, siteli);
                return container;
        }
 public void CreateRole(Role role, Site currentSite)
 {
     ConnectRoleToSites(role, currentSite);
     CheckRightsForRoleAndSite(role, currentSite);
     this._commonDao.SaveObject(role);
 }
 private void CheckRightsForRoleAndSite(Role role, Site currentSite)
 {
     // Make sure that the role hasn't any rights that the user doesn't have for the current site.
     User currentUser = (User)Thread.CurrentPrincipal;
     foreach (Right right in role.Rights)
     {
         if (! currentUser.HasRight(right.Name, currentSite))
         {
             throw new SecurityException("You can not assign rights to a role that you don't have yourself.");
         }
     }
 }
        private void ConnectRoleToSites(Role role, Site currentSite)
        {
            role.Sites.Clear();
            // If role is global, it has to be connected to all sites
            if (role.IsGlobal)
            {
                // First check if the user is allowed to connect to all sites.
                CheckGlobalRole(role);

                IList<Site> allSites = this._commonDao.GetAll<Site>();
                foreach (Site site in allSites)
                {
                    role.Sites.Add(site);
                }
            }
            else
            {
                role.Sites.Add(currentSite);
            }
        }
 public void UpdateRole(Role role, Site currentSite)
 {
     ConnectRoleToSites(role, currentSite);
     this._commonDao.SaveOrUpdateObject(role);
 }
 public IList<Role> GetAllRolesBySite(Site site)
 {
     return this._userDao.GetAllRolesBySite(site);
 }
        public IList<User> FindUsers(string username, int? roleId, bool? isActive, Site site, int pageSize, int? pageNumber, out int totalCount)
        {
            int? siteId = null;
            // When site is null, the user needs to have permissions to perform a global search across all sites.
            if (site == null)
            {
                User currentUser = Thread.CurrentPrincipal as User;
                if (currentUser == null || ! currentUser.HasRight(Rights.GlobalPermissions))
                {
                    throw new SecurityException("ActionNotAllowedException");
                }
            }
            else
            {
                siteId = site.Id;
            }

            if (!pageNumber.HasValue)
            {
                pageNumber = 1;
            }
            return this._userDao.FindUsers(username, roleId, isActive, siteId, pageSize, pageNumber.Value, out totalCount);
        }
예제 #24
0
        // added for 1.6.0
        public IList GetNodesBySite( Site site )
        {
            ISession session = this._sessionManager.OpenSession();

            string hql = "from Node n where n.Site.Id = :siteId ";
            IQuery q = session.CreateQuery( hql );
            q.SetInt32( "siteId", site.Id );
            return q.List();
        }
예제 #25
0
        public IList GetRootNodes(Site site)
        {
            ISession session = this._sessionManager.OpenSession();

            string hql = "from Node n where n.ParentNode is null and n.Site.Id = :siteId order by n.Position";
            IQuery q = session.CreateQuery(hql);
            q.SetInt32("siteId", site.Id);
            q.SetCacheable(true);
            q.SetCacheRegion("Nodes");
            return q.List();
        }
예제 #26
0
        public Node GetRootNodeByCultureAndSite(string culture, Site site)
        {
            ISession session = this._sessionManager.OpenSession();

            string hql = "from Node n where n.ParentNode is null and n.Culture = :culture and n.Site.Id = :siteId";
            IQuery q = session.CreateQuery(hql);
            q.SetString("culture", culture);
            q.SetInt32("siteId", site.Id);
            q.SetCacheable(true);
            q.SetCacheRegion("Nodes");
            IList results = q.List();
            if (results.Count == 1)
            {
                return results[0] as Node;
            }
            else if (results.Count == 0)
            {
                throw new NodeNullException(String.Format("No root node found for culture {0} and site {1}.", culture, site.Id));
            }
            else
            {
                throw new Exception(String.Format("Multiple root nodes found for culture {0} and site {1}.", culture, site.Id));
            }
        }
예제 #27
0
        private Control CreateNewNodeControl(Site site, HtmlGenericControl container)
        {
            string imgFolder = UrlHelper.GetSiteUrl() + "/Admin/Images/";

                Image img = new Image();
                img.ImageUrl = imgFolder + "sitepage-new-home.png";
                img.ImageAlign = ImageAlign.Left;
                img.AlternateText = "New Node";
                container.Controls.Add(img);
                HyperLink hpl = new HyperLink();
                hpl.Text = "Add new root node";
                hpl.NavigateUrl = String.Format("NodeEdit.aspx?SiteId={0}&NodeId=-1", site.Id.ToString());
                hpl.CssClass = "navLink";
                container.Controls.Add(hpl);
                return container;
        }
예제 #28
0
        public IList GetSiteAliasesBySite(Site site)
        {
            ISession session = this._sessionManager.OpenSession();

            string hql = "from SiteAlias sa where sa.Site.Id = :siteId ";
            IQuery query = session.CreateQuery(hql);
            query.SetInt32("siteId", site.Id);
            return query.List();
        }
예제 #29
0
        private void Page_Load(object sender, EventArgs e)
        {
            base.Title = "Edit site";

            if (Context.Request.QueryString["SiteId"] != null)
            {
                if (Int32.Parse(Context.Request.QueryString["SiteId"]) == -1)
                {
                    // Create a new site instance
                    this._activeSite = new Site();
                    this.btnDelete.Visible = false;
                    this.hplNewAlias.Visible = false;
                }
                else
                {
                    // Get site data
                    this._activeSite = base.SiteService.GetSiteById(Int32.Parse(Context.Request.QueryString["SiteId"]));
                    this.btnDelete.Visible = true;
                    this.btnDelete.Attributes.Add("onclick", "return confirm('Are you sure?')");
                }
                if (! this.IsPostBack)
                {
                    BindSiteControls();
                    BindTemplates();
                    BindCultures();
                    BindRoles();
                    if (this._activeSite.Id > 0)
                    {
                        BindAliases();
                    }
                }
            }
        }
예제 #30
0
        public Node GetNodeByShortDescriptionAndSite(string shortDescription, Site site)
        {
            ISession session = this._sessionManager.OpenSession();

            string hql = "from Node n where n.ShortDescription = :shortDescription and n.Site.Id = :siteId";
            IQuery q = session.CreateQuery(hql);
            q.SetString("shortDescription", shortDescription);
            q.SetInt32("siteId", site.Id);
            q.SetCacheable(true);
            q.SetCacheRegion("Nodes");
            IList results = q.List();
            if (results.Count == 1)
            {
                return (Node)results[0];
            }
            else if (results.Count > 1)
            {
                throw new Exception(String.Format("Multiple nodes found for ShortDescription {0}. The ShortDescription should be unique.", shortDescription));
            }
            else
            {
                return null;
            }
        }
예제 #31
0
 public IList<Role> GetAllRolesBySite(Site site)
 {
     ISession session = this._sessionManager.OpenSession();
     ICriteria crit = session.CreateCriteria(typeof (Role))
         .AddOrder(Order.Asc("Name"))
         .CreateCriteria("Sites")
         .Add(Expression.Eq("Id", site.Id));
     return crit.List<Role>();
 }