comparison rhodecode/controllers/api/api.py @ 1500:256e729a94cd beta

Extended API - updated docs - created two new methods for creating users and creating users groups - changed user attribute generated from api_key to apiuser for better name compatibility with functoin parameters
author Marcin Kuzminski <marcin@python-works.com>
date Fri, 30 Sep 2011 18:03:20 +0300
parents c78f6bf52e9c
children 4aba7be311e8
comparison
equal deleted inserted replaced
1499:182f5bd3b49d 1500:256e729a94cd
1 import traceback
2 import logging
3
1 from rhodecode.controllers.api import JSONRPCController, JSONRPCError 4 from rhodecode.controllers.api import JSONRPCController, JSONRPCError
2 from rhodecode.lib.auth import HasPermissionAllDecorator 5 from rhodecode.lib.auth import HasPermissionAllDecorator
3 from rhodecode.model.scm import ScmModel 6 from rhodecode.model.scm import ScmModel
7
8 from rhodecode.model.db import User, UsersGroup
9
10 log = logging.getLogger(__name__)
4 11
5 12
6 class ApiController(JSONRPCController): 13 class ApiController(JSONRPCController):
7 """ 14 """
8 API Controller 15 API Controller
18 errors that happens 25 errors that happens
19 26
20 """ 27 """
21 28
22 @HasPermissionAllDecorator('hg.admin') 29 @HasPermissionAllDecorator('hg.admin')
23 def pull(self, user, repo): 30 def pull(self, apiuser, repo):
24 """ 31 """
25 Dispatch pull action on given repo 32 Dispatch pull action on given repo
26 33
27 34
28 param user: 35 :param user:
29 param repo: 36 :param repo:
30 """ 37 """
31 38
32 try: 39 try:
33 ScmModel().pull_changes(repo, self.rhodecode_user.username) 40 ScmModel().pull_changes(repo, self.rhodecode_user.username)
34 return 'Pulled from %s' % repo 41 return 'Pulled from %s' % repo
35 except Exception: 42 except Exception:
36 raise JSONRPCError('Unable to pull changes from "%s"' % repo) 43 raise JSONRPCError('Unable to pull changes from "%s"' % repo)
37 44
38 45
46 @HasPermissionAllDecorator('hg.admin')
47 def create_user(self, apiuser, username, password, active, admin, name,
48 lastname, email):
49 """
50 Creates new user
51
52 :param apiuser:
53 :param username:
54 :param password:
55 :param active:
56 :param admin:
57 :param name:
58 :param lastname:
59 :param email:
60 """
61
62 form_data = dict(username=username,
63 password=password,
64 active=active,
65 admin=admin,
66 name=name,
67 lastname=lastname,
68 email=email)
69 try:
70 u = User.create(form_data)
71 return {'id':u.user_id,
72 'msg':'created new user %s' % name}
73 except Exception:
74 log.error(traceback.format_exc())
75 raise JSONRPCError('failed to create user %s' % name)
39 76
40 77
78 @HasPermissionAllDecorator('hg.admin')
79 def create_users_group(self, apiuser, name, active):
80 """
81 Creates an new usergroup
82
83 :param name:
84 :param active:
85 """
86 form_data = {'users_group_name':name,
87 'users_group_active':active}
88 try:
89 ug = UsersGroup.create(form_data)
90 return {'id':ug.users_group_id,
91 'msg':'created new users group %s' % name}
92 except Exception:
93 log.error(traceback.format_exc())
94 raise JSONRPCError('failed to create group %s' % name)
95