[autotest] Always direct restricted user to google storage.

Currently, retrieve_logs.cgi will check all the drones and shards
to see if it has the requested result and return a url pointing
to drone or shards if result if found. However,
restricted users do not have access to drones or shards.
Simply always redirect them to google storage for results.

TEST=Test on a ganeti instance. Make sure the link redirect correctly.
BUG=chromium:561131

Change-Id: Ib174886857e694763337d01d69b773fef84b1a77
Reviewed-on: https://chromium-review.googlesource.com/316492
Commit-Ready: Fang Deng <fdeng@chromium.org>
Tested-by: Fang Deng <fdeng@chromium.org>
Reviewed-by: Dan Shi <dshi@google.com>
diff --git a/server/site_utils.py b/server/site_utils.py
index 5880c67..4d676f3 100644
--- a/server/site_utils.py
+++ b/server/site_utils.py
@@ -3,6 +3,7 @@
 # found in the LICENSE file.
 
 
+import grp
 import httplib
 import json
 import logging
@@ -478,6 +479,26 @@
     return bool(hostname)
 
 
+def is_restricted_user(username):
+    """Determines if a user is in a restricted group.
+
+    User in restricted group only have access to master.
+
+    @param username: A string, representing a username.
+
+    @returns: True if the user is in a restricted group.
+    """
+    if not username:
+        return False
+
+    restricted_groups = global_config.global_config.get_config_value(
+            'AUTOTEST_WEB', 'restricted_groups', default='').split(',')
+    for group in restricted_groups:
+        if group and username in grp.getgrnam(group).gr_mem:
+            return True
+    return False
+
+
 def get_special_task_status(is_complete, success, is_active):
     """Get the status of a special task.