summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/gitblit/transport
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2014-03-22 20:37:51 -0400
committerJames Moger <james.moger@gitblit.com>2014-04-10 18:58:10 -0400
commit07fd0117bddd67e141d4c1f405e2a1e9f815c9e3 (patch)
tree055362c53777e367f61bca46d1a0e577740728fd /src/main/java/com/gitblit/transport
parent4a69998080bd01180c5e46e4f4fd2c50586fea80 (diff)
downloadgitblit-07fd0117bddd67e141d4c1f405e2a1e9f815c9e3.tar.gz
gitblit-07fd0117bddd67e141d4c1f405e2a1e9f815c9e3.zip
Improve table rendering and uer details display
Diffstat (limited to 'src/main/java/com/gitblit/transport')
-rw-r--r--src/main/java/com/gitblit/transport/ssh/gitblit/KeysDispatcher.java14
-rw-r--r--src/main/java/com/gitblit/transport/ssh/gitblit/ProjectsDispatcher.java6
-rw-r--r--src/main/java/com/gitblit/transport/ssh/gitblit/RepositoriesDispatcher.java18
-rw-r--r--src/main/java/com/gitblit/transport/ssh/gitblit/UsersDispatcher.java71
4 files changed, 75 insertions, 34 deletions
diff --git a/src/main/java/com/gitblit/transport/ssh/gitblit/KeysDispatcher.java b/src/main/java/com/gitblit/transport/ssh/gitblit/KeysDispatcher.java
index b8c18a03..3422f506 100644
--- a/src/main/java/com/gitblit/transport/ssh/gitblit/KeysDispatcher.java
+++ b/src/main/java/com/gitblit/transport/ssh/gitblit/KeysDispatcher.java
@@ -142,10 +142,6 @@ public class KeysDispatcher extends DispatchCommand {
IPublicKeyManager keyManager = getContext().getGitblit().getPublicKeyManager();
String username = getContext().getClient().getUsername();
List<SshKey> keys = keyManager.getKeys(username);
- if (keys == null || keys.isEmpty()) {
- stdout.println("You have not registered any public keys for ssh authentication.");
- return;
- }
if (showRaw) {
asRaw(keys);
@@ -156,6 +152,9 @@ public class KeysDispatcher extends DispatchCommand {
/* output in the same format as authorized_keys */
protected void asRaw(List<SshKey> keys) {
+ if (keys == null) {
+ return;
+ }
for (SshKey key : keys) {
stdout.println(key.getRawData());
}
@@ -163,15 +162,16 @@ public class KeysDispatcher extends DispatchCommand {
protected void asTable(List<SshKey> keys) {
String[] headers = { "#", "Fingerprint", "Comment", "Type" };
- String[][] data = new String[keys.size()][];
- for (int i = 0; i < keys.size(); i++) {
+ int len = keys == null ? 0 : keys.size();
+ String[][] data = new String[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 String[] { "" + (i + 1), k.getFingerprint(), k.getComment(), k.getAlgorithm() };
}
- stdout.println(FlipTable.of(headers, data, Borders.BODY_COLS));
+ stdout.println(FlipTable.of(headers, data, Borders.BODY_HCOLS));
}
}
}
diff --git a/src/main/java/com/gitblit/transport/ssh/gitblit/ProjectsDispatcher.java b/src/main/java/com/gitblit/transport/ssh/gitblit/ProjectsDispatcher.java
index 926d4806..177102e4 100644
--- a/src/main/java/com/gitblit/transport/ssh/gitblit/ProjectsDispatcher.java
+++ b/src/main/java/com/gitblit/transport/ssh/gitblit/ProjectsDispatcher.java
@@ -67,7 +67,7 @@ public class ProjectsDispatcher extends DispatchCommand {
String[] h = { "Name", "Description", "Last Modified", "# Repos" };
headers = h;
} else {
- String[] h = { "Name", "Description" };
+ String[] h = { "Name", "Last Modified", "# Repos" };
headers = h;
}
@@ -79,10 +79,10 @@ public class ProjectsDispatcher extends DispatchCommand {
if (verbose) {
data[i] = new String[] { p.name, p.description, df.format(p.lastChange), "" + p.repositories.size() };
} else {
- data[i] = new String[] { p.name, p.description };
+ data[i] = new String[] { p.name, df.format(p.lastChange), "" + p.repositories.size() };
}
}
- stdout.println(FlipTable.of(headers, data, Borders.BODY_COLS));
+ stdout.println(FlipTable.of(headers, data, Borders.BODY_HCOLS));
}
protected void asTabbed(List<ProjectModel> list) {
diff --git a/src/main/java/com/gitblit/transport/ssh/gitblit/RepositoriesDispatcher.java b/src/main/java/com/gitblit/transport/ssh/gitblit/RepositoriesDispatcher.java
index 30f7393c..329e95e2 100644
--- a/src/main/java/com/gitblit/transport/ssh/gitblit/RepositoriesDispatcher.java
+++ b/src/main/java/com/gitblit/transport/ssh/gitblit/RepositoriesDispatcher.java
@@ -69,7 +69,7 @@ public class RepositoriesDispatcher extends DispatchCommand {
String[] h = { "Name", "Description", "Owners", "Last Modified", "Size" };
headers = h;
} else {
- String[] h = { "Name", "Description" };
+ String[] h = { "Name", "Last Modified", "Size" };
headers = h;
}
@@ -77,22 +77,23 @@ public class RepositoriesDispatcher extends DispatchCommand {
for (int i = 0; i < list.size(); i++) {
RepositoryModel r = list.get(i);
+ String lm = df.format(r.lastChange);
+ String size = r.size;
+ if (!r.hasCommits) {
+ lm = "";
+ size = "(empty)";
+ }
if (verbose) {
- String lm = df.format(r.lastChange);
String owners = "";
if (!ArrayUtils.isEmpty(r.owners)) {
owners = Joiner.on(",").join(r.owners);
}
- String size = r.size;
- if (!r.hasCommits) {
- size = "(empty)";
- }
data[i] = new String[] { r.name, r.description, owners, lm, size };
} else {
- data[i] = new String[] { r.name, r.description };
+ data[i] = new String[] { r.name, lm, size };
}
}
- stdout.println(FlipTable.of(headers, data, Borders.BODY_COLS));
+ stdout.println(FlipTable.of(headers, data, Borders.BODY_HCOLS));
}
protected void asTabbed(List<RepositoryModel> list) {
@@ -112,6 +113,7 @@ public class RepositoriesDispatcher extends DispatchCommand {
}
String size = r.size;
if (!r.hasCommits) {
+ lm = "";
size = "(empty)";
}
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 10ce26f0..1682ab48 100644
--- a/src/main/java/com/gitblit/transport/ssh/gitblit/UsersDispatcher.java
+++ b/src/main/java/com/gitblit/transport/ssh/gitblit/UsersDispatcher.java
@@ -22,6 +22,7 @@ import org.kohsuke.args4j.Option;
import com.gitblit.manager.IGitblit;
import com.gitblit.models.RegistrantAccessPermission;
+import com.gitblit.models.TeamModel;
import com.gitblit.models.UserModel;
import com.gitblit.transport.ssh.commands.CommandMetaData;
import com.gitblit.transport.ssh.commands.DispatchCommand;
@@ -32,6 +33,10 @@ import com.gitblit.utils.FlipTable.Borders;
@CommandMetaData(name = "users", description = "User management commands", admin = true)
public class UsersDispatcher extends DispatchCommand {
+ private static final String banner1 = "===========================================================";
+
+ private static final String banner2 = "-----------------------------------------------------------";
+
@Override
protected void setup(UserModel user) {
register(user, ShowUser.class);
@@ -46,16 +51,51 @@ public class UsersDispatcher extends DispatchCommand {
@Override
public void run() throws UnloggedFailure {
IGitblit gitblit = getContext().getGitblit();
- UserModel user = gitblit.getUserModel(username);
- if (user == null) {
+ UserModel u = gitblit.getUserModel(username);
+ if (u == null) {
throw new UnloggedFailure(1, String.format("Unknown user \"%s\"", username));
}
- stdout.println();
- stdout.println(user.username);
- stdout.println();
- for (RegistrantAccessPermission ap : user.getRepositoryPermissions()) {
- stdout.println(String.format("%s %s", ap.registrant, ap.permission));
+
+ // fields
+ String [] fheaders = new String [] { "Field", "Value" };
+ String [][] fdata = new String[5][];
+ fdata[0] = new String [] { "Email", u.emailAddress };
+ fdata[1] = new String [] { "Type", u.accountType.toString() };
+ fdata[2] = new String [] { "Can Admin", u.canAdmin() ? "Y":"N" };
+ fdata[3] = new String [] { "Can Fork", u.canFork() ? "Y":"N" };
+ fdata[4] = new String [] { "Can Create", u.canCreate() ? "Y":"N" };
+ String fields = FlipTable.of(fheaders, fdata, Borders.COLS);
+
+ // teams
+ String [] theaders = new String [] { "Team", "Type" };
+ String [][] tdata = new String[u.teams.size()][];
+ int i = 0;
+ for (TeamModel t : u.teams) {
+ tdata[i] = new String [] { t.name, t.accountType.toString() };
+ i++;
+ }
+ String teams = FlipTable.of(theaders, tdata, Borders.COLS);
+
+ // permissions
+ List<RegistrantAccessPermission> perms = u.getRepositoryPermissions();
+ String[] pheaders = { "Repository", "Permission", "Type", "Source", "Mutable" };
+ String [][] pdata = new String[perms.size()][];
+ for (i = 0; i < perms.size(); i++) {
+ RegistrantAccessPermission ap = perms.get(i);
+ pdata[i] = new String[] { ap.registrant, ap.permission.toString(), ap.permissionType.toString(), ap.source, ap.mutable ? "Y":"N" };
}
+ String permissions = FlipTable.of(pheaders, pdata, Borders.COLS);
+
+ // assemble user table
+ String [] headers = new String[] { u.getDisplayName() + (u.username.equals(u.getDisplayName()) ? "" : (" (" + u.username + ")")) };
+ String[][] data = new String[6][];
+ data[0] = new String [] { "FIELDS" };
+ data[1] = new String [] { fields };
+ data[2] = new String [] { "TEAMS" };
+ data[3] = new String [] { teams };
+ data[4] = new String [] { "PERMISSIONS" };
+ data[5] = new String [] { permissions };
+ stdout.println(FlipTable.of(headers, data));
}
}
@@ -83,10 +123,10 @@ public class UsersDispatcher extends DispatchCommand {
protected void asTable(List<UserModel> list) {
String[] headers;
if (verbose) {
- String[] h = { "Name", "Display name", "Type", "E-mail", "Create?", "Fork?"};
+ String[] h = { "Name", "Display name", "Type", "Email", "Create?", "Fork?"};
headers = h;
} else {
- String[] h = { "Name", "Display name", "Type", "E-mail"};
+ String[] h = { "Name", "Display name", "Type", "Email"};
headers = h;
}
@@ -96,16 +136,15 @@ public class UsersDispatcher extends DispatchCommand {
String name = u.disabled ? "-" : ((u.canAdmin() ? "*" : " ")) + u.username;
if (verbose) {
- data[i] = new String[] { name, u.displayName == null ? "" : u.displayName,
- u.accountType.name(), u.emailAddress == null ? "" : u.emailAddress ,
- u.canCreate() ? "Y":"", u.canFork() ? "Y" : ""};
+ data[i] = new String[] { name, u.displayName, u.accountType.name(),
+ u.emailAddress, u.canCreate() ? "Y":"", u.canFork() ? "Y" : ""};
} else {
- data[i] = new String[] { name, u.displayName == null ? "" : u.displayName,
- u.accountType.name(), u.emailAddress == null ? "" : u.emailAddress };
+ data[i] = new String[] { name, u.displayName, u.accountType.name(),
+ u.emailAddress };
}
}
- stdout.print(FlipTable.of(headers, data, Borders.BODY_COLS));
- stdout.println("* = admin account, - = disabled account");
+ stdout.print(FlipTable.of(headers, data, Borders.BODY_HCOLS));
+ stdout.println(" * = admin account, - = disabled account");
stdout.println();
}