~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to lib/common/db.py

  • Committer: mattgiuca
  • Date: 2008-02-14 00:50:38 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:451
Updated common/db.py and listusers to deal with the new "state" column in the
login table. When creating a new user, state is always set to "no_agreement";
there is no argument for it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
85
85
        Arguments are the same as those in the "login" table of the schema.
86
86
        The exception is "password", which is a cleartext password. makeuser
87
87
        will hash the password.
 
88
        Also "state" is not given explicitly; it is implicitly set to
 
89
        "no_agreement".
88
90
        Raises an exception if the user already exists.
89
91
        """
90
92
        passhash = _passhash(password)
91
 
        query = ("INSERT INTO login (login, unixid, passhash, nick, fullname,"
92
 
            " rolenm, studentid) VALUES (%s, %d, %s, %s, %s, %s, %s);" %
93
 
            (_escape(login), unixid, _escape(passhash), _escape(nick),
 
93
        query = ("INSERT INTO login (login, passhash, state, unixid, nick, "
 
94
            "fullname, rolenm, studentid) VALUES "
 
95
            "(%s, %s, 'no_agreement', %d, %s, %s, %s, %s);" %
 
96
            (_escape(login), _escape(passhash), unixid, _escape(nick),
94
97
            _escape(fullname), _escape(rolenm), _escape(studentid)))
95
98
        if dry: return query
96
99
        self.db.query(query)
97
100
 
98
 
    def update_user(self, login, password=None, nick=None,
 
101
    def update_user(self, login, password=None, state=None, nick=None,
99
102
        fullname=None, rolenm=None, dry=False):
100
103
        """Updates fields of a particular user. login is the name of the user
101
104
        to update. The other arguments are optional fields which may be
113
116
        setlist = []
114
117
        if password is not None:
115
118
            setlist.append("passhash = " + _escape(_passhash(password)))
 
119
        if state is not None:
 
120
            setlist.append("state = " + _escape(state))
116
121
        if nick is not None:
117
122
            setlist.append("nick = " + _escape(nick))
118
123
        if fullname is not None:
141
146
 
142
147
        Raises a DBException if the login is not found in the DB.
143
148
        """
144
 
        query = ("SELECT login, unixid, nick, fullname, rolenm, studentid "
145
 
            "FROM login WHERE login = %s;" % _escape(login))
 
149
        query = ("SELECT login, state, unixid, nick, fullname, rolenm, "
 
150
            "studentid FROM login WHERE login = %s;" % _escape(login))
146
151
        if dry: return query
147
152
        result = self.db.query(query)
148
153
        # Expecting exactly one
157
162
        """Returns a list of all users. The list elements are a dictionary of
158
163
        the user's DB fields, excluding the passhash field.
159
164
        """
160
 
        query = ("SELECT login, unixid, nick, fullname, rolenm, studentid "
161
 
            "FROM login")
 
165
        query = ("SELECT login, state, unixid, nick, fullname, rolenm, "
 
166
            "studentid FROM login")
162
167
        if dry: return query
163
168
        return self.db.query(query).dictresult()
164
169