首页 > 解决方案 > 如何使 Drupal Commerce 配置实体可修改

问题描述

我在前端有一个使用 Drupal 的 JSONAPI 的 Ember 应用程序。

Drupal 安装了商务模块。

ember 应用程序正在请求所有 product_types,并且需要显示有关产品类型的信息。

产品类型上有描述变量类型和标签等字段,但作为匿名用户,我看不到所有这些属性,只有标签。

这似乎是商务模块检查权限的方式的问题。

if (!$access->isAllowed()) {
      // If this is the default revision or the entity is not revisionable, then
      // check access to the entity label. Revision support is all or nothing.
      if (!$entity->getEntityType()->isRevisionable() || $entity->isDefaultRevision()) {
        $label_access = $entity->access('view label', NULL, TRUE);
        $entity->addCacheableDependency($label_access);
        if ($label_access->isAllowed()) {
          return LabelOnlyResourceObject::createFromEntity($resource_type, $entity);

在野外——https: //github.com/Free5Dev/drupalMagellium/blob/f5b0344a528a1df788c94e7558a6826dc9a2f736/core/modules/jsonapi/src/Access/EntityAccessChecker.php#L181

这里 jsonapi 决定渲染实体的有限版本。

似乎需要使该实体可修改才能通过上述检查并完全呈现。

https://github.com/drupalcommerce/commerce/blob/8.x-2.x/modules/product/src/Entity/ProductType.php

如何使 ProductType 实体可修改?

我发现了这个https://www.drupal.org/docs/8/api/entity-api/making-an-entity-revisionable但它的解释似乎有限。

标签: drupaljson-apidrupal-commercedrupal-content-typesdrupal-entities

解决方案


Drupal 的JSON:API 模块没有自带授权逻辑。它尊重并使用 Drupal 针对该数据采取的所有安全措施。您可以在模块文档的安全注意事项章节中找到有关该内容的更多详细信息。

Drupal Commerce 也不提供它自己的访问管理。至少这是我从他们的文档中得到的。

您应该检查您的字段权限。也许它们是使用字段权限模块定制的?您可能希望按照JSON:API 模块文档中的建议审核实体访问和字段访问。


推荐阅读