Changeset - 92a4f7c496a5
[Not reviewed]
beta
0 6 0
Nicolas VINOT - 14 years ago 2011-10-23 01:16:55
aeris@imirhil.fr
Correct code style
2 files changed with 9 insertions and 9 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/api/api.py
Show inline comments
 
@@ -343,30 +343,30 @@ class ApiController( JSONRPCController )
 
            raise JSONRPCError( 'failed to create repository %s' % name )
 

	
 
    @HasPermissionAnyDecorator( 'hg.admin' )
 
    def add_user_to_repo( self, apiuser, repo_name, user_name, perm ):
 
        """
 
        Add permission for a user to a repository
 

	
 
        :param apiuser
 
        :param repo_name
 
        :param user_name
 
        :param perm
 
        """
 

	
 
        try:
 
            try:
 
                repo = Repository.get_by_repo_name( repo_name )
 
            except NoResultFound:
 
                raise JSONRPCError( 'unknown repository %s' % repo )
 

	
 
            try:
 
                user = User.get_by_username( user_name )
 
            except NoResultFound:
 
                raise JSONRPCError( 'unknown user %s' % user )
 

	
 
            RepositoryPermissionModel().updateOrDeleteUserPermission( repo, user, perm )
 
            RepositoryPermissionModel().update_or_delete_user_permission(repo, user, perm)
 
        except Exception:
 
            log.error( traceback.format_exc() )
 
            raise JSONRPCError( 'failed to edit permission %(repo)s for %(user)s'
 
                            % dict( user = user_name, repo = repo_name ) )
 

	
rhodecode/model/repo_permission.py
Show inline comments
 
@@ -9,55 +9,55 @@
 
    :author: nvinot
 
    :copyright: (C) 2011-2011 Nicolas Vinot <aeris@imirhil.fr>
 
    :license: GPLv3, see COPYING for more details.
 
"""
 
# This program is free software: you can redistribute it and/or modify
 
# it under the terms of the GNU General Public License as published by
 
# the Free Software Foundation, either version 3 of the License, or
 
# (at your option) any later version.
 
#
 
# This program is distributed in the hope that it will be useful,
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
# GNU General Public License for more details.
 
#
 
# You should have received a copy of the GNU General Public License
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 

	
 
import logging
 
from rhodecode.model.db import BaseModel, RepoToPerm, Permission
 
from rhodecode.model.meta import Session
 

	
 
log = logging.getLogger( __name__ )
 

	
 
class RepositoryPermissionModel( BaseModel ):
 
    def getUserPermission( self, repository, user ):
 
    def get_user_permission(self, repository, user):
 
        return RepoToPerm.query() \
 
                .filter( RepoToPerm.user == user ) \
 
                .filter( RepoToPerm.repository == repository ) \
 
                .scalar()
 

	
 
    def updateUserPermission( self, repository, user, permission ):
 
    def update_user_permission(self, repository, user, permission):
 
        permission = Permission.get_by_key( permission )
 
        current = self.getUserPermission( repository, user )
 
        current = self.get_user_permission(repository, user)
 
        if current:
 
            if not current.permission is permission:
 
                current.permission = permission
 
        else:
 
            p = RepoToPerm()
 
            p.user = user
 
            p.repository = repository
 
            p.permission = permission
 
            Session.add( p )
 
        Session.commit()
 

	
 
    def deleteUserPermission( self, repository, user ):
 
        current = self.getUserPermission( repository, user )
 
    def delete_user_permission(self, repository, user):
 
        current = self.get_user_permission(repository, user)
 
        if current:
 
            Session.delete( current )
 
            Session.commit()
 

	
 
    def updateOrDeleteUserPermission( self, repository, user, permission ):
 
    def update_or_delete_user_permission(self, repository, user, permission):
 
        if permission:
 
            self.updateUserPermission( repository, user, permission )
 
            self.update_user_permission(repository, user, permission)
 
        else:
 
            self.deleteUserPermission( repository, user )
 
            self.delete_user_permission(repository, user)
0 comments (0 inline, 0 general)