Add report on diff of users in portal vs. AFS
authoradamch <adamch>
Sun, 11 Nov 2007 21:03:54 +0000 (21:03 +0000)
committeradamch <adamch>
Sun, 11 Nov 2007 21:03:54 +0000 (21:03 +0000)
init.sig
init.sml
users.mlt

index 1c5f0a2..19bad59 100644 (file)
--- a/init.sig
+++ b/init.sig
@@ -59,4 +59,9 @@ signature INIT = sig
     val explain : exn -> string
     val tokens : unit -> string
     val tokensForked : unit -> unit
+
+    val usersDiff : string list * string list ->
+                   {onlyInFirst : string list, onlyInSecond : string list}
+    val listUsernames : unit -> string list
+    val usersInAfs : unit -> string list
 end
index 97128a5..c5f5fa9 100644 (file)
--- a/init.sml
+++ b/init.sml
@@ -244,4 +244,43 @@ fun unmigratedUsers () =
                     false)
                    handle OS.SysErr _ => true) (listActiveUsers ())
 
+fun usersDiff (ls1, ls2) =
+    {onlyInFirst = List.filter (fn x => not (Util.mem (x, ls2))) ls1,
+     onlyInSecond = List.filter (fn x => not (Util.mem (x, ls1))) ls2}
+
+fun listUsernames () = C.map (getDb ())
+                            (fn [name] => C.stringFromSql name
+                              | row => rowError ("listUsernames", row))
+                            "SELECT name FROM WebUserActive ORDER BY name"
+fun usersInAfs () =
+    let
+       fun explore (dir, level, acc) =
+           if level = 3 then
+               dir :: acc
+           else
+               let
+                   val dr = Posix.FileSys.opendir dir
+
+                   fun loop acc =
+                       case Posix.FileSys.readdir dr of
+                           NONE => acc
+                         | SOME name =>
+                           let
+                               val dir' = OS.Path.joinDirFile {dir = dir,
+                                                               file = name}
+
+                               val acc = explore (dir', level+1, acc)
+                           in
+                               loop acc
+                           end
+               in
+                   loop acc
+                   before Posix.FileSys.closedir dr
+               end
+
+       val acc = explore ("/afs/hcoop.net/user", 0, [])
+    in
+       List.map OS.Path.file acc
+    end
+
 end
index a4a8cb3..1cd37f0 100644 (file)
--- a/users.mlt
+++ b/users.mlt
@@ -124,6 +124,31 @@ end %>
 
 <p><% negative %> have negative balances.</p>
 
+<% elseif $"cmd" = "diff" then
+   showNormal := false;
+
+   val against = (case $"against" of
+                              "" => Init.usersInAfs ()
+                    | x => String.tokens Char.isSpace x);
+
+   val diff = Init.usersDiff (Init.listUsernames (), against) %>
+
+<h3>User diff</h3>
+
+<h4>Only on the portal:</h4>
+<ul>
+<% foreach user in #onlyInFirst diff do %>
+   <li> <a href="user?id=<% valOf (Init.userNameToId user) %>"><% Web.html user %></a></li>
+<% end %>
+</ul>
+
+<h4>Only in AFS:</h4>
+<ul>
+<% foreach user in #onlyInSecond diff do %>
+   <li> <% Web.html user %></li>
+<% end %>
+</ul>
+
 <% end %>
 
 <% if showNormal then %>
@@ -145,6 +170,7 @@ if #name bal <> #name user then %>
 
 <br><a href="users?cmd=grandfather">Grandfather old users to have applications</a><br>
 <a href="users?cmd=unmigrated">Who hasn't migrated yet?</a><br>
+<a href="users?cmd=diff">How does the set of users in AFS compare with the set of active portal users?</a><br>
 
 <% end %>