Mercurial > kallithea
diff 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 |
line wrap: on
line diff
--- a/rhodecode/controllers/api/api.py Fri Sep 30 01:50:21 2011 +0300 +++ b/rhodecode/controllers/api/api.py Fri Sep 30 18:03:20 2011 +0300 @@ -1,7 +1,14 @@ +import traceback +import logging + from rhodecode.controllers.api import JSONRPCController, JSONRPCError from rhodecode.lib.auth import HasPermissionAllDecorator from rhodecode.model.scm import ScmModel +from rhodecode.model.db import User, UsersGroup + +log = logging.getLogger(__name__) + class ApiController(JSONRPCController): """ @@ -20,13 +27,13 @@ """ @HasPermissionAllDecorator('hg.admin') - def pull(self, user, repo): + def pull(self, apiuser, repo): """ Dispatch pull action on given repo - param user: - param repo: + :param user: + :param repo: """ try: @@ -36,5 +43,53 @@ raise JSONRPCError('Unable to pull changes from "%s"' % repo) + @HasPermissionAllDecorator('hg.admin') + def create_user(self, apiuser, username, password, active, admin, name, + lastname, email): + """ + Creates new user + + :param apiuser: + :param username: + :param password: + :param active: + :param admin: + :param name: + :param lastname: + :param email: + """ + + form_data = dict(username=username, + password=password, + active=active, + admin=admin, + name=name, + lastname=lastname, + email=email) + try: + u = User.create(form_data) + return {'id':u.user_id, + 'msg':'created new user %s' % name} + except Exception: + log.error(traceback.format_exc()) + raise JSONRPCError('failed to create user %s' % name) + @HasPermissionAllDecorator('hg.admin') + def create_users_group(self, apiuser, name, active): + """ + Creates an new usergroup + + :param name: + :param active: + """ + form_data = {'users_group_name':name, + 'users_group_active':active} + try: + ug = UsersGroup.create(form_data) + return {'id':ug.users_group_id, + 'msg':'created new users group %s' % name} + except Exception: + log.error(traceback.format_exc()) + raise JSONRPCError('failed to create group %s' % name) + \ No newline at end of file