Browse Source

Merge "Fix on duplicated scopes on OAUTH2 client"

tags/1.0.20^0
Jenkins 2 years ago
parent
commit
ccb82bcd0b

+ 18
- 3
app/Http/Controllers/AdminController.php View File

@@ -195,8 +195,23 @@ class AdminController extends Controller {
195 195
             array_push($aux_scopes, $scope->id);
196 196
         }
197 197
 
198
-        $scopes        = $this->scope_service->getAvailableScopes();
199
-        $group_scopes  = $user->getGroupScopes();
198
+        // scope pre processing
199
+        $scopes           = $this->scope_service->getAvailableScopes();
200
+        $group_scopes     = $user->getGroupScopes();
201
+        $merged_scopes    = array_merge($scopes, $group_scopes);
202
+        $final_scopes     = [];
203
+        $processed_scopes = [];
204
+        foreach($merged_scopes as  $test_scope){
205
+            if(isset($processed_scopes[$test_scope->id])) continue;
206
+
207
+            $processed_scopes[$test_scope->id] = $test_scope->id;
208
+            $final_scopes[] = $test_scope;
209
+        }
210
+
211
+        usort($final_scopes, function($elem1, $elem2){
212
+            return $elem1->api_id > $elem2->api_id;
213
+        });
214
+        // scope pre processing
200 215
 
201 216
         $access_tokens = $this->access_token_repository->getAllValidByClientIdentifier($client->getId(), 1 , self::TokenPageSize);
202 217
 
@@ -216,7 +231,7 @@ class AdminController extends Controller {
216 231
             [
217 232
                 'client'               => $client,
218 233
                 'selected_scopes'      => $aux_scopes,
219
-                'scopes'               => array_merge($scopes, $group_scopes),
234
+                'scopes'               => $final_scopes,
220 235
                 'access_tokens'        => $access_tokens->items(),
221 236
                 'access_tokens_pages'  => $access_tokens->total() > 0 ? intval(ceil($access_tokens->total() / self::TokenPageSize)) : 0,
222 237
                 "is_oauth2_admin"      => $user->isOAuth2ServerAdmin(),

+ 1
- 8
app/Models/OAuth2/ApiScope.php View File

@@ -93,14 +93,7 @@ class ApiScope extends BaseModelEloquent implements IApiScope
93 93
      * @return IApi
94 94
      */
95 95
     public function getApi(){
96
-        return Cache::remember
97
-        (
98
-            'api_'.$this->api_id,
99
-            Config::get("cache_regions.region_api_lifetime", 1140),
100
-            function() {
101
-                return $this->api()->first();
102
-            }
103
-       );
96
+        return $this->api()->first();
104 97
     }
105 98
 
106 99
     public function getApiName()

+ 1
- 1
resources/views/oauth2/profile/edit-client-scopes.blade.php View File

@@ -5,7 +5,7 @@
5 5
             @foreach ($scopes as $scope)
6 6
             <?php $current_api      = $scope->getApiName(); ?>
7 7
             <?php $current_api_logo = $scope->getApiLogo(); ?>
8
-            @if($last_api!=$current_api && !empty($current_api))
8
+            @if($last_api != $current_api && !empty($current_api))
9 9
                 @if(!empty($last_api))
10 10
                     </li></ul>
11 11
                 @endif

Loading…
Cancel
Save