Fix GroupControl check for isOwner()
This check was broken when groups were changed to use UUIDs for the effective groups set of an IdentifiedUser. The check must pass the new UUID type to contains() rather than the older Id type. We cache the owner decision in case we get multiple calls are made to this GroupControl. This happens in the loops that invoke the canSee() methods for each element. Change-Id: Ifaa6adb456183267fc8030a1fcb04c283b20e941 Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
parent
b352fc6c5e
commit
3d1f73fff7
|
@ -39,7 +39,7 @@ public class GroupControl {
|
|||
if (group == null) {
|
||||
throw new NoSuchGroupException(groupId);
|
||||
}
|
||||
return new GroupControl(user.get(), group);
|
||||
return new GroupControl(groupCache, user.get(), group);
|
||||
}
|
||||
|
||||
public GroupControl controlFor(final AccountGroup.UUID groupId)
|
||||
|
@ -48,11 +48,11 @@ public class GroupControl {
|
|||
if (group == null) {
|
||||
throw new NoSuchGroupException(groupId);
|
||||
}
|
||||
return new GroupControl(user.get(), group);
|
||||
return new GroupControl(groupCache, user.get(), group);
|
||||
}
|
||||
|
||||
public GroupControl controlFor(final AccountGroup group) {
|
||||
return new GroupControl(user.get(), group);
|
||||
return new GroupControl(groupCache, user.get(), group);
|
||||
}
|
||||
|
||||
public GroupControl validateFor(final AccountGroup.Id groupId)
|
||||
|
@ -65,10 +65,13 @@ public class GroupControl {
|
|||
}
|
||||
}
|
||||
|
||||
private final GroupCache groupCache;
|
||||
private final CurrentUser user;
|
||||
private final AccountGroup group;
|
||||
private Boolean isOwner;
|
||||
|
||||
GroupControl(final CurrentUser who, final AccountGroup gc) {
|
||||
GroupControl(GroupCache g, CurrentUser who, AccountGroup gc) {
|
||||
groupCache = g;
|
||||
user = who;
|
||||
group = gc;
|
||||
}
|
||||
|
@ -87,9 +90,13 @@ public class GroupControl {
|
|||
}
|
||||
|
||||
public boolean isOwner() {
|
||||
final AccountGroup.Id owner = group.getOwnerGroupId();
|
||||
return getCurrentUser().getEffectiveGroups().contains(owner)
|
||||
|| getCurrentUser().isAdministrator();
|
||||
if (isOwner == null) {
|
||||
AccountGroup g = groupCache.get(group.getOwnerGroupId());
|
||||
AccountGroup.UUID ownerUUID = g != null ? g.getGroupUUID() : null;
|
||||
isOwner = getCurrentUser().getEffectiveGroups().contains(ownerUUID)
|
||||
|| getCurrentUser().isAdministrator();
|
||||
}
|
||||
return isOwner;
|
||||
}
|
||||
|
||||
public boolean canAddMember(final Account.Id id) {
|
||||
|
|
Loading…
Reference in New Issue