]> BookStack Code Mirror - bookstack/commitdiff
Appeased codeclimate by extracting out external_auth_id group matching
authorDan Brown <redacted>
Sat, 16 Nov 2019 15:24:09 +0000 (15:24 +0000)
committerDan Brown <redacted>
Sat, 16 Nov 2019 15:24:09 +0000 (15:24 +0000)
app/Auth/Access/ExternalAuthService.php
app/Auth/Access/Saml2Service.php
app/Auth/Role.php

index 77c7d1351551da091ebf048b7477b48c7f01fd61..4bd8f868014e337e8a6b79f9b9e85033a68092dd 100644 (file)
@@ -9,26 +9,33 @@ class ExternalAuthService
     /**
      * Check a role against an array of group names to see if it matches.
      * Checked against role 'external_auth_id' if set otherwise the name of the role.
-     * @param \BookStack\Auth\Role $role
-     * @param array $groupNames
-     * @return bool
      */
-    protected function roleMatchesGroupNames(Role $role, array $groupNames)
+    protected function roleMatchesGroupNames(Role $role, array $groupNames): bool
     {
         if ($role->external_auth_id) {
-            $externalAuthIds = explode(',', strtolower($role->external_auth_id));
-            foreach ($externalAuthIds as $externalAuthId) {
-                if (in_array(trim($externalAuthId), $groupNames)) {
-                    return true;
-                }
-            }
-            return false;
+            return $this->externalIdMatchesGroupNames($role->external_auth_id, $groupNames);
         }
 
         $roleName = str_replace(' ', '-', trim(strtolower($role->display_name)));
         return in_array($roleName, $groupNames);
     }
 
+    /**
+     * Check if the given external auth ID string matches one of the given group names.
+     */
+    protected function externalIdMatchesGroupNames(string $externalId, array $groupNames): bool
+    {
+        $externalAuthIds = explode(',', strtolower($externalId));
+
+        foreach ($externalAuthIds as $externalAuthId) {
+            if (in_array(trim($externalAuthId), $groupNames)) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
     /**
      * Match an array of group names to BookStack system roles.
      * Formats group names to be lower-case and hyphenated.
index bb57ceb73a46221e11f8fb9358d9d8ffa1d77bad..57db3ce65ec4dd5f77057d6efe289ad5b90d5b19 100644 (file)
@@ -147,10 +147,9 @@ class Saml2Service extends ExternalAuthService
     protected function registerUser(array $userDetails): User
     {
         // Create an array of the user data to create a new user instance
-
         $userData = [
             'name' => $userDetails['name'],
-            'email' => $userDetails['email'] ?? '',
+            'email' => $userDetails['email'],
             'password' => Str::random(32),
             'external_auth_id' => $userDetails['external_id'],
             'email_confirmed' => true,
index 712f5299b7b1d2ff5485179621aeddf9a1c5efbd..3342ef5a8cadfd8ba9701ebf254f8bd4a6cb1f72 100644 (file)
@@ -4,6 +4,13 @@ use BookStack\Auth\Permissions\JointPermission;
 use BookStack\Auth\Permissions\RolePermission;
 use BookStack\Model;
 
+/**
+ * Class Role
+ * @property string $display_name
+ * @property string $description
+ * @property string $external_auth_id
+ * @package BookStack\Auth
+ */
 class Role extends Model
 {