Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Button to remove exempt orgs #131

Merged
merged 3 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/Konmaripo.Web/Controllers/OrgWideVisibilityController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,31 @@ public async Task<IActionResult> CreateOrgWideTeam()

return RedirectToAction("Index");
}
public IActionResult ExemptRepositoryCheck()
{
var tagName = _settings.ExemptionTagName;

var repos = _gitHubService.GetRepositoriesWithTopicThatAreVisibleToTeam(
tagName,
_settings.AllOrgMembersGroupName);

var vm = new ExemptRepositoryCheckViewModel(tagName, repos);
// TODO
return View();
}
}

public class ExemptRepositoryCheckViewModel
{
public string TagName { get; }
public List<string> RepositoryNames { get; }

public ExemptRepositoryCheckViewModel(string tagName, List<string> repoNames)
{
TagName = tagName;
RepositoryNames = repoNames;
}
}
public class OrgWideVisibilityIndexVM
{
public string OrgWideTeamName { get; }
Expand Down
1 change: 1 addition & 0 deletions src/Konmaripo.Web/Models/OrgWideVisibilitySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ public class OrgWideVisibilitySettings
{
public string AllOrgMembersGroupName { get; set; }
public string AllOrgMembersGroupDescription { get; set; }
public string ExemptionTagName { get; set; }
}
}
5 changes: 5 additions & 0 deletions src/Konmaripo.Web/Services/CachedGitHubService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ public async Task AddMembersToTeam(int teamId, List<string> loginsToAdd)
await _gitHubService.AddMembersToTeam(teamId, loginsToAdd);
}

public Task<List<string>> GetRepositoriesWithTopicThatAreVisibleToTeam(string topicName, string teamName)
{
return _gitHubService.GetRepositoriesWithTopicThatAreVisibleToTeam(topicName, teamName);
}

public async Task<List<User>> GetUsersNotInTeam(string teamName)
{
var allTeams = await GetAllTeams();
Expand Down
7 changes: 7 additions & 0 deletions src/Konmaripo.Web/Services/GitHubService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,12 @@ public async Task AddMembersToTeam(int teamId, List<string> loginsToAdd)
await _githubClient.Organization.Team.AddOrEditMembership(teamId, login, request);
}
}

public async Task<List<string>> GetRepositoriesWithTopicThatAreVisibleToTeam(string topicName, string teamName)
{
var allRepos = await GetRepositoriesForOrganizationAsync();

// TODO Filter repos by topic.
}
}
}
1 change: 1 addition & 0 deletions src/Konmaripo.Web/Services/IGitHubService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ public interface IGitHubService
Task<IReadOnlyList<User>> GetTeamMembers(int teamId);
Task AddMembersToTeam(string teamName, List<string> loginsToAdd);
Task AddMembersToTeam(int teamId, List<string> loginsToAdd);
Task<List<string>> GetRepositoriesWithTopicThatAreVisibleToTeam(string topicName, string teamName);
}
}
34 changes: 23 additions & 11 deletions src/Konmaripo.Web/Views/OrgWideVisibility/AddOrgMembers.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,34 @@

<div class="text-center">
<h2>Step 2: Add Missing team members</h2>
<p>The @Model.Count below organization members are not a part of the org-wide group.</p>
</div>

<div class="container">
@foreach (var row in Model.ToArray().Split(4))
@if (!Model.Any())
{
<div class="row">
@foreach (var login in row)
<div class="alert alert-success">
<h4 class="alert-heading">Great! No missing members.</h4>
<p>All your org's members are within the group.</p>
@Html.ActionLink($"Next step: Remove access for exempt repositories", "ExemptRepositoryCheck", "OrgWideVisibility", null, new { @class = "btn btn-success", role = "button" })
</div>

}
else
{
<div class="container">
@foreach (var row in Model.ToArray().Split(4))
{
<div class="col">
@login
<div class="row">
@foreach (var login in row)
{
<div class="col">
@login
</div>
}
</div>
}
</div>
<div>
@Html.ActionLink($"Add these {Model.Count} members to the group.", "AddOrgMembersList", "OrgWideVisibility", new { loginsToAdd = Model }, new { @class = "btn btn-success", role = "button" })
</div>
}
</div>
<div>
@Html.ActionLink($"Add these {Model.Count} members to the group.", "AddOrgMembersList", "OrgWideVisibility", new { loginsToAdd = Model }, new { @class = "btn btn-success", role = "button" })
</div>

2 changes: 1 addition & 1 deletion src/Konmaripo.Web/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"OrgWideVisibilitySettings": {
"AllOrgMembersGroupName": "all-org-members",
"AllOrgMembersGroupDescription": "A group created by the Konmaripo tool, which includes everyone who is a member of the GitHub organization.",
"ExemptionTagName": "ExemptFromOrgWideVisibility"
"ExemptionTagName": "exempt-from-org-visibility"
},
"ArchivalSettings": {
"ArchivalUrl": "CHANGE_ME"
Expand Down