Changeset - 44e18bd4c3b2
[Not reviewed]
stable
0 1 0
Mads Kiilerich (mads) - 6 years ago 2019-12-30 01:38:59
mads@kiilerich.com
ssh: make it clear that SshKeyModel.delete has user as mandatory parameter

It is already provided in the two uses:
kallithea/controllers/admin/my_account.py: SshKeyModel().delete(fingerprint, request.authuser.user_id)
kallithea/controllers/admin/users.py: SshKeyModel().delete(fingerprint, c.user.user_id)
1 file changed with 4 insertions and 6 deletions:
0 comments (0 inline, 0 general)
kallithea/model/ssh_key.py
Show inline comments
 
@@ -63,35 +63,33 @@ class SshKeyModel(object):
 
        new_ssh_key.user_id = user.user_id
 
        new_ssh_key.description = description
 
        new_ssh_key.public_key = public_key
 

	
 
        for ssh_key in UserSshKeys.query().filter(UserSshKeys.fingerprint == new_ssh_key.fingerprint).all():
 
            raise SshKeyModelException(_('SSH key %s is already used by %s') %
 
                                       (new_ssh_key.fingerprint, ssh_key.user.username))
 

	
 
        Session().add(new_ssh_key)
 

	
 
        return new_ssh_key
 

	
 
    def delete(self, fingerprint, user=None):
 
    def delete(self, fingerprint, user):
 
        """
 
        Deletes ssh key with given fingerprint. If user is set, it also filters
 
        the object for deletion by given user.
 
        Deletes ssh key with given fingerprint for the given user.
 
        Will raise SshKeyModelException on errors
 
        """
 
        ssh_key = UserSshKeys.query().filter(UserSshKeys.fingerprint == fingerprint)
 

	
 
        if user:
 
            user = User.guess_instance(user)
 
            ssh_key = ssh_key.filter(UserSshKeys.user_id == user.user_id)
 
        user = User.guess_instance(user)
 
        ssh_key = ssh_key.filter(UserSshKeys.user_id == user.user_id)
 

	
 
        ssh_key = ssh_key.scalar()
 
        if ssh_key is None:
 
            raise SshKeyModelException(_('SSH key with fingerprint %r found') % safe_str(fingerprint))
 
        Session().delete(ssh_key)
 

	
 
    def get_ssh_keys(self, user):
 
        user = User.guess_instance(user)
 
        user_ssh_keys = UserSshKeys.query() \
 
            .filter(UserSshKeys.user_id == user.user_id).all()
 
        return user_ssh_keys
 

	
0 comments (0 inline, 0 general)