Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement permission checks to prevent unnecessary overwrit… #2506

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

aktaskaan
Copy link
Contributor

JIRA link (if applicable)

https://tools.hmcts.net/jira/browse/CCD-6022

Change description

Does this PR introduce a breaking change? (check one with "x")

[ ] Yes
[ ] No

Copy link
Member

@danlysiak danlysiak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few suggestions for readability related things in the implementation

Comment on lines +58 to +62
CaseFieldDefinition rootFieldDefinition = caseTypeDefinition.getCaseFieldDefinitions()
.stream()
.filter(field -> field.getId().equals(key))
.findFirst()
.orElse(null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can instead use an existing method?

Suggested change
CaseFieldDefinition rootFieldDefinition = caseTypeDefinition.getCaseFieldDefinitions()
.stream()
.filter(field -> field.getId().equals(key))
.findFirst()
.orElse(null);
Optional<CaseFieldDefinition> rootFieldDefinition = caseTypeDefinition.getCaseField(key);


@Slf4j
@Service
public class RestrictedFieldProcessor {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Restricted fields" are already an existing concept to do with the classification, which this new logic is not related to, so perhaps we should rename this to something a bit more specific around the use case it's for. I think a comment on this one would be useful too for people looking back at this in future to explain the purpose of this class, since it's for a very specific type of scenario.

Comment on lines +262 to +265
return parentFieldType.getComplexFields()
.stream()
.filter(subField -> subField.getId().equals(fieldName))
.findFirst()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a useful helper so worth moving to FieldTypeDefinition.

Comment on lines +271 to +275
return parentFieldType.getCollectionFieldTypeDefinition().getComplexFields()
.stream()
.filter(subField -> subField.getId().equals(fieldName))
.findFirst()
.orElse(parentFieldDefinition);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could then use the same helper as the previous comment!

Comment on lines +231 to +235
private boolean isNullId(JsonNode newItem) {
return newItem.get(ID) == null
|| newItem.get(ID).equals(NullNode.getInstance())
|| "null".equalsIgnoreCase(newItem.get(ID).asText());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering whether we can delete this method and sufficiently use newItem.hasNonNull(ID) in the single place this is being used instead, or are we treating the string "null" as null elsewhere in CCD too? While it's an edge case and would be strange for anyone to try, from a quick look at CollectionValidator we just verify it's some text so technically one item could be set to "null"!

this.caseAccessService = caseAccessService;
}

public Map<String, JsonNode> filterRestrictedFields(final CaseTypeDefinition caseTypeDefinition,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not really filtering here, if anything it's sometimes the opposite? Maybe just call it process() or apply() and with a suitable class name should make sense!

Comment on lines +241 to +242
.anyMatch(acl -> accessProfileNames.contains(acl.getAccessProfile())
&& Boolean.TRUE.equals(acl.isRead()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.anyMatch(acl -> accessProfileNames.contains(acl.getAccessProfile())
&& Boolean.TRUE.equals(acl.isRead()));
.anyMatch(acl -> accessProfileNames.contains(acl.getAccessProfile()) && acl.isRead());

Comment on lines +246 to +247
.anyMatch(acl -> accessProfileNames.contains(acl.getAccessProfile())
&& Boolean.TRUE.equals(acl.isCreate()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.anyMatch(acl -> accessProfileNames.contains(acl.getAccessProfile())
&& Boolean.TRUE.equals(acl.isCreate()));
.anyMatch(acl -> accessProfileNames.contains(acl.getAccessProfile()) && acl.isCreate());

return !hasReadPermission && hasCreatePermission;
}

private CaseFieldDefinition getFieldDefinition(String fieldName,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method might sit better in CaseFieldDefinition as getSubfieldDefinition(fieldName).

}
}

private JsonNode processValueField(CaseFieldDefinition subFieldDefinition,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this work if we had collections of collections?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants