Show More
The requested changes are too big and content was truncated. Show full diff
|
1 | NO CONTENT: new file 100644 | |
The requested commit or file is too big and content was truncated. Show full diff |
@@ -0,0 +1,32 b'' | |||
|
1 | # -*- coding: utf-8 -*- | |
|
2 | ||
|
3 | import logging | |
|
4 | ||
|
5 | from sqlalchemy import * | |
|
6 | ||
|
7 | from rhodecode.model import meta | |
|
8 | from rhodecode.lib.dbmigrate.versions import _reset_base, notify | |
|
9 | ||
|
10 | log = logging.getLogger(__name__) | |
|
11 | ||
|
12 | ||
|
13 | def upgrade(migrate_engine): | |
|
14 | """ | |
|
15 | Upgrade operations go here. | |
|
16 | Don't create your own engine; bind migrate_engine to your metadata | |
|
17 | """ | |
|
18 | _reset_base(migrate_engine) | |
|
19 | from rhodecode.lib.dbmigrate.schema import db_4_18_0_1 as db | |
|
20 | ||
|
21 | db.FileStoreMetadata.__table__.create() | |
|
22 | ||
|
23 | fixups(db, meta.Session) | |
|
24 | ||
|
25 | ||
|
26 | def downgrade(migrate_engine): | |
|
27 | meta = MetaData() | |
|
28 | meta.bind = migrate_engine | |
|
29 | ||
|
30 | ||
|
31 | def fixups(models, _SESSION): | |
|
32 | pass |
@@ -45,7 +45,7 b' PYRAMID_SETTINGS = {}' | |||
|
45 | 45 | EXTENSIONS = {} |
|
46 | 46 | |
|
47 | 47 | __version__ = ('.'.join((str(each) for each in VERSION[:3]))) |
|
48 |
__dbversion__ = 10 |
|
|
48 | __dbversion__ = 101 # defines current db version for migrations | |
|
49 | 49 | __platform__ = platform.system() |
|
50 | 50 | __license__ = 'AGPLv3, and Commercial License' |
|
51 | 51 | __author__ = 'RhodeCode GmbH' |
@@ -4996,8 +4996,7 b' class _BaseBranchPerms(BaseModel):' | |||
|
4996 | 4996 | class UserToRepoBranchPermission(Base, _BaseBranchPerms): |
|
4997 | 4997 | __tablename__ = 'user_to_repo_branch_permissions' |
|
4998 | 4998 | __table_args__ = ( |
|
4999 | {'extend_existing': True, 'mysql_engine': 'InnoDB', | |
|
5000 | 'mysql_charset': 'utf8', 'sqlite_autoincrement': True,} | |
|
4999 | base_table_args | |
|
5001 | 5000 | ) |
|
5002 | 5001 | |
|
5003 | 5002 | branch_rule_id = Column('branch_rule_id', Integer(), primary_key=True) |
@@ -5023,8 +5022,7 b' class UserToRepoBranchPermission(Base, _' | |||
|
5023 | 5022 | class UserGroupToRepoBranchPermission(Base, _BaseBranchPerms): |
|
5024 | 5023 | __tablename__ = 'user_group_to_repo_branch_permissions' |
|
5025 | 5024 | __table_args__ = ( |
|
5026 | {'extend_existing': True, 'mysql_engine': 'InnoDB', | |
|
5027 | 'mysql_charset': 'utf8', 'sqlite_autoincrement': True,} | |
|
5025 | base_table_args | |
|
5028 | 5026 | ) |
|
5029 | 5027 | |
|
5030 | 5028 | branch_rule_id = Column('branch_rule_id', Integer(), primary_key=True) |
@@ -5121,6 +5119,8 b' class FileStore(Base, BaseModel):' | |||
|
5121 | 5119 | user_id = Column('user_id', Integer(), ForeignKey('users.user_id'), nullable=False) |
|
5122 | 5120 | upload_user = relationship('User', lazy='joined', primaryjoin='User.user_id==FileStore.user_id') |
|
5123 | 5121 | |
|
5122 | file_metadata = relationship('FileStoreMetadata', lazy='joined') | |
|
5123 | ||
|
5124 | 5124 | # scope limited to user, which requester have access to |
|
5125 | 5125 | scope_user_id = Column( |
|
5126 | 5126 | 'scope_user_id', Integer(), ForeignKey('users.user_id'), |
@@ -5170,6 +5170,25 b' class FileStore(Base, BaseModel):' | |||
|
5170 | 5170 | return store_entry |
|
5171 | 5171 | |
|
5172 | 5172 | @classmethod |
|
5173 | def store_metadata(cls, file_store_id, args, commit=True): | |
|
5174 | file_store = FileStore.get(file_store_id) | |
|
5175 | if file_store is None: | |
|
5176 | return | |
|
5177 | ||
|
5178 | for section, key, value, value_type in args: | |
|
5179 | meta_entry = FileStoreMetadata() | |
|
5180 | meta_entry.file_store = file_store | |
|
5181 | meta_entry.file_store_meta_section = section | |
|
5182 | meta_entry.file_store_meta_key = key | |
|
5183 | meta_entry.file_store_meta_value_type = value_type | |
|
5184 | meta_entry.file_store_meta_value = value | |
|
5185 | ||
|
5186 | Session().add(meta_entry) | |
|
5187 | ||
|
5188 | if commit: | |
|
5189 | Session().commit() | |
|
5190 | ||
|
5191 | @classmethod | |
|
5173 | 5192 | def bump_access_counter(cls, file_uid, commit=True): |
|
5174 | 5193 | FileStore().query()\ |
|
5175 | 5194 | .filter(FileStore.file_uid == file_uid)\ |
@@ -5182,6 +5201,85 b' class FileStore(Base, BaseModel):' | |||
|
5182 | 5201 | return '<FileStore({})>'.format(self.file_store_id) |
|
5183 | 5202 | |
|
5184 | 5203 | |
|
5204 | class FileStoreMetadata(Base, BaseModel): | |
|
5205 | __tablename__ = 'file_store_metadata' | |
|
5206 | __table_args__ = ( | |
|
5207 | UniqueConstraint('file_store_meta_section', 'file_store_meta_key'), | |
|
5208 | Index('file_store_meta_section_idx', 'file_store_meta_section'), | |
|
5209 | Index('file_store_meta_key_idx', 'file_store_meta_key'), | |
|
5210 | base_table_args | |
|
5211 | ) | |
|
5212 | SETTINGS_TYPES = { | |
|
5213 | 'str': safe_str, | |
|
5214 | 'int': safe_int, | |
|
5215 | 'unicode': safe_unicode, | |
|
5216 | 'bool': str2bool, | |
|
5217 | 'list': functools.partial(aslist, sep=',') | |
|
5218 | } | |
|
5219 | ||
|
5220 | file_store_meta_id = Column( | |
|
5221 | "file_store_meta_id", Integer(), nullable=False, unique=True, default=None, | |
|
5222 | primary_key=True) | |
|
5223 | file_store_meta_section = Column( | |
|
5224 | "file_store_meta_section", UnicodeText().with_variant(UnicodeText(1024), 'mysql'), | |
|
5225 | nullable=True, unique=None, default=None) | |
|
5226 | file_store_meta_key = Column( | |
|
5227 | "file_store_meta_key", UnicodeText().with_variant(UnicodeText(1024), 'mysql'), | |
|
5228 | nullable=True, unique=None, default=None) | |
|
5229 | _file_store_meta_value = Column( | |
|
5230 | "file_store_meta_value", UnicodeText().with_variant(UnicodeText(20480), 'mysql'), | |
|
5231 | nullable=True, unique=None, default=None) | |
|
5232 | _file_store_meta_value_type = Column( | |
|
5233 | "file_store_meta_value_type", String(255), nullable=True, unique=None, | |
|
5234 | default='unicode') | |
|
5235 | ||
|
5236 | file_store_id = Column( | |
|
5237 | 'file_store_id', Integer(), ForeignKey('file_store.file_store_id'), | |
|
5238 | nullable=True, unique=None, default=None) | |
|
5239 | ||
|
5240 | file_store = relationship('FileStore', lazy='joined') | |
|
5241 | ||
|
5242 | @hybrid_property | |
|
5243 | def file_store_meta_value(self): | |
|
5244 | v = self._file_store_meta_value | |
|
5245 | _type = self._file_store_meta_value | |
|
5246 | if _type: | |
|
5247 | # e.g unicode.encrypted == unicode | |
|
5248 | _type = self._file_store_meta_value.split('.')[0] | |
|
5249 | # decode the encrypted value | |
|
5250 | if '.encrypted' in self._file_store_meta_value_type: | |
|
5251 | cipher = EncryptedTextValue() | |
|
5252 | v = safe_unicode(cipher.process_result_value(v, None)) | |
|
5253 | ||
|
5254 | converter = self.SETTINGS_TYPES.get(_type) or self.SETTINGS_TYPES['unicode'] | |
|
5255 | return converter(v) | |
|
5256 | ||
|
5257 | @file_store_meta_value.setter | |
|
5258 | def file_store_meta_value(self, val): | |
|
5259 | val = safe_unicode(val) | |
|
5260 | # encode the encrypted value | |
|
5261 | if '.encrypted' in self.file_store_meta_value_type: | |
|
5262 | cipher = EncryptedTextValue() | |
|
5263 | val = safe_unicode(cipher.process_bind_param(val, None)) | |
|
5264 | self._file_store_meta_value = val | |
|
5265 | ||
|
5266 | @hybrid_property | |
|
5267 | def file_store_meta_value_type(self): | |
|
5268 | return self._file_store_meta_value_type | |
|
5269 | ||
|
5270 | @file_store_meta_value_type.setter | |
|
5271 | def file_store_meta_value_type(self, val): | |
|
5272 | # e.g unicode.encrypted | |
|
5273 | if val.split('.')[0] not in self.SETTINGS_TYPES: | |
|
5274 | raise Exception('type must be one of %s got %s' | |
|
5275 | % (self.SETTINGS_TYPES.keys(), val)) | |
|
5276 | self._file_store_meta_value_type = val | |
|
5277 | ||
|
5278 | def __repr__(self): | |
|
5279 | return '<%s[%s]%s=>%s]>' % (self.__class__.__name__, self.file_store_meta_section, | |
|
5280 | self.file_store_meta_key, self.file_store_meta_value) | |
|
5281 | ||
|
5282 | ||
|
5185 | 5283 | class DbMigrateVersion(Base, BaseModel): |
|
5186 | 5284 | __tablename__ = 'db_migrate_version' |
|
5187 | 5285 | __table_args__ = ( |
@@ -383,15 +383,12 b'' | |||
|
383 | 383 | ## ARTIFACT RENDERERS |
|
384 | 384 | <%def name="repo_artifact_name(repo_name, file_uid, artifact_display_name)"> |
|
385 | 385 | <a href="${h.route_path('repo_artifacts_get', repo_name=repo_name, uid=file_uid)}"> |
|
386 |
${artifact_display_name or ' |
|
|
386 | ${artifact_display_name or '_EMPTY_NAME_'} | |
|
387 | 387 | </a> |
|
388 | 388 | </%def> |
|
389 | 389 | |
|
390 | 390 | <%def name="repo_artifact_uid(repo_name, file_uid)"> |
|
391 |
<code>${h.shorter(file_uid, size= |
|
|
392 | </%def> | |
|
393 | ||
|
394 | <%def name="repo_artifact_uid_action(repo_name, file_uid)"> | |
|
391 | <code>${h.shorter(file_uid, size=24, prefix=True)}</code> | |
|
395 | 392 | <i class="tooltip icon-clipboard clipboard-action" data-clipboard-text="${h.route_url('repo_artifacts_get', repo_name=repo_name, uid=file_uid)}" title="${_('Copy the full url')}"></i> |
|
396 | 393 | </%def> |
|
397 | 394 |
General Comments 0
You need to be logged in to leave comments.
Login now