Esempio n. 1
0
        /// <summary>
        /// Handle form submit, delete all from table and re-insert
        /// </summary>
        /// <param name="zoneList"></param>
        /// <returns></returns>
        protected string handleZoneAuthorityUpdate(List <CmsPageSecurityZone> zoneList, List <WebPortalUserRole> roleList)
        {
            if (PageUtils.getFromForm("update", "") != "updateZoneAuthority")
            {
                return("");
            }

            List <CmsPageSecurityZoneUserRole> authority = new List <CmsPageSecurityZoneUserRole>();

            foreach (CmsPageSecurityZone z in zoneList)
            {
                roleDb.deleteByZone(z);
                foreach (WebPortalUserRole r in roleList)
                {
                    // for each zone and role, we expect a pair of html input elements: R, W
                    string   htmlInputName = "z" + z.Id + "r" + r.RoleID;
                    string[] accessMode    = PageUtils.getFromForm(htmlInputName);
                    if (accessMode.Length == 0)
                    {
                        continue;
                    }

                    CmsPageSecurityZoneUserRole entity = createUserRoleEntity(z, r, accessMode);
                    authority.Add(entity);
                }
            }
            if (roleDb.insert(authority))
            {
                return(formatNormalMsg("Updated successfully."));
            }
            else
            {
                return(formatErrorMsg("Database error, please contract administrator."));
            }
        }
Esempio n. 2
0
        private void InsertAdminAreaZone(int AdminPageId)
        {
            CmsPageSecurityZone z = new CmsPageSecurityZone();

            z.ZoneName       = "Internal Author Tools Zone";
            z.StartingPageId = AdminPageId;
            if (new CmsPageSecurityZoneDb().insert(z) == false)
            {
                throw new Exception("Cannot insert Zone");
            }

            // anonymous users cannot read or write in this zone
            CmsPageSecurityZoneUserRole anonZoneRole = new CmsPageSecurityZoneUserRole(z.ZoneId, WebPortalUserRole.DUMMY_PUBLIC_ROLE_ID, false, false);

            if (new CmsPageSecurityZoneUserRoleDb().insert(anonZoneRole) == false)
            {
                throw new Exception("Cannot insert anonymous ZoneUserRole");
            }

            // authors can write and read all pages in this zone
            WebPortalUserRole authorRole = WebPortalUserRole.Fetch(CmsConfig.getConfigValue("AuthorAccessUserRole", "Author"));

            if (authorRole.RoleID >= 0)
            {
                CmsPageSecurityZoneUserRole authorZoneRole = new CmsPageSecurityZoneUserRole(z.ZoneId, authorRole.RoleID, true, true);
                if (new CmsPageSecurityZoneUserRoleDb().insert(authorZoneRole) == false)
                {
                    throw new Exception("Cannot insert author ZoneUserRole");
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Create the default home page zone and zone user role during setup.
        /// </summary>
        /// <returns></returns>
        private void InsertHomePageZone(int HomePageId)
        {
            CmsPageSecurityZone z = new CmsPageSecurityZone();

            z.ZoneName = "Default zone";

            z.StartingPage = pagerepository.Get(HomePageId);
            if (new CmsPageSecurityZoneDb().insert(z) == false)
            {
                throw new Exception("Cannot insert Home Page Zone");
            }

            // anonymous users can read, but not write pages in this zone
            CmsPageSecurityZoneUserRole anonZoneRole = new CmsPageSecurityZoneUserRole(z.Id, WebPortalUserRole.DUMMY_PUBLIC_ROLE_ID, true, false);

            if (new CmsPageSecurityZoneUserRoleDb().insert(anonZoneRole) == false)
            {
                throw new Exception("Cannot insert anonymous ZoneUserRole");
            }

            // authors can write and read all pages in this zone
            WebPortalUserRole authorRole = WebPortalUserRole.Fetch(CmsConfig.getConfigValue("AuthorAccessUserRole", "Author"));

            if (authorRole.RoleID >= 0)
            {
                CmsPageSecurityZoneUserRole authorZoneRole = new CmsPageSecurityZoneUserRole(z.Id, authorRole.RoleID, true, true);
                if (new CmsPageSecurityZoneUserRoleDb().insert(authorZoneRole) == false)
                {
                    throw new Exception("Cannot insert author ZoneUserRole");
                }
            }
        }
        public void CanInsertObject()
        {
            PageSecurityZoneUserRoleRepository repository    = new PageSecurityZoneUserRoleRepository();
            CmsPageSecurityZoneUserRoleDb      dboperation   = new CmsPageSecurityZoneUserRoleDb();
            CmsPageSecurityZoneUserRole        insertobject  = new CmsPageSecurityZoneUserRole(1, 2, true, false);
            CmsPageSecurityZoneUserRole        insertobject2 = new CmsPageSecurityZoneUserRole(2, 2, false, false);
            List <CmsPageSecurityZoneUserRole> objectlist    = new List <CmsPageSecurityZoneUserRole>();

            objectlist.Add(insertobject);
            objectlist.Add(insertobject2);
            if (dboperation.insert(objectlist) == false)
            {
                throw new Exception("insert test fail");
            }
            //CmsPageSecurityZoneUserRole returnobject = repository.SaveOrUpdate(insertobject);
            //Assert.That(repository, Is.Not.Null);
        }
Esempio n. 5
0
        /// <summary>
        /// Create the role entity object by reading the html form params
        /// </summary>
        /// <param name="z"></param>
        /// <param name="r"></param>
        /// <param name="accessMode"></param>
        /// <returns></returns>
        protected CmsPageSecurityZoneUserRole createUserRoleEntity(CmsPageSecurityZone z, WebPortalUserRole r, string[] accessMode)
        {
            CmsPageSecurityZoneUserRole entity = new CmsPageSecurityZoneUserRole(z.Id, r.RoleID);

            foreach (string s in accessMode)
            {
                if (s.ToLower() == "r")
                {
                    entity.ReadAccess = true;
                }
                if (s.ToLower() == "w")
                {
                    entity.WriteAccess = true;
                }
            }
            if (r.RoleID == WebPortalUserRole.DUMMY_PUBLIC_ROLE_ID)
            {
                entity.WriteAccess = false;
            }

            return(entity);
        }