Exemple #1
0
    public void BuildGroupsFromGroupsString(string groupsString)
    {
        if (groupsString == "NONE" || groupsString == "" || groupsString == null)
        {
            return;
        }

        string[] groupStringList = IGC_Utils.SplitString("\n", groupsString);

        //foreach group in groupstring
        for (int i = 0; i < groupStringList.Length; i++)
        {
            string[]
            group = IGC_Utils.SplitString(":", groupStringList[i]),
            groupUsers  = IGC_Utils.SplitString("~", group[2]),
            groupAdmins = IGC_Utils.SplitString("~", group[3]);

            //create group
            IGC_UserGroup newGroup = AddGroup(group[0], users[group[1]]);
            //add users
            foreach (string user in groupUsers)
            {
                newGroup.AddUser(users[user], false);
            }
            //add admins
            foreach (string admin in groupAdmins)
            {
                newGroup.AddUser(users[admin], true);
            }
        }
    }
Exemple #2
0
    private string AddUserToGroup()
    {
        if (argv.Length != 5)
        {
            return(malformed_error + "\n" + "usage: groups adduser <group_name> <username> <group admin? y|n>");
        }

        IGC_User user = registry.GetUser(argv[3]);

        if (user == null)
        {
            return("user " + argv[3] + " does not exist");
        }

        IGC_UserGroup group = registry.GetGroup(argv [2]);

        if (group == null)
        {
            return("group " + argv[2] + " does not exist");
        }

        if (user.groups.Contains(group))
        {
            return(user.name + " is already in " + group.name);
        }

        if (!group.admins.Contains(issuer) && !issuer.isAdmin)
        {
            return("only system or group administrators can add or remove users");
        }

        bool asAdmin = argv [4] == "y" ? true : false;

        group.AddUser(user, asAdmin);

        return(user.name + " added to group " + group.name + (asAdmin ? " as admin" : ""));
    }