Merge "Improve suggest user performance when adding a reviewer."
This commit is contained in:
commit
3a50e57890
@ -224,16 +224,27 @@ class SuggestServiceImpl extends BaseServiceImplementation implements
|
||||
} catch (NoSuchChangeException e) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
VisibilityControl visibilityControl = new VisibilityControl() {
|
||||
@Override
|
||||
public boolean isVisible(Account account) throws OrmException {
|
||||
IdentifiedUser who =
|
||||
identifiedUserFactory.create(reviewDbProvider, account.getId());
|
||||
// we can't use changeControl directly as it won't suggest reviewers
|
||||
// to drafts
|
||||
return changeControl.forUser(who).isRefVisible();
|
||||
}
|
||||
};
|
||||
|
||||
VisibilityControl visibilityControl;
|
||||
if (changeControl.getRefControl().isVisibleByRegisteredUsers()) {
|
||||
visibilityControl = new VisibilityControl() {
|
||||
@Override
|
||||
public boolean isVisible(Account account) throws OrmException {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
} else {
|
||||
visibilityControl = new VisibilityControl() {
|
||||
@Override
|
||||
public boolean isVisible(Account account) throws OrmException {
|
||||
IdentifiedUser who =
|
||||
identifiedUserFactory.create(reviewDbProvider, account.getId());
|
||||
// we can't use changeControl directly as it won't suggest reviewers
|
||||
// to drafts
|
||||
return changeControl.forUser(who).isRefVisible();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
final List<AccountInfo> suggestedAccounts =
|
||||
suggestAccount(db, query, Boolean.TRUE, limit, visibilityControl);
|
||||
|
@ -20,6 +20,7 @@ import com.google.gerrit.common.data.PermissionRange;
|
||||
import com.google.gerrit.common.data.PermissionRule;
|
||||
import com.google.gerrit.common.data.RefConfigSection;
|
||||
import com.google.gerrit.common.errors.InvalidNameException;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
@ -106,6 +107,25 @@ public class RefControl {
|
||||
&& canRead();
|
||||
}
|
||||
|
||||
/**
|
||||
* True if this reference is visible by all REGISTERED_USERS
|
||||
*/
|
||||
public boolean isVisibleByRegisteredUsers() {
|
||||
List<PermissionRule> access = relevant.getPermission(Permission.READ);
|
||||
for (PermissionRule rule : access) {
|
||||
if (rule.isBlock()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (PermissionRule rule : access) {
|
||||
if (rule.getGroup().getUUID().equals(AccountGroup.ANONYMOUS_USERS)
|
||||
|| rule.getGroup().getUUID().equals(AccountGroup.REGISTERED_USERS)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the user can upload a change to the ref controlled by
|
||||
* this object.
|
||||
|
Loading…
Reference in New Issue
Block a user