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

DRUP-624 Add revisions to API Docs #161

Closed

Conversation

arlina-espinoza
Copy link
Contributor

This will add revisioning to the API Docs entities:

  • A log message when editing.
  • Revision history for the entity.
  • Viewing past revisions.
  • Reverting to past revisions.
  • Granular permissions to view and revert revisions.
  • Tests.

@arlina-espinoza
Copy link
Contributor Author

arlina-espinoza commented Mar 28, 2019

Added ApiDoc settings for configuring default revision options.
API Doc settings   Drupal 8 m10n

@mxr576 mxr576 self-requested a review March 29, 2019 06:37
}

$map = [
'view' => "view all {$this->entityTypeId} revisions",
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you are unintentionally mixing what is the scope that an entity access handler should handle and what is the scope of a route access handler.
https://github.com/fago/entity/blob/85f76b56f25d7c3f5bc466f94db30a9b63d97fc5/src/Access/EntityRevisionRouteAccessChecker.php#L86 This is a route access handler and you can see the similarity between your implementation and this class.

Copy link
Contributor

Choose a reason for hiding this comment

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

So probably this is the right place to ask again, can we get rid of the custom entity access and entity route handlers that we implemented and rely on what the Entity module provides?
I would feel much safer if access handlers from a well-tested framework would ensure the entity access in our system.

Copy link
Contributor

Choose a reason for hiding this comment

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

@Jaesin @cnovak Please share your thoughts about this ^ We are still maintaining and testing our own solution instead of relying on an OOTB solution by Entity module - which has its own test coverage.

Copy link
Contributor

Choose a reason for hiding this comment

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

}

$map = [
'view' => "view all {$this->entityTypeId} revisions",
Copy link
Contributor

Choose a reason for hiding this comment

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

@Jaesin @cnovak Please share your thoughts about this ^ We are still maintaining and testing our own solution instead of relying on an OOTB solution by Entity module - which has its own test coverage.


// If no revision author has been set explicitly, make the current user
// the revision author.
if (!$this->getRevisionUser()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

In Node, the owner id is the uid field, which we don't have in the ApiDoc entity.

Should not we have an owner on ApiDoc entities? :) This is kinda an OOTB feature on content entities (nodes) that now we are intentionally removing from API doc entities - although it could be useful in the content moderation workflows, ex.: the owner (creator) of an API documentation cannot publish the API documentation only an other evaluated user.

Copy link
Contributor

@mxr576 mxr576 left a comment

Choose a reason for hiding this comment

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

As @arunz6161 requested I approved this PR, but please create follow up tasks for all remaining, unresolved comments in this PR, especially cleaning up the entity/route access checks on the API documentation entity type.


// If no revision author has been set explicitly, make the current user
// the revision author.
if (!$this->getRevisionUser()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since there is no BC guaranteed for experimental modules, we can revisit this later - together with replacing the custom entity access on this entity type with what Entity module provides.

$default_revision = $entity_storage->load($entity->id());
$entity_access_default = $default_revision->access($operation, $account);
if (!$entity_access_default) {
return AccessResult::forbidden();
Copy link
Contributor

Choose a reason for hiding this comment

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

If you extend this class then yes it is cached, but this comment is in connection with my next comment
https://github.com/apigee/apigee-edge-drupal/pull/161/files#r271145040 in which I described that I think you are mixing what an entity access handler and an entity route access handler should do. Consequently, this class should not extend this EntityAccessControlHandler base class.

If you do not believe the Entity (contrib) module, this is how it is implemented for the Node entity in Drupal core:
This is the route access handler for node revision access - which cares about revision elated permissions.
https://github.com/drupal/core/blob/17557c97a816bc78e70989a86064c562bc27027f/modules/node/node.services.yml#L11
https://github.com/drupal/core/blob/17557c97a816bc78e70989a86064c562bc27027f/modules/node/src/Access/NodeRevisionAccessCheck.php#L93-L103
and this is the entity access handler on the Node entity that does not care about revisioning related permissions...
https://github.com/drupal/core/blob/17557c97a816bc78e70989a86064c562bc27027f/modules/node/src/Entity/Node.php#L31
https://github.com/drupal/core/blob/c784c6a8e416505fdbd7f8ab1a6608ad58d37dd9/modules/node/src/NodeAccessControlHandler.php

Also, there is this major difference between entity and route access handlers: https://www.drupal.org/node/2122195#multiple

Please create a follow-up task about cleaning up the access check on the API documentation entity type.

@mxr576 mxr576 added apigee_edge_apidocs enhancement New feature or request labels Apr 29, 2019
@Jaesin
Copy link
Contributor

Jaesin commented May 17, 2019

This PR has been moved to the API Catalog module: https://github.com/cnovak/apigee-api-catalog-drupal/pull/7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants