Repository navigation
[2.0] Authorize Document Store writes in one place (backport 2.0 #38196) - #38204
Conversation
Code Review ✅ Approved 🔴 High riskAdmin-only enforcement across email-template writes and resets changes authorization; absent checks, document editors could alter templates used in outgoing emails. Ports the email template write authorization into VerificationRules No rules evaluated Functional validation Not enabledAuto-approval Not enabledFor more verification details, comment OptionsDisplay: compact → Showing compact verification results. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
| CreateUser createUser = new CreateUser(); | ||
| createUser.setName(prefix + "_user"); | ||
| createUser.setEmail(prefix + "[email protected]"); | ||
| createUser.setRoles(List.of(role.getId())); | ||
| User user = admin.users().create(createUser); | ||
| return SdkClients.createClient(user.getName(), user.getEmail(), new String[] {}); |
There was a problem hiding this comment.
Test accounts are never removed. Each call to
documentEditor creates a policy, role, and user without arranging cleanup. Both new tests leave these records behind, so repeated runs grow the shared test cluster. Add cleanup for all three records, including when setup or assertions fail; NamespaceCleanup currently has no mapping for policies or roles.
| private static OpenMetadataClient documentEditor(String prefix) { | ||
| OpenMetadataClient admin = SdkClients.adminClient(); | ||
| Rule rule = | ||
| new Rule() | ||
| .withName(prefix + "_edit") | ||
| .withResources(List.of(Entity.DOCUMENT)) | ||
| .withOperations( | ||
| List.of( | ||
| MetadataOperation.CREATE, | ||
| MetadataOperation.EDIT_ALL, | ||
| MetadataOperation.DELETE, | ||
| MetadataOperation.VIEW_ALL)) | ||
| .withEffect(Rule.Effect.ALLOW); |
There was a problem hiding this comment.
Test setup is too large.
documentEditor builds a rule, policy, role, user, and client in one long method. The repository guide requires small, focused methods and asks for about 15 lines or fewer. Extract the policy and account setup into named helpers. The two added test methods also exceed that guidance.
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| private String storedEntityType(String fullyQualifiedName) { | ||
| Document stored = repository.findByNameOrNull(fullyQualifiedName, Include.ALL); |
There was a problem hiding this comment.
Unchanged bindings lack
final. The new helper parameters and local variables are never reassigned but omit final. The repository guide requires final on local variables and parameters that do not change. Apply it here and throughout the added helpers and tests.
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| private static final ObjectMapper MAPPER = | ||
| new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | ||
| private static final String EMAIL_TEMPLATE_NAME = "testMail"; | ||
| private static final String EMAIL_TEMPLATE = "EmailTemplate"; |
There was a problem hiding this comment.
Template type constant is duplicated.
EMAIL_TEMPLATE repeats the existing DefaultTemplateProvider.ENTITY_TYPE_EMAIL_TEMPLATE value. The repository guide requires one definition per constant across classes. Reuse the existing constant instead of adding another definition.
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| private String storedEntityType(UUID id) { | ||
| return repository.find(id, Include.ALL).getEntityType(); | ||
| } | ||
|
|
||
| private String storedEntityType(String fullyQualifiedName) { |
There was a problem hiding this comment.
Helper names omit actions. The new
storedEntityType helpers use noun phrases, while the repository guide requires method names to be verb phrases. Rename them to getStoredEntityType or another action name. The new documentEditor factory should likewise use an action name such as createDocumentEditor.
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Describe your changes:
Backport of #38196 to
2.0. No linked issue.The email template authorization in the Document Store moves into
DocStoreResource: one helper,requireAdminForEmailTemplates, that every write endpoint calls.DocStoreMapperonly converts the request and validates the template content, and PATCH keeps a document'sentityType, the same way it keeps the name and FQN.The cherry-pick did not apply cleanly, because
2.0does not have the private document types thatmainchecks in the same methods. So this is a port, not a copy:DocStoreMapper,DocumentRepository, thePatchEntityToolcomment andDocStoreResourceIT.DocStoreResourcelooks the stored document up with two small helpers instead ofmain's private-type guard.main:resetEmailTemplatechecks for an admin, as it does onmain, with one assertion for it inDocStoreResourceIT.Type of change:
Tests:
Unit tests
Not added, as in #38196: the change is an HTTP authorization rule, covered end to end by
DocStoreResourceIT.Backend integration tests
DocStoreResourceITon2.0(MySQL + Elasticsearch, parallel lane): 14 tests, all passed.2.0without this change.UI screen recording:
Not applicable: backend-only change.
Checklist:
Fixes #<issue-number>above. No linked issue, as in Authorize Document Store writes in one place #38196.REVIEW.md; Authorize Document Store writes in one place #38196 itself had a fresh-eyes review with no 🔴.Meet the repository’s Java requirements before merging; test-record cleanup is also worth fixing.
Findings
Summary
This PR moves email-template write checks into
DocStoreResourceand keeps a document’s type unchanged during PATCH.Reviews (1) · Last reviewed commit: "[2.0] Authorize Document Store writes in..." · Reviewed by Greptile