Skip to content

Commit

Permalink
Fix where memeber or token with null permission
Browse files Browse the repository at this point in the history
  • Loading branch information
minwoox committed Dec 24, 2024
1 parent f4dda40 commit a0f108e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package com.linecorp.centraldogma.server.metadata;

import static com.google.common.collect.ImmutableMap.toImmutableMap;

import java.io.IOException;
import java.util.Collection;
import java.util.Map;
Expand All @@ -29,6 +27,8 @@
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;

import com.linecorp.centraldogma.common.RepositoryRole;
import com.linecorp.centraldogma.internal.Jackson;
Expand Down Expand Up @@ -94,7 +94,16 @@ private static RepositoryRole repositoryRole(Collection<Permission> permissions)
}

private static Map<String, RepositoryRole> convert(Map<String, Collection<Permission>> permissions) {
return permissions.entrySet().stream()
.collect(toImmutableMap(Entry::getKey, entry -> repositoryRole(entry.getValue())));
final Builder<String, RepositoryRole> builder = ImmutableMap.builder();
for (Entry<String, Collection<Permission>> entry : permissions.entrySet()) {
final Collection<Permission> value = entry.getValue();
if (!value.isEmpty()) {
final RepositoryRole repositoryRole = repositoryRole(value);
assert repositoryRole != null;
builder.put(entry.getKey(), repositoryRole);
}
}

return builder.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ void deserializeLegacyFormat() throws Exception {
" \"[email protected]\": [" +
" \"READ\"," +
" \"WRITE\"" +
" ]" +
" ]," +
" \"emptyMember\": []" + // Will be removed
" }," +
" \"perTokenPermissions\": {" +
" \"goodman\": [" +
" \"READ\"" +
" ]" +
" ]," +
" \"emptyToken\": []" + // Will be removed
" }," +
" \"creation\": {" +
" \"user\": \"[email protected]\"," +
Expand Down

0 comments on commit a0f108e

Please sign in to comment.