Tenant field is not queried in resouce collections
Bradleykingz opened this issue · 3 comments
When querying resource collections, the tenant
field is not returned, making it impossible for the frontend to filter documents according to the tenant.
For example, here is the "pages" resource.
Even querying via GraphQL leads to the same result - tenant is always null.
And, since the tenant
field doesn't exist, the frontend can't filter by tenant id
, and users can see each other's documents.
Adding hidden: false
to the CollectionConfig
seems to help, but only when querying for a single page:
But when querying all the pages, it remains null:
However, it works just fine for the user collection:
Any clues what the issue might be?
Changing hidden: false
in resourceTenant
fixes the issue.
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createResourceTenantField = void 0;
/** @returns Tenant field for generic resources. */
var createResourceTenantField = function (_a) {
var tenantCollection = _a.options.tenantCollection;
return ({
type: "relationship",
name: "tenant",
relationTo: tenantCollection,
hidden: false, // changed this
hooks: {
beforeChange: [
function (_a) {
var _b;
var req = _a.req;
// Assign tenant to the document when it's created (or updated).
var _c = req, tenant = _c.tenant, user = _c.user;
return (tenant === null || tenant === void 0 ? void 0 : tenant.id) || ((_b = user === null || user === void 0 ? void 0 : user.tenant) === null || _b === void 0 ? void 0 : _b.id);
},
],
},
});
};
exports.createResourceTenantField = createResourceTenantField;
The compiled code looks different from what's in the repo. Maybe fc7c4f7 is missing from npm?
I fixed this by updating Payload, confusingly 😅