Make isIdDeveloper() also able to check an is_developer Boolean property in
authorTodd Larsen <tlarsen@google.com>
Fri, 12 Sep 2008 20:31:56 +0000
changeset 137 0f572149449d
parent 136 a95f511bfcf8
child 138 e1167bdf71a4
Make isIdDeveloper() also able to check an is_developer Boolean property in User entities. Review URL: http://codereviews.googleopensourceprograms.com/601
app/soc/logic/site/id_user.py
app/soc/models/user.py
app/soc/templates/soc/site/user/profile/lookup.html
app/soc/views/user/profile.py
--- a/app/soc/logic/site/id_user.py	Fri Sep 12 19:01:44 2008 +0000
+++ b/app/soc/logic/site/id_user.py	Fri Sep 12 20:31:56 2008 +0000
@@ -139,21 +139,34 @@
 def isIdDeveloper(id=None):
   """Returns True if Google Account is a Developer with special privileges.
   
+  using the App Engine Users API.
+  
   Args:
     id: a Google Account (users.User) object; if id is not supplied,
-      the current logged-in user is checked using the App Engine Users API.
-      THIS ARGUMENT IS CURRENTLY IGNORED AND ONLY THE CURRENTLY LOGGED-IN
-      USER IS CHECKED!
-
-  See the TODO in the code below...
+      the current logged-in user is checked
   """
+  id = getIdIfMissing(id)
+ 
   if not id:
-    return users.is_current_user_admin()
+    # no Google Account was supplied or is logged in, so an unspecified
+    # User is definitely *not* a Developer
+    return False
 
-  # TODO(tlarsen): this Google App Engine function only checks the currently
-  #   logged in user.  There needs to be another way to do this, such as a
-  #   field in the User Model...
-  return users.is_current_user_admin()
+  if id == users.get_current_user():
+    if users.is_current_user_admin():
+      # supplied id is current logged-in user, and that user is in the
+      # Administration->Developers list in the App Engine console
+      return True
+  
+  user = getUserFromId(id)
+
+  if not user:
+    # no User entity for this Google Account, and id is not the currently
+    # logged-in user, so there is no conclusive way to check the
+    # Administration->Developers list in the App Engine console
+    return False
+  
+  return user.is_developer
 
 
 LINKNAME_PATTERN = r'''(?x)
--- a/app/soc/models/user.py	Fri Sep 12 19:01:44 2008 +0000
+++ b/app/soc/models/user.py	Fri Sep 12 20:31:56 2008 +0000
@@ -75,3 +75,9 @@
   link_name.help_text = ugettext_lazy(
       'Field used in URLs to identify user. '
       'Lower ASCII characters only.')
+
+  #: field storing whether User is a Developer with site-wide access.
+  is_developer = db.BooleanProperty(
+      verbose_name=ugettext_lazy('Is Developer'))
+  is_developer.help_text = ugettext_lazy(
+      'Field used to indicate user with site-wide "Developer" access.')
--- a/app/soc/templates/soc/site/user/profile/lookup.html	Fri Sep 12 19:01:44 2008 +0000
+++ b/app/soc/templates/soc/site/user/profile/lookup.html	Fri Sep 12 20:31:56 2008 +0000
@@ -37,6 +37,12 @@
   <td>{{ found_user.nick_name }}</td>
   <td class="formfieldhelptext">&nbsp;</td>
  </tr>
+ <tr>
+  <td class="formfieldlabel">Is Developer</td>
+  <td class="formfieldrequired">&nbsp;</td>
+  <td>{{ found_user.is_developer }}</td>
+  <td class="formfieldhelptext">&nbsp;</td>
+ </tr>
 {% endif %}
   <tr>
    <td colspan="4">&nbsp;</td>
--- a/app/soc/views/user/profile.py	Fri Sep 12 19:01:44 2008 +0000
+++ b/app/soc/views/user/profile.py	Fri Sep 12 20:31:56 2008 +0000
@@ -49,7 +49,7 @@
     model = soc.models.user.User
     
     #: list of model fields which will *not* be gathered by the form
-    exclude = ['id', 'former_ids']
+    exclude = ['id', 'former_ids', 'is_developer']
   
   def clean_link_name(self):
     link_name = self.cleaned_data.get('link_name')