]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1736] map roles to ldap groups
authorOlivier Lamy <olamy@apache.org>
Fri, 15 Feb 2013 14:14:35 +0000 (14:14 +0000)
committerOlivier Lamy <olamy@apache.org>
Fri, 15 Feb 2013 14:14:35 +0000 (14:14 +0000)
update mapping implemented.

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1446590 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/archiva/general-admin.js
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/templates/archiva/general-admin.html

index e27f4857eb6b039ebfb881b0be5096b92d411810..02cf3403c76deb615d882337d0c8b2e7f0b0c5ce 100644 (file)
@@ -1372,6 +1372,8 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout"
 
     this.usedUserManagerImpls=ko.observableArray([]);
 
+    this.modifiesLdapGroupMappings=ko.observableArray([]);
+
     this.allRoleNames=[];
 
     self.gridViewModel = new ko.simpleGrid.viewModel({
@@ -1392,24 +1394,6 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout"
       }
     });
 
-    self.ldapGroupMappingsViewModel=new ko.simpleGrid.viewModel({
-      data: self.redbackRuntimeConfiguration().ldapGroupMappings,
-      columns: [
-        {
-          headerText: $.i18n.prop('redback.runtime.ldap.mapping.group.label'),
-          rowText: "group"
-        },
-        {
-          headerText: $.i18n.prop('redback.runtime.ldap.mapping.roles.label'),
-          rowText: "value"
-        }
-      ],
-      pageSize: 10,
-      gridUpdateCallBack: function(){
-        activatePopoverDoc();
-      }
-    });
-
     findUserManagerImplementationInformation=function(id){
       for(var i= 0;i<self.userManagerImplementationInformations().length;i++){
         $.log(id+""+self.userManagerImplementationInformations()[i].beanId);
@@ -1509,6 +1493,7 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout"
     }
 
     saveRedbackRuntimeConfiguration=function(){
+
       var mainContent=$("#main-content");
       var valid = mainContent.find("#redback-runtime-general-form-id").valid();
       if (valid==false) {
@@ -1564,14 +1549,71 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout"
             saveButton.button('reset');
             self.redbackRuntimeConfiguration().modified(false);
             self.redbackRuntimeConfiguration().ldapConfiguration().modified(false);
+            saveModifyLdapGroupMapping();
           }
         }
       );
 
+
+
     }
 
-    modifyLdapGroupMapping=function(ldapGroupMapping){
-      $.log('modifyLdapGroupMapping');
+    saveModifyLdapGroupMapping=function(){
+      //save modified ldap group mappings if any
+      if(self.modifiesLdapGroupMappings().length>0){
+        $.log("save modifiesLdapGroupMappings");
+        $.each(self.modifiesLdapGroupMappings(),function(idx,item){
+          if(!(item.automatic&item.roleNames().length<2)){
+            $.log("update mapping for group:"+item.group());
+            var mainContent=$("#main-content");
+            var saveButton = mainContent.find("#redback-runtime-configuration-save" );
+            saveButton.button('loading');
+            clearUserMessages();
+            var userMessages=$("#user-messages");
+            userMessages.html(mediumSpinnerImg());
+            $.ajax("restServices/redbackServices/ldapGroupMappingService",
+                   {
+                     type: "POST",
+                     contentType: 'application/json',
+                     data:ko.toJSON(item),
+                     dataType: 'json',
+                     success: function(data) {
+                       var message=$.i18n.prop('redback-runtime-ldap-group-mapping.updated');
+                       displaySuccessMessage(message);
+                     },
+                     error: function(data) {
+                       var res = $.parseJSON(data.responseText);
+                       displayRestError(res);
+                     },
+                     complete:function(data){
+                       removeMediumSpinnerImg(userMessages);
+                       saveButton.button('reset');
+                       self.redbackRuntimeConfiguration().modified(false);
+                       self.redbackRuntimeConfiguration().ldapConfiguration().modified(false);
+                     }
+                   }
+            );
+          }
+        });
+
+
+      } else {
+        $.log("not save modifiesLdapGroupMappings");
+      }
+      self.modifiesLdapGroupMappings=ko.observableArray([]);
+    }
+
+    this.modifyLdapGroupMapping=function(roleNames,ldapGroupMapping){
+      var toAdd=true;
+      $.each(self.modifiesLdapGroupMappings(),function(idx,item){
+        if(item.group()==ldapGroupMapping.group()){
+          toAdd=false;
+        }
+      });
+      if(toAdd){
+        self.modifiesLdapGroupMappings().push(ldapGroupMapping);
+      }
+      $.log('modifyLdapGroupMapping:'+ldapGroupMapping.group()+','+self.modifiesLdapGroupMappings().length);
     };
   }
 
@@ -1726,9 +1768,6 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout"
             }
           });
 
-
-
-
         }
       });
 
@@ -1755,11 +1794,12 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout"
       self.modified(true);
       $.log("roleNames modified");
       if(subscribeFn){
-        subscribeFn(newValue)
+        subscribeFn(newValue,self);
       }
     });
 
     this.automatic=automatic?automatic:false;
+    this.update=true;
   }
 
   mapLdapGroupMappings=function(data,modifyLdapGroupMapping){
index 20d067185575f6893e50b916e896f76fae7f42f8..43d87876ecd259908e9c8698fbbd960768f5a924 100644 (file)
   <table class="table table-condensed">
     <thead>
       <tr>
-        <th>group</th>
-        <th>roles</th>
+        <th>${$.i18n.prop('redback.runtime.ldap.mapping.group.label')}</th>
+        <th>${$.i18n.prop('redback.runtime.ldap.mapping.roles.label')}</th>
       </tr>
     </thead>
     <tbody id="ldap-group-mappings-tbody">
         <td>${ldapGroupMapping.group()}</td>
         <td>
           <div>
-            <select id="roles-group-${ldapGroupMapping.group()}" data-bind="options: $parent.allRoleNames, selectedOptions: ldapGroupMapping.roleNames()"
+            <select id="roles-group-${ldapGroupMapping.group()}" data-bind="options: $parent.allRoleNames, selectedOptions: ldapGroupMapping.roleNames"
                     size="5" multiple="true" ></select>
           </div>