diff --git a/plinth/modules/gitweb/__init__.py b/plinth/modules/gitweb/__init__.py index ead2bdc3b..0254ef98c 100644 --- a/plinth/modules/gitweb/__init__.py +++ b/plinth/modules/gitweb/__init__.py @@ -15,7 +15,7 @@ from plinth.package import Packages from . import manifest, privileged from .forms import is_repo_url -from .manifest import GIT_REPO_PATH +from .manifest import GIT_REPO_PATH, REPO_DIR_OWNER _description = [ _('Git is a distributed version-control system for tracking changes in ' @@ -213,7 +213,7 @@ def get_repo_list(): def repo_info(repo): """Get information about repository.""" - info = privileged.repo_info(repo) + info = privileged.repo_info(repo, _run_as_user=REPO_DIR_OWNER) if info['access'] == 'private': info['is_private'] = True else: @@ -244,4 +244,5 @@ def edit_repo(form_initial, form_cleaned): privileged.set_repo_access(repo, 'public') if form_cleaned['default_branch'] != form_initial['default_branch']: - privileged.set_default_branch(repo, form_cleaned['default_branch']) + privileged.set_default_branch(repo, form_cleaned['default_branch'], + _run_as_user=REPO_DIR_OWNER) diff --git a/plinth/modules/gitweb/forms.py b/plinth/modules/gitweb/forms.py index 76ba8a314..b47ef9e5a 100644 --- a/plinth/modules/gitweb/forms.py +++ b/plinth/modules/gitweb/forms.py @@ -14,11 +14,12 @@ from django.utils.translation import gettext_lazy as _ from plinth.modules import gitweb from . import privileged +from .manifest import REPO_DIR_OWNER def _get_branches(repo): """Get all the branches in the repository.""" - branch_data = privileged.get_branches(repo) + branch_data = privileged.get_branches(repo, _run_as_user=REPO_DIR_OWNER) default_branch = branch_data['default_branch'] branches = branch_data['branches'] diff --git a/plinth/modules/gitweb/manifest.py b/plinth/modules/gitweb/manifest.py index 92847f90d..cb83f8353 100644 --- a/plinth/modules/gitweb/manifest.py +++ b/plinth/modules/gitweb/manifest.py @@ -4,6 +4,7 @@ from django.utils.translation import gettext_lazy as _ CONFIG_FILE = '/etc/gitweb-freedombox.conf' GIT_REPO_PATH = '/var/lib/git' +REPO_DIR_OWNER = 'www-data' clients = [ { diff --git a/plinth/modules/gitweb/privileged.py b/plinth/modules/gitweb/privileged.py index 3bb213eed..9717ff616 100644 --- a/plinth/modules/gitweb/privileged.py +++ b/plinth/modules/gitweb/privileged.py @@ -13,7 +13,7 @@ from typing import Any, Optional from plinth import action_utils from plinth.actions import privileged from plinth.modules.gitweb.forms import RepositoryValidator, get_name_from_url -from plinth.modules.gitweb.manifest import GIT_REPO_PATH +from plinth.modules.gitweb.manifest import GIT_REPO_PATH, REPO_DIR_OWNER logger = logging.getLogger(__name__) @@ -166,8 +166,9 @@ def _clone_repo(url: str, description: str, owner: str, keep_ownership: bool): shutil.rmtree(repo_temp_path) if not keep_ownership: - subprocess.check_call(['chown', '-R', 'www-data:www-data', repo], - cwd=GIT_REPO_PATH) + subprocess.check_call( + ['chown', '-R', f'{REPO_DIR_OWNER}:{REPO_DIR_OWNER}', repo], + cwd=GIT_REPO_PATH) _set_repo_description(repo, description) _set_repo_owner(repo, owner) @@ -180,8 +181,9 @@ def _create_repo(repo: str, description: str, owner: str, is_private: bool, subprocess.check_call(['git', 'init', '-q', '--bare', repo], cwd=GIT_REPO_PATH) if not keep_ownership: - subprocess.check_call(['chown', '-R', 'www-data:www-data', repo], - cwd=GIT_REPO_PATH) + subprocess.check_call( + ['chown', '-R', f'{REPO_DIR_OWNER}:{REPO_DIR_OWNER}', repo], + cwd=GIT_REPO_PATH) _set_repo_description(repo, description) _set_repo_owner(repo, owner) if is_private: