Пример #1
0
        /// <summary>
        /// Change the owner of a UserObject
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>

        public static string ChangeOwner(
            int objId,
            string newOwner)
        {
            newOwner = newOwner.ToUpper();

            UserObject uo = UserObjectDao.ReadHeader(objId);

            if (uo == null)
            {
                return("User object not found: " + objId);
            }
            if (uo.Owner == newOwner)
            {
                return("This user object is already owned by " + newOwner);
            }
            if (!Security.IsAdministrator(SS.I.UserName) && Lex.Ne(uo.Owner, SS.I.UserName))
            {
                return("You're not authorized to change the owner of this user object");
            }

            if (!Security.CanLogon(newOwner))
            {
                return("Not a valid userId: " + newOwner);
            }

            UserInfo ui  = Security.GetUserInfo(newOwner);
            string   msg = "Are you sure you want to transfer ownership of " + Lex.AddDoubleQuotes(uo.Name) + "\n" +
                           "to " + ui.FullName + "?";
            DialogResult dr = MessageBoxMx.Show(msg, "Change Owner", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

            if (dr != DialogResult.Yes)
            {
                return("");
            }

            UserObject uo2 = uo.Clone();

            uo2.Owner = newOwner;
            UserObjectTree.GetValidUserObjectTypeFolder(uo2);          // set valid parent folder
            Permissions.UpdateAclForNewOwner(uo2, uo.Owner, newOwner); // Set the ACL to give us r/w access
            uo2.Content = "ChangeOwner";                               // indicate changing owner
            if (UserObjectDao.ReadHeader(uo2) != null)
            {
                return("A user object with that name already exists for the specified new user");
            }
            UserObjectDao.UpdateHeader(uo2, false, false);

            if (Data.InterfaceRefs.IUserObjectIUD != null)
            {
                Data.InterfaceRefs.IUserObjectIUD.UserObjectDeleted(uo);                                                        // remove from view
            }
            string newOwnerName = SecurityUtil.GetPersonNameReversed(newOwner);

            return("Ownership of \"" + uo2.Name + "\" has been changed to " + newOwnerName);
        }
Пример #2
0
/// <summary>
/// Get an internal user name from an external name
/// </summary>
/// <param name="externalUserName"></param>
/// <returns></returns>

        public static string GetInternalUserName(
            string externalUserName)
        {
            DictionaryMx users = DictionaryMx.Get("UserName");

            if (users == null)
            {
                users = new DictionaryMx();
            }

            for (int i1 = 0; i1 < users.Words.Count; i1++)
            {
                string userId = users.Words[i1];
                string name   = SecurityUtil.GetPersonNameReversed(userId);
                if (Lex.Eq(userId, externalUserName) || Lex.Eq(name, externalUserName))
                {
                    return(userId);
                }
            }

            return(null);
        }
Пример #3
0
/// <summary>
/// Get a sorted list of all user names
/// </summary>
/// <returns></returns>

        public static List <string> GetAllUsers()
        {
            DictionaryMx users = DictionaryMx.Get("UserName");

            if (users == null)
            {
                users = new DictionaryMx();
            }

            List <string> names = new List <string>();

            for (int i1 = 0; i1 < users.Words.Count; i1++)
            {
                string name = SecurityUtil.GetPersonNameReversed(users.Words[i1]);
                if (!Lex.IsNullOrEmpty(name))
                {
                    names.Add(name);
                }
            }

            names.Sort();
            return(names);
        }