public static FindUserWithName ( IEnumerable |
||
siteUsers | IEnumerable |
|
findName | string | |
compareMode | StringComparison | |
Résultat | SiteUser, |
/// <summary> /// Assign ownership /// </summary> /// <param name="datasource"></param> /// <param name="publishSettings"></param> /// <param name="siteUsers"></param> /// <returns>TRUE: The server content has the correct owner now. FALSE: We were unable to give the server content the correct owner</returns> private bool AttemptOwnerReassignment(SiteDatasource datasource, DatasourcePublishSettings publishSettings, IEnumerable <SiteUser> siteUsers) { this.StatusLog.AddStatusHeader("Attempting ownership assignement for Datasource " + datasource.Name + "/" + datasource.Id); //Something went wrong if we don't have a set of site users to do the look up if (siteUsers == null) { throw new ArgumentException("No set of site users provided for lookup"); } //Look the local meta data to see what the desired name is var desiredOwnerName = publishSettings.OwnerName; if (string.IsNullOrEmpty(desiredOwnerName)) { this.StatusLog.AddStatus("Skipping owner assignment. The local file system has no metadata with an owner information for " + datasource.Name); LogManualAction_ReassignOwnership(datasource.Name, "none specified", "No client ownership information was specified"); return(true); //Since there is no ownership preference stated locally, then ownership we assigned during upload was fine. } //Look on the list of users in the target site/server, and try to find a match // //NOTE: We are doing a CASE INSENSITIVE name comparison. We assume that there are not 2 users with the same name on server w/differet cases // Because if this, we want to be flexible and allow that our source/destination servers may have the user name specified with a differnt // case. -- This is less secure than a case-sensitive comparison, but is almost always what we want when porting content between servers var desiredServerUser = SiteUser.FindUserWithName(siteUsers, desiredOwnerName, StringComparison.InvariantCultureIgnoreCase); if (desiredServerUser == null) { this.StatusLog.AddError("The local file has a workbook/user mapping: " + datasource.Name + "/" + desiredOwnerName + ", but this user does not exist on the target site"); LogManualAction_ReassignOwnership(datasource.Name, desiredOwnerName, "The target site does not contain a user name that matches the owner specified by the local metadata"); return(false); //Not a run time error, but we have manual steps to perform } //If the server content is already correct, then there is nothing to do if (desiredServerUser.Id == datasource.OwnerId) { this.StatusLog.AddStatus("Workbook " + datasource.Name + "/" + datasource.Id + ", already has correct ownership. No update requried"); return(true); } //Lets tell server to update the owner var changeOwnership = new SendUpdateDatasourceOwner(_onlineUrls, _onlineSession, datasource.Id, desiredServerUser.Id); SiteDatasource updatedDatasource; try { this.StatusLog.AddStatus("Server request to change Datasource ownership, ds: " + datasource.Name + "/" + datasource.Id + ", user:"******"/" + desiredServerUser.Id); updatedDatasource = changeOwnership.ExecuteRequest(); } catch (Exception exChangeOnwnerhsip) { throw exChangeOnwnerhsip; //Unexpected error, send it upward } //Sanity check the result we got back: Double check to make sure we have the expected owner. if (updatedDatasource.OwnerId != desiredServerUser.Id) { this.StatusLog.AddError("Unexpected server error! Updated workbook Owner Id does not match expected. ds: " + datasource.Name + "/" + datasource.Id + ", " + "expected user: "******", " + "actual user: " + updatedDatasource.OwnerId ); } return(true); }