##// END OF EJS Templates
dbmigrate: fixed migration problems
super-admin -
r5166:f519a80b default
parent child Browse files
Show More
@@ -447,7 +447,7 b' class UserGroup(Base, BaseModel):'
447 447 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
448 448 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
449 449 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
450 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
450 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
451 451
452 452 user = relationship('User')
453 453
@@ -449,7 +449,7 b' class UserGroup(Base, BaseModel):'
449 449 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
450 450 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
451 451 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
452 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
452 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
453 453
454 454 user = relationship('User')
455 455
@@ -472,7 +472,7 b' class UserGroup(Base, BaseModel):'
472 472 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
473 473 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
474 474 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
475 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
475 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
476 476
477 477 user = relationship('User')
478 478
@@ -471,7 +471,7 b' class UserGroup(Base, BaseModel):'
471 471 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
472 472 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
473 473 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
474 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
474 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
475 475
476 476 user = relationship('User')
477 477
@@ -471,7 +471,7 b' class UserGroup(Base, BaseModel):'
471 471 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
472 472 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
473 473 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
474 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
474 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
475 475
476 476 user = relationship('User')
477 477
@@ -505,7 +505,7 b' class UserGroup(Base, BaseModel):'
505 505 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
506 506 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
507 507 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
508 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
508 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
509 509
510 510 user = relationship('User')
511 511
@@ -516,7 +516,7 b' class UserGroup(Base, BaseModel):'
516 516 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
517 517 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
518 518 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
519 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
519 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
520 520
521 521 user = relationship('User')
522 522
@@ -517,7 +517,7 b' class UserGroup(Base, BaseModel):'
517 517 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
518 518 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
519 519 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
520 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
520 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
521 521
522 522 user = relationship('User')
523 523
@@ -523,7 +523,7 b' class UserGroup(Base, BaseModel):'
523 523 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
524 524 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
525 525 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
526 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
526 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
527 527
528 528 user = relationship('User')
529 529
@@ -523,7 +523,7 b' class UserGroup(Base, BaseModel):'
523 523 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
524 524 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
525 525 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
526 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
526 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
527 527
528 528 user = relationship('User')
529 529
@@ -544,7 +544,7 b' class UserGroup(Base, BaseModel):'
544 544 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
545 545 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
546 546 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
547 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
547 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
548 548
549 549 user = relationship('User')
550 550
@@ -554,7 +554,7 b' class UserGroup(Base, BaseModel):'
554 554 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
555 555 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
556 556 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
557 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
557 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
558 558
559 559 user = relationship('User')
560 560
@@ -595,7 +595,7 b' class UserGroup(Base, BaseModel):'
595 595 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
596 596 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
597 597 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
598 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
598 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
599 599
600 600 user = relationship('User')
601 601
@@ -595,7 +595,7 b' class UserGroup(Base, BaseModel):'
595 595 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
596 596 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
597 597 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
598 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
598 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
599 599
600 600 user = relationship('User')
601 601
@@ -596,7 +596,7 b' class UserGroup(Base, BaseModel):'
596 596 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
597 597 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
598 598 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
599 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
599 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
600 600
601 601 user = relationship('User')
602 602
@@ -596,7 +596,7 b' class UserGroup(Base, BaseModel):'
596 596 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
597 597 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
598 598 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
599 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
599 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
600 600
601 601 user = relationship('User')
602 602
@@ -602,7 +602,7 b' class UserGroup(Base, BaseModel):'
602 602 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
603 603 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
604 604 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
605 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
605 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
606 606
607 607 user = relationship('User')
608 608
@@ -719,7 +719,7 b' class UserGroup(Base, BaseModel):'
719 719 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
720 720 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
721 721 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
722 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
722 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
723 723
724 724 user = relationship('User')
725 725
@@ -41,6 +41,7 b' from beaker.cache import cache_region, r'
41 41 from webob.exc import HTTPNotFound
42 42 from zope.cachedescriptors.property import Lazy as LazyProperty
43 43
44 from rhodecode.lib import enc_utils
44 45 from rhodecode.translation import _
45 46
46 47 from rhodecode.lib.vcs import get_backend
@@ -69,7 +70,7 b' log = logging.getLogger(__name__)'
69 70
70 71 # this is propagated from .ini file beaker.session.secret
71 72 # and initialized at environment.py
72 ENCRYPTION_KEY = None
73 ENCRYPTION_KEY: bytes = b''
73 74
74 75 # used to sort permissions by types, '#' used here is not allowed to be in
75 76 # usernames, and it's very early in sorted string.printable table.
@@ -106,30 +107,38 b' class EncryptedValue(TypeDecorator):'
106 107 impl = String
107 108
108 109 def process_bind_param(self, value, dialect):
109 if not value:
110 return value
111 if value.startswith('enc$aes$'):
112 # protect against double encrypting if someone manually starts doing
113 raise ValueError('value needs to be in unencrypted format, ie. '
114 'not starting with enc$aes$')
115 return 'enc$aes$%s' % AESCipher(ENCRYPTION_KEY).encrypt(value)
116
117 def process_result_value(self, value, dialect):
110 """
111 Setter for storing value
112 """
113 import rhodecode
118 114 if not value:
119 115 return value
120 116
121 parts = value.split('$', 3)
122 if not len(parts) == 3:
123 # probably not encrypted values
117 # protect against double encrypting if values is already encrypted
118 if value.startswith('enc$aes$') \
119 or value.startswith('enc$aes_hmac$') \
120 or value.startswith('enc2$'):
121 raise ValueError('value needs to be in unencrypted format, '
122 'ie. not starting with enc$ or enc2$')
123
124 algo = rhodecode.CONFIG.get('rhodecode.encrypted_values.algorithm') or 'aes'
125 bytes_val = enc_utils.encrypt_value(value, enc_key=ENCRYPTION_KEY, algo=algo)
126 return safe_str(bytes_val)
127
128 def process_result_value(self, value, dialect):
129 """
130 Getter for retrieving value
131 """
132
133 import rhodecode
134 if not value:
124 135 return value
125 else:
126 if parts[0] != 'enc':
127 # parts ok but without our header ?
128 return value
136
137 enc_strict_mode = rhodecode.ConfigGet().get_bool('rhodecode.encrypted_values.strict', missing=True)
129 138
130 # at that stage we know it's our encryption
131 decrypted_data = AESCipher(ENCRYPTION_KEY).decrypt(parts[2])
132 return decrypted_data
139 bytes_val = enc_utils.decrypt_value(value, enc_key=ENCRYPTION_KEY, strict_mode=enc_strict_mode)
140
141 return safe_str(bytes_val)
133 142
134 143
135 144 class BaseModel(object):
@@ -742,7 +751,7 b' class UserGroup(Base, BaseModel):'
742 751 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
743 752 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
744 753 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
745 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
754 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
746 755
747 756 user = relationship('User')
748 757
@@ -1303,7 +1303,7 b' class UserGroup(Base, BaseModel):'
1303 1303 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
1304 1304 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
1305 1305 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
1306 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1306 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1307 1307
1308 1308 user_group_review_rules = relationship('RepoReviewRuleUserGroup', cascade='all')
1309 1309 user = relationship('User', primaryjoin="User.user_id==UserGroup.user_id")
@@ -1307,7 +1307,7 b' class UserGroup(Base, BaseModel):'
1307 1307 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
1308 1308 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
1309 1309 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
1310 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1310 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1311 1311
1312 1312 user_group_review_rules = relationship('RepoReviewRuleUserGroup', cascade='all')
1313 1313 user = relationship('User', primaryjoin="User.user_id==UserGroup.user_id")
@@ -1314,7 +1314,7 b' class UserGroup(Base, BaseModel):'
1314 1314 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
1315 1315 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
1316 1316 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
1317 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1317 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1318 1318
1319 1319 user_group_review_rules = relationship('RepoReviewRuleUserGroup', cascade='all')
1320 1320 user = relationship('User', primaryjoin="User.user_id==UserGroup.user_id")
@@ -1316,7 +1316,7 b' class UserGroup(Base, BaseModel):'
1316 1316 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
1317 1317 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
1318 1318 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
1319 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1319 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1320 1320
1321 1321 user_group_review_rules = relationship('RepoReviewRuleUserGroup', cascade='all')
1322 1322 user = relationship('User', primaryjoin="User.user_id==UserGroup.user_id")
@@ -1316,7 +1316,7 b' class UserGroup(Base, BaseModel):'
1316 1316 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
1317 1317 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
1318 1318 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
1319 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1319 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1320 1320
1321 1321 user_group_review_rules = relationship('RepoReviewRuleUserGroup', cascade='all')
1322 1322 user = relationship('User', primaryjoin="User.user_id==UserGroup.user_id")
@@ -1333,7 +1333,7 b' class UserGroup(Base, BaseModel):'
1333 1333 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
1334 1334 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
1335 1335 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
1336 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1336 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1337 1337
1338 1338 user_group_review_rules = relationship('RepoReviewRuleUserGroup', cascade='all')
1339 1339 user = relationship('User', primaryjoin="User.user_id==UserGroup.user_id")
@@ -1386,7 +1386,7 b' class UserGroup(Base, BaseModel):'
1386 1386 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
1387 1387 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
1388 1388 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
1389 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1389 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1390 1390
1391 1391 user_group_review_rules = relationship('RepoReviewRuleUserGroup', cascade='all')
1392 1392 user = relationship('User', primaryjoin="User.user_id==UserGroup.user_id")
@@ -1392,7 +1392,7 b' class UserGroup(Base, BaseModel):'
1392 1392 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
1393 1393 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
1394 1394 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
1395 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1395 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1396 1396
1397 1397 user_group_review_rules = relationship('RepoReviewRuleUserGroup', cascade='all')
1398 1398 user = relationship('User', primaryjoin="User.user_id==UserGroup.user_id")
@@ -1415,7 +1415,7 b' class UserGroup(Base, BaseModel):'
1415 1415 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
1416 1416 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
1417 1417 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
1418 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1418 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1419 1419
1420 1420 user_group_review_rules = relationship('RepoReviewRuleUserGroup', cascade='all')
1421 1421 user = relationship('User', primaryjoin="User.user_id==UserGroup.user_id")
@@ -1035,7 +1035,7 b' class UserGroup(Base, BaseModel):'
1035 1035 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
1036 1036 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
1037 1037 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
1038 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1038 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1039 1039
1040 1040 user = relationship('User')
1041 1041
@@ -1036,7 +1036,7 b' class UserGroup(Base, BaseModel):'
1036 1036 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
1037 1037 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
1038 1038 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
1039 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1039 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1040 1040
1041 1041 user = relationship('User')
1042 1042
@@ -1035,7 +1035,7 b' class UserGroup(Base, BaseModel):'
1035 1035 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
1036 1036 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
1037 1037 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
1038 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1038 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1039 1039
1040 1040 user = relationship('User')
1041 1041
@@ -1037,7 +1037,7 b' class UserGroup(Base, BaseModel):'
1037 1037 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
1038 1038 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
1039 1039 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
1040 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1040 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1041 1041
1042 1042 user = relationship('User')
1043 1043
@@ -1037,7 +1037,7 b' class UserGroup(Base, BaseModel):'
1037 1037 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
1038 1038 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
1039 1039 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
1040 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1040 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1041 1041
1042 1042 user = relationship('User')
1043 1043
@@ -1080,7 +1080,7 b' class UserGroup(Base, BaseModel):'
1080 1080 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
1081 1081 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
1082 1082 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
1083 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1083 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1084 1084
1085 1085 user = relationship('User')
1086 1086
@@ -1081,7 +1081,7 b' class UserGroup(Base, BaseModel):'
1081 1081 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
1082 1082 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
1083 1083 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
1084 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1084 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1085 1085
1086 1086 user = relationship('User')
1087 1087
@@ -1242,7 +1242,7 b' class UserGroup(Base, BaseModel):'
1242 1242 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
1243 1243 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
1244 1244 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
1245 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1245 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1246 1246
1247 1247 user = relationship('User', primaryjoin="User.user_id==UserGroup.user_id")
1248 1248
@@ -35,7 +35,7 b' def upgrade(migrate_engine):'
35 35 username.create(table=tbl)
36 36
37 37 _Session = meta.Session()
38 ## after adding that column fix all usernames
38 # after adding that column fix all usernames
39 39 users_log = _Session.query(db_1_5_0.UserLog)\
40 40 .options(joinedload(db_1_5_0.UserLog.user))\
41 41 .options(joinedload(db_1_5_0.UserLog.repository)).all()
@@ -45,7 +45,7 b' def upgrade(migrate_engine):'
45 45 _Session.add(entry)
46 46 _Session.commit()
47 47
48 #alter username to not null
48 # alter username to not null
49 49 tbl_name = db_1_5_0.UserLog.__tablename__
50 50 tbl = Table(tbl_name,
51 51 MetaData(bind=migrate_engine), autoload=True,
@@ -74,19 +74,18 b' def get_by_name(cls, key):'
74 74
75 75 def fixups(models, _SESSION):
76 76 # ** create default permissions ** #
77 #=====================================
77
78 78 for p in models.Permission.PERMS:
79 79 if not get_by_key(models.Permission, p[0]):
80 80 new_perm = models.Permission()
81 81 new_perm.permission_name = p[0]
82 new_perm.permission_longname = p[0] #translation err with p[1]
82 new_perm.permission_longname = p[0] # translation err with p[1]
83 83 print('Creating new permission %s' % p[0])
84 84 _SESSION().add(new_perm)
85 85
86 86 _SESSION().commit()
87 87
88 88 # ** populate default permissions ** #
89 #=====================================
90 89
91 90 user = models.User.query().filter(models.User.username == 'default').scalar()
92 91
@@ -100,9 +99,10 b' def fixups(models, _SESSION):'
100 99 return '.'.join(perm_name.split('.')[:1])
101 100
102 101 perms = models.UserToPerm.query().filter(models.UserToPerm.user == user).all()
103 defined_perms_groups = map(
104 _get_group, (x.permission.permission_name for x in perms))
105 log.debug('GOT ALREADY DEFINED:%s', perms)
102 defined_perms_groups = list(map(
103 _get_group, (x.permission.permission_name for x in perms)))
104 perms_show = [p.__dict__ for p in perms]
105 log.debug('GOT ALREADY DEFINED:%s', perms_show)
106 106 DEFAULT_PERMS = models.Permission.DEFAULT_USER_PERMISSIONS
107 107
108 108 # for every default permission that needs to be created, we check if
@@ -70,14 +70,18 b' def downgrade(migrate_engine):'
70 70 meta.bind = migrate_engine
71 71
72 72
73 def get_by_key(cls, key):
74 return cls.query().filter(cls.permission_name == key).scalar()
75
76
73 77 def fixups(models, _SESSION):
74 78 # ** create default permissions ** #
75 79 #=====================================
76 80 for p in models.Permission.PERMS:
77 if not models.Permission.get_by_key(p[0]):
81 if not get_by_key(models.Permission, p[0]):
78 82 new_perm = models.Permission()
79 83 new_perm.permission_name = p[0]
80 new_perm.permission_longname = p[0] #translation err with p[1]
84 new_perm.permission_longname = p[0] # translation err with p[1]
81 85 _SESSION().add(new_perm)
82 86
83 87 _SESSION().commit()
@@ -97,8 +101,7 b' def fixups(models, _SESSION):'
97 101 return '.'.join(perm_name.split('.')[:1])
98 102
99 103 perms = models.UserToPerm.query().filter(models.UserToPerm.user == user).all()
100 defined_perms_groups = map(_get_group,
101 (x.permission.permission_name for x in perms))
104 defined_perms_groups = list(map(_get_group, (x.permission.permission_name for x in perms)))
102 105 log.debug('GOT ALREADY DEFINED:%s', perms)
103 106 DEFAULT_PERMS = models.Permission.DEFAULT_USER_PERMISSIONS
104 107
@@ -10,6 +10,7 b' from sqlalchemy.engine import reflection'
10 10 from sqlalchemy.sql import text
11 11
12 12 from rhodecode.lib.dbmigrate.versions import _reset_base
13 from rhodecode.lib.hash_utils import sha1_safe
13 14 from rhodecode.lib.utils2 import safe_str
14 15 from rhodecode.model import meta, init_model_encryption
15 16
@@ -69,11 +70,9 b' def downgrade(migrate_engine):'
69 70 def _generate_repo_name_hashes(models, op, session):
70 71 repositories = models.Repository.get_all()
71 72 for repository in repositories:
72 hash_ = hashlib.sha1(safe_str(repository.repo_name)).hexdigest()
73 hash_ = sha1_safe(repository.repo_name)
73 74 params = {'hash': hash_, 'id': repository.repo_id}
74 query = text(
75 'UPDATE repositories SET repo_name_hash = :hash'
76 ' WHERE repo_id = :id').bindparams(**params)
75 query = text('UPDATE repositories SET repo_name_hash = :hash WHERE repo_id = :id').bindparams(**params)
77 76 op.execute(query)
78 77 session().commit()
79 78
@@ -117,15 +117,19 b' class AESCipher(object):'
117 117 def validate_and_decrypt_data(enc_data, enc_key, enc_strict_mode=False, safe=True):
118 118 enc_data = safe_str(enc_data)
119 119
120 if '$' not in enc_data:
121 # probably not encrypted values
122 return enc_data
123
120 124 parts = enc_data.split('$', 3)
121 125 if len(parts) != 3:
122 raise ValueError(f'Encrypted Data has invalid format, expected {KEY_FORMAT}, got {parts}')
126 raise ValueError(f'Encrypted Data has invalid format, expected {KEY_FORMAT}, got {parts}, org value: {enc_data}')
123 127
124 128 enc_type = parts[1]
125 129 enc_data_part = parts[2]
126 130
127 131 if parts[0] != 'enc':
128 # parts ok but without our header ?
132 # parts ok but without our header?
129 133 return enc_data
130 134
131 135 # at that stage we know it's our encryption
General Comments 0
You need to be logged in to leave comments. Login now