Very cool. So I agree with you that the limitation here is in that the Custom Filters wouldn’t work for dynamically enabling/disabling the field level permission, but only the record level permission. Because of that, I think the approach would actually require a Custom Resolver (if you’re not comfortable simply having your frontend hide/show or use 2 different queries for the Content field based on the deactivated value.
With a Custom Resolver, you could then protect your API with two Roles (this is a hypothetical):
- “Author” Role: Can see their own Comments and the Content.
- “Reader” Role: Can only see Comments that are not Deactivated.
This would then make sure that a user cannot hit the API (with an API client) and get your deactivated records.
Then, you create a custom Resolver called, let’s say getCommentsWithDeactivated(...args)
that does something like the following:
export default function (event, ctx) {
// Get all comments bypassing the roles and permissions.
const allComments = await ctx.gqlRequest(MY_COMMENTS_QUERY, { ...anyVars }, { checkPermissions: false})
// Map your comments and remove the text on deactivated ones
const scrubbedComments = allComments.map(item => {
if (item.deactivated) item.content = "Content Hidden";
return item;
})
// Return scrubbed comments
return scrubbedComments;
}
Does this make sense? Definitely takes a little more work, but I think it could be the right approach to satisfying the requirement. LMK if it helps!
Dropping in Custom Resolver Docs aqui Resolvers - 8base Documentation