##// END OF EJS Templates
fixes problem with basic auth and pushes
fixes problem with basic auth and pushes

File last commit:

r1508:4aba7be3 beta
r1534:72c3cea0 beta
Show More
api.py
97 lines | 2.8 KiB | text/x-python | PythonLexer
Extended API...
r1500 import traceback
import logging
Beginning of API implementation for rhodecode
r1445 from rhodecode.controllers.api import JSONRPCController, JSONRPCError
from rhodecode.lib.auth import HasPermissionAllDecorator
from rhodecode.model.scm import ScmModel
API added checks for a valid repository on pull command...
r1508 from rhodecode.model.db import User, UsersGroup, Repository
Extended API...
r1500
log = logging.getLogger(__name__)
Beginning of API implementation for rhodecode
r1445
class ApiController(JSONRPCController):
"""
API Controller
Each method needs to have USER as argument this is then based on given
API_KEY propagated as instance of user object
Preferably this should be first argument also
Each function should also **raise** JSONRPCError for any
errors that happens
"""
@HasPermissionAllDecorator('hg.admin')
Extended API...
r1500 def pull(self, apiuser, repo):
Beginning of API implementation for rhodecode
r1445 """
Dispatch pull action on given repo
Extended API...
r1500 :param user:
:param repo:
Beginning of API implementation for rhodecode
r1445 """
API added checks for a valid repository on pull command...
r1508 if Repository.is_valid(repo) is False:
raise JSONRPCError('Unknown repo "%s"' % repo)
Beginning of API implementation for rhodecode
r1445 try:
ScmModel().pull_changes(repo, self.rhodecode_user.username)
return 'Pulled from %s' % repo
except Exception:
raise JSONRPCError('Unable to pull changes from "%s"' % repo)
Extended API...
r1500 @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)
Beginning of API implementation for rhodecode
r1445
Extended API...
r1500 @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)