Add group editing support to the UI
Admins and members who have the "owner" flag set to true may edit the contents of a group by changing its description or editing its membership list. Changes are mostly done live, as soon as the user presses the action keys. Account lookup is completed through the suggest service, helping the user to complete an account identity by name and/or the user's preferred email address. Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -16,8 +16,11 @@ package com.google.gerrit.client.reviewdb;
|
||||
|
||||
import com.google.gwtorm.client.Column;
|
||||
import com.google.gwtorm.client.IntKey;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.gwtorm.client.ResultSet;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
/** Preferences and information about a single user. */
|
||||
public final class Account {
|
||||
@@ -27,6 +30,37 @@ public final class Account {
|
||||
/** Typical valid choices for the default context setting. */
|
||||
public static final short[] CONTEXT_CHOICES = {3, 10, 25, 50, 75, 100};
|
||||
|
||||
/**
|
||||
* Locate exactly one account matching the name or name/email string.
|
||||
*
|
||||
* @param db open database handle to use for the query.
|
||||
* @param nameOrEmail a string of the format
|
||||
* "Full Name <email@example>", or just the preferred email
|
||||
* address ("email@example"), or a full name.
|
||||
* @return the single account that matches; null if no account matches or
|
||||
* there are multiple candidates.
|
||||
*/
|
||||
public static Account find(final ReviewDb db, final String nameOrEmail)
|
||||
throws OrmException {
|
||||
final int lt = nameOrEmail.indexOf('<');
|
||||
final int gt = nameOrEmail.indexOf('>');
|
||||
if (lt >= 0 && gt > lt) {
|
||||
final String email = nameOrEmail.substring(lt + 1, gt);
|
||||
return one(db.accounts().byPreferredEmail(email));
|
||||
}
|
||||
|
||||
if (nameOrEmail.contains("@")) {
|
||||
return one(db.accounts().byPreferredEmail(nameOrEmail));
|
||||
}
|
||||
|
||||
return one(db.accounts().suggestByFullName(nameOrEmail, nameOrEmail, 2));
|
||||
}
|
||||
|
||||
private static Account one(final ResultSet<Account> rs) {
|
||||
final List<Account> r = rs.toList();
|
||||
return r.size() == 1 ? r.get(0) : null;
|
||||
}
|
||||
|
||||
/** Key local to Gerrit to identify a user. */
|
||||
public static class Id extends IntKey<com.google.gwtorm.client.Key<?>> {
|
||||
@Column
|
||||
|
||||
@@ -28,4 +28,12 @@ public interface AccountAccess extends Access<Account, Account.Id> {
|
||||
|
||||
@Query("WHERE preferredEmail = ? LIMIT 2")
|
||||
ResultSet<Account> byPreferredEmail(String email) throws OrmException;
|
||||
|
||||
@Query("WHERE fullName >= ? AND fullName <= ? ORDER BY fullName LIMIT ?")
|
||||
ResultSet<Account> suggestByFullName(String nameA, String nameB, int limit)
|
||||
throws OrmException;
|
||||
|
||||
@Query("WHERE preferredEmail >= ? AND preferredEmail <= ? ORDER BY preferredEmail LIMIT ?")
|
||||
ResultSet<Account> suggestByPreferredEmail(String nameA, String nameB,
|
||||
int limit) throws OrmException;
|
||||
}
|
||||
|
||||
@@ -65,6 +65,13 @@ public final class AccountGroup {
|
||||
protected void set(int newValue) {
|
||||
id = newValue;
|
||||
}
|
||||
|
||||
/** Parse an AccountGroup.Id out of a string representation. */
|
||||
public static Id parse(final String str) {
|
||||
final Id r = new Id();
|
||||
r.fromString(str);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
@Column
|
||||
|
||||
@@ -41,6 +41,10 @@ public final class AccountGroupMember {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
public AccountGroup.Id getAccountGroupId(){
|
||||
return groupId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public com.google.gwtorm.client.Key<?>[] members() {
|
||||
return new com.google.gwtorm.client.Key<?>[] {groupId};
|
||||
@@ -61,6 +65,10 @@ public final class AccountGroupMember {
|
||||
key = k;
|
||||
}
|
||||
|
||||
public AccountGroupMember.Key getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public Account.Id getAccountId() {
|
||||
return key.accountId;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,9 @@ public interface AccountGroupMemberAccess extends
|
||||
@Query("WHERE key.accountId = ?")
|
||||
ResultSet<AccountGroupMember> byAccount(Account.Id id) throws OrmException;
|
||||
|
||||
@Query("WHERE key.accountId = ? AND owner = 'Y'")
|
||||
ResultSet<AccountGroupMember> owned(Account.Id id) throws OrmException;
|
||||
|
||||
@Query("WHERE key.groupId = ?")
|
||||
ResultSet<AccountGroupMember> byGroup(AccountGroup.Id id) throws OrmException;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user