🇺🇸United States @josh.estep

Account created on 20 February 2007, almost 18 years ago
#

Recent comments

🇺🇸United States josh.estep

josh.estep → made their first commit to this issue’s fork.

🇺🇸United States josh.estep

My issue, perhaps appropriate for this thread, was that I need to be able to support multiple IMCE configuration profiles associated with a given user where each profile assigns different permissions to a single folder.

To solve this, I updated userProfile() in IMCE.php to iterate over the different permissions for a given folder and then merge.

+        // Get IMCE settings and role-profile mappings
+        $imce_settings = \Drupal::config('imce.settings');
+        $storage = \Drupal::entityTypeManager()->getStorage('imce_profile');
+        $roles_profiles = $imce_settings->get('roles_profiles');
+        $user_roles = array_flip($user->getRoles());
+
+        // Initialize an array to hold the most permissive permissions for each folder
+        $folder_perms = [];
+
+        // Loop through user roles to get profile configurations
+        foreach ($user_roles as $rid => $role) {
+          // Check if the role has a profile mapping
+          if (isset($role) && !empty($roles_profiles[$rid][$scheme])) {
+            // Load the IMCE profile and its config
+            $test_config = $storage->load($roles_profiles[$rid][$scheme]);
+            $profile_config = $test_config->getConf();
+
+            // Loop through folders in profile to keep the most permissive permissions
+            foreach ($profile_config['folders'] as $folder) {
+              $path = $folder['path'];
+              if (!isset($folder_perms[$path])) {
+                $folder_perms[$path] = [];
+              }
+              foreach ($folder['permissions'] as $perm => $value) {
+                // Store the most permissive value of each permission
+                if ($perm === 'all' || !isset($folder_perms[$path][$perm]) || $value > $folder_perms[$path][$perm]) {
+                  $folder_perms[$path][$perm] = $value;
+                }
+              }
+            }
+          }
+        }
+
+        // Convert the permissive permissions back to the original folder array format
+        $conf['folders'] = [];
+        foreach ($folder_perms as $path => $permissions) {
+          $conf['folders'][] = ['path' => $path, 'permissions' => $permissions];
+        }

       return static::processUserConf($conf, $user);

This probably needs to be updated to use dependency injection, but I hope this helps somebody else.

Production build 0.71.5 2024