Package Products :: Package Zuul :: Package routers :: Module users
[hide private]
[frames] | no frames]

Source Code for Module Products.Zuul.routers.users

  1  ############################################################################## 
  2  # 
  3  # Copyright (C) Zenoss, Inc. 2010, all rights reserved. 
  4  # 
  5  # This content is made available according to terms specified in 
  6  # License.zenoss under the directory where your Zenoss product is installed. 
  7  # 
  8  ############################################################################## 
  9   
 10   
 11  """ 
 12  Operations for Users 
 13  """ 
 14   
 15  import logging 
 16  from Products.ZenUtils.Ext import DirectRouter, DirectResponse 
 17  from Products.Zuul.decorators import require 
 18  from Products import Zuul 
 19  from Products.ZenMessaging.audit import audit 
 20   
 21  log = logging.getLogger('zen.UserRouter') 
22 23 24 -class UsersRouter(DirectRouter):
25 """ 26 A JSON/ExtDirect interface to operations on Users 27 """ 28
29 - def __init__(self, context, request):
30 self.facade = Zuul.getFacade('user', context) 31 self.context = context 32 self.request = request 33 super(UsersRouter, self).__init__(context, request)
34
35 - def _getFacade(self):
36 return self.facade
37 38 @require('Manage DMD')
39 - def setAdminPassword(self, newPassword):
40 audit('UI.Users.UpdateAdminPassword') 41 self.facade.setAdminPassword(newPassword) 42 return DirectResponse.succeed()
43
44 - def deleteUsers(self, userIds):
45 """ 46 Removes all the users with the given user ids. Will continue 47 upon removing users if an invalid id is specified. 48 @type userIds: List of Strings 49 @param userIds: (optional) list of ids to remove. 50 """ 51 facade = self._getFacade() 52 facade.removeUsers(userIds) 53 audit('UI.Users.RemoveUsers', userIds=userIds) 54 return DirectResponse.succeed()
55
56 - def getUsers(self, keys=None, start=0, limit=50, page=0, 57 sort='name', dir='ASC', name=None):
58 """ 59 Retrieves a list of users. This method supports pagination. 60 @type start: integer 61 @param start: (optional) Offset to return the results from; used in 62 pagination (default: 0) 63 @type name: string 64 @param name: (optional) filter to be applied to users returned (default: None) 65 @type limit: integer 66 @param limit: (optional) Number of items to return; used in pagination 67 (default: 50) 68 @type sort: string 69 @param sort: (optional) Key on which to sort the return results (default: 70 'name') 71 @type dir: string 72 @param dir: (optional) Sort order; can be either 'ASC' or 'DESC' 73 (default: 'ASC') 74 @rtype: DirectResponse 75 @return: B{Properties}: 76 - data: (list) Dictionaries of user properties 77 - totalCount: (integer) Number of devices returned 78 """ 79 facade = self._getFacade() 80 users = facade.getUsers(start=start, limit=limit, sort=sort, 81 dir=dir, name=name) 82 total = users.total 83 data = Zuul.marshal(users, keys) 84 return DirectResponse.succeed(data=data, totalCount=total)
85 86 @require('Manage DMD')
87 - def addUser(self, id, password, email, roles=('ZenUser',)):
88 """ 89 Adds a new user to the system. 90 @type id: string 91 @param id: The unique identifier of the user, same as their login 92 @type password: string 93 @param password: the password of the new user 94 @type roles: list of strings 95 @param roles: (optional) roles to be applied to the new user 96 @rtype: DirectResponse 97 @return: B{Properties}: 98 - data: properties of the new users 99 """ 100 facade = self._getFacade() 101 newUser = facade.addUser(id, password, email, roles) 102 audit('UI.Users.Add', id, email=email, roles=roles) 103 return DirectResponse.succeed(data=Zuul.marshal(newUser))
104 105 @require('Manage DMD')
106 - def markWizardAsFinished(self):
107 facade = self._getFacade() 108 facade.markWizardAsFinished() 109 audit('UI.Wizard.Complete') 110 return DirectResponse.succeed()
111