Problem/Motivation

In order to be truely API first we need to not just expose entity types. #2913790: List of missing APIs lists a lot of those examples.
One example is the list of available permissions. This is needed to build something like a permissions page

Proposed resolution

https://gitlab.com/dawehner/permissions_elm/tree/8.x-1.x used a fully custom controller, which works fine, but I think for core making it a rest resource makes the most sense

Remaining tasks

User interface changes

API changes

Data model changes

Comments

dawehner created an issue. See original summary.

dawehner’s picture

Status: Active » Needs review
StatusFileSize
new6.97 KB

I'm not sure about the test coverage. Maybe we should add test coverage for all authentications/formats, too?

Status: Needs review » Needs work

The last submitted patch, 2: 29476050-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new6.97 KB

There was a typo in the PHP namespace.

dawehner’s picture

wim leers’s picture

Thanks so much for getting this going!

  1. +++ b/core/modules/user/src/Plugin/rest/resource/PermissionResource.php
    @@ -0,0 +1,98 @@
    + *   id = "user_permission",
    ...
    +class PermissionResource extends ResourceBase {
    

    Singular.

  2. +++ b/core/modules/user/src/Plugin/rest/resource/PermissionResource.php
    @@ -0,0 +1,98 @@
    + *     "canonical" = "/permissions"
    

    Plural.

  3. +++ b/core/modules/user/src/Plugin/rest/resource/PermissionResource.php
    @@ -0,0 +1,98 @@
    +   * Response to GET requests.
    

    Nit: Responds

  4. +++ b/core/modules/user/src/Plugin/rest/resource/PermissionResource.php
    @@ -0,0 +1,98 @@
    +  public function get() {
    +    $permissions = $this->permissionHandler->getPermissions();
    +    foreach ($permissions as $id => $permission) {
    +      $permissions[$id]['id'] = $id;
    +    }
    +
    +    return new ResourceResponse($permissions);
    +  }
    

    This would be the first REST resource that (arguably) returns a collection.

    Related: #2908800: RestResource plugins: use get() method with optional parameter (or no parameter) to signal list support?.

I'm wondering if we should keep this in an experimental module for now? This would be the first of its kind. Likely a pattern will emerge that we don't quite see just yet. By shipping this the official/real API, we'd have to maintain BC for the rest of the D8 cycle. If we initially ship this as experimental and wait to "graduate" to non-experimental until we have several of these, we diminish that risk.

wim leers’s picture

dawehner’s picture

I'm wondering if we should keep this in an experimental module for now? This would be the first of its kind. Likely a pattern will emerge that we don't quite see just yet. By shipping this the official/real API, we'd have to maintain BC for the rest of the D8 cycle. If we initially ship this as experimental and wait to "graduate" to non-experimental until we have several of these, we diminish that risk.

That is a good question. I agree with you that putting that into rest/user module itself feels wrong. At least in the context of the JS Initiative a helper module dedicated for the new admin theme would be actually the right solution. I think custom code for non generic solutions isn't the worst idea.

dawehner’s picture

StatusFileSize
new6.97 KB
new621 bytes

Thank you for your reviews!

Singular.
Plural.

Haha, well I really couldn't decide which one to pick :) Thoughts?

wim leers’s picture

At least in the context of the JS Initiative a helper module dedicated for the new admin theme would be actually the right solution. I think custom code for non generic solutions isn't the worst idea.

👍

You're always getting all permissions, so I'd say plural? That, or even rename it to permissions_collection?

dawehner’s picture

I like permissions_collection!

dawehner’s picture

StatusFileSize
new11.45 KB
new5.58 KB

We are using the new name and a experimental module now.

Status: Needs review » Needs work

The last submitted patch, 12: 2947605-12.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new8.03 KB
new5.46 KB

Status: Needs review » Needs work

The last submitted patch, 14: 2947605-14.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new8.65 KB
new3.08 KB

I just had tested the resource as logged out user. This fixes some exception.

Status: Needs review » Needs work

The last submitted patch, 16: 2947605-16.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

smustgrave’s picture

Status: Needs work » Postponed (maintainer needs more info)
Issue tags: +stale-issue-cleanup

Thank you for creating this issue to improve Drupal.

We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.

Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

Thanks!