]> source.dussan.org Git - nextcloud-server.git/commitdiff
LDAP: Implement clear mappings functionality
authorArthur Schiwon <blizzz@owncloud.com>
Wed, 8 May 2013 15:47:07 +0000 (17:47 +0200)
committerArthur Schiwon <blizzz@owncloud.com>
Thu, 16 May 2013 12:47:52 +0000 (14:47 +0200)
apps/user_ldap/ajax/clearMappings.php [new file with mode: 0644]
apps/user_ldap/js/settings.js
apps/user_ldap/lib/helper.php
apps/user_ldap/templates/settings.php

diff --git a/apps/user_ldap/ajax/clearMappings.php b/apps/user_ldap/ajax/clearMappings.php
new file mode 100644 (file)
index 0000000..5dab398
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+
+/**
+ * ownCloud - user_ldap
+ *
+ * @author Arthur Schiwon
+ * @copyright 2013 Arthur Schiwon blizzz@owncloud.com
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+// Check user and app status
+OCP\JSON::checkAdminUser();
+OCP\JSON::checkAppEnabled('user_ldap');
+OCP\JSON::callCheck();
+
+$subject = $_POST['ldap_clear_mapping'];
+if(\OCA\user_ldap\lib\Helper::clearMapping($subject)) {
+       OCP\JSON::success();
+} else {
+       $l=OC_L10N::get('user_ldap');
+       OCP\JSON::error(array('message' => $l->t('Failed to clear the mappings.')));
+}
\ No newline at end of file
index e34849ec8878e394b23e90e01acd4996a13d5a74..5e4c0262a6d0bc9f7d036be98448faa515ad2485 100644 (file)
@@ -99,6 +99,26 @@ var LdapConfiguration = {
                                }
                        }
                );
+       },
+
+       clearMappings: function(mappingSubject) {
+               $.post(
+                       OC.filePath('user_ldap','ajax','clearMappings.php'),
+                       'ldap_clear_mapping='+mappingSubject,
+                       function(result) {
+                               if(result.status == 'success') {
+                                       OC.dialogs.info(
+                                               t('user_ldap', 'mappings cleared'),
+                                               t('user_ldap', 'Success')
+                                       );
+                               } else {
+                                       OC.dialogs.alert(
+                                               result.message,
+                                               t('user_ldap', 'Error')
+                                       );
+                               }
+                       }
+               );
        }
 }
 
@@ -166,6 +186,16 @@ $(document).ready(function() {
                );
        });
 
+       $('#ldap_action_clear_user_mappings').click(function(event) {
+               event.preventDefault();
+               LdapConfiguration.clearMappings('user');
+       });
+
+       $('#ldap_action_clear_group_mappings').click(function(event) {
+               event.preventDefault();
+               LdapConfiguration.clearMappings('group');
+       });
+
        $('#ldap_serverconfig_chooser').change(function(event) {
                value = $('#ldap_serverconfig_chooser option:selected:first').attr('value');
                if(value == 'NEW') {
index 612a088269bec3382b8a659188ef4a2678aed6ea..7720c356a13ddad3ad3e7c0abc02ac40c0bf77a1 100644 (file)
@@ -102,4 +102,29 @@ class Helper {
 
                return true;
        }
+
+       /**
+        * Truncate's the given mapping table
+        *
+        * @param string $mapping either 'user' or 'group'
+        * @return boolean true on success, false otherwise
+        */
+       static public function clearMapping($mapping) {
+               if($mapping === 'user') {
+                       $table = '`*PREFIX*ldap_user_mapping`';
+               } else if ($mapping === 'group') {
+                       $table = '`*PREFIX*ldap_group_mapping`';
+               } else {
+                       return false;
+               }
+
+               $query = \OCP\DB::prepare('TRUNCATE '.$table);
+               $res = $query->execute();
+
+               if(\OCP\DB::isError($res)) {
+                       return false;
+               }
+
+               return true;
+       }
 }
index 3c7dd7cce6e687ed2f5898f11925519be8b17f69..ee1250fc911e71d169d55adcf9550ee6bdc0b931 100644 (file)
                <p class="ldapIndent"><label for="ldap_expert_uuid_attr"><?php p($l->t('UUID Attribute:'));?></label><input type="text" id="ldap_expert_uuid_attr" name="ldap_expert_uuid_attr" data-default="<?php p($_['ldap_expert_uuid_attr_default']); ?>" /></p>
                <p><strong><?php p($l->t('Username-LDAP User Mapping'));?></strong></p>
                <p class="ldapIndent"><?php p($l->t('ownCloud uses usernames to store and assign (meta) data. In order to precisely identify and recognize users, each LDAP user will have a internal username. This requires a mapping from ownCloud username to LDAP user. The created username is mapped to the UUID of the LDAP user. Additionally the DN is cached as well to reduce LDAP interaction, but it is not used for identification. If the DN changes, the changes will be found by ownCloud. The internal ownCloud name is used all over in ownCloud. Clearing the Mappings will have leftovers everywhere. Clearing the Mappings is not configuration sensitive, it affects all LDAP configurations! Do never clear the mappings in a production environment. Only clear mappings in a testing or experimental stage.'));?></p>
-               <p class="ldapIndent"><button id="ldap_action_clear_mappings" name="ldap_action_clear_mappings"><?php p($l->t('Clear Username-LDAP User Mapping'));?></button></p>
+               <p class="ldapIndent"><button id="ldap_action_clear_user_mappings" name="ldap_action_clear_user_mappings"><?php p($l->t('Clear Username-LDAP User Mapping'));?></button><br/><button id="ldap_action_clear_group_mappings" name="ldap_action_clear_group_mappings"><?php p($l->t('Clear Groupname-LDAP Group Mapping'));?></button></p>
        </fieldset>
        <input id="ldap_submit" type="submit" value="Save" /> <button id="ldap_action_test_connection" name="ldap_action_test_connection"><?php p($l->t('Test Configuration'));?></button> <a href="http://doc.owncloud.org/server/5.0/admin_manual/auth_ldap.html" target="_blank"><img src="<?php print_unescaped(OCP\Util::imagePath('', 'actions/info.png')); ?>" style="height:1.75ex" /> <?php p($l->t('Help'));?></a>
        </div>