Show More
@@ -1313,7 +1313,10 b' class AuthUser(object):' | |||||
1313 | if not perms: |
|
1313 | if not perms: | |
1314 | perms = AuthUser.repo_read_perms |
|
1314 | perms = AuthUser.repo_read_perms | |
1315 |
|
1315 | |||
1316 | def _cached_repo_acl(user_id, perm_def, _name_filter): |
|
1316 | if not isinstance(perms, list): | |
|
1317 | raise ValueError('perms parameter must be a list got {} instead'.format(perms)) | |||
|
1318 | ||||
|
1319 | def _cached_repo_acl(perm_def, _name_filter): | |||
1317 | qry = Repository.query() |
|
1320 | qry = Repository.query() | |
1318 | if _name_filter: |
|
1321 | if _name_filter: | |
1319 | ilike_expression = u'%{}%'.format(safe_unicode(_name_filter)) |
|
1322 | ilike_expression = u'%{}%'.format(safe_unicode(_name_filter)) | |
@@ -1323,7 +1326,21 b' class AuthUser(object):' | |||||
1323 | return [x.repo_id for x in |
|
1326 | return [x.repo_id for x in | |
1324 | RepoList(qry, perm_set=perm_def, extra_kwargs={'user': self})] |
|
1327 | RepoList(qry, perm_set=perm_def, extra_kwargs={'user': self})] | |
1325 |
|
1328 | |||
1326 | return _cached_repo_acl(self.user_id, perms, name_filter) |
|
1329 | log.debug('Computing REPO ACL IDS user %s', self) | |
|
1330 | ||||
|
1331 | cache_namespace_uid = 'cache_user_repo_acl_ids.{}'.format(self.user_id) | |||
|
1332 | region = rc_cache.get_or_create_region('cache_perms', cache_namespace_uid) | |||
|
1333 | ||||
|
1334 | @region.conditional_cache_on_arguments(namespace=cache_namespace_uid, condition=cache) | |||
|
1335 | def compute_repo_acl_ids(cache_ver, user_id, perm_def, _name_filter): | |||
|
1336 | return _cached_repo_acl(perm_def, _name_filter) | |||
|
1337 | ||||
|
1338 | start = time.time() | |||
|
1339 | result = compute_repo_acl_ids('v1', self.user_id, perms, name_filter) | |||
|
1340 | total = time.time() - start | |||
|
1341 | log.debug('REPO ACL IDS for user %s computed in %.4fs', self, total) | |||
|
1342 | ||||
|
1343 | return result | |||
1327 |
|
1344 | |||
1328 | def repo_group_acl_ids_from_stack(self, perms=None, prefix_filter=None, cache=False): |
|
1345 | def repo_group_acl_ids_from_stack(self, perms=None, prefix_filter=None, cache=False): | |
1329 | if not perms: |
|
1346 | if not perms: | |
@@ -1347,7 +1364,10 b' class AuthUser(object):' | |||||
1347 | if not perms: |
|
1364 | if not perms: | |
1348 | perms = AuthUser.repo_group_read_perms |
|
1365 | perms = AuthUser.repo_group_read_perms | |
1349 |
|
1366 | |||
1350 | def _cached_repo_group_acl(user_id, perm_def, _name_filter): |
|
1367 | if not isinstance(perms, list): | |
|
1368 | raise ValueError('perms parameter must be a list got {} instead'.format(perms)) | |||
|
1369 | ||||
|
1370 | def _cached_repo_group_acl(perm_def, _name_filter): | |||
1351 | qry = RepoGroup.query() |
|
1371 | qry = RepoGroup.query() | |
1352 | if _name_filter: |
|
1372 | if _name_filter: | |
1353 | ilike_expression = u'%{}%'.format(safe_unicode(_name_filter)) |
|
1373 | ilike_expression = u'%{}%'.format(safe_unicode(_name_filter)) | |
@@ -1357,7 +1377,21 b' class AuthUser(object):' | |||||
1357 | return [x.group_id for x in |
|
1377 | return [x.group_id for x in | |
1358 | RepoGroupList(qry, perm_set=perm_def, extra_kwargs={'user': self})] |
|
1378 | RepoGroupList(qry, perm_set=perm_def, extra_kwargs={'user': self})] | |
1359 |
|
1379 | |||
1360 | return _cached_repo_group_acl(self.user_id, perms, name_filter) |
|
1380 | log.debug('Computing REPO GROUP ACL IDS user %s', self) | |
|
1381 | ||||
|
1382 | cache_namespace_uid = 'cache_user_repo_group_acl_ids.{}'.format(self.user_id) | |||
|
1383 | region = rc_cache.get_or_create_region('cache_perms', cache_namespace_uid) | |||
|
1384 | ||||
|
1385 | @region.conditional_cache_on_arguments(namespace=cache_namespace_uid, condition=cache) | |||
|
1386 | def compute_repo_group_acl_ids(cache_ver, user_id, perm_def, _name_filter): | |||
|
1387 | return _cached_repo_group_acl(perm_def, _name_filter) | |||
|
1388 | ||||
|
1389 | start = time.time() | |||
|
1390 | result = compute_repo_group_acl_ids('v1', self.user_id, perms, name_filter) | |||
|
1391 | total = time.time() - start | |||
|
1392 | log.debug('REPO GROUP ACL IDS for user %s computed in %.4fs', self, total) | |||
|
1393 | ||||
|
1394 | return result | |||
1361 |
|
1395 | |||
1362 | def user_group_acl_ids_from_stack(self, perms=None, cache=False): |
|
1396 | def user_group_acl_ids_from_stack(self, perms=None, cache=False): | |
1363 | if not perms: |
|
1397 | if not perms: | |
@@ -1379,17 +1413,34 b' class AuthUser(object):' | |||||
1379 | if not perms: |
|
1413 | if not perms: | |
1380 | perms = AuthUser.user_group_read_perms |
|
1414 | perms = AuthUser.user_group_read_perms | |
1381 |
|
1415 | |||
1382 | def _cached_user_group_acl(user_id, perm_def, name_filter): |
|
1416 | if not isinstance(perms, list): | |
|
1417 | raise ValueError('perms parameter must be a list got {} instead'.format(perms)) | |||
|
1418 | ||||
|
1419 | def _cached_user_group_acl(perm_def, _name_filter): | |||
1383 | qry = UserGroup.query() |
|
1420 | qry = UserGroup.query() | |
1384 | if name_filter: |
|
1421 | if _name_filter: | |
1385 | ilike_expression = u'%{}%'.format(safe_unicode(name_filter)) |
|
1422 | ilike_expression = u'%{}%'.format(safe_unicode(_name_filter)) | |
1386 | qry = qry.filter( |
|
1423 | qry = qry.filter( | |
1387 | UserGroup.users_group_name.ilike(ilike_expression)) |
|
1424 | UserGroup.users_group_name.ilike(ilike_expression)) | |
1388 |
|
1425 | |||
1389 | return [x.users_group_id for x in |
|
1426 | return [x.users_group_id for x in | |
1390 | UserGroupList(qry, perm_set=perm_def, extra_kwargs={'user': self})] |
|
1427 | UserGroupList(qry, perm_set=perm_def, extra_kwargs={'user': self})] | |
1391 |
|
1428 | |||
1392 | return _cached_user_group_acl(self.user_id, perms, name_filter) |
|
1429 | log.debug('Computing USER GROUP ACL IDS user %s', self) | |
|
1430 | ||||
|
1431 | cache_namespace_uid = 'cache_user_user_group_acl_ids.{}'.format(self.user_id) | |||
|
1432 | region = rc_cache.get_or_create_region('cache_perms', cache_namespace_uid) | |||
|
1433 | ||||
|
1434 | @region.conditional_cache_on_arguments(namespace=cache_namespace_uid, condition=cache) | |||
|
1435 | def compute_user_group_acl_ids(cache_ver, user_id, perm_def, _name_filter): | |||
|
1436 | return _cached_user_group_acl(perm_def, _name_filter) | |||
|
1437 | ||||
|
1438 | start = time.time() | |||
|
1439 | result = compute_user_group_acl_ids('v1', self.user_id, perms, name_filter) | |||
|
1440 | total = time.time() - start | |||
|
1441 | log.debug('USER GROUP ACL IDS for user %s computed in %.4fs', self, total) | |||
|
1442 | ||||
|
1443 | return result | |||
1393 |
|
1444 | |||
1394 | @property |
|
1445 | @property | |
1395 | def ip_allowed(self): |
|
1446 | def ip_allowed(self): | |
@@ -1403,6 +1454,7 b' class AuthUser(object):' | |||||
1403 | inherit = self.inherit_default_permissions |
|
1454 | inherit = self.inherit_default_permissions | |
1404 | return AuthUser.check_ip_allowed(self.user_id, self.ip_addr, |
|
1455 | return AuthUser.check_ip_allowed(self.user_id, self.ip_addr, | |
1405 | inherit_from_default=inherit) |
|
1456 | inherit_from_default=inherit) | |
|
1457 | ||||
1406 | @property |
|
1458 | @property | |
1407 | def personal_repo_group(self): |
|
1459 | def personal_repo_group(self): | |
1408 | return RepoGroup.get_user_personal_repo_group(self.user_id) |
|
1460 | return RepoGroup.get_user_personal_repo_group(self.user_id) |
General Comments 0
You need to be logged in to leave comments.
Login now