public void Application_Make_New_Assign_User_And_Delete()
        {
            var name = Guid.NewGuid().ToString("N");

            //new user
            var ut   = UserType.GetAllUserTypes().First();
            var user = User.MakeNew(name, name, name, ut);

            Application.MakeNew(name, name, "icon.jpg");

            //check if it exists
            var app = Application.getByAlias(name);

            Assert.IsNotNull(app);

            //assign the app
            user.addApplication(app.alias);
            //ensure it's added
            Assert.AreEqual(1, user.Applications.Where(x => x.alias == app.alias).Count());

            //delete the app
            app.Delete();

            //make sure the assigned applications are gone
            Assert.AreEqual(0, user.Applications.Where(x => x.alias == name).Count());
        }
예제 #2
0
        /// <summary>
        /// Creates child controls for this control
        /// </summary>
        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            // set-up child controls
            this.ListControlType = new RadioButtonList()
            {
                ID = "ListControlType",
                RepeatDirection = RepeatDirection.Vertical,
                RepeatLayout    = RepeatLayout.Flow
            };

            this.UserTypesList = new CheckBoxList()
            {
                ID = "UserTypesList",
                RepeatDirection = RepeatDirection.Vertical,
                RepeatLayout    = RepeatLayout.Flow
            };

            // populate the controls
            this.ListControlType.Items.Clear();
            this.ListControlType.Items.Add("DropDownList");
            this.ListControlType.Items.Add("RadioButtonList");

            this.UserTypesList.Items.Clear();
            foreach (var userType in UserType.GetAllUserTypes())
            {
                this.UserTypesList.Items.Add(new ListItem(userType.Name, userType.Alias));
            }

            // add the child controls
            this.Controls.AddPrevalueControls(this.ListControlType, this.UserTypesList);
        }
예제 #3
0
        public void User_Make_New_Override2()
        {
            var name     = "TEST" + Guid.NewGuid().ToString("N");
            var username = "******" + Guid.NewGuid().ToString("N");
            var password = "******" + Guid.NewGuid().ToString("N");
            var email    = "TEST" + Guid.NewGuid().ToString("N") + "@test.com";

            UserType ut = UserType.GetAllUserTypes().First();

            User.MakeNew(name, username, password, email, ut);

            //make sure it's there
            var id = User.getUserId(username);

            Assert.IsTrue(id > 0);

            var user = User.GetUser(id);

            Assert.AreEqual(id, user.Id);

            user.delete();

            var stillUser = User.GetUser(id);

            Assert.IsNull(stillUser);
        }
예제 #4
0
        public void User_Make_New_Override1()
        {
            //System.Diagnostics.Debugger.Break();
            var      name     = "TEST" + Guid.NewGuid().ToString("N");
            var      username = "******" + Guid.NewGuid().ToString("N");
            var      password = "******" + Guid.NewGuid().ToString("N");
            UserType ut       = UserType.GetAllUserTypes().First();

            User.MakeNew(name, username, password, ut);

            //make sure it's there
            var id = User.getUserId(username);

            Assert.IsTrue(id > 0);

            var user = User.GetUser(id);

            Assert.AreEqual(id, user.Id);

            //System.Diagnostics.Debugger.Launch();
            user.delete();

            var stillUser = User.GetUser(id);

            Assert.IsNull(stillUser);
        }
예제 #5
0
        public void User_Make_New_Duplicate_Login()
        {
            var name1     = "TEST" + Guid.NewGuid().ToString("N");
            var name2     = "TEST" + Guid.NewGuid().ToString("N");
            var username  = "******" + Guid.NewGuid().ToString("N");
            var password1 = "TEST" + Guid.NewGuid().ToString("N");
            var password2 = "TEST" + Guid.NewGuid().ToString("N");

            UserType ut = UserType.GetAllUserTypes().First();

            User.MakeNew(name1, username, password1, ut);

            var hasError = false;

            try
            {
                User.MakeNew(name2, username, password2, ut);
            }
            catch (SqlHelperException)
            {
                hasError = true;
            }
            Assert.IsTrue(hasError);

            var user = User.GetUser(User.getUserId(username));

            //TODO: Move to common method
            user.delete();
            var stillUser = User.GetUser(User.getUserId(username));

            Assert.IsNull(stillUser);
        }
예제 #6
0
        protected void Button1_Click(object sender, System.EventArgs e)
        {
            Hashtable allUserTypes = new Hashtable();

            foreach (umbraco.BusinessLogic.UserType u in UserType.GetAllUserTypes())
            {
                allUserTypes.Add(u.Id, "");
            }

            foreach (CheckBox c in permissions)
            {
                // Update the user with the new permission
                if (c.Checked)
                {
                    allUserTypes[int.Parse(c.ID.Substring(0, c.ID.IndexOf("_")))] = (string)allUserTypes[int.Parse(c.ID.Substring(0, c.ID.IndexOf("_")))] + c.ID.Substring(c.ID.IndexOf("_") + 1, c.ID.Length - c.ID.IndexOf("_") - 1);
                }
            }


            // Loop through the users and update their Cruds...
            IDictionaryEnumerator uEnum = allUserTypes.GetEnumerator();

            while (uEnum.MoveNext())
            {
                string cruds = "-";
                if (uEnum.Value.ToString().Trim() != "")
                {
                    cruds = uEnum.Value.ToString();
                }
                UserType usertype = umbraco.BusinessLogic.UserType.GetUserType(int.Parse(uEnum.Key.ToString()));
                UserGroupPermissions.Businesslogic.UserTypePermissions.UpdateCruds(usertype, node, cruds);

                if (ReplacePermissionsOnChildren.Checked)
                {
                    //Replace permissions on all children
                    UserTypePermissions.CopyPermissions(usertype, node);
                }
            }

            // Update feedback message
            feedback1.type        = umbraco.uicontrols.Feedback.feedbacktype.success;
            feedback1.Text        = "Usergroup permissions saved ok ";
            pane_form.Visible     = false;
            panel_buttons.Visible = false;
        }
예제 #7
0
        public void Notification_Assign_To_New_User_Then_Delete_User()
        {
            //create anew document
            var ut = UserType.GetAllUserTypes().First();
            var u  = User.MakeNew(Guid.NewGuid().ToString("N"), Guid.NewGuid().ToString("N"), Guid.NewGuid().ToString("N"), ut);
            //get a doc
            var doc = Document.GetRootDocuments().First();

            //assign a notification to the user
            Notification.MakeNew(u, doc, ActionNew.Instance.Letter);

            //delete the document permanently
            u.delete();

            //make sure they're gone
            Assert.AreEqual <int>(0, Notification.GetUserNotifications(u).Count());
            Assert.IsNull(User.GetUser(u.Id));
        }
        public void Application_Create_New_User_Assign_Application_And_Delete_User()
        {
            var name = Guid.NewGuid().ToString("N");

            //new user
            var ut   = UserType.GetAllUserTypes().First();
            var user = User.MakeNew(name, name, name, ut);

            //get application
            var app = Application.getAll().First();

            //assign the app
            user.addApplication(app.alias);
            //ensure it's added
            Assert.AreEqual(1, user.Applications.Where(x => x.alias == app.alias).Count());

            //delete the user
            user.delete();

            //make sure the assigned applications are gone
            Assert.AreEqual(0, user.Applications.Where(x => x.alias == name).Count());
        }
예제 #9
0
        public override void Render(ref XmlTree tree)
        {
            List <UserType> userTypes = UserType.GetAllUserTypes();

            foreach (UserType userType in userTypes)
            {
                if (userType.Id > 1) //don't show the admin user type, they should always have full permissions
                {
                    XmlTreeNode node = XmlTreeNode.Create(this);
                    node.NodeID = userType.Id.ToString();
                    node.Action = string.Format("javascript:openUserTypes({0})", userType.Id.ToString());
                    node.Icon   = "user.gif";
                    node.Text   = userType.Alias;

                    OnBeforeNodeRender(ref tree, ref node, EventArgs.Empty);
                    if (node != null)
                    {
                        tree.Add(node);
                        OnAfterNodeRender(ref tree, ref node, EventArgs.Empty);
                    }
                }
            }
        }
예제 #10
0
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            SelectionMode = ListSelectionMode.Multiple;

            DataSource = UserType.GetAllUserTypes();

            DataValueField = "Id";
            DataTextField  = "Alias";

            DataBind();

            if (_value == null)
            {
                return;
            }

            foreach (var item in Items.Cast <ListItem>().Where(item => _value.Contains(item.Value)))
            {
                item.Selected = true;
            }
        }
예제 #11
0
 /// <summary>
 /// Gets all current user types
 /// </summary>
 public static IEnumerable <UserType> GetCurrentUserTypes()
 {
     return(UserType.GetAllUserTypes());
 }
예제 #12
0
        /// <summary>
        /// Get all the users by a specific user type alias
        /// </summary>
        /// <param name="typeAlias"></param>
        public static IEnumerable <User> GetUsersByType(string typeAlias)
        {
            var currentUserType = UserType.GetAllUserTypes().FirstOrDefault(t => t.Alias == typeAlias);

            return(currentUserType == null ? null : User.getAll().Where(u => u.UserType == currentUserType && !string.IsNullOrWhiteSpace(u.Email) && !u.Disabled));
        }
예제 #13
0
        /// <summary>
        /// Gets all the users
        /// </summary>
        public static IEnumerable <User> GetAllUsers()
        {
            var currentUserTypes = UserType.GetAllUserTypes();

            return(User.getAll().Where(u => currentUserTypes.Contains(u.UserType)));
        }