##// END OF EJS Templates
artifacts: added DB store models.
marcink -
r3456:a0562f8e default
parent child Browse files
Show More

The requested changes are too big and content was truncated. Show full diff

1 NO CONTENT: new file 100644
NO CONTENT: new file 100644
The requested commit or file is too big and content was truncated. Show full diff
@@ -0,0 +1,30 b''
1 import logging
2
3 from sqlalchemy import *
4
5 from rhodecode.model import meta
6 from rhodecode.lib.dbmigrate.versions import _reset_base, notify
7
8 log = logging.getLogger(__name__)
9
10
11 def upgrade(migrate_engine):
12 """
13 Upgrade operations go here.
14 Don't create your own engine; bind migrate_engine to your metadata
15 """
16 _reset_base(migrate_engine)
17 from rhodecode.lib.dbmigrate.schema import db_4_16_0_2 as db
18
19 db.FileStore.__table__.create()
20
21 fixups(db, meta.Session)
22
23
24 def downgrade(migrate_engine):
25 meta = MetaData()
26 meta.bind = migrate_engine
27
28
29 def fixups(models, _SESSION):
30 pass
@@ -45,7 +45,7 b' PYRAMID_SETTINGS = {}'
45 EXTENSIONS = {}
45 EXTENSIONS = {}
46
46
47 __version__ = ('.'.join((str(each) for each in VERSION[:3])))
47 __version__ = ('.'.join((str(each) for each in VERSION[:3])))
48 __dbversion__ = 94 # defines current db version for migrations
48 __dbversion__ = 95 # defines current db version for migrations
49 __platform__ = platform.system()
49 __platform__ = platform.system()
50 __license__ = 'AGPLv3, and Commercial License'
50 __license__ = 'AGPLv3, and Commercial License'
51 __author__ = 'RhodeCode GmbH'
51 __author__ = 'RhodeCode GmbH'
@@ -417,65 +417,3 b' def store_exception(request, apiuser, ex'
417 exc_url = request.route_url(
417 exc_url = request.route_url(
418 'admin_settings_exception_tracker_show', exception_id=exc_id)
418 'admin_settings_exception_tracker_show', exception_id=exc_id)
419 return {'exc_id': exc_id, 'exc_url': exc_url}
419 return {'exc_id': exc_id, 'exc_url': exc_url}
420
421
422 @jsonrpc_method()
423 def upload_file(request, apiuser, filename, content):
424 """
425 Upload API for the file_store
426
427 Example usage from CLI::
428 rhodecode-api --instance-name=enterprise-1 upload_file "{\"content\": \"$(cat image.jpg | base64)\", \"filename\":\"image.jpg\"}"
429
430
431 This command can only be run using an |authtoken| with admin rights to
432 the specified repository.
433
434 This command takes the following options:
435
436 :param apiuser: This is filled automatically from the |authtoken|.
437 :type apiuser: AuthUser
438 :param filename: name of the file uploaded
439 :type filename: str
440 :param content: base64 encoded content of the uploaded file
441 :type prefix: str
442
443 Example output:
444
445 .. code-block:: bash
446
447 id : <id_given_in_input>
448 result: {
449 "access_path": "/_file_store/download/84d156f7-8323-4ad3-9fce-4a8e88e1deaf-0.jpg",
450 "access_path_fqn": "http://server.domain.com/_file_store/download/84d156f7-8323-4ad3-9fce-4a8e88e1deaf-0.jpg",
451 "store_fid": "84d156f7-8323-4ad3-9fce-4a8e88e1deaf-0.jpg"
452 }
453 error : null
454 """
455 if not has_superadmin_permission(apiuser):
456 raise JSONRPCForbidden()
457
458 storage = utils.get_file_storage(request.registry.settings)
459
460 try:
461 file_obj = compat.NativeIO(base64.decodestring(content))
462 except Exception as exc:
463 raise JSONRPCError('File `{}` content decoding error: {}.'.format(filename, exc))
464
465 metadata = {
466 'filename': filename,
467 'size': '', # filled by save_file
468 'user_uploaded': {'username': apiuser.username,
469 'user_id': apiuser.user_id,
470 'ip': apiuser.ip_addr}}
471 try:
472 store_fid, metadata = storage.save_file(file_obj, filename, metadata=metadata)
473 except FileNotAllowedException:
474 raise JSONRPCError('File `{}` is not allowed.'.format(filename))
475
476 except FileOverSizeException:
477 raise JSONRPCError('File `{}` is exceeding allowed limit.'.format(filename))
478
479 return {'store_fid': store_fid,
480 'access_path_fqn': request.route_url('download_file', fid=store_fid),
481 'access_path': request.route_path('download_file', fid=store_fid)}
@@ -4841,6 +4841,62 b' class UserBookmark(Base, BaseModel):'
4841 return u'<UserBookmark(%d @ %r)>' % (self.position, self.redirect_url)
4841 return u'<UserBookmark(%d @ %r)>' % (self.position, self.redirect_url)
4842
4842
4843
4843
4844 class FileStore(Base, BaseModel):
4845 __tablename__ = 'file_store'
4846 __table_args__ = (
4847 base_table_args
4848 )
4849
4850 file_store_id = Column('file_store_id', Integer(), primary_key=True)
4851 file_uid = Column('file_uid', String(1024), nullable=False)
4852 file_display_name = Column('file_display_name', UnicodeText().with_variant(UnicodeText(2048), 'mysql'), nullable=True)
4853 file_description = Column('file_description', UnicodeText().with_variant(UnicodeText(10240), 'mysql'), nullable=True)
4854 file_org_name = Column('file_org_name', UnicodeText().with_variant(UnicodeText(10240), 'mysql'), nullable=False)
4855
4856 # sha256 hash
4857 file_hash = Column('file_hash', String(512), nullable=False)
4858 file_size = Column('file_size', Integer(), nullable=False)
4859
4860 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
4861 accessed_on = Column('accessed_on', DateTime(timezone=False), nullable=True)
4862 accessed_count = Column('accessed_count', Integer(), default=0)
4863
4864 enabled = Column('enabled', Boolean(), nullable=False, default=True)
4865
4866 # if repo/repo_group reference is set, check for permissions
4867 check_acl = Column('check_acl', Boolean(), nullable=False, default=True)
4868
4869 user_id = Column('user_id', Integer(), ForeignKey('users.user_id'), nullable=False)
4870 upload_user = relationship('User', lazy='joined', primaryjoin='User.user_id==FileStore.user_id')
4871
4872 # scope limited to user, which requester have access to
4873 scope_user_id = Column(
4874 'scope_user_id', Integer(), ForeignKey('users.user_id'),
4875 nullable=True, unique=None, default=None)
4876 user = relationship('User', lazy='joined', primaryjoin='User.user_id==FileStore.scope_user_id')
4877
4878 # scope limited to user group, which requester have access to
4879 scope_user_group_id = Column(
4880 'scope_user_group_id', Integer(), ForeignKey('users_groups.users_group_id'),
4881 nullable=True, unique=None, default=None)
4882 user_group = relationship('UserGroup', lazy='joined')
4883
4884 # scope limited to repo, which requester have access to
4885 scope_repo_id = Column(
4886 'scope_repo_id', Integer(), ForeignKey('repositories.repo_id'),
4887 nullable=True, unique=None, default=None)
4888 repo = relationship('Repository', lazy='joined')
4889
4890 # scope limited to repo group, which requester have access to
4891 scope_repo_group_id = Column(
4892 'scope_repo_group_id', Integer(), ForeignKey('groups.group_id'),
4893 nullable=True, unique=None, default=None)
4894 repo_group = relationship('RepoGroup', lazy='joined')
4895
4896 def __repr__(self):
4897 return '<FileStore({})>'.format(self.file_store_id)
4898
4899
4844 class DbMigrateVersion(Base, BaseModel):
4900 class DbMigrateVersion(Base, BaseModel):
4845 __tablename__ = 'db_migrate_version'
4901 __tablename__ = 'db_migrate_version'
4846 __table_args__ = (
4902 __table_args__ = (
General Comments 0
You need to be logged in to leave comments. Login now