/// <summary>
    /// Provision the groups
    /// </summary>
    /// <param name="siteSignIn"></param>
    private void Execute_ProvisionGroups(TableauServerSignIn siteSignIn, WorkingListSiteUsers workingList_allKnownUsers)
    {
        //If there are no provisioning instructions, then there is nothing we need to do here
        if (_provisionInstructions.GroupsToProvision == null)
        {
            _statusLogs.AddStatus("Skipping groups provisioning, because there are no instructions for this...");
            return;
        }

        _statusLogs.AddStatusHeader("Provision the specified groups in site");

        //=================================================================================
        //If we do not have it already, load the set of users for the site...we will need this to look up users
        //=================================================================================
        if (workingList_allKnownUsers == null)
        {
            var existingUsers = DownloadUsersList.CreateAndExecute(siteSignIn);
            existingUsers.ExecuteRequest();

            workingList_allKnownUsers = new WorkingListSiteUsers(existingUsers.Users);
        }

        //=================================================================================
        //Download the groups
        //=================================================================================
        var downloadGroups = new DownloadGroupsList(siteSignIn);

        downloadGroups.ExecuteRequest(false); //Download the list of groups, but not the membership of the groups (we will only do that for the groups we care about)

        //Go through each of the groups...
        foreach (var thisProvisionGroup in _provisionInstructions.GroupsToProvision)
        {
            Execute_ProvisionGroups_SingleGroup(siteSignIn, thisProvisionGroup, downloadGroups, workingList_allKnownUsers);
        }
    }
Beispiel #2
0
    /// <summary>
    /// Downloads the set of groups in the site
    /// </summary>
    /// <param name="onlineLogin"></param>
    /// <returns></returns>
    private DownloadGroupsList Execute_DownloadGroupsList(TableauServerSignIn onlineLogin)
    {
        var onlineUrls = _onlineUrls;

        _statusLog.AddStatusHeader("Request site groups");
        DownloadGroupsList groups = null;

        //===================================================================================
        //Projects...
        //===================================================================================
        try
        {
            groups = new DownloadGroupsList(onlineUrls, onlineLogin);
            groups.ExecuteRequest();

            //List all the groups
            foreach (var thisGroup in groups.Groups)
            {
                _statusLog.AddStatus(thisGroup.ToString());
            }
        }
        catch (Exception ex)
        {
            _statusLog.AddError("Error during groups query, " + ex.ToString());
        }

        //Store it
        _downloadedList_Groups = groups.Groups;
        return(groups);
    }
Beispiel #3
0
    /// <summary>
    /// Download information about all the users and all the groups
    /// </summary>
    /// <param name="siteSignIn"></param>
    private void GenerateGroupsMembersList_FromTableauSite(TableauServerSignIn siteSignIn)
    {
        var downloadGroups = new DownloadGroupsList(siteSignIn);

        var downloadSuccess = downloadGroups.ExecuteRequest(true);

        if (!downloadSuccess)
        {
            throw new Exception("1012-512: Fatal error attempting to download groups");
        }

        //Loop through all the groups
        foreach (var thisGroup in downloadGroups.Groups)
        {
            if (GenerateGroupsMembersList_IsGroupToExport(thisGroup.Name))
            {
                GenerateGroupsMembersList_FromTableauSite_ProcessSingleGroup(thisGroup);
            }
        }
    }
    /// <summary>
    /// Provision the groups
    /// </summary>
    /// <param name="siteSignIn"></param>
    private void Execute_ProvisionGroups(TableauServerSignIn siteSignIn)
    {
        _statusLogs.AddStatusHeader("Provision the specified groups in site");

        //=================================================================================
        //Load the set of users for the site...we will need this to look up users
        //=================================================================================
        var existingUsers = DownloadUsersList.CreateAndExecute(siteSignIn);

        existingUsers.ExecuteRequest();

        //=================================================================================
        //Download the groups
        //=================================================================================
        var downloadGroups = new DownloadGroupsList(siteSignIn);

        downloadGroups.ExecuteRequest(false); //Download the list of groups, but not the membership of the groups (we will only do that for the groups we care about)

        //Go through each of the groups...
        foreach (var thisProvisionGroup in _provisionInstructions.GroupsToProvision)
        {
            Execute_ProvisionGroups_SingleGroup(siteSignIn, thisProvisionGroup, downloadGroups, existingUsers);
        }
    }
Beispiel #5
0
    /// <summary>
    /// Downloads the set of groups in the site
    /// </summary>
    /// <param name="onlineLogin"></param>
    /// <returns></returns>
    private DownloadGroupsList Execute_DownloadGroupsList(TableauServerSignIn onlineLogin)
    {
        var onlineUrls = _onlineUrls;
        _statusLog.AddStatusHeader("Request site groups");
        DownloadGroupsList groups = null;
        //===================================================================================
        //Projects...
        //===================================================================================
        try
        {
            groups = new DownloadGroupsList(onlineUrls, onlineLogin);
            groups.ExecuteRequest();

            //List all the groups
            foreach (var thisGroup in groups.Groups)
            {
                _statusLog.AddStatus(thisGroup.ToString());
            }
        }
        catch (Exception ex)
        {
            _statusLog.AddError("Error during groups query, " + ex.ToString());
        }

        //Store it
        _downloadedList_Groups = groups.Groups;
        return groups;
    }
    /// <summary>
    /// Provisioning for a single group
    /// </summary>
    /// <param name="siteSignIn"></param>
    /// <param name="thisProvisionGroup"></param>
    /// <param name="existingGroups"></param>
    private void Execute_ProvisionGroups_SingleGroup(
        TableauServerSignIn siteSignIn,
        ProvisioningGroup thisProvisionGroup,
        DownloadGroupsList existingGroups,
        DownloadUsersList siteUsersList)
    {
        _statusLogs.AddStatusHeader("Provision the group: " + thisProvisionGroup.GroupName);

        var thisExistingGroup = existingGroups.FindGroupWithName(thisProvisionGroup.GroupName);
        ICollection <SiteUser> existingUsersInGroup = new List <SiteUser>();

        //If the Group does not exist on server then create it
        if (thisExistingGroup == null)
        {
            var createGroup = new SendCreateGroup(siteSignIn, thisProvisionGroup.GroupName);
            thisExistingGroup = createGroup.ExecuteRequest();

            CSVRecord_GroupModified(thisExistingGroup.Name, "created group", "");
            _statusLogs.AddStatus("Created group: " + thisExistingGroup.Name);
        }
        else
        {
            //Download the members of the group
            var downloadGroupMembers = new DownloadUsersListInGroup(siteSignIn, thisExistingGroup.Id);
            downloadGroupMembers.ExecuteRequest();
            existingUsersInGroup = downloadGroupMembers.Users;
        }

        //====================================================================================
        //Keep a list of the remaining users in the Server Site's group
        //====================================================================================
        var workingListUnexaminedUsers = new WorkingListSiteUsers(existingUsersInGroup);

        //====================================================================================
        //Go through each of the users we need to provision, and see if they are in the group
        //already
        //====================================================================================
        foreach (var provisionThisUser in thisProvisionGroup.Members)
        {
            var userInGroup = workingListUnexaminedUsers.FindUser(provisionThisUser);
            if (userInGroup != null)
            {
                //The user is already in the group, no need to add them
                workingListUnexaminedUsers.RemoveUser(userInGroup);
            }
            else
            {
                //Add the user to the group
                try
                {
                    Execute_ProvisionGroups_SingleGroup_AddUser(siteSignIn, provisionThisUser, thisExistingGroup, siteUsersList);
                }
                catch (Exception exAddUserToGroup) //Unexpected error case
                {
                    IwsDiagnostics.Assert(false, "811-700: Internal error adding user to group: " + exAddUserToGroup.Message);
                    _statusLogs.AddError("811-700: Internal error adding user to group: " + exAddUserToGroup.Message);
                }
            }
        }

        //==============================================================================
        //Remove any remaining users that are in the Server Site's Group but not in
        //our provisioning list
        //==============================================================================
        foreach (var unexpectedUser in workingListUnexaminedUsers.GetUsers())
        {
            try
            {
                Execute_ProvisionGroups_RemoveSingleUser(siteSignIn, unexpectedUser, thisExistingGroup);
            }
            catch (Exception exUnxpectedUsers)
            {
                _statusLogs.AddError("Error removing unexpected user in GROUP " + unexpectedUser.ToString() + ", " + exUnxpectedUsers.Message);
                CSVRecord_Error(unexpectedUser.Name, unexpectedUser.SiteRole, unexpectedUser.SiteAuthentication, "Error removing unexpected user in GROUP" + unexpectedUser.ToString() + ", " + exUnxpectedUsers.Message);
            }
        }
    }