Changeset - 9b7c5d7ad1a2
[Not reviewed]
default
0 7 0
Mads Kiilerich (mads) - 5 years ago 2020-11-02 14:07:16
mads@kiilerich.com
Grafted from: 44a50670a755
hooks: import whole hooks module

Minimize impact if there should be cycles.
7 files changed with 19 insertions and 24 deletions:
0 comments (0 inline, 0 general)
kallithea/config/middleware/simplegit.py
Show inline comments
 
@@ -32,8 +32,8 @@ import logging
 
import re
 

	
 
from kallithea.config.middleware.pygrack import make_wsgi_app
 
from kallithea.lib import hooks
 
from kallithea.lib.base import BaseVCSController, get_path_info
 
from kallithea.lib.hooks import log_pull_action
 
from kallithea.lib.utils import make_ui
 
from kallithea.model import db
 

	
 
@@ -90,7 +90,7 @@ class SimpleGit(BaseVCSController):
 
                repo = db.Repository.get_by_repo_name(parsed_request.repo_name)
 
                scm_repo = repo.scm_instance
 
                # Run hooks, like Mercurial outgoing.pull_logger does
 
                log_pull_action(ui=baseui, repo=scm_repo._repo)
 
                hooks.log_pull_action(ui=baseui, repo=scm_repo._repo)
 
            # Note: push hooks are handled by post-receive hook
 

	
 
            return pygrack_app(environ, start_response)
kallithea/lib/celerylib/tasks.py
Show inline comments
 
@@ -42,8 +42,7 @@ from tg import config
 

	
 
import kallithea
 
import kallithea.lib.helpers as h
 
from kallithea.lib import celerylib, conf, ext_json
 
from kallithea.lib.hooks import log_create_repository
 
from kallithea.lib import celerylib, conf, ext_json, hooks
 
from kallithea.lib.indexers.daemon import WhooshIndexingDaemon
 
from kallithea.lib.utils import action_logger
 
from kallithea.lib.utils2 import asbool, ascii_bytes
 
@@ -407,7 +406,7 @@ def create_repo(form_data, cur_user):
 
            clone_uri=clone_uri,
 
        )
 
        repo = db.Repository.get_by_repo_name(repo_name_full)
 
        log_create_repository(repo.get_dict(), created_by=owner.username)
 
        hooks.log_create_repository(repo.get_dict(), created_by=owner.username)
 

	
 
        # update repo changeset caches initially
 
        repo.update_changeset_cache()
 
@@ -483,7 +482,7 @@ def create_repo_fork(form_data, cur_user
 
            clone_uri=source_repo_path,
 
        )
 
        repo = db.Repository.get_by_repo_name(repo_name_full)
 
        log_create_repository(repo.get_dict(), created_by=owner.username)
 
        hooks.log_create_repository(repo.get_dict(), created_by=owner.username)
 

	
 
        # update repo changeset caches initially
 
        repo.update_changeset_cache()
kallithea/lib/vcs/ssh/git.py
Show inline comments
 
@@ -15,7 +15,7 @@
 
import logging
 
import os
 

	
 
from kallithea.lib.hooks import log_pull_action
 
from kallithea.lib import hooks
 
from kallithea.lib.utils import make_ui
 
from kallithea.lib.vcs.ssh import base
 

	
 
@@ -66,7 +66,7 @@ class GitSshHandler(base.BaseSshHandler)
 
    def _serve(self):
 
        if self.verb == 'git-upload-pack': # action 'pull'
 
            # base class called set_hook_environment - action is hardcoded to 'pull'
 
            log_pull_action(ui=make_ui(), repo=self.db_repo.scm_instance._repo)
 
            hooks.log_pull_action(ui=make_ui(), repo=self.db_repo.scm_instance._repo)
 
        else: # probably verb 'git-receive-pack', action 'push'
 
            if not self.allow_push:
 
                self.exit('Push access to %r denied' % self.repo_name)
kallithea/model/pull_request.py
Show inline comments
 
@@ -32,8 +32,7 @@ import re
 
from tg import request
 
from tg.i18n import ugettext as _
 

	
 
from kallithea.lib import auth, webutils
 
from kallithea.lib.hooks import log_create_pullrequest
 
from kallithea.lib import auth, hooks, webutils
 
from kallithea.lib.utils import extract_mentioned_users
 
from kallithea.lib.utils2 import ascii_bytes, short_ref_name, shorter
 
from kallithea.model import changeset_status, comment, db, meta, notification
 
@@ -290,7 +289,7 @@ class CreatePullRequestAction(object):
 
        mention_recipients = extract_mentioned_users(self.description)
 
        PullRequestModel().add_reviewers(created_by, pr, self.reviewers, mention_recipients)
 

	
 
        log_create_pullrequest(pr.get_dict(), created_by)
 
        hooks.log_create_pullrequest(pr.get_dict(), created_by)
 

	
 
        return pr
 

	
kallithea/model/repo.py
Show inline comments
 
@@ -33,9 +33,9 @@ import traceback
 
from datetime import datetime
 

	
 
import kallithea.lib.utils2
 
from kallithea.lib import hooks
 
from kallithea.lib.auth import HasRepoPermissionLevel, HasUserGroupPermissionLevel
 
from kallithea.lib.exceptions import AttachedForksError
 
from kallithea.lib.hooks import log_delete_repository
 
from kallithea.lib.utils import is_valid_repo_uri, make_ui
 
from kallithea.lib.utils2 import LazyProperty, get_current_authuser, obfuscate_url_pw, remove_prefix
 
from kallithea.lib.vcs.backends import get_backend
 
@@ -483,7 +483,7 @@ class RepoModel(object):
 
                    self._delete_filesystem_repo(repo)
 
                else:
 
                    log.debug('skipping removal from filesystem')
 
                log_delete_repository(old_repo_dict,
 
                hooks.log_delete_repository(old_repo_dict,
 
                                      deleted_by=cur_user)
 
            except Exception:
 
                log.error(traceback.format_exc())
kallithea/model/scm.py
Show inline comments
 
@@ -37,9 +37,9 @@ import pkg_resources
 
from tg.i18n import ugettext as _
 

	
 
import kallithea
 
from kallithea.lib import hooks
 
from kallithea.lib.auth import HasPermissionAny, HasRepoGroupPermissionLevel, HasRepoPermissionLevel, HasUserGroupPermissionLevel
 
from kallithea.lib.exceptions import IMCCommitError, NonRelativePathError
 
from kallithea.lib.hooks import process_pushed_raw_ids
 
from kallithea.lib.utils import action_logger, get_filesystem_repos, make_ui
 
from kallithea.lib.utils2 import safe_bytes, safe_str, set_hook_environment, umask
 
from kallithea.lib.vcs import get_repo
 
@@ -328,7 +328,7 @@ class ScmModel(object):
 
        :param revisions: list of revisions that we pushed
 
        """
 
        set_hook_environment(username, ip_addr, repo_name, repo_alias=repo.alias, action=action)
 
        process_pushed_raw_ids(revisions) # also calls mark_for_invalidation
 
        hooks.process_pushed_raw_ids(revisions) # also calls mark_for_invalidation
 

	
 
    def pull_changes(self, repo, username, ip_addr, clone_uri=None):
 
        """
kallithea/model/user.py
Show inline comments
 
@@ -36,7 +36,7 @@ from sqlalchemy.exc import DatabaseError
 
from tg import config
 
from tg.i18n import ugettext as _
 

	
 
from kallithea.lib import webutils
 
from kallithea.lib import hooks, webutils
 
from kallithea.lib.exceptions import DefaultUserException, UserOwnsReposException
 
from kallithea.lib.utils2 import check_password, generate_api_key, get_crypt_password, get_current_authuser
 
from kallithea.model import db, forms, meta
 
@@ -59,7 +59,6 @@ class UserModel(object):
 
        if not cur_user:
 
            cur_user = getattr(get_current_authuser(), 'username', None)
 

	
 
        from kallithea.lib.hooks import check_allowed_create_user, log_create_user
 
        _fd = form_data
 
        user_data = {
 
            'username': _fd['username'],
 
@@ -71,7 +70,7 @@ class UserModel(object):
 
            'admin': False
 
        }
 
        # raises UserCreationError if it's not allowed
 
        check_allowed_create_user(user_data, cur_user)
 
        hooks.check_allowed_create_user(user_data, cur_user)
 

	
 
        new_user = db.User()
 
        for k, v in form_data.items():
 
@@ -85,7 +84,7 @@ class UserModel(object):
 
        meta.Session().add(new_user)
 
        meta.Session().flush() # make database assign new_user.user_id
 

	
 
        log_create_user(new_user.get_dict(), cur_user)
 
        hooks.log_create_user(new_user.get_dict(), cur_user)
 
        return new_user
 

	
 
    def create_or_update(self, username, password, email, firstname='',
 
@@ -109,14 +108,13 @@ class UserModel(object):
 
        if not cur_user:
 
            cur_user = getattr(get_current_authuser(), 'username', None)
 

	
 
        from kallithea.lib.hooks import check_allowed_create_user, log_create_user
 
        user_data = {
 
            'username': username, 'password': password,
 
            'email': email, 'firstname': firstname, 'lastname': lastname,
 
            'active': active, 'admin': admin
 
        }
 
        # raises UserCreationError if it's not allowed
 
        check_allowed_create_user(user_data, cur_user)
 
        hooks.check_allowed_create_user(user_data, cur_user)
 

	
 
        log.debug('Checking for %s account in Kallithea database', username)
 
        user = db.User.get_by_username(username, case_insensitive=True)
 
@@ -156,7 +154,7 @@ class UserModel(object):
 
                meta.Session().flush() # make database assign new_user.user_id
 

	
 
            if not edit:
 
                log_create_user(new_user.get_dict(), cur_user)
 
                hooks.log_create_user(new_user.get_dict(), cur_user)
 

	
 
            return new_user
 
        except (DatabaseError,):
 
@@ -255,8 +253,7 @@ class UserModel(object):
 
                % (user.username, len(usergroups), ', '.join(usergroups)))
 
        meta.Session().delete(user)
 

	
 
        from kallithea.lib.hooks import log_delete_user
 
        log_delete_user(user.get_dict(), cur_user)
 
        hooks.log_delete_user(user.get_dict(), cur_user)
 

	
 
    def can_change_password(self, user):
 
        from kallithea.lib import auth_modules
0 comments (0 inline, 0 general)