rcUsers.py

Go to the documentation of this file.
00001 #!/usr/local/bin/python
00002 #
00003 #                               Copyright 2005
00004 #                                     by
00005 #                        The Board of Trustees of the
00006 #                     Leland Stanford Junior University.
00007 #                            All rights reserved.
00008 #
00009 
00010 __facility__ = "Online"
00011 __abstract__ = "User maintenance classes"
00012 __author__   = "S. Tuvi <stuvi@SLAC.Stanford.edu> SLAC - GLAST LAT I&T/Online"
00013 __date__     = "2005/07/23 00:08:27"
00014 __updated__  = "$Date: 2005/09/22 00:29:31 $"
00015 __version__  = "$Revision: 1.5 $"
00016 __release__  = "$Name: HEAD $"
00017 __credits__  = "SLAC"
00018 
00019 import LICOS.copyright_SLAC
00020 
00021 class rcUser(object):
00022   """!\brief Class that stores security and identification information about users.
00023 
00024   """
00025   def __init__(self, userId, loginId, userName):
00026     """!\brief rcUser constructor.
00027 
00028     \param userId   User id
00029     \param loginId  Login id
00030     \param userName User name
00031     """
00032     self.__userId = userId
00033     self.__loginId = loginId
00034     self.__userName = userName
00035     self.__roles = []
00036     self.__permissions = []
00037 
00038   def getId(self):
00039     """!\brief Returns the three digit user id.
00040 
00041     \return User Id
00042     """
00043     return self.__userId
00044 
00045   def getLoginId(self):
00046     """!\brief Returns the user's login id.
00047 
00048     \return Login id
00049     """
00050     return self.__loginId
00051 
00052   def getName(self):
00053     """!\brief Returns the user name.
00054 
00055     \return User name
00056     """
00057     return self.__userName
00058 
00059   def getRoles(self):
00060     """!\brief Returns the list of roles that this user belongs in.
00061 
00062     \return List of roles
00063     """
00064     return self.__roles
00065 
00066   def getPermissions(self):
00067     """!\brief Returns the list of permissions that this user has.
00068 
00069     \return List of permissions
00070     """
00071     return self.__permissions
00072 
00073   def addRole(self, role):
00074     """!\brief Adds \a role to this user's roles.
00075 
00076     \param role Role name
00077     """
00078     self.__roles.append(role)
00079 
00080   def addPermission(self, permission):
00081     """!\brief Adds \a permission to this user's permissions.
00082 
00083     \param permission Permission name
00084     """
00085     self.__permissions.append(permission)
00086 
00087   def isAdministrator(self):
00088     """!\brief Returns the user's administrator status.
00089 
00090     \return 1: If this user is an administrator
00091             0: Otherwise
00092     """
00093     return ('administrator' in self.__roles)
00094 
00095   def __str__(self):
00096     return self.getName()
00097 
00098 class rcUsers(object):
00099   """!\brief A dictionary like class that maintains a list of user objects.
00100 
00101   """
00102   def __init__(self):
00103     """!\brief rcUsers constructor.
00104 
00105     """
00106     self.__users = {}
00107 
00108   def addUser(self, user):
00109     """!\brief Adds the \a user to the list.
00110 
00111     \param user An rcUser object instance
00112     """
00113     self.__users[user.getId()] = user
00114 
00115   def deleteUser(self, userId):
00116     """!\brief Deletes the user from the list based on the \a userId.
00117 
00118     \param  userId The three digit id of the user
00119 
00120     \return  True: If the user was successfully deleted
00121             False: If the user does not exist
00122     """
00123     if userId in self.__users:
00124       self.__users.__delitem__(userId)
00125       return True
00126     else:
00127       return False
00128 
00129 
00130   def getUserByLoginId(self, loginId):
00131     """!\brief Retrieves the user based on the \a loginId.
00132 
00133     \param loginId Login id of the user
00134 
00135     \return rcUser object instance
00136     """
00137     for user in self.__users.values():
00138       if loginId == user.getLoginId():
00139         return user
00140 
00141   def getUserByName(self, name):
00142     """!\brief Retrieves the user based on the \a name.
00143 
00144     \param name Name of the user
00145 
00146     \return rcUser object instance
00147     """
00148     for user in self.__users.values():
00149       if name == user.getName():
00150         return user
00151 
00152   def getUser(self, userId):
00153     """!\brief Retrieves the user based on \a userid.
00154 
00155     \param Three digit of the user
00156 
00157     \return rcUser object instance
00158     """
00159     if userId in self.__users:
00160       return self.__users[userId]
00161 
00162   def getUsers(self):
00163     """!\brief Retrieves all users.
00164 
00165     \return A dictionary of all users keyed by the user id
00166     """
00167     return self.__users
00168 
00169   def getIdNameDict(self):
00170     """!\brief Retrieves all users in the form of a dictionary.
00171 
00172     In this dictionary the values are user names.
00173     Provided for backward compatibility with the old code.
00174 
00175     \return A dictionary of user names keyed by the user id
00176     """
00177     # Provided for backward compatibility to mimick the old list
00178     userList = {}
00179     for (userId, user) in self.__users.items():
00180       userList[userId] = user.getName()
00181     return userList
00182 

Generated on Thu Apr 27 20:52:43 2006 for LICOS L02-01-00 by doxygen 1.4.6-NO