Teach PermissionBackend to accept plugin defined project permission
This commit allows plugins to define project permissions and updates the PermissionBackend interface to accept plugin defined project permissions. This commit doesn't implement the strategies for handling plugin project permissions and leave it to follow-up commits. Change-Id: Ib9d8d80045e50d51237da6d420aa9bfe001ca207
This commit is contained in:
@@ -40,7 +40,6 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import java.util.Collection;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
@@ -128,7 +127,7 @@ public class DefaultPermissionBackend extends PermissionBackend {
|
||||
@Override
|
||||
public <T extends GlobalOrPluginPermission> Set<T> test(Collection<T> permSet)
|
||||
throws PermissionBackendException {
|
||||
Set<T> ok = newSet(permSet);
|
||||
Set<T> ok = Sets.newHashSetWithExpectedSize(permSet.size());
|
||||
for (T perm : permSet) {
|
||||
if (can(perm)) {
|
||||
ok.add(perm);
|
||||
@@ -147,7 +146,7 @@ public class DefaultPermissionBackend extends PermissionBackend {
|
||||
return can((GlobalPermission) perm);
|
||||
} else if (perm instanceof PluginPermission) {
|
||||
PluginPermission pluginPermission = (PluginPermission) perm;
|
||||
return has(DefaultPermissionMappings.pluginPermissionName(pluginPermission))
|
||||
return has(DefaultPermissionMappings.pluginCapabilityName(pluginPermission))
|
||||
|| (pluginPermission.fallBackToAdmin() && isAdmin());
|
||||
}
|
||||
throw new PermissionBackendException(perm + " unsupported");
|
||||
@@ -269,14 +268,4 @@ public class DefaultPermissionBackend extends PermissionBackend {
|
||||
return denied.isEmpty() || !user.getEffectiveGroups().containsAnyOf(denied);
|
||||
}
|
||||
}
|
||||
|
||||
private static <T extends GlobalOrPluginPermission> Set<T> newSet(Collection<T> permSet) {
|
||||
if (permSet instanceof EnumSet) {
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
Set<T> s = ((EnumSet) permSet).clone();
|
||||
s.clear();
|
||||
return s;
|
||||
}
|
||||
return Sets.newHashSetWithExpectedSize(permSet.size());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user