##// END OF EJS Templates
release: Finish preparation for 4.15.2
release: Finish preparation for 4.15.2

File last commit:

r3411:2e06ebce stable
r3421:4aaa40b6 v4.15.2 stable
Show More
db.py
4754 lines | 172.5 KiB | text/x-python | PythonLexer
project: added all source files and assets
r1 # -*- coding: utf-8 -*-
release: update copyright year to 2018
r2487 # Copyright (C) 2010-2018 RhodeCode GmbH
project: added all source files and assets
r1 #
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
"""
Database Models for RhodeCode Enterprise
"""
dan
reviewers: add repo review rule models and expose default...
r821 import re
project: added all source files and assets
r1 import os
import time
import hashlib
import logging
import datetime
import warnings
import ipaddress
import functools
import traceback
import collections
db-models: fix usage of import *....
r2398 from sqlalchemy import (
or_, and_, not_, func, TypeDecorator, event,
scheduler: added DB models and db parsers for the RhodeCode scheduler....
r2406 Index, Sequence, UniqueConstraint, ForeignKey, CheckConstraint, Column,
db-models: fix usage of import *....
r2398 Boolean, String, Unicode, UnicodeText, DateTime, Integer, LargeBinary,
Text, Float, PickleType)
from sqlalchemy.sql.expression import true, false
code: unified coverage notes to # pragma: no cover
r3282 from sqlalchemy.sql.functions import coalesce, count # pragma: no cover
db-models: fix usage of import *....
r2398 from sqlalchemy.orm import (
relationship, joinedload, class_mapper, validates, aliased)
project: added all source files and assets
r1 from sqlalchemy.ext.declarative import declared_attr
from sqlalchemy.ext.hybrid import hybrid_property
code: unified coverage notes to # pragma: no cover
r3282 from sqlalchemy.exc import IntegrityError # pragma: no cover
db: use LONGTEXT for mysql in user_logs. Fixes #5385, problem with mysql rejecting...
r2087 from sqlalchemy.dialects.mysql import LONGTEXT
project: added all source files and assets
r1 from zope.cachedescriptors.property import Lazy as LazyProperty
home: moved home and repo group views into pyramid....
r1774 from pyramid.threadlocal import get_current_request
project: added all source files and assets
r1
pyramid: don't use pylons translation string in db models.
r1917 from rhodecode.translation import _
Martin Bornhold
models: Remove unused imports.
r895 from rhodecode.lib.vcs import get_vcs_instance
from rhodecode.lib.vcs.backends.base import EmptyCommit, Reference
project: added all source files and assets
r1 from rhodecode.lib.utils2 import (
db: don't use md5 for cache key calculation. Md5 is now fully deprecated.
r2837 str2bool, safe_str, get_commit_safe, safe_unicode, sha1_safe,
dan
reviewers: add repo review rule models and expose default...
r821 time_to_datetime, aslist, Optional, safe_int, get_clone_url, AttributeDict,
Bartłomiej Wołyńczyk
url-parsing: fix for bug #5218, remove not allowed chars from uri...
r1452 glob2re, StrictAttributeDict, cleaned_uri)
db-models: fix missing JsonRaw import.
r2493 from rhodecode.lib.jsonalchemy import MutationObj, MutationList, JsonType, \
JsonRaw
project: added all source files and assets
r1 from rhodecode.lib.ext_json import json
from rhodecode.lib.caching_query import FromCache
from rhodecode.lib.encrypt import AESCipher
from rhodecode.model.meta import Base, Session
URL_SEP = '/'
log = logging.getLogger(__name__)
# =============================================================================
# BASE CLASSES
# =============================================================================
encryption: Implement a slightly improved AesCipher encryption....
r281 # this is propagated from .ini file rhodecode.encrypted_values.secret or
# beaker.session.secret if first is not set.
project: added all source files and assets
r1 # and initialized at environment.py
ENCRYPTION_KEY = None
# used to sort permissions by types, '#' used here is not allowed to be in
# usernames, and it's very early in sorted string.printable table.
PERMISSION_TYPE_SORT = {
'admin': '####',
'write': '###',
'read': '##',
'none': '#',
}
permissions: use same way of sorting of user_group permissions like user ones....
r2060 def display_user_sort(obj):
project: added all source files and assets
r1 """
Sort function used to sort permissions in .permissions() function of
Repository, RepoGroup, UserGroup. Also it put the default user in front
of all other resources
"""
if obj.username == User.DEFAULT_USER:
return '#####'
prefix = PERMISSION_TYPE_SORT.get(obj.permission.split('.')[-1], '')
return prefix + obj.username
permissions: use same way of sorting of user_group permissions like user ones....
r2060 def display_user_group_sort(obj):
"""
Sort function used to sort permissions in .permissions() function of
Repository, RepoGroup, UserGroup. Also it put the default user in front
of all other resources
"""
prefix = PERMISSION_TYPE_SORT.get(obj.permission.split('.')[-1], '')
return prefix + obj.users_group_name
project: added all source files and assets
r1 def _hash_key(k):
db: don't use md5 for cache key calculation. Md5 is now fully deprecated.
r2837 return sha1_safe(k)
project: added all source files and assets
r1
goto-switcher: optimized performance and query capabilities....
r2038 def in_filter_generator(qry, items, limit=500):
"""
Splits IN() into multiple with OR
e.g.::
cnt = Repository.query().filter(
or_(
*in_filter_generator(Repository.repo_id, range(100000))
)).count()
"""
quick-filter: make sure we always apply IN filter query. Otherwise we can...
r2167 if not items:
# empty list will cause empty query which might cause security issues
# this can lead to hidden unpleasant results
items = [-1]
goto-switcher: optimized performance and query capabilities....
r2038 parts = []
for chunk in xrange(0, len(items), limit):
parts.append(
qry.in_(items[chunk: chunk + limit])
)
return parts
db: use base table args for all models defined.
r2830 base_table_args = {
'extend_existing': True,
'mysql_engine': 'InnoDB',
'mysql_charset': 'utf8',
'sqlite_autoincrement': True
}
project: added all source files and assets
r1 class EncryptedTextValue(TypeDecorator):
"""
Special column for encrypted long text data, use like::
value = Column("encrypted_value", EncryptedValue(), nullable=False)
This column is intelligent so if value is in unencrypted form it return
unencrypted form, but on save it always encrypts
"""
impl = Text
def process_bind_param(self, value, dialect):
if not value:
return value
encryption: Implement a slightly improved AesCipher encryption....
r281 if value.startswith('enc$aes$') or value.startswith('enc$aes_hmac$'):
project: added all source files and assets
r1 # protect against double encrypting if someone manually starts
# doing
raise ValueError('value needs to be in unencrypted format, ie. '
encryption: Implement a slightly improved AesCipher encryption....
r281 'not starting with enc$aes')
return 'enc$aes_hmac$%s' % AESCipher(
ENCRYPTION_KEY, hmac=True).encrypt(value)
project: added all source files and assets
r1
def process_result_value(self, value, dialect):
encryption: Implement a slightly improved AesCipher encryption....
r281 import rhodecode
project: added all source files and assets
r1 if not value:
return value
parts = value.split('$', 3)
if not len(parts) == 3:
# probably not encrypted values
return value
else:
if parts[0] != 'enc':
# parts ok but without our header ?
return value
encryption: Implement a slightly improved AesCipher encryption....
r281 enc_strict_mode = str2bool(rhodecode.CONFIG.get(
'rhodecode.encrypted_values.strict') or True)
project: added all source files and assets
r1 # at that stage we know it's our encryption
encryption: Implement a slightly improved AesCipher encryption....
r281 if parts[1] == 'aes':
decrypted_data = AESCipher(ENCRYPTION_KEY).decrypt(parts[2])
elif parts[1] == 'aes_hmac':
decrypted_data = AESCipher(
ENCRYPTION_KEY, hmac=True,
strict_verification=enc_strict_mode).decrypt(parts[2])
else:
raise ValueError(
'Encryption type part is wrong, must be `aes` '
'or `aes_hmac`, got `%s` instead' % (parts[1]))
project: added all source files and assets
r1 return decrypted_data
class BaseModel(object):
"""
Base Model for all classes
"""
@classmethod
def _get_keys(cls):
"""return column names for this model """
return class_mapper(cls).c.keys()
def get_dict(self):
"""
return dict with keys and values corresponding
to this model data """
d = {}
for k in self._get_keys():
d[k] = getattr(self, k)
# also use __json__() if present to get additional fields
_json_attr = getattr(self, '__json__', None)
if _json_attr:
# update with attributes from __json__
if callable(_json_attr):
_json_attr = _json_attr()
for k, val in _json_attr.iteritems():
d[k] = val
return d
def get_appstruct(self):
"""return list with keys and values tuples corresponding
to this model data """
scheduler: added DB models and db parsers for the RhodeCode scheduler....
r2406 lst = []
project: added all source files and assets
r1 for k in self._get_keys():
scheduler: added DB models and db parsers for the RhodeCode scheduler....
r2406 lst.append((k, getattr(self, k),))
return lst
project: added all source files and assets
r1
def populate_obj(self, populate_dict):
"""populate model with data from given populate_dict"""
for k in self._get_keys():
if k in populate_dict:
setattr(self, k, populate_dict[k])
@classmethod
def query(cls):
return Session().query(cls)
@classmethod
def get(cls, id_):
if id_:
return cls.query().get(id_)
@classmethod
core: no longer rely on webob exception inside get_or_404 function....
r1956 def get_or_404(cls, id_):
from pyramid.httpexceptions import HTTPNotFound
models: allow different exception between pylons and pyramid for get_or_404 view.
r1512
project: added all source files and assets
r1 try:
id_ = int(id_)
except (TypeError, ValueError):
core: no longer rely on webob exception inside get_or_404 function....
r1956 raise HTTPNotFound()
project: added all source files and assets
r1
res = cls.query().get(id_)
if not res:
core: no longer rely on webob exception inside get_or_404 function....
r1956 raise HTTPNotFound()
project: added all source files and assets
r1 return res
@classmethod
def getAll(cls):
# deprecated and left for backward compatibility
return cls.get_all()
@classmethod
def get_all(cls):
return cls.query().all()
@classmethod
def delete(cls, id_):
obj = cls.query().get(id_)
Session().delete(obj)
caches: use optional identity cache options on get_by_repo_name and get_by_username...
r255 @classmethod
def identity_cache(cls, session, attr_name, value):
exist_in_session = []
for (item_cls, pkey), instance in session.identity_map.items():
if cls == item_cls and getattr(instance, attr_name) == value:
exist_in_session.append(instance)
if exist_in_session:
if len(exist_in_session) == 1:
return exist_in_session[0]
log.exception(
'multiple objects with attr %s and '
'value %s found with same name: %r',
attr_name, value, exist_in_session)
project: added all source files and assets
r1 def __repr__(self):
if hasattr(self, '__unicode__'):
# python repr needs to return str
try:
return safe_str(self.__unicode__())
except UnicodeDecodeError:
pass
return '<DB:%s>' % (self.__class__.__name__)
class RhodeCodeSetting(Base, BaseModel):
__tablename__ = 'rhodecode_settings'
__table_args__ = (
UniqueConstraint('app_settings_name'),
db: use base table args for all models defined.
r2830 base_table_args
project: added all source files and assets
r1 )
SETTINGS_TYPES = {
'str': safe_str,
'int': safe_int,
'unicode': safe_unicode,
'bool': str2bool,
'list': functools.partial(aslist, sep=',')
}
DEFAULT_UPDATE_URL = 'https://rhodecode.com/api/v1/info/versions'
GLOBAL_CONF_KEY = 'app_settings'
app_settings_id = Column("app_settings_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
app_settings_name = Column("app_settings_name", String(255), nullable=True, unique=None, default=None)
_app_settings_value = Column("app_settings_value", String(4096), nullable=True, unique=None, default=None)
_app_settings_type = Column("app_settings_type", String(255), nullable=True, unique=None, default=None)
def __init__(self, key='', val='', type='unicode'):
self.app_settings_name = key
self.app_settings_type = type
self.app_settings_value = val
@validates('_app_settings_value')
def validate_settings_value(self, key, val):
assert type(val) == unicode
return val
@hybrid_property
def app_settings_value(self):
v = self._app_settings_value
_type = self.app_settings_type
if _type:
_type = self.app_settings_type.split('.')[0]
# decode the encrypted value
if 'encrypted' in self.app_settings_type:
cipher = EncryptedTextValue()
v = safe_unicode(cipher.process_result_value(v, None))
converter = self.SETTINGS_TYPES.get(_type) or \
self.SETTINGS_TYPES['unicode']
return converter(v)
@app_settings_value.setter
def app_settings_value(self, val):
"""
Setter that will always make sure we use unicode in app_settings_value
:param val:
"""
val = safe_unicode(val)
# encode the encrypted value
if 'encrypted' in self.app_settings_type:
cipher = EncryptedTextValue()
val = safe_unicode(cipher.process_bind_param(val, None))
self._app_settings_value = val
@hybrid_property
def app_settings_type(self):
return self._app_settings_type
@app_settings_type.setter
def app_settings_type(self, val):
if val.split('.')[0] not in self.SETTINGS_TYPES:
raise Exception('type must be one of %s got %s'
% (self.SETTINGS_TYPES.keys(), val))
self._app_settings_type = val
db-models: added some helpers for auth, and external identity code.
r3251 @classmethod
def get_by_prefix(cls, prefix):
return RhodeCodeSetting.query()\
.filter(RhodeCodeSetting.app_settings_name.startswith(prefix))\
.all()
project: added all source files and assets
r1 def __unicode__(self):
return u"<%s('%s:%s[%s]')>" % (
self.__class__.__name__,
self.app_settings_name, self.app_settings_value,
self.app_settings_type
)
class RhodeCodeUi(Base, BaseModel):
__tablename__ = 'rhodecode_ui'
__table_args__ = (
UniqueConstraint('ui_key'),
db: use base table args for all models defined.
r2830 base_table_args
project: added all source files and assets
r1 )
HOOK_REPO_SIZE = 'changegroup.repo_size'
# HG
HOOK_PRE_PULL = 'preoutgoing.pre_pull'
HOOK_PULL = 'outgoing.pull_logger'
HOOK_PRE_PUSH = 'prechangegroup.pre_push'
hooks: added new pretx hook to allow mercurial checks such as protected branches, or force push.
r1461 HOOK_PRETX_PUSH = 'pretxnchangegroup.pre_push'
project: added all source files and assets
r1 HOOK_PUSH = 'changegroup.push_logger'
hooks: added pushkey Mercurial hook....
r1753 HOOK_PUSH_KEY = 'pushkey.key_push'
project: added all source files and assets
r1
# TODO: johbo: Unify way how hooks are configured for git and hg,
# git part is currently hardcoded.
# SVN PATTERNS
SVN_BRANCH_ID = 'vcs_svn_branch'
SVN_TAG_ID = 'vcs_svn_tag'
ui_id = Column(
"ui_id", Integer(), nullable=False, unique=True, default=None,
primary_key=True)
ui_section = Column(
"ui_section", String(255), nullable=True, unique=None, default=None)
ui_key = Column(
"ui_key", String(255), nullable=True, unique=None, default=None)
ui_value = Column(
"ui_value", String(255), nullable=True, unique=None, default=None)
ui_active = Column(
"ui_active", Boolean(), nullable=True, unique=None, default=True)
def __repr__(self):
return '<%s[%s]%s=>%s]>' % (self.__class__.__name__, self.ui_section,
self.ui_key, self.ui_value)
class RepoRhodeCodeSetting(Base, BaseModel):
__tablename__ = 'repo_rhodecode_settings'
__table_args__ = (
UniqueConstraint(
'app_settings_name', 'repository_id',
name='uq_repo_rhodecode_setting_name_repo_id'),
db: use base table args for all models defined.
r2830 base_table_args
project: added all source files and assets
r1 )
repository_id = Column(
"repository_id", Integer(), ForeignKey('repositories.repo_id'),
nullable=False)
app_settings_id = Column(
"app_settings_id", Integer(), nullable=False, unique=True,
default=None, primary_key=True)
app_settings_name = Column(
"app_settings_name", String(255), nullable=True, unique=None,
default=None)
_app_settings_value = Column(
"app_settings_value", String(4096), nullable=True, unique=None,
default=None)
_app_settings_type = Column(
"app_settings_type", String(255), nullable=True, unique=None,
default=None)
repository = relationship('Repository')
def __init__(self, repository_id, key='', val='', type='unicode'):
self.repository_id = repository_id
self.app_settings_name = key
self.app_settings_type = type
self.app_settings_value = val
@validates('_app_settings_value')
def validate_settings_value(self, key, val):
assert type(val) == unicode
return val
@hybrid_property
def app_settings_value(self):
v = self._app_settings_value
type_ = self.app_settings_type
SETTINGS_TYPES = RhodeCodeSetting.SETTINGS_TYPES
converter = SETTINGS_TYPES.get(type_) or SETTINGS_TYPES['unicode']
return converter(v)
@app_settings_value.setter
def app_settings_value(self, val):
"""
Setter that will always make sure we use unicode in app_settings_value
:param val:
"""
self._app_settings_value = safe_unicode(val)
@hybrid_property
def app_settings_type(self):
return self._app_settings_type
@app_settings_type.setter
def app_settings_type(self, val):
SETTINGS_TYPES = RhodeCodeSetting.SETTINGS_TYPES
if val not in SETTINGS_TYPES:
raise Exception('type must be one of %s got %s'
% (SETTINGS_TYPES.keys(), val))
self._app_settings_type = val
def __unicode__(self):
return u"<%s('%s:%s:%s[%s]')>" % (
self.__class__.__name__, self.repository.repo_name,
self.app_settings_name, self.app_settings_value,
self.app_settings_type
)
class RepoRhodeCodeUi(Base, BaseModel):
__tablename__ = 'repo_rhodecode_ui'
__table_args__ = (
UniqueConstraint(
'repository_id', 'ui_section', 'ui_key',
name='uq_repo_rhodecode_ui_repository_id_section_key'),
db: use base table args for all models defined.
r2830 base_table_args
project: added all source files and assets
r1 )
repository_id = Column(
"repository_id", Integer(), ForeignKey('repositories.repo_id'),
nullable=False)
ui_id = Column(
"ui_id", Integer(), nullable=False, unique=True, default=None,
primary_key=True)
ui_section = Column(
"ui_section", String(255), nullable=True, unique=None, default=None)
ui_key = Column(
"ui_key", String(255), nullable=True, unique=None, default=None)
ui_value = Column(
"ui_value", String(255), nullable=True, unique=None, default=None)
ui_active = Column(
"ui_active", Boolean(), nullable=True, unique=None, default=True)
repository = relationship('Repository')
def __repr__(self):
return '<%s[%s:%s]%s=>%s]>' % (
self.__class__.__name__, self.repository.repo_name,
self.ui_section, self.ui_key, self.ui_value)
class User(Base, BaseModel):
__tablename__ = 'users'
__table_args__ = (
UniqueConstraint('username'), UniqueConstraint('email'),
Index('u_username_idx', 'username'),
Index('u_email_idx', 'email'),
db: use base table args for all models defined.
r2830 base_table_args
project: added all source files and assets
r1 )
db: use base table args for all models defined.
r2830
project: added all source files and assets
r1 DEFAULT_USER = 'default'
DEFAULT_USER_EMAIL = 'anonymous@rhodecode.org'
DEFAULT_GRAVATAR_URL = 'https://secure.gravatar.com/avatar/{md5email}?d=identicon&s={size}'
user_id = Column("user_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
username = Column("username", String(255), nullable=True, unique=None, default=None)
password = Column("password", String(255), nullable=True, unique=None, default=None)
active = Column("active", Boolean(), nullable=True, unique=None, default=True)
admin = Column("admin", Boolean(), nullable=True, unique=None, default=False)
name = Column("firstname", String(255), nullable=True, unique=None, default=None)
lastname = Column("lastname", String(255), nullable=True, unique=None, default=None)
_email = Column("email", String(255), nullable=True, unique=None, default=None)
last_login = Column("last_login", DateTime(timezone=False), nullable=True, unique=None, default=None)
users: last_activity should be null if user haven't performed any actions.
r1635 last_activity = Column('last_activity', DateTime(timezone=False), nullable=True, unique=None, default=None)
users: migrate last_activity column so it's part of user table....
r1545
project: added all source files and assets
r1 extern_type = Column("extern_type", String(255), nullable=True, unique=None, default=None)
extern_name = Column("extern_name", String(255), nullable=True, unique=None, default=None)
user: remove usage of api_key....
r1481 _api_key = Column("api_key", String(255), nullable=True, unique=None, default=None)
project: added all source files and assets
r1 inherit_default_permissions = Column("inherit_default_permissions", Boolean(), nullable=False, unique=None, default=True)
created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
_user_data = Column("user_data", LargeBinary(), nullable=True) # JSON data
user_log = relationship('UserLog')
user_perms = relationship('UserToPerm', primaryjoin="User.user_id==UserToPerm.user_id", cascade='all')
repositories = relationship('Repository')
repository_groups = relationship('RepoGroup')
user_groups = relationship('UserGroup')
user_followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_user_id==User.user_id', cascade='all')
followings = relationship('UserFollowing', primaryjoin='UserFollowing.user_id==User.user_id', cascade='all')
repo_to_perm = relationship('UserRepoToPerm', primaryjoin='UserRepoToPerm.user_id==User.user_id', cascade='all')
repo_group_to_perm = relationship('UserRepoGroupToPerm', primaryjoin='UserRepoGroupToPerm.user_id==User.user_id', cascade='all')
user_group_to_perm = relationship('UserUserGroupToPerm', primaryjoin='UserUserGroupToPerm.user_id==User.user_id', cascade='all')
group_member = relationship('UserGroupMember', cascade='all')
notifications = relationship('UserNotification', cascade='all')
# notifications assigned to this user
user_created_notifications = relationship('Notification', cascade='all')
# comments created by this user
user_comments = relationship('ChangesetComment', cascade='all')
# user profile extra info
user_emails = relationship('UserEmailMap', cascade='all')
user_ip_map = relationship('UserIpMap', cascade='all')
user_auth_tokens = relationship('UserApiKeys', cascade='all')
users: added SSH key management for user admin pages
r1993 user_ssh_keys = relationship('UserSshKeys', cascade='all')
project: added all source files and assets
r1 # gists
user_gists = relationship('Gist', cascade='all')
# user pull requests
user_pull_requests = relationship('PullRequest', cascade='all')
# external identities
extenal_identities = relationship(
'ExternalIdentity',
primaryjoin="User.user_id==ExternalIdentity.local_user_id",
cascade='all')
user/user-groups: show if users or user groups are a part of review rules....
r2054 # review rules
user_review_rules = relationship('RepoReviewRuleUser', cascade='all')
project: added all source files and assets
r1
def __unicode__(self):
return u"<%s('id:%s:%s')>" % (self.__class__.__name__,
self.user_id, self.username)
@hybrid_property
def email(self):
return self._email
@email.setter
def email(self, val):
self._email = val.lower() if val else None
user: remove usage of api_key....
r1481 @hybrid_property
User: use new escaped hybrid properties for usage in code....
r1814 def first_name(self):
from rhodecode.lib import helpers as h
security: use new safe escaped user attributes across the application....
r1815 if self.name:
return h.escape(self.name)
return self.name
User: use new escaped hybrid properties for usage in code....
r1814
@hybrid_property
def last_name(self):
from rhodecode.lib import helpers as h
security: use new safe escaped user attributes across the application....
r1815 if self.lastname:
return h.escape(self.lastname)
return self.lastname
User: use new escaped hybrid properties for usage in code....
r1814
@hybrid_property
user: remove usage of api_key....
r1481 def api_key(self):
"""
Fetch if exist an auth-token with role ALL connected to this user
"""
user_auth_token = UserApiKeys.query()\
.filter(UserApiKeys.user_id == self.user_id)\
.filter(or_(UserApiKeys.expires == -1,
UserApiKeys.expires >= time.time()))\
.filter(UserApiKeys.role == UserApiKeys.ROLE_ALL).first()
auth-tokens: fixed tests
r1482 if user_auth_token:
user_auth_token = user_auth_token.api_key
user: remove usage of api_key....
r1481 return user_auth_token
@api_key.setter
def api_key(self, val):
# don't allow to set API key this is deprecated for now
self._api_key = None
project: added all source files and assets
r1 @property
dan
users: add additional information why user with pending reviews shouldn't be deleted.
r1923 def reviewer_pull_requests(self):
return PullRequestReviewers.query() \
.options(joinedload(PullRequestReviewers.pull_request)) \
.filter(PullRequestReviewers.user_id == self.user_id) \
.all()
@property
project: added all source files and assets
r1 def firstname(self):
# alias for future
return self.name
@property
def emails(self):
db: use consistent order of auth-tokens and emails when fetching those from user.
r1981 other = UserEmailMap.query()\
.filter(UserEmailMap.user == self) \
.order_by(UserEmailMap.email_id.asc()) \
.all()
project: added all source files and assets
r1 return [self.email] + [x.email for x in other]
@property
def auth_tokens(self):
user: deprecated usage of api_keys....
r1953 auth_tokens = self.get_auth_tokens()
return [x.api_key for x in auth_tokens]
def get_auth_tokens(self):
db: use consistent order of auth-tokens and emails when fetching those from user.
r1981 return UserApiKeys.query()\
.filter(UserApiKeys.user == self)\
.order_by(UserApiKeys.user_api_key_id.asc())\
.all()
project: added all source files and assets
r1
feed-token, user, performance: lazy load the feed_token. We only need it for...
r2424 @LazyProperty
project: added all source files and assets
r1 def feed_token(self):
auth-tokens: updated logic of authentication to a common shared user method.
r1421 return self.get_feed_token()
feed-token, user, performance: lazy load the feed_token. We only need it for...
r2424 def get_feed_token(self, cache=True):
project: added all source files and assets
r1 feed_tokens = UserApiKeys.query()\
.filter(UserApiKeys.user == self)\
feed-token, user, performance: lazy load the feed_token. We only need it for...
r2424 .filter(UserApiKeys.role == UserApiKeys.ROLE_FEED)
if cache:
feed_tokens = feed_tokens.options(
caches: use dogpile for sql_cache_short region.
r2883 FromCache("sql_cache_short", "get_user_feed_token_%s" % self.user_id))
feed-token, user, performance: lazy load the feed_token. We only need it for...
r2424
feed_tokens = feed_tokens.all()
project: added all source files and assets
r1 if feed_tokens:
return feed_tokens[0].api_key
auth-tokens: updated logic of authentication to a common shared user method.
r1421 return 'NO_FEED_TOKEN_AVAILABLE'
project: added all source files and assets
r1
@classmethod
users: ported controllers from pylons into pyramid views.
r2114 def get(cls, user_id, cache=False):
if not user_id:
return
user = cls.query()
if cache:
user = user.options(
FromCache("sql_cache_short", "get_users_%s" % user_id))
return user.get(user_id)
@classmethod
project: added all source files and assets
r1 def extra_valid_auth_tokens(cls, user, role=None):
tokens = UserApiKeys.query().filter(UserApiKeys.user == user)\
.filter(or_(UserApiKeys.expires == -1,
UserApiKeys.expires >= time.time()))
if role:
tokens = tokens.filter(or_(UserApiKeys.role == role,
UserApiKeys.role == UserApiKeys.ROLE_ALL))
return tokens.all()
authentication: enabled authentication with auth_token and repository scope....
r1510 def authenticate_by_token(self, auth_token, roles=None, scope_repo_id=None):
auth-tokens: updated logic of authentication to a common shared user method.
r1421 from rhodecode.lib import auth
log.debug('Trying to authenticate user: %s via auth-token, '
'and roles: %s', self, roles)
if not auth_token:
return False