Implements administrator actions on Google Apps accounts (password synchronization...
authorVincent Zanotti <vincent.zanotti@m4x.org>
Fri, 10 Apr 2009 15:28:41 +0000 (17:28 +0200)
committerVincent Zanotti <vincent.zanotti@m4x.org>
Fri, 10 Apr 2009 15:28:41 +0000 (17:28 +0200)
Signed-off-by: Vincent Zanotti <vincent.zanotti@m4x.org>
modules/googleapps.php
templates/googleapps/admin.user.tpl

index 1419e22..7b63604 100644 (file)
@@ -180,7 +180,7 @@ class GoogleAppsModule extends PLModule
         }
     }
 
-    function handler_admin_user(&$page, $user = null, $action = null) {
+    function handler_admin_user(&$page, $user = null) {
         require_once("emails.inc.php");
         require_once("googleapps.inc.php");
         $page->changeTpl('googleapps/admin.user.tpl');
@@ -196,11 +196,25 @@ class GoogleAppsModule extends PLModule
             $account = new GoogleAppsAccount($user);
             $storage = new EmailStorage($user, 'googleapps');
 
-            // Force synchronization of plat/al and Google Apps passwords.
-            if ($action == 'forcesync' && $account->sync_password) {
+            // Apply requested actions.
+            if (Post::has('suspend') && $account->active() && !$account->pending_update_suspension) {
+                S::assert_xsrf_token();
+                $account->suspend();
+                $page->trigSuccess('Le compte est en cours de suspension.');
+            } else if (Post::has('unsuspend') && $account->suspended() && !$account->pending_update_suspension) {
+                S::assert_xsrf_token();
+                $account->do_unsuspend();
+                $page->trigSuccess('Le compte est en cours de réactivation.');
+            } else if (Post::has('forcesync') && $account->active() && $account->sync_password) {
+                $res = XDB::query("SELECT password FROM auth_user_md5 WHERE user_id = {?}", $user->id());
+                $account->set_password($res->fetchOneCell());
+                $page->trigSuccess('Le mot de passe est en cours de synchronisation.');
+            } else if (Post::has('sync') && $account->active()) {
                 $res = XDB::query("SELECT password FROM auth_user_md5 WHERE user_id = {?}", $user->id());
                 $account->set_password($res->fetchOneCell());
-                $page->trigSuccess('Le mot de passe a été synchronisé.');
+                $account->set_password_sync(true);
+            } else if (Post::has('nosync') && $account->active()) {
+                $account->set_password_sync(false);
             }
 
             // Displays basic account information.
index 8d553f4..1663dbf 100644 (file)
@@ -22,7 +22,7 @@
 
 <h1>Compte Google Apps</h1>
 
-{if $account}
+{if $account && $account->provisioned()}
 {assign var=a value=$account}
 <table class="bicol">
   <col width="50%" />
   {/if}
   <tr class="impair">
     <td class="titre">Mots de passes synchronisés</td>
-    <td>
-      {if $a->sync_password}
-        oui (<a href="admin/googleapps/user/{$a->g_account_name}/forcesync">lancer une synchronisation</a>)
-      {else}non{/if}
-    </td>
+    <td>{if $a->sync_password}oui{else}non{/if}</td>
   </tr>
   <tr class="impair">
     <td class="titre">Redirection des emails</td><td>{if $googleapps_storage}activée{else}désactivee{/if}</td>
   </tr>
 </table><br />
 
+<form action="admin/googleapps/user/{$a->g_account_name}" method="post">
+  {xsrf_token_field}
+  <table class="bicol">
+    <tr>
+      <th colspan="2" style="text-align: left">Actions sur le compte</th>
+    </tr>
+
+    <tr class="impair">
+      <td colspan="2" class="titre">Statut du compte</td>
+    </tr>
+    <tr class="impair">
+      <td>&nbsp;</td>
+      <td>
+        {if $a->pending_update_suspension}
+        <div class="erreur smaller">Le statut du compte est en cours de changement. Aucune opération n'est possible.</div>
+        {elseif $a->active()}
+        <input type="submit" name="suspend" value="Suspendre le compte" />
+        {elseif $a->suspended()}
+        <input type="submit" name="unsuspend" value="Réactiver le compte" />
+        {/if}
+      </td>
+    </tr>
+
+    <tr class="pair">
+      <td colspan="2" class="titre">Mot de passe</td>
+    </tr>
+    <tr class="pair">
+      <td>&nbsp;</td>
+      <td>
+        {if !$a->active()}
+        <div class="erreur smaller">Aucune opération n'est possible sur un compte inactif.</div>
+        {elseif $a->pending_update_password}
+        <div class="erreur smaller">Le mot de passe du compte est en cours de changement. Aucune opération n'est possible.</div>
+        {elseif $a->sync_password}
+        <input type="submit" name="forcesync" value="Synchroniser les mots de passes maintenant" />
+        <input type="submit" name="nosync" value="Désactiver la synchronisation automatique" />
+        {else}
+        <input type="submit" name="sync" value="Activer la synchronisation automatique" />
+        {/if}
+      </td>
+    </tr>
+  </table><br />
+</form>
+
 <table class="bicol" style="text-align: center">
   <tr>
     <th colspan="4" style="text-align: left">Requêtes en attente</th>
   </tr>
   {/iterate}
 </table>
+{elseif $account}
+<p><strong>Cet utilisateur n'a pas de compte Google Apps.</strong></p>
 {else}
 <p><strong>Aucun utilisateur n'a été trouvé.</strong></p>
 {/if}