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