roundabout,
created on Monday, 13 May 2024, 15:30:37 (1715614237),
received on Wednesday, 31 July 2024, 06:54:48 (1722408888)
Author identity: vlad <vlad.muntoiu@gmail.com>
0498cd1b766fcca155349150001d5d48306f32d9
git_http.py
@@ -31,9 +31,37 @@ def verify_password(username, password):
return False
def get_commit_identity(identity, logged_in_user):
def get_commit_identity(identity, pusher, repo):
email = identity.rpartition("<")[2].rpartition(">")[0].strip()
# If the email is not valid, attribute the commit to the pusher.
if not email:
return pusher
email_users = db.query(User).filter_by(email=email).all()
# If no user has the email, attribute the commit to the pusher.
if not email_users:
return pusher
# If only one user has the email, attribute the commit to them.
if email_users.count() == 1:
return email_users[0]
# If it's ambiguous, attribute the commit to an user with a higher permission level.
for user in email_users:
if repo.owner == user:
return user
for user in email_users:
relationship = db.query(RepoAccess).filter_by(user=user, repo=repo).first()
if relationship.permission_level == 2:
return user
for user in email_users:
relationship = db.query(RepoAccess).filter_by(user=user, repo=repo).first()
if relationship.permission_level == 1:
return user
# If no user has a higher permission level, attribute the commit to the pusher.:(
return pusher
@app.route("/<username>/<repository>/git-upload-pack", methods=["POST"])
@@ -88,7 +116,8 @@ def git_receive_pack(username, repository):
login = flask.g.user
if not Commit.query.filter_by(identifier=f"/{username}/{repository}/{sha}").first():
user = User.query.filter_by(username=login).first()
logged_in_user = User.query.filter_by(username=login).first()
user = get_commit_identity(identity, logged_in_user, db.session.get(Repo, f"/{username}/{repository}"))
repo = Repo.query.filter_by(route=f"/{username}/{repository}").first()
commit = Commit(sha, user, repo, time, body, identity)