Changeset 228 for trunk/web


Ignore:
Timestamp:
Oct 28, 2007, 11:57:32 PM (17 years ago)
Author:
ecprice
Message:

Remove the useless User class (now user is a string)
Allow creation under another owner.

Location:
trunk/web/templates
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/web/templates/controls.py

    r216 r228  
    8888    remctl('web', 'unregister', machine.name)
    8989
    90 def createVm(user, name, memory, disk, is_hvm, cdrom):
     90def createVm(owner, contact, name, memory, disk, is_hvm, cdrom):
    9191    """Create a VM and put it in the database"""
    9292    # put stuff in the table
    9393    transaction = ctx.current.create_transaction()
    9494    try:
    95         validation.validMemory(user, memory)
    96         validation.validDisk(user, disk  * 1. / 1024)
    97         validation.validAddVm(user)
     95        validation.validMemory(owner, memory)
     96        validation.validDisk(owner, disk  * 1. / 1024)
     97        validation.validAddVm(owner)
    9898        res = meta.engine.execute('select nextval('
    9999                                  '\'"machines_machine_id_seq"\')')
     
    103103        machine.name = name
    104104        machine.memory = memory
    105         machine.owner = user.username
    106         machine.administrator = user.username
    107         machine.contact = user.email
     105        machine.owner = owner
     106        machine.administrator = owner
     107        machine.contact = contact
    108108        machine.uuid = uuidToString(randomUUID())
    109109        machine.boot_off_cd = True
  • trunk/web/templates/list.tmpl

    r227 r228  
    5252        </tr>
    5353$errorRow('cdrom', $err)
     54        <tr>
     55          <td>Owner</td>
     56          <td><input type="text" name="owner" value="$defaults.owner"/></td>
     57        </tr>
     58        $errorRow('owner', $err)
    5459      </table>
    5560      <input type="submit" class="button" value="Create it!"/>
     
    8994                   value="$machine.machine_id"/>
    9095<input type="submit" class="button" name="action" value="#slurp
    91 #if $machine.uptime then 'Shutdown' else 'Power on'
     96#if $machine.uptime then 'Power off' else 'Power on'
    9297"/>
    9398          </form>
     
    101106        <td>Name</td>
    102107        <td>Memory</td>
    103         <td>owner</td>
     108        <td>Owner</td>
    104109        <td>IP</td>
    105110        <td>Uptime</td>
  • trunk/web/templates/main.py

    r227 r228  
    4747            '&amp;simple=true" target="_blank" ' +
    4848            'onclick="return helppopup(\'' + subj + '\')">(?)</a></span>')
    49 
    50 class User:
    51     """User class (sort of useless, I admit)"""
    52     def __init__(self, username, email):
    53         self.username = username
    54         self.email = email
    5549
    5650def makeErrorPre(old, addition):
     
    134128                           "Name already exists.")
    135129   
     130    owner = validation.testOwner(user, fields.getfirst('owner'))
     131
    136132    memory = fields.getfirst('memory')
    137133    memory = validation.validMemory(user, memory, on=True)
     
    148144    if cdrom is not None and not CDROM.get(cdrom):
    149145        raise CodeError("Invalid cdrom type '%s'" % cdrom)
    150     return dict(user=user, name=name, memory=memory, disk=disk,
    151                 is_hvm=is_hvm, cdrom=cdrom)
     146    return dict(contact=user, name=name, memory=memory, disk=disk,
     147                owner=owner, is_hvm=is_hvm, cdrom=cdrom)
    152148
    153149def create(user, fields):
     
    189185    defaults = Defaults(max_memory=max_memory,
    190186                        max_disk=max_disk,
     187                        owner=user,
    191188                        cdrom='gutsy-i386')
    192189    d = dict(user=user,
     
    231228
    232229    data = {}
    233     data["user"] = user.username
     230    data["user"] = user
    234231    data["machine"] = machine.name
    235232    data["expires"] = time.time()+(5*60)
     
    545542    if 'SSL_CLIENT_S_DN_Email' in os.environ:
    546543        username = os.environ['SSL_CLIENT_S_DN_Email'].split("@")[0]
    547         return User(username, os.environ['SSL_CLIENT_S_DN_Email'])
    548     else:
    549         return User('moo', 'nobody')
     544        return username
     545    else:
     546        return 'moo'
    550547
    551548def main(operation, user, fields):   
  • trunk/web/templates/skeleton.tmpl

    r207 r228  
    3939
    4040#if not $varExists('simple') or not $simple
    41 <p>[You are logged in as $user.username.]</p>
     41<p>[You are logged in as $user.]</p>
    4242
    4343<div class="navigation">
  • trunk/web/templates/validation.py

    r211 r228  
    2525        owner = machine.owner
    2626    else:
    27         owner = user.username
     27        owner = user
    2828    return Machine.select_by(owner=owner)
    2929
     
    6969def haveAccess(user, machine):
    7070    """Return whether a user has adminstrative access to a machine"""
    71     if user.username == 'moo':
    72         return True
    73     if user.username in (machine.administrator, machine.owner):
    74         return True
    75     if getafsgroups.checkAfsGroup(user.username, machine.administrator,
     71    if user == 'moo':
     72        return True
     73    if user in (machine.administrator, machine.owner):
     74        return True
     75    if getafsgroups.checkAfsGroup(user, machine.administrator,
    7676                                  'athena.mit.edu'): #XXX Cell?
    7777        return True
    78     if getafsgroups.checkLockerOwner(user.username, machine.owner):
     78    if getafsgroups.checkLockerOwner(user, machine.owner):
    7979        return True
    8080    return owns(user, machine)
     
    8282def owns(user, machine):
    8383    """Return whether a user owns a machine"""
    84     if user.username == 'moo':
    85         return True
    86     return getafsgroups.checkLockerOwner(user.username, machine.owner)
     84    if user == 'moo':
     85        return True
     86    return getafsgroups.checkLockerOwner(user, machine.owner)
    8787
    8888def validMachineName(name):
     
    154154    if admin in (None, machine.administrator):
    155155        return None
    156     if admin == user.username:
     156    if admin == user:
    157157        return admin
    158     if getafsgroups.checkAfsGroup(user.username, admin, 'athena.mit.edu'):
     158    if getafsgroups.checkAfsGroup(user, admin, 'athena.mit.edu'):
    159159        return admin
    160     if getafsgroups.checkAfsGroup(user.username, 'system:'+admin,
     160    if getafsgroups.checkAfsGroup(user, 'system:'+admin,
    161161                                  'athena.mit.edu'):
    162162        return 'system:'+admin
    163163    return admin
    164164   
    165 def testOwner(user, owner, machine):
    166     if owner in (None, machine.owner):
    167         return None
    168     value = getafsgroups.checkLockerOwner(user.username, owner, verbose=True)
     165def testOwner(user, owner, machine=None):
     166    if owner == user or machine is not None and owner == machine.owner:
     167        return owner
     168    if owner is None:
     169        raise InvalidInput('owner', owner, "Owner must be specified")
     170    value = getafsgroups.checkLockerOwner(user, owner, verbose=True)
    169171    if not value:
    170172        return owner
Note: See TracChangeset for help on using the changeset viewer.