0

我正在使用以下代码获取所有 GitHub Enterprise 用户的列表,然后我试图暂停那些不再在 AD 中的用户。Suspend 函数有效,但 User.Suspended 属性始终返回 false。

var searhRequest = new SearchUsersRequest("type:user&page="+pageNumber+"&page_size=100");
                githubUsers = await client.Search.SearchUsers(searhRequest);   

 client.User.Administration.Suspend(userId);
4

1 回答 1

0

是的,我认为问题在于,当最终在幕后进行的调用没有返回该数据时,我们试图将返回值转换为用户。作为一种变通方法,我刚刚调用了 get user 方法来获取用户,然后我将原始结果四舍五入。

它可能可以做得更好,但这就是我现在所拥有的

Task<SearchUsersResult> task;
List<User> users = new List<User>();
int page = 1;

do
{
  task = github.Search.SearchUsers(new SearchUsersRequest("type:user&repos:>=0") { Page = page, PerPage = 500 });
  task.Wait();

  users.AddRange(task.Result.Items.ToList<User>());
  page++;
}
while (users.Count < task.Result.TotalCount);

// Get all users by login (this calls the api once for every user you have)
var tasks = users.Select(u => github.User.Get(u.Login));

// Get all unsuspended users
var activeUsers = Task.WhenAll<User>(tasks).Result.Where<User>(u => !u.Suspended).ToList();

请注意,调用结果中不包括“isSuspended”数据(使用 fiddler 从我的本地企业实例中提取,然后进行清理)

{"login":"User1"
"id":45
"avatar_url":"http://github.com/avatars/u/45?"
"gravatar_id":""
"url":"http://github.com/api/v3/users/User1"
"html_url":"http://github.com/User1"
"followers_url":"http://github.com/api/v3/users/User1/followers"
"following_url":"http://github.com/api/v3/users/User1/following{/other_user}"
"gists_url":"http://github.com/api/v3/users/User1/gists{/gist_id}"
"starred_url":"http://github.com/api/v3/users/User1/starred{/owner}{/repo}"
"subscriptions_url":"http://github.com/api/v3/users/User1/subscriptions"
"organizations_url":"http://github.com/api/v3/users/User1/orgs"
"repos_url":"http://github.com/api/v3/users/User1/repos"
"events_url":"http://github.com/api/v3/users/User1/events{/privacy}"
"received_events_url":"http://github.com/api/v3/users/User1/received_events"
"type":"User"
"site_admin":false
"ldap_dn":"CN=User1
OU=CompanyDEVUsers
OU=Users
OU=Company
DC=Company
DC=com"
"score":1.0}
于 2016-06-24T21:38:11.847 回答