Customer has requested the ability to give access to the Translations > Manage page without giving full module admin access (meaning they don't want the user to have access to the Settings tab). This would be an additional user permissions type.

CommentFileSizeAuthor
#81 2876128-interdiff.76-78.txt2.35 KBpenyaskito
#76 2876128-manage-translations-permission-76.patch253.41 KBpenyaskito
#76 2876128-manage-translations-permission-76.only-text.txt33.93 KBpenyaskito
#76 2876128-interdiff.74-76.txt3.44 KBpenyaskito
#74 2876128-manage-translations-permission-74.patch30.92 KBpenyaskito
#74 2876128-interdiff.72-74.txt3.73 KBpenyaskito
#72 2876128-manage-translations-permission-72.patch27.43 KBpenyaskito
#72 2876128-interdiff.70-72.txt5.62 KBpenyaskito
#70 2876128-manage-translations-permission-70.patch22.59 KBpenyaskito
#70 2876128-interdiff.69-70.txt13.17 KBpenyaskito
#69 2876128-manage-translations-permission-69.patch13.71 KBpenyaskito
#69 2876128-interdiff.67-69.txt11.9 KBpenyaskito
#67 additional_privilege_show_settings_tab-2876128-59.patch3.98 KBmdahl328151
#64 additional_privilege_show_settings_tab-2876128-58.patch3.94 KBmdahl328151
#62 interdiff.txt1.73 KBpenyaskito
#59 additional_privilege_show_settings_tab-2876128-56.patch4.83 KBmdahl328151
#56 additional_privilege_show_settings_tab-2876128-54.patch4.83 KBmdahl328151
#50 additional_privilege_show_settings_tab-2876128-46.patch3.07 KBmdahl328151
#48 additional_privilege_show_settings_tab-2876128-44.patch4.8 KBmdahl328151
#47 additional_privilege_show_settings_tab-2876128-42.patch3.01 KBmdahl328151
#45 additional_privilege_show_settings_tab-2876128-37.patch2.28 KBmdahl328151
#42 additional_privilege_show_settings_tab-2876128-33.patch5.79 KBmdahl328151
#40 additional_privilege_show_settings_tab-2876128-32.patch4.56 KBmdahl328151
#38 additional_privilege_show_settings_tab-2876128-31.patch4.42 KBmdahl328151
#37 additional_privilege_show_settings_tab-2876128-30.patch3.53 KBmdahl328151
#36 additional_privilege_show_settings_tab-2876128-29.patch3.53 KBmdahl328151
#35 additional_privilege_show_settings_tab-2876128-28.patch3.56 KBmdahl328151
#34 additional_privilege_show_settings_tab-2876128-27.patch3.56 KBmdahl328151
#33 additional_privilege_show_settings_tab-2876128-26.patch2.21 KBmdahl328151
#31 additional_privilege_show_settings_tab-2876128-25.patch2.24 KBmdahl328151
#29 additional_privilege_show_settings_tab-2876128-24.patch2.24 KBmdahl328151
#28 additional_privilege_show_settings_tab-2876128-23.patch2.25 KBmdahl328151
#25 additional_privilege_show_settings_tab-2876128-22.patch3.43 KBmdahl328151
#24 additional_privilege_show_settings_tab-2876128-21.patch3.44 KBmdahl328151
#19 additional_privilege_show_settings_tab-2876128-19.patch1.66 KBmdahl328151
#16 additional_privilege_show_settings_tab-2876128-17.patch3.16 KBmdahl328151
#12 additional_privilege_show_settings_tab-2876128-12.patch21.85 KBmdahl328151
#10 interdiff-2876128-8-10.txt5.97 KBmdahl328151
#10 additional_privilege_show_settings_tab-2876128-10.patch27.77 KBmdahl328151
#2 additional_privilege_show_settings_tab-2876128-2.patch4.61 KBmdahl328151
#6 additional_privilege_show_settings_tab-2876128-6.patch7.24 KBmdahl328151
#8 additional_privilege_show_settings_tab-2876128-8.patch28.13 KBmdahl328151
#9 interdiff-2876128-6-8.txt20.76 KBmdahl328151
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mdahl328151 created an issue. See original summary.

mdahl328151’s picture

t.murphy’s picture

Issue summary: View changes
mdahl328151’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: additional_privilege_show_settings_tab-2876128-2.patch, failed testing.

mdahl328151’s picture

mdahl328151’s picture

Status: Needs work » Needs review
mdahl328151’s picture

mdahl328151’s picture

FileSize
20.76 KB
mdahl328151’s picture

penyaskito’s picture

Status: Needs review » Needs work

Hi McCann!

I think we should just add a new permission in lingotek.permissions.yml and modify lingotek.routing.yml for using that one. Is all of this really necessary?

If it is, I fail to see how at the moment.

mdahl328151’s picture

mdahl328151’s picture

Status: Needs work » Needs review
penyaskito’s picture

Status: Needs review » Needs work
  1. +++ b/lingotek.permissions.yml
    @@ -5,3 +5,5 @@ administer lingotek:
    +show lingotek settings tab:
    +  title: 'Show Lingotek Settings Tab'
    

    I would rename this to "Manage Lingotek translations"

  2. +++ b/src/Tests/LingotekDashboardTestHideSettingsTab.php
    @@ -0,0 +1,517 @@
    +class LingotekDashboardTestHideSettingsTab extends LingotekTestBase {
    

    A lot of tests here are unrelated, I guess copied from somewhere else. Let's remove those.

  3. +++ b/src/Tests/LingotekDashboardTestHideSettingsTab.php
    @@ -0,0 +1,517 @@
    +  public function makeNewRoleCalledSubAdmin(){
    ...
    +  public function makeNewUserWithSubAdminRole(){
    ...
    +  public function logIntoAdminRoleAndSeeSettingsTab($uid){
    ...
    +  public function logIntoSubAdminRoleAndDontSeeSettingsTab($uid){
    

    Where are these used? We can do the same more easily just with

    $userWithRoleX = $this->createUser([array of permissions])
    $this->drupalLogin($userWithRoleX);
    
penyaskito’s picture

Also, we will need changes to \Drupal\lingotek\Routing\LingotekRouteSubscriber::alterRoutes, which creates the manage routes dinamically for each enabled entity.

mdahl328151’s picture

mdahl328151’s picture

Status: Needs work » Needs review
penyaskito’s picture

Status: Needs review » Needs work

This feature needs testing. We need to test that a user without the proper permission gets a "Not allowed" error when going to that url, and that the permissions gives access back to this feature.

+++ b/lingotek.permissions.yml
@@ -5,3 +5,7 @@ administer lingotek:
+  ¶
\ No newline at end of file

+++ b/src/Controller/LingotekDashboardController.php
@@ -106,7 +106,8 @@ class LingotekDashboardController extends LingotekControllerBase {
-    }
+    } ¶
+    ¶

+++ b/src/Routing/LingotekRouteSubscriber.php
@@ -33,7 +33,7 @@ class LingotekRouteSubscriber extends RouteSubscriberBase {
-    $this->entityManager = $entity_manager;
+  	 $this->entityManager = $entity_manager;

@@ -54,7 +54,7 @@ class LingotekRouteSubscriber extends RouteSubscriberBase {
-
+        ¶

@@ -67,11 +67,11 @@ class LingotekRouteSubscriber extends RouteSubscriberBase {
-
+        ¶

We need to fix the spacing issues.

mdahl328151’s picture

mdahl328151’s picture

When un-authorized user attempts to go to /admin/lingotek/settings this is displayed:

Access denied
You are not authorized to access this page.

The URL can only be accessed after that if a user with the "settings tab" permission logs in.

mdahl328151’s picture

Spacing issues fixed.

mdahl328151’s picture

Status: Needs work » Needs review
penyaskito’s picture

Status: Needs review » Needs work
  1. +++ b/lingotek.permissions.yml
    @@ -5,3 +5,6 @@ administer lingotek:
    \ No newline at end of file
    

    I can fix this at commit, but take into account for other patches.

Did you forget to include the automated tests in the patch? Ping me if you need help with that.

mdahl328151’s picture

mdahl328151’s picture

mdahl328151’s picture

Status: Needs work » Needs review
penyaskito’s picture

Status: Needs review » Needs work
  1. +++ b/lingotek.permissions.yml
    @@ -5,3 +5,6 @@ administer lingotek:
    +show lingotek settings tab:
    

    Let's call this "manage lingotek translations".

  2. +++ b/lingotek.permissions.yml
    @@ -5,3 +5,6 @@ administer lingotek:
    +  description: 'Allow access to the settings tab in the Lingotek Translation Module.'
    

    The description is "Allow users to send content for translations and download translations when they are ready" or something alike. Feel free to improve :-)

  3. +++ b/lingotek.routing.yml
    @@ -78,6 +78,7 @@ lingotek.settings:
         _permission: 'administer lingotek'
    +    _permission: 'show lingotek settings tab'
    

    No, "administer lingotek" will mean access to lingotek.settings.

    "manage lingotek translations" will mean, access to the operations in the translate tab + access to the bulk management pages.

  4. +++ b/src/Routing/LingotekRouteSubscriber.php
    @@ -67,7 +67,7 @@ class LingotekRouteSubscriber extends RouteSubscriberBase {
    +          array('_permission' => 'administer lingotek','_permission' => 'show lingotek settings tab'),
    

    "administer lingotek" should not be required for accessing these pages. They are the bulk management tab.

  5. +++ b/src/Tests/LingotekHideSettingsTabTest.php
    @@ -0,0 +1,60 @@
    +class LingotekSettingsTabContentFormTest extends LingotekTestBase {
    

    This test is a great start but we need more I guess :-)

  6. +++ b/src/Tests/LingotekHideSettingsTabTest.php
    @@ -0,0 +1,60 @@
    +    $permissions = \Drupal::service('user.permissions')->getPermissions();
    +    $role = \Drupal\user\Entity\Role::create(array('id' => 'client', 'label' => 'Client'));
    +    foreach( $permissions as $permission ) {
    +      $role->grantPermission( $permission );
    +    }
    +    $role->revokePermission('Manage Lingotek translations');
    +    $role->save();
    +
    +    // Create user object.
    +    $user = User::create();
    +
    +    //Mandatory settings
    +    $user->setPassword("password");
    +    $user->enforceIsNew();
    +    $user->setEmail("email");
    +    $user->setUsername("username");
    +    $user->addRole($role);
    +
    +    $this->drupalLogin($user);
    

    We don't want to access all the permissions. Also, see comment #14:

    $userWithRoleX = $this->createUser([array of permissions])
    $this->drupalLogin($userWithRoleX);
    
mdahl328151’s picture

mdahl328151’s picture

mdahl328151’s picture

Status: Needs work » Needs review
mdahl328151’s picture

mdahl328151’s picture

+++ b/src/Tests/LingotekHideSettingsTabTest.php
@@ -0,0 +1,38 @@
+    $userWithRoleX = $this->createUser(array('Administer Lingotek Translation Module','Assign Lingotek translation profiles to content'));

This should be:
'administer lingotek','assign lingotek translation profiles'

mdahl328151’s picture

mdahl328151’s picture

mdahl328151’s picture

mdahl328151’s picture

mdahl328151’s picture

mdahl328151’s picture

Status: Needs review » Needs work

The last submitted patch, 38: additional_privilege_show_settings_tab-2876128-31.patch, failed testing.

mdahl328151’s picture

Status: Needs review » Needs work

The last submitted patch, 40: additional_privilege_show_settings_tab-2876128-32.patch, failed testing.

mdahl328151’s picture

mdahl328151’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 42: additional_privilege_show_settings_tab-2876128-33.patch, failed testing.

mdahl328151’s picture

mdahl328151’s picture

Status: Needs work » Needs review
mdahl328151’s picture

mdahl328151’s picture

Status: Needs review » Needs work

The last submitted patch, 48: additional_privilege_show_settings_tab-2876128-44.patch, failed testing.

mdahl328151’s picture

mdahl328151’s picture

Status: Needs work » Needs review
penyaskito’s picture

Status: Needs review » Needs work
+++ b/lingotek.module
@@ -16,6 +16,15 @@ use Drupal\lingotek\Exception\LingotekApiException;
+ * Implements hook_user_login().
+ */
+function lingotek_user_login($account) {
+  if ($account->getLastAccessedTime() == 0) {
+    drupal_flush_all_caches();
+  }
+}
+
+/**

Why is this needed? Flush all caches must need a very good reason to happen, as it can really slow down a site.

penyaskito’s picture

We need an upgrade function for this issue. When a site upgrades from a previous version of the module, any user role with the permission for "administer lingotek'" should have this new permission too.

We ideally need tests for that upgrade.

mdahl328151’s picture

I could not re-create the issue I was having before, so the user login hook is not needed. When a module is upgraded, is there a function that is called within the module, or would I have to write code that compares different module versions?

penyaskito’s picture

mdahl328151’s picture

mdahl328151’s picture

Version: 8.x-1.x-dev » 8.x-2.x-dev
Status: Needs work » Needs review

Status: Needs review » Needs work
mdahl328151’s picture

mdahl328151’s picture

Status: Needs work » Needs review
penyaskito’s picture

Status: Needs review » Needs work
+++ b/src/Tests/LingotekManageLingotekTranslationsPermissionTest.php
@@ -0,0 +1,51 @@
+    $user = $this->drupalCreateUser([
...
+      'assign lingotek translation profiles'
+    ]);
+    // Login as user.
+    $this->drupalLogin($user);
+    // Get the settings form.
+    $this->drupalGet('admin/lingotek/settings');
+    // Assert translation profile cannot be assigned.
+    $this->assertText('You are not authorized to access this page.');

This is not what this permission is aiming for.

User with 'administer Lingotek' should be able of seeing the settings page.

The 'manage lingotek translations' is required for the bulk translation tabs, to see the Lingotek operations in the Translate tab of content or config. 'administer lingotek' is for accessing settings of the module.

Just because of this test I'm assuming this permission is not worked as expected.

penyaskito’s picture

FileSize
1.73 KB

Best practices say we should move the hook_update_N to a post-update:

https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Extension...

In particular, loading, saving, or performing any other CRUD operation on an entity is never safe to do (they always involve hooks and services).

https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Extension...

Executes an update which is intended to update data, like entities.

mdahl328151’s picture

That makes sense. So this is what the routing should look like?

lingotek.manage:
  path: '/admin/lingotek/manage'
  defaults:
    _controller: '\Drupal\lingotek\Controller\LingotekManagementController::content'
    _title: 'Manage Translations'
  requirements:
    _permission: 'manage lingotek translations'

lingotek.manage_config:
  path: '/admin/lingotek/config/manage'
  defaults:
    _form: '\Drupal\lingotek\Form\LingotekConfigManagementForm'
    _title: 'Manage Configuration Translation'
  requirements:
    _permission: 'manage lingotek translations'
lingotek.settings:
  path: '/admin/lingotek/settings'
  defaults:
    _controller: '\Drupal\lingotek\Controller\LingotekSettingsController::content'
    _title: 'Translation Settings'
  requirements:
    _permission: 'administer lingotek'

lingotek.settings_profile:
  path: '/admin/lingotek/settings/profile'
  defaults:
    _controller: '\Drupal\lingotek\Controller\LingotekSettingsController::profileForm'
    _title: 'Add or Edit a Profile'
  requirements:
    _permission: 'administer lingotek'
mdahl328151’s picture

mdahl328151’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work
mdahl328151’s picture

mdahl328151’s picture

Status: Needs work » Needs review
penyaskito’s picture

Assigned: mdahl328151 » penyaskito
FileSize
11.9 KB
13.71 KB

Changed more permissions, the previous patch could be functionally correct, but it wasn't possible to navigate through the admin pages for reaching the desired functionality.

Implemented more tests:

  • testCannotSeeSettingsTabWithoutRightPermission
  • testDashboardAsTranslationsManager
  • testNavigationThroughSiteForBulkContentTranslationAsTranslationsManager
  • testNavigationThroughSiteForBulkConfigTranslationAsTranslationsManager
  • testNavigationThroughSiteForBulkConfigTranslationAsTranslationsManagerWithTranslateConfigPermission

We still need tests for the "Translate pages". Users shouldn't upload without the right permissions there.
We still need tests for ensuring the links on the bulk management page and the bulk actions work for a user with restricted permissions (only translate).

penyaskito’s picture

Changed existing tests so we add the following scenarios:

* Tests for ensuring the links on the bulk management page and the bulk actions work for a user with restricted permissions (only translate).

Status: Needs review » Needs work

The last submitted patch, 70: 2876128-manage-translations-permission-70.patch, failed testing. View results

penyaskito’s picture

* Tests for ensuring the links on the translation pages are not available without the manage translations permission.

Status: Needs review » Needs work

The last submitted patch, 72: 2876128-manage-translations-permission-72.patch, failed testing. View results

penyaskito’s picture

Status: Needs review » Needs work

The last submitted patch, 74: 2876128-manage-translations-permission-74.patch, failed testing. View results

penyaskito’s picture

Fixed tests. Added post-upgrade test.

penyaskito’s picture

Status: Needs review » Reviewed & tested by the community

Looks like everything is good now :-)

penyaskito’s picture

Status: Reviewed & tested by the community » Fixed

Fixed some phpcs issues on commit, attached interdiff.

penyaskito’s picture

Committed 440c1ed and pushed to 8.x-2.x. Thanks!

  • penyaskito committed 440c1ed on 8.x-2.x
    Issue #2876128 by mdahl328151, penyaskito: Add a 'Manage Lingotek...
penyaskito’s picture

FileSize
2.35 KB

The interdiff

penyaskito’s picture

Title: Additional privilege to access only the Translations > Manage portion of Module » Add a ''Manage Lingotek translations permission'' allowing operations related to translation but not module settings

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.