diff --git a/resources/js/app/components/relation-view/roles-list-view.vue b/resources/js/app/components/relation-view/roles-list-view.vue index ec6b3e61f..2f26ed7f4 100644 --- a/resources/js/app/components/relation-view/roles-list-view.vue +++ b/resources/js/app/components/relation-view/roles-list-view.vue @@ -20,10 +20,10 @@ import RelationshipsView from 'app/components/relation-view/relationships-view/relationships-view'; export default { - name: 'roles-list-view', - extends: RelationshipsView, + name: 'RolesListView', + props: { groups: { type: Object, @@ -33,10 +33,6 @@ export default { type: Array, default: () => [], }, - userRolePriority: { - type: Number, - default: () => 500, - }, userRoles: { type: Array, default: () => [], @@ -47,7 +43,9 @@ export default { return { method: 'resources', objectsByGroups: {}, + prioritiesMap: {}, removedRelations: [], + userRolePriority: 500, } }, @@ -68,8 +66,12 @@ export default { for (let roleName of groups[groupName]) { const role = this.objects.filter((v) => v.attributes.name === roleName)[0]; this.objectsByGroups[groupName].push(role); + this.prioritiesMap[role.attributes.name] = role.meta.priority; } } + this.userRolePriority = this.userRoles.reduce((acc, role) => { + return Math.min(acc, this.prioritiesMap[role]); + }, 500); this.objectsByGroups = {...this.objectsByGroups}; }); }, diff --git a/src/Identifier/Resolver/ApiResolver.php b/src/Identifier/Resolver/ApiResolver.php index b2c2f1182..cfc258a3f 100644 --- a/src/Identifier/Resolver/ApiResolver.php +++ b/src/Identifier/Resolver/ApiResolver.php @@ -68,19 +68,8 @@ public function find(array $conditions, $type = self::TYPE_AND) } $roles = Hash::extract($result, 'included.{n}.attributes.name'); - // check if meta.priority is available (api versions >= 4.11.0|5.7.0) - $hasPriority = false; - foreach ($result['included'] as $included) { - if (Hash::check($included, 'meta.priority')) { - $hasPriority = true; - break; - } - } - $priorities = Hash::extract($result, 'included.{n}.meta.priority'); - // if api do not expose meta.priority, user priority is 0 (admin) - $rolePriority = $hasPriority ? min($priorities) : 0; $tokens = $apiClient->getTokens(); - return $result['data'] + compact('tokens') + compact('roles', 'rolePriority'); + return $result['data'] + compact('roles', 'tokens'); } } diff --git a/templates/Element/Form/roles.twig b/templates/Element/Form/roles.twig index 1a8c7748e..dab9976f6 100644 --- a/templates/Element/Form/roles.twig +++ b/templates/Element/Form/roles.twig @@ -39,7 +39,6 @@ :related-objects="objects" :groups="{{ rolesGroups|length == 0 ? '{}' : rolesGroups|json_encode }}" :user-roles="{{ user.roles|default([])|json_encode }}" - :user-role-priority="{{ user.rolePriority|default(500)|json_encode }}" @remove-relations="setRemovedRelated"> {% do Form.unlockField('relations.' ~ relationName ~ '.addRelated') %} diff --git a/templates/Pages/UserProfile/view.twig b/templates/Pages/UserProfile/view.twig index de3adbdce..98355d708 100644 --- a/templates/Pages/UserProfile/view.twig +++ b/templates/Pages/UserProfile/view.twig @@ -38,6 +38,20 @@ {% endif %} {% endfor %} +
+
+

{{ __('Roles') }}

+
+
+
+ {% for role in user.roles %} + + {{ role }} + + {% endfor %} +
+
+