diff options
author | James Moger <james.moger@gitblit.com> | 2014-03-27 13:06:14 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2014-04-10 19:00:05 -0400 |
commit | 47d53364625ba9c4c89171a28f22271efa37b554 (patch) | |
tree | 43c7019a4d200e4645efe2894e9f8edbaa3ba4b2 /src/main/java/com/gitblit/transport | |
parent | bfa998a3d04e759be555dd8136aaa9450960a879 (diff) | |
download | gitblit-47d53364625ba9c4c89171a28f22271efa37b554.tar.gz gitblit-47d53364625ba9c4c89171a28f22271efa37b554.zip |
Add owned repositories and public key fingerprints to admin show user command
Diffstat (limited to 'src/main/java/com/gitblit/transport')
-rw-r--r-- | src/main/java/com/gitblit/transport/ssh/gitblit/UsersDispatcher.java | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/src/main/java/com/gitblit/transport/ssh/gitblit/UsersDispatcher.java b/src/main/java/com/gitblit/transport/ssh/gitblit/UsersDispatcher.java index d892d9a0..0b83cecd 100644 --- a/src/main/java/com/gitblit/transport/ssh/gitblit/UsersDispatcher.java +++ b/src/main/java/com/gitblit/transport/ssh/gitblit/UsersDispatcher.java @@ -27,6 +27,7 @@ import com.gitblit.models.RegistrantAccessPermission; import com.gitblit.models.RepositoryModel; import com.gitblit.models.TeamModel; import com.gitblit.models.UserModel; +import com.gitblit.transport.ssh.SshKey; import com.gitblit.transport.ssh.commands.CommandMetaData; import com.gitblit.transport.ssh.commands.DispatchCommand; import com.gitblit.transport.ssh.commands.ListFilterCommand; @@ -296,6 +297,27 @@ public class UsersDispatcher extends DispatchCommand { teams = FlipTable.of(theaders, tdata, Borders.COLS); } + // owned repositories + String ownedTable; + List<RepositoryModel> owned = new ArrayList<RepositoryModel>(); + for (RepositoryModel repository : getContext().getGitblit().getRepositoryModels(u)) { + if (repository.isOwner(u.username)) { + owned.add(repository); + } + } + if (owned.isEmpty()) { + ownedTable = FlipTable.EMPTY; + } else { + String [] theaders = new String [] { "Repository", "Description" }; + Object [][] tdata = new Object[owned.size()][]; + int i = 0; + for (RepositoryModel r : owned) { + tdata[i] = new Object [] { r.name, r.description }; + i++; + } + ownedTable = FlipTable.of(theaders, tdata, Borders.COLS); + } + // permissions List<RegistrantAccessPermission> perms = u.getRepositoryPermissions(); String permissions; @@ -311,25 +333,47 @@ public class UsersDispatcher extends DispatchCommand { permissions = FlipTable.of(pheaders, pdata, Borders.COLS); } + // keys + String keyTable; + List<SshKey> keys = getContext().getGitblit().getPublicKeyManager().getKeys(u.username); + if (ArrayUtils.isEmpty(keys)) { + keyTable = FlipTable.EMPTY; + } else { + String[] headers = { "#", "Fingerprint", "Comment", "Type" }; + int len = keys == null ? 0 : keys.size(); + Object[][] data = new Object[len][]; + for (int i = 0; i < len; i++) { + // show 1-based index numbers with the fingerprint + // this is useful for comparing with "ssh-add -l" + SshKey k = keys.get(i); + data[i] = new Object[] { (i + 1), k.getFingerprint(), k.getComment(), k.getAlgorithm() }; + } + keyTable = FlipTable.of(headers, data, Borders.COLS); + } + // assemble user table String userTitle = u.getDisplayName() + (u.username.equals(u.getDisplayName()) ? "" : (" (" + u.username + ")")); if (u.disabled) { userTitle += " [DISABLED]"; } String [] headers = new String[] { userTitle }; - String[][] data = new String[6][]; + String[][] data = new String[8][]; data[0] = new String [] { "FIELDS" }; data[1] = new String [] { fields }; data[2] = new String [] { "TEAMS" }; data[3] = new String [] { teams }; + data[4] = new String [] { "OWNED REPOSITORIES" }; + data[5] = new String [] { ownedTable }; data[4] = new String [] { "PERMISSIONS" }; data[5] = new String [] { permissions }; + data[6] = new String [] { "SSH PUBLIC KEYS" }; + data[7] = new String [] { keyTable }; stdout.println(FlipTable.of(headers, data)); } } @CommandMetaData(name = "list", aliases= { "ls" }, description = "List accounts") - @UsageExamples( examples = { + @UsageExamples(examples = { @UsageExample(syntax = "${cmd}", description = "List accounts as a table"), @UsageExample(syntax = "${cmd} j.*", description = "List all accounts that start with 'j'"), }) |