diff --git a/themes/src/main/resources/theme/base/admin/messages/admin-messages_en.properties b/themes/src/main/resources/theme/base/admin/messages/admin-messages_en.properties index 42b99cbfe9..a844b52c55 100644 --- a/themes/src/main/resources/theme/base/admin/messages/admin-messages_en.properties +++ b/themes/src/main/resources/theme/base/admin/messages/admin-messages_en.properties @@ -1919,6 +1919,7 @@ dialogs.delete.message=Are you sure you want to permanently delete the {{type}} dialogs.delete.confirm=Delete dialogs.cancel=Cancel dialogs.ok=Ok +use=Use user.profile.attribute=Attribute user.profile.attribute.name=Name @@ -1947,4 +1948,10 @@ user.profile.attribute.validation.add.validator=Add Validator user.profile.attribute.validation.add.validator.tooltip=Select a validator to enforce specific constraints to the attribute value. user.profile.attribute.validation.no.validators=No validators. user.profile.attribute.annotation=Annotation -use=Use \ No newline at end of file +user.profile.attribute.group=Attribute Group +attribute-groups=Attribute Groups +user.profile.attributegroup.displayHeader=Display header +user.profile.attributegroup.displayDescription=Display description +user.profile.attributegroup=Attribute Group +user.profile.attributegroup.name=Name +user.profile.attributegroup.annotation=Annotation diff --git a/themes/src/main/resources/theme/base/admin/resources/js/controllers/realm.js b/themes/src/main/resources/theme/base/admin/resources/js/controllers/realm.js index aeae780f8e..9f37f1acf3 100644 --- a/themes/src/main/resources/theme/base/admin/resources/js/controllers/realm.js +++ b/themes/src/main/resources/theme/base/admin/resources/js/controllers/realm.js @@ -1415,23 +1415,38 @@ module.controller('RealmUserProfileCtrl', function($scope, Realm, realm, clientS $scope.validatorProviders = serverInfo.componentTypes['org.keycloak.validate.Validator']; $scope.isShowAttributes = true; + $scope.isShowAttributeGroups = false; + $scope.isShowJsonEditor = false; UserProfile.get({realm: realm.realm}, function(config) { $scope.config = config; $scope.rawConfig = angular.toJson(config, true); }); - + $scope.isShowAttributes = true; - + $scope.isShowAttributeGroups = false; + $scope.isShowJsonEditor = false; + $scope.showAttributes = function() { $route.reload(); + delete $scope.currentAttributeGroup; + } + + $scope.showAttributeGroups = function() { + $scope.isShowAttributes = false; + $scope.isShowAttributeGroups = true; + $scope.isShowJsonEditor = false; + delete $scope.currentAttribute; } $scope.showJsonEditor = function() { $scope.isShowAttributes = false; + $scope.isShowAttributeGroups = false; + $scope.isShowJsonEditor = true; delete $scope.currentAttribute; + delete $scope.currentAttributeGroup; } - + $scope.isRequiredRoles = { minimumInputLength: 0, delay: 500, @@ -1516,13 +1531,17 @@ module.controller('RealmUserProfileCtrl', function($scope, Realm, realm, clientS }; $scope.attributeSelected = false; - - $scope.showListing = function() { + + $scope.showAttributeListing = function() { return !$scope.attributeSelected && $scope.currentAttribute == null && $scope.isShowAttributes; } - $scope.create = function() { - $scope.isCreate = true; + $scope.showAttributeGroupListing = function() { + return !$scope.attributeGroupSelected && $scope.currentAttributeGroup == null && $scope.isShowAttributeGroups; + } + + $scope.createAttribute = function() { + $scope.isCreateAttribute = true; $scope.currentAttribute = { selector: { scopes: [] @@ -1538,6 +1557,11 @@ module.controller('RealmUserProfileCtrl', function($scope, Realm, realm, clientS }; }; + $scope.createAttributeGroup = function() { + $scope.isCreateAttributeGroup = true; + $scope.currentAttributeGroup = {}; + }; + $scope.isNotUsernameOrEmail = function(attributeName) { return attributeName != "username" && attributeName != "email"; }; @@ -1555,6 +1579,19 @@ module.controller('RealmUserProfileCtrl', function($scope, Realm, realm, clientS $scope.save(); } + $scope.groupOrderUp = function(index) { + $scope.moveAttributeGroup(index, index - 1); + }; + + $scope.groupOrderDown = function(index) { + $scope.moveAttributeGroup(index, index + 1); + }; + + $scope.moveAttributeGroup = function(old_index, new_index){ + $scope.config.groups.splice(new_index, 0, $scope.config.groups.splice(old_index, 1)[0]); + $scope.save(false); + } + $scope.removeAttribute = function(attribute) { Dialog.confirmDelete(attribute.name, 'attribute', function() { let newAttributes = []; @@ -1570,7 +1607,22 @@ module.controller('RealmUserProfileCtrl', function($scope, Realm, realm, clientS }); }; - $scope.addAnnotation = function() { + $scope.removeAttributeGroup = function(attributeGroup) { + Dialog.confirmDelete(attributeGroup.name, 'group', function() { + let newGroups = []; + + for (var v of $scope.config.groups) { + if (v != attributeGroup) { + newGroups.push(v); + } + } + + $scope.config.groups = newGroups; + $scope.save(); + }); + }; + + $scope.addAttributeAnnotation = function() { if (!$scope.currentAttribute.annotations) { $scope.currentAttribute.annotations = {}; } @@ -1578,11 +1630,23 @@ module.controller('RealmUserProfileCtrl', function($scope, Realm, realm, clientS delete $scope.newAnnotation; } - $scope.removeAnnotation = function(key) { + $scope.removeAttributeAnnotation = function(key) { delete $scope.currentAttribute.annotations[key]; } - $scope.edit = function(attribute) { + $scope.addAttributeGroupAnnotation = function() { + if (!$scope.currentAttributeGroup.annotations) { + $scope.currentAttributeGroup.annotations = {}; + } + $scope.currentAttributeGroup.annotations[$scope.newAttributeGroupAnnotation.key] = $scope.newAttributeGroupAnnotation.value; + delete $scope.newGroupAnnotation; + } + + $scope.removeAttributeGroupAnnotation = function(key) { + delete $scope.currentAttributeGroup.annotations[key]; + } + + $scope.editAttribute = function(attribute) { if (attribute.permissions == null) { attribute.permissions = { view: [], @@ -1628,6 +1692,20 @@ module.controller('RealmUserProfileCtrl', function($scope, Realm, realm, clientS $scope.attributeSelected = true; }; + $scope.editAttributeGroup = function(attributeGroup) { + $scope.currentAttributeGroup = attributeGroup; + $scope.attributeGroupSelected = true; + }; + + $scope.groupIsReferencedInAnyAttribute = function(group) { + for (var currentAttribute of $scope.config.attributes) { + if (currentAttribute.group === group.name) { + return true + } + } + return false; + } + $scope.$watch('isRequired', function() { if ($scope.isRequired) { $scope.currentAttribute.required = { @@ -1720,8 +1798,19 @@ module.controller('RealmUserProfileCtrl', function($scope, Realm, realm, clientS $scope.currentAttribute.validations = newValidators; }; + $scope.reloadConfigurationFromUserProfile = function () { + UserProfile.get({realm: realm.realm}, function(config) { + $scope.config = config; + $scope.rawConfig = angular.toJson(config, true); + }); + } + $scope.save = function() { - if (!$scope.isShowAttributes) { + $scope.save(true) + } + + $scope.save = function(reload) { + if ($scope.isShowJsonEditor) { $scope.config = JSON.parse($scope.rawConfig); } @@ -1740,26 +1829,52 @@ module.controller('RealmUserProfileCtrl', function($scope, Realm, realm, clientS $scope.currentAttribute.selector.scopes.push($scope.selectorByScope[i].name); } - if ($scope.isCreate) { + if ($scope.isCreateAttribute) { $scope.config['attributes'].push($scope.currentAttribute); } } + if ($scope.currentAttributeGroup) { + if ($scope.config['groups'] == null) { + $scope.config['groups'] = [] + } + if ($scope.isCreateAttributeGroup) { + $scope.config['groups'].push($scope.currentAttributeGroup); + } + } + UserProfile.update({realm: realm.realm}, + $scope.config, function () { $scope.attributeSelected = false; delete $scope.currentAttribute; - delete $scope.isCreate; + delete $scope.isCreateAttribute + delete $scope.attributeSelected; + delete $scope.currentAttributeGroup; + delete $scope.isCreateAttributeGroup; + delete $scope.attributeGroupSelected; delete $scope.isRequired; delete $scope.canUserView; delete $scope.canAdminView; delete $scope.canUserEdit; delete $scope.canAdminEdit; - $route.reload(); + + if (reload) { + $route.reload(); + } else { + $scope.reloadConfigurationFromUserProfile(); + } Notifications.success("User Profile configuration has been saved."); }); }; - + + $scope.cancelEditAttributeGroup = function() { + delete $scope.currentAttributeGroup; + delete $scope.isCreateAttributeGroup; + delete $scope.attributeGroupSelected; + $scope.reloadConfigurationFromUserProfile(); + } + $scope.reset = function() { $route.reload(); }; diff --git a/themes/src/main/resources/theme/base/admin/resources/partials/realm-user-profile.html b/themes/src/main/resources/theme/base/admin/resources/partials/realm-user-profile.html index abfd4fd27f..f071f3e72f 100755 --- a/themes/src/main/resources/theme/base/admin/resources/partials/realm-user-profile.html +++ b/themes/src/main/resources/theme/base/admin/resources/partials/realm-user-profile.html @@ -3,19 +3,22 @@
-+ |
-
@@ -24,7 +27,8 @@
| |||||||
---|---|---|---|---|---|---|---|---|
{{:: 'name' | translate}} | -{{:: 'user.profile.attribute.displayName' | translate}} | +{{:: 'user.profile.attribute.displayName' | translate}} | +{{:: 'user.profile.attribute.group' | translate}} | {{:: 'actions' | translate}} |
|
{{attribute.displayName}} | -{{:: 'edit' | translate}} | +{{attribute.group}} | +{{:: 'edit' | translate}} | {{:: 'delete' | translate}} |
+
+
+
+
+ |
+ |||||
---|---|---|---|---|---|
{{:: 'name' | translate}} | +{{:: 'user.profile.attributegroup.displayHeader' | translate}} | +{{:: 'user.profile.attributegroup.displayDescription' | translate}} | +{{:: 'actions' | translate}} | +||
+ |
+ {{group.displayHeader}} | +{{group.displayDescription}} | +{{:: 'edit' | translate}} | + +{{:: 'delete' | translate}} | +{{:: 'delete' | translate}} | +