Show More
@@ -0,0 +1,1 b'' | |||||
|
1 | from pyramid.compat import configparser No newline at end of file |
@@ -209,7 +209,9 b' class RepoAppView(BaseAppView):' | |||||
209 | try: |
|
209 | try: | |
210 | self.rhodecode_vcs_repo = self.db_repo.scm_instance() |
|
210 | self.rhodecode_vcs_repo = self.db_repo.scm_instance() | |
211 | if self.rhodecode_vcs_repo: |
|
211 | if self.rhodecode_vcs_repo: | |
212 |
|
|
212 | path_perms = self.rhodecode_vcs_repo.get_path_permissions( | |
|
213 | c.auth_user.username) | |||
|
214 | self.path_filter = PathFilter(path_perms) | |||
213 | else: |
|
215 | else: | |
214 | self.path_filter = PathFilter(None) |
|
216 | self.path_filter = PathFilter(None) | |
215 | except RepositoryRequirementError as e: |
|
217 | except RepositoryRequirementError as e: | |
@@ -218,7 +220,7 b' class RepoAppView(BaseAppView):' | |||||
218 | self.rhodecode_vcs_repo = None |
|
220 | self.rhodecode_vcs_repo = None | |
219 | self.path_filter = None |
|
221 | self.path_filter = None | |
220 |
|
222 | |||
221 | c.path_filter = self.path_filter # used by atom_feed_entry.mako |
|
223 | c.path_filter = self.path_filter # used by atom_feed_entry.mako | |
222 |
|
224 | |||
223 | if (not c.repository_requirements_missing |
|
225 | if (not c.repository_requirements_missing | |
224 | and self.rhodecode_vcs_repo is None): |
|
226 | and self.rhodecode_vcs_repo is None): | |
@@ -244,7 +246,8 b' class RepoAppView(BaseAppView):' | |||||
244 | return default |
|
246 | return default | |
245 |
|
247 | |||
246 | def _get_f_path(self, matchdict, default=None): |
|
248 | def _get_f_path(self, matchdict, default=None): | |
247 |
|
|
249 | f_path_match = self._get_f_path_unchecked(matchdict, default) | |
|
250 | return self.path_filter.assert_path_permissions(f_path_match) | |||
248 |
|
251 | |||
249 |
|
252 | |||
250 | class PathFilter(object): |
|
253 | class PathFilter(object): |
@@ -639,10 +639,8 b' class BaseRepository(object):' | |||||
639 | warnings.warn("Use in_memory_commit instead", DeprecationWarning) |
|
639 | warnings.warn("Use in_memory_commit instead", DeprecationWarning) | |
640 | return self.in_memory_commit |
|
640 | return self.in_memory_commit | |
641 |
|
641 | |||
642 | # |
|
|||
643 | def get_path_permissions(self, username): |
|
642 | def get_path_permissions(self, username): | |
644 | """ |
|
643 | """ | |
645 |
|
||||
646 | Returns a path permission checker or None if not supported |
|
644 | Returns a path permission checker or None if not supported | |
647 |
|
645 | |||
648 | :param username: session user name |
|
646 | :param username: session user name | |
@@ -1677,18 +1675,20 b' class PatternPathPermissionChecker(BaseP' | |||||
1677 | def __init__(self, includes, excludes): |
|
1675 | def __init__(self, includes, excludes): | |
1678 | self.includes = includes |
|
1676 | self.includes = includes | |
1679 | self.excludes = excludes |
|
1677 | self.excludes = excludes | |
1680 |
self.includes_re = [] if not includes else [ |
|
1678 | self.includes_re = [] if not includes else [ | |
1681 |
|
|
1679 | re.compile(fnmatch.translate(pattern)) for pattern in includes] | |
|
1680 | self.excludes_re = [] if not excludes else [ | |||
|
1681 | re.compile(fnmatch.translate(pattern)) for pattern in excludes] | |||
1682 |
|
1682 | |||
1683 | @property |
|
1683 | @property | |
1684 | def has_full_access(self): |
|
1684 | def has_full_access(self): | |
1685 | return '*' in self.includes and not self.excludes |
|
1685 | return '*' in self.includes and not self.excludes | |
1686 |
|
1686 | |||
1687 | def has_access(self, path): |
|
1687 | def has_access(self, path): | |
1688 | for re in self.excludes_re: |
|
1688 | for regex in self.excludes_re: | |
1689 | if re.match(path): |
|
1689 | if regex.match(path): | |
1690 | return False |
|
1690 | return False | |
1691 | for re in self.includes_re: |
|
1691 | for regex in self.includes_re: | |
1692 | if re.match(path): |
|
1692 | if regex.match(path): | |
1693 | return True |
|
1693 | return True | |
1694 | return False No newline at end of file |
|
1694 | return False |
@@ -28,7 +28,6 b' from itertools import chain' | |||||
28 | from StringIO import StringIO |
|
28 | from StringIO import StringIO | |
29 |
|
29 | |||
30 | from zope.cachedescriptors.property import Lazy as LazyProperty |
|
30 | from zope.cachedescriptors.property import Lazy as LazyProperty | |
31 | from pyramid.compat import configparser |
|
|||
32 |
|
31 | |||
33 | from rhodecode.lib.datelib import utcdate_fromtimestamp |
|
32 | from rhodecode.lib.datelib import utcdate_fromtimestamp | |
34 | from rhodecode.lib.utils import safe_unicode, safe_str |
|
33 | from rhodecode.lib.utils import safe_unicode, safe_str | |
@@ -40,6 +39,7 b' from rhodecode.lib.vcs.nodes import (' | |||||
40 | FileNode, DirNode, NodeKind, RootNode, SubModuleNode, |
|
39 | FileNode, DirNode, NodeKind, RootNode, SubModuleNode, | |
41 | ChangedFileNodesGenerator, AddedFileNodesGenerator, |
|
40 | ChangedFileNodesGenerator, AddedFileNodesGenerator, | |
42 | RemovedFileNodesGenerator, LargeFileNode) |
|
41 | RemovedFileNodesGenerator, LargeFileNode) | |
|
42 | from rhodecode.lib.vcs.compat import configparser | |||
43 |
|
43 | |||
44 |
|
44 | |||
45 | class GitCommit(base.BaseCommit): |
|
45 | class GitCommit(base.BaseCommit): |
@@ -21,10 +21,9 b'' | |||||
21 | """ |
|
21 | """ | |
22 | HG repository module |
|
22 | HG repository module | |
23 | """ |
|
23 | """ | |
24 |
import |
|
24 | import os | |
25 | import logging |
|
25 | import logging | |
26 | import binascii |
|
26 | import binascii | |
27 | import os |
|
|||
28 | import shutil |
|
27 | import shutil | |
29 | import urllib |
|
28 | import urllib | |
30 |
|
29 | |||
@@ -32,8 +31,7 b' from zope.cachedescriptors.property impo' | |||||
32 |
|
31 | |||
33 | from rhodecode.lib.compat import OrderedDict |
|
32 | from rhodecode.lib.compat import OrderedDict | |
34 | from rhodecode.lib.datelib import ( |
|
33 | from rhodecode.lib.datelib import ( | |
35 |
date_to_timestamp_plus_offset, utcdate_fromtimestamp, makedate |
|
34 | date_to_timestamp_plus_offset, utcdate_fromtimestamp, makedate) | |
36 | date_astimestamp) |
|
|||
37 | from rhodecode.lib.utils import safe_unicode, safe_str |
|
35 | from rhodecode.lib.utils import safe_unicode, safe_str | |
38 | from rhodecode.lib.vcs import connection, exceptions |
|
36 | from rhodecode.lib.vcs import connection, exceptions | |
39 | from rhodecode.lib.vcs.backends.base import ( |
|
37 | from rhodecode.lib.vcs.backends.base import ( | |
@@ -45,6 +43,7 b' from rhodecode.lib.vcs.backends.hg.inmem' | |||||
45 | from rhodecode.lib.vcs.exceptions import ( |
|
43 | from rhodecode.lib.vcs.exceptions import ( | |
46 | EmptyRepositoryError, RepositoryError, TagAlreadyExistError, |
|
44 | EmptyRepositoryError, RepositoryError, TagAlreadyExistError, | |
47 | TagDoesNotExistError, CommitDoesNotExistError, SubrepoMergeError) |
|
45 | TagDoesNotExistError, CommitDoesNotExistError, SubrepoMergeError) | |
|
46 | from rhodecode.lib.vcs.compat import configparser | |||
48 |
|
47 | |||
49 | hexlify = binascii.hexlify |
|
48 | hexlify = binascii.hexlify | |
50 | nullid = "\0" * 20 |
|
49 | nullid = "\0" * 20 | |
@@ -778,6 +777,7 b' class MercurialRepository(BaseRepository' | |||||
778 | else: |
|
777 | else: | |
779 | merge_possible = True |
|
778 | merge_possible = True | |
780 |
|
779 | |||
|
780 | needs_push = False | |||
781 | if merge_possible: |
|
781 | if merge_possible: | |
782 | try: |
|
782 | try: | |
783 | merge_commit_id, needs_push = shadow_repo._local_merge( |
|
783 | merge_commit_id, needs_push = shadow_repo._local_merge( | |
@@ -892,36 +892,43 b' class MercurialRepository(BaseRepository' | |||||
892 | self._remote.invalidate_vcs_cache() |
|
892 | self._remote.invalidate_vcs_cache() | |
893 |
|
893 | |||
894 | def get_path_permissions(self, username): |
|
894 | def get_path_permissions(self, username): | |
895 |
hgacl_file = self.path |
|
895 | hgacl_file = os.path.join(self.path, '.hg/hgacl') | |
|
896 | ||||
|
897 | def read_patterns(suffix): | |||
|
898 | svalue = None | |||
|
899 | try: | |||
|
900 | svalue = hgacl.get('narrowhgacl', username + suffix) | |||
|
901 | except configparser.NoOptionError: | |||
|
902 | try: | |||
|
903 | svalue = hgacl.get('narrowhgacl', 'default' + suffix) | |||
|
904 | except configparser.NoOptionError: | |||
|
905 | pass | |||
|
906 | if not svalue: | |||
|
907 | return None | |||
|
908 | result = ['/'] | |||
|
909 | for pattern in svalue.split(): | |||
|
910 | result.append(pattern) | |||
|
911 | if '*' not in pattern and '?' not in pattern: | |||
|
912 | result.append(pattern + '/*') | |||
|
913 | return result | |||
|
914 | ||||
896 | if os.path.exists(hgacl_file): |
|
915 | if os.path.exists(hgacl_file): | |
897 | try: |
|
916 | try: | |
898 |
hgacl = |
|
917 | hgacl = configparser.RawConfigParser() | |
899 | hgacl.read(hgacl_file) |
|
918 | hgacl.read(hgacl_file) | |
900 | def read_patterns(suffix): |
|
919 | ||
901 | svalue = None |
|
|||
902 | try: |
|
|||
903 | svalue = hgacl.get('narrowhgacl', username + suffix) |
|
|||
904 | except ConfigParser.NoOptionError: |
|
|||
905 | try: |
|
|||
906 | svalue = hgacl.get('narrowhgacl', 'default' + suffix) |
|
|||
907 | except ConfigParser.NoOptionError: |
|
|||
908 | pass |
|
|||
909 | if not svalue: |
|
|||
910 | return None |
|
|||
911 | result = ['/'] |
|
|||
912 | for pattern in svalue.split(): |
|
|||
913 | result.append(pattern) |
|
|||
914 | if '*' not in pattern and '?' not in pattern: |
|
|||
915 | result.append(pattern + '/*') |
|
|||
916 | return result |
|
|||
917 | includes = read_patterns('.includes') |
|
920 | includes = read_patterns('.includes') | |
918 | excludes = read_patterns('.excludes') |
|
921 | excludes = read_patterns('.excludes') | |
919 |
return BasePathPermissionChecker.create_from_patterns( |
|
922 | return BasePathPermissionChecker.create_from_patterns( | |
|
923 | includes, excludes) | |||
920 | except BaseException as e: |
|
924 | except BaseException as e: | |
921 |
|
|
925 | msg = 'Cannot read ACL settings from {} on {}: {}'.format( | |
|
926 | hgacl_file, self.name, e) | |||
|
927 | raise exceptions.RepositoryRequirementError(msg) | |||
922 | else: |
|
928 | else: | |
923 | return None |
|
929 | return None | |
924 |
|
930 | |||
|
931 | ||||
925 | class MercurialIndexBasedCollectionGenerator(CollectionGenerator): |
|
932 | class MercurialIndexBasedCollectionGenerator(CollectionGenerator): | |
926 |
|
933 | |||
927 | def _commit_factory(self, commit_id): |
|
934 | def _commit_factory(self, commit_id): |
General Comments 0
You need to be logged in to leave comments.
Login now